/* test case */ #define t(x,y,z) x ## y ## z int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), t(10,,), t(,11,), t(,,12), t(,,) }; tcc -E: xpected result: int j[] = { 123, 45, 67, 89, 10, 11, 12, };
Unified · Split
| @@ -4429,45 +4429,38 @@ static int macro_subst_tok(TokenString *tok_str, · 4428 unmodified lines | ||
| 4429 | 4429 | static inline int *macro_twosharps(const int *macro_str) |
| 4430 | 4430 | { |
| 4431 | 4431 | TokenSym *ts; |
| 4432 | − const int *macro_ptr1, *start_macro_ptr, *ptr, *saved_macro_ptr; | |
| 4432 | + const int *ptr, *saved_macro_ptr; | |
| 4433 | 4433 | int t; |
| 4434 | 4434 | const char *p1, *p2; |
| 4435 | 4435 | CValue cval; |
| 4436 | 4436 | TokenString macro_str1; |
| 4437 | 4437 | CString cstr; |
| 4438 | 4438 | |
| 4439 | − start_macro_ptr = macro_str; | |
| 4440 | 4439 | /* we search the first '##' */ |
| 4441 | − for(;;) { | |
| 4442 | − macro_ptr1 = macro_str; | |
| 4443 | − TOK_GET(t, macro_str, cval); | |
| 4440 | + for(ptr = macro_str;;) { | |
| 4441 | + TOK_GET(t, ptr, cval); | |
| 4442 | + if (t == TOK_TWOSHARPS) | |
| 4443 | + break; | |
| 4444 | 4444 | /* nothing more to do if end of string */ |
| 4445 | 4445 | if (t == 0) |
| 4446 | 4446 | return NULL; |
| 4447 | − if (*macro_str == TOK_TWOSHARPS) | |
| 4448 | − break; | |
| 4449 | 4447 | } |
| 4450 | 4448 | |
| 4451 | 4449 | /* we saw '##', so we need more processing to handle it */ |
| 4452 | 4450 | cstr_new(&cstr); |
| 4453 | 4451 | tok_str_new(¯o_str1); |
| 4454 | − tok = t; | |
| 4455 | − tokc = cval; | |
| 4456 | − | |
| 4457 | − /* add all tokens seen so far */ | |
| 4458 | − for(ptr = start_macro_ptr; ptr < macro_ptr1;) { | |
| 4459 | − TOK_GET(t, ptr, cval); | |
| 4460 | − tok_str_add2(¯o_str1, t, &cval); | |
| 4461 | − } | |
| 4462 | 4452 | saved_macro_ptr = macro_ptr; |
| 4463 | 4453 | /* XXX: get rid of the use of macro_ptr here */ |
| 4464 | 4454 | macro_ptr = (int *)macro_str; |
| 4465 | 4455 | for(;;) { |
| 4456 | + next_nomacro_spc(); | |
| 4457 | + if (tok == 0) | |
| 4458 | + break; | |
| 4459 | + if (tok == TOK_TWOSHARPS) | |
| 4460 | + continue; | |
| 4466 | 4461 | while (*macro_ptr == TOK_TWOSHARPS) { |
| 4467 | − macro_ptr++; | |
| 4468 | − macro_ptr1 = macro_ptr; | |
| 4469 | − t = *macro_ptr; | |
| 4470 | − if (t) { | |
| 4462 | + t = *++macro_ptr; | |
| 4463 | + if (t && t != TOK_TWOSHARPS) { | |
| 4471 | 4464 | TOK_GET(t, macro_ptr, cval); |
| 4472 | 4465 | /* We concatenate the two tokens if we have an |
| 4473 | 4466 | identifier or a preprocessing number */ |
| @@ -4477,7 +4470,7 @@ static inline int *macro_twosharps(const int *macro_str) · 3 unmodified lines | ||
| 4477 | 4470 | p2 = get_tok_str(t, &cval); |
| 4478 | 4471 | cstr_cat(&cstr, p2); |
| 4479 | 4472 | cstr_ccat(&cstr, '\0'); |
| 4480 | − | |
| 4473 | + | |
| 4481 | 4474 | if ((tok >= TOK_IDENT || tok == TOK_PPNUM) && |
| 4482 | 4475 | (t >= TOK_IDENT || t == TOK_PPNUM)) { |
| 4483 | 4476 | if (tok == TOK_PPNUM) { |
| @@ -4549,9 +4542,6 @@ static inline int *macro_twosharps(const int *macro_str) · 65 unmodified lines | ||
| 4549 | 4542 | } |
| 4550 | 4543 | } |
| 4551 | 4544 | tok_str_add2(¯o_str1, tok, &tokc); |
| 4552 | − next_nomacro(); | |
| 4553 | − if (tok == 0) | |
| 4554 | − break; | |
| 4555 | 4545 | } |
| 4556 | 4546 | macro_ptr = (int *)saved_macro_ptr; |
| 4557 | 4547 | cstr_free(&cstr); |