/* 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 | static inline int *macro_twosharps(const int *macro_str) | 4429 | static inline int *macro_twosharps(const int *macro_str) |
| 4430 | { | 4430 | { |
| 4431 | TokenSym *ts; | 4431 | TokenSym *ts; |
| 4432 | const int *macro_ptr1, *start_macro_ptr, *ptr, *saved_macro_ptr; | 4432 | const int *ptr, *saved_macro_ptr; |
| 4433 | int t; | 4433 | int t; |
| 4434 | const char *p1, *p2; | 4434 | const char *p1, *p2; |
| 4435 | CValue cval; | 4435 | CValue cval; |
| 4436 | TokenString macro_str1; | 4436 | TokenString macro_str1; |
| 4437 | CString cstr; | 4437 | CString cstr; |
| 4438 | 4438 | ||
| 4439 | start_macro_ptr = macro_str; | ||
| 4440 | /* we search the first '##' */ | 4439 | /* we search the first '##' */ |
| 4441 | for(;;) { | 4440 | for(ptr = macro_str;;) { |
| 4442 | macro_ptr1 = macro_str; | 4441 | TOK_GET(t, ptr, cval); |
| 4443 | TOK_GET(t, macro_str, cval); | 4442 | if (t == TOK_TWOSHARPS) |
| 4443 | break; | ||
| 4444 | /* nothing more to do if end of string */ | 4444 | /* nothing more to do if end of string */ |
| 4445 | if (t == 0) | 4445 | if (t == 0) |
| 4446 | return NULL; | 4446 | return NULL; |
| 4447 | if (*macro_str == TOK_TWOSHARPS) | ||
| 4448 | break; | ||
| 4449 | } | 4447 | } |
| 4450 | 4448 | ||
| 4451 | /* we saw '##', so we need more processing to handle it */ | 4449 | /* we saw '##', so we need more processing to handle it */ |
| 4452 | cstr_new(&cstr); | 4450 | cstr_new(&cstr); |
| 4453 | tok_str_new(¯o_str1); | 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 | saved_macro_ptr = macro_ptr; | 4452 | saved_macro_ptr = macro_ptr; |
| 4463 | /* XXX: get rid of the use of macro_ptr here */ | 4453 | /* XXX: get rid of the use of macro_ptr here */ |
| 4464 | macro_ptr = (int *)macro_str; | 4454 | macro_ptr = (int *)macro_str; |
| 4465 | for(;;) { | 4455 | for(;;) { |
| 4456 | next_nomacro_spc(); | ||
| 4457 | if (tok == 0) | ||
| 4458 | break; | ||
| 4459 | if (tok == TOK_TWOSHARPS) | ||
| 4460 | continue; | ||
| 4466 | while (*macro_ptr == TOK_TWOSHARPS) { | 4461 | while (*macro_ptr == TOK_TWOSHARPS) { |
| 4467 | macro_ptr++; | 4462 | t = *++macro_ptr; |
| 4468 | macro_ptr1 = macro_ptr; | 4463 | if (t && t != TOK_TWOSHARPS) { |
| 4469 | t = *macro_ptr; | ||
| 4470 | if (t) { | ||
| 4471 | TOK_GET(t, macro_ptr, cval); | 4464 | TOK_GET(t, macro_ptr, cval); |
| 4472 | /* We concatenate the two tokens if we have an | 4465 | /* We concatenate the two tokens if we have an |
| 4473 | identifier or a preprocessing number */ | 4466 | identifier or a preprocessing number */ |
| @@ -4477,7 +4470,7 @@ static inline int *macro_twosharps(const int *macro_str) · 3 unmodified lines | |||
| 4477 | p2 = get_tok_str(t, &cval); | 4470 | p2 = get_tok_str(t, &cval); |
| 4478 | cstr_cat(&cstr, p2); | 4471 | cstr_cat(&cstr, p2); |
| 4479 | cstr_ccat(&cstr, '\0'); | 4472 | cstr_ccat(&cstr, '\0'); |
| 4480 | 4473 | ||
| 4481 | if ((tok >= TOK_IDENT || tok == TOK_PPNUM) && | 4474 | if ((tok >= TOK_IDENT || tok == TOK_PPNUM) && |
| 4482 | (t >= TOK_IDENT || t == TOK_PPNUM)) { | 4475 | (t >= TOK_IDENT || t == TOK_PPNUM)) { |
| 4483 | if (tok == TOK_PPNUM) { | 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 | tok_str_add2(¯o_str1, tok, &tokc); | 4544 | tok_str_add2(¯o_str1, tok, &tokc); |
| 4552 | next_nomacro(); | ||
| 4553 | if (tok == 0) | ||
| 4554 | break; | ||
| 4555 | } | 4545 | } |
| 4556 | macro_ptr = (int *)saved_macro_ptr; | 4546 | macro_ptr = (int *)saved_macro_ptr; |
| 4557 | cstr_free(&cstr); | 4547 | cstr_free(&cstr); |