History

tcc -E: fix pasting empty tokens

/* 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, };

grischka committed 17 years ago

Commit dd5630f1 parent 0f0ed4a1 file · +13 −23Browse files

Unified · Split

tcc.c+13−23
@@ -4429,45 +4429,38 @@ static int macro_subst_tok(TokenString *tok_str, · 4428 unmodified lines
44294429 static inline int *macro_twosharps(const int *macro_str)
44304430 {
44314431 TokenSym *ts;
4432− const int *macro_ptr1, *start_macro_ptr, *ptr, *saved_macro_ptr;
4432+ const int *ptr, *saved_macro_ptr;
44334433 int t;
44344434 const char *p1, *p2;
44354435 CValue cval;
44364436 TokenString macro_str1;
44374437 CString cstr;
44384438
4439− start_macro_ptr = macro_str;
44404439 /* 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;
44444444 /* nothing more to do if end of string */
44454445 if (t == 0)
44464446 return NULL;
4447− if (*macro_str == TOK_TWOSHARPS)
4448− break;
44494447 }
44504448
44514449 /* we saw '##', so we need more processing to handle it */
44524450 cstr_new(&cstr);
44534451 tok_str_new(&macro_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(&macro_str1, t, &cval);
4461− }
44624452 saved_macro_ptr = macro_ptr;
44634453 /* XXX: get rid of the use of macro_ptr here */
44644454 macro_ptr = (int *)macro_str;
44654455 for(;;) {
4456+ next_nomacro_spc();
4457+ if (tok == 0)
4458+ break;
4459+ if (tok == TOK_TWOSHARPS)
4460+ continue;
44664461 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) {
44714464 TOK_GET(t, macro_ptr, cval);
44724465 /* We concatenate the two tokens if we have an
44734466 identifier or a preprocessing number */
@@ -4477,7 +4470,7 @@ static inline int *macro_twosharps(const int *macro_str) · 3 unmodified lines
44774470 p2 = get_tok_str(t, &cval);
44784471 cstr_cat(&cstr, p2);
44794472 cstr_ccat(&cstr, '\0');
4480−
4473+
44814474 if ((tok >= TOK_IDENT || tok == TOK_PPNUM) &&
44824475 (t >= TOK_IDENT || t == TOK_PPNUM)) {
44834476 if (tok == TOK_PPNUM) {
@@ -4549,9 +4542,6 @@ static inline int *macro_twosharps(const int *macro_str) · 65 unmodified lines
45494542 }
45504543 }
45514544 tok_str_add2(&macro_str1, tok, &tokc);
4552− next_nomacro();
4553− if (tok == 0)
4554− break;
45554545 }
45564546 macro_ptr = (int *)saved_macro_ptr;
45574547 cstr_free(&cstr);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t