History

Mostly revert "tccpp.c: minor fix I'd accidentally not committed"

This reverts commit 27ec4f67a33a354c8f377dd4a5b42491c2b43beb. Sorry about that, I included changes which are still being tested, by accident.

Philip committed 11 years ago

Commit 929d1711 parent 27ec4f61 file · +17 −40Browse files

Unified · Split

tccpp.c+17−40
@@ -2996,30 +2996,8 @@ static int macro_subst_tok(TokenString *tok_str, · 2995 unmodified lines
29962996 else
29972997 break;
29982998 }
2999− /*
3000− * #define f(a) f(a)
3001− * #define h f(r
3002− * h 5)
3003− */
3004− if (tok != ',') {
3005− /* Argh! Not a macro invocation after all, at this
3006− * point, so put everything back onto mstr that's
3007− * been skipped since we saw the '(' )*/
3008− tok_str_new(&str);
3009− tok_str_add(&str, mtok);
3010− tok_str_add(&str, '(');
3011− for (sa = s->next; sa; sa = sa->next) {
3012− int *p = sa->d;
3013− while (p && *p) {
3014− tok_str_add(&str, *p);
3015− p++;
3016− }
3017− mstr = str.str;
3018− /* leak memory */;
3019− mstr_allocated = 0;
3020− goto free_memory;
3021− }
3022− }
2999+ if (tok != ',')
3000+ expect(",");
30233001 next_nomacro();
30243002 }
30253003 if (sa) {
@@ -3029,7 +3007,6 @@ static int macro_subst_tok(TokenString *tok_str, · 3 unmodified lines
30293007
30303008 /* now subst each arg */
30313009 mstr = macro_arg_subst(nested_list, mstr, args);
3032− free_memory:
30333010 /* free memory */
30343011 sa = args;
30353012 while (sa) {
@@ -3081,6 +3058,8 @@ static inline int *macro_twosharps(const int *macro_str) · 45 unmodified lines
30813058 TOK_GET(&tok, &ptr, &tokc);
30823059 if (tok == 0)
30833060 break;
3061+ if (tok == TOK_TWOSHARPS)
3062+ continue;
30843063 if (tok == TOK_NOSUBST && start_of_nosubsts < 0)
30853064 start_of_nosubsts = macro_str1.len;
30863065 while (*ptr == TOK_TWOSHARPS) {
@@ -3100,15 +3079,13 @@ static inline int *macro_twosharps(const int *macro_str) · 13 unmodified lines
31003079 if (tok != TOK_PLCHLDR)
31013080 cstr_cat(&cstr, get_tok_str(tok, &tokc));
31023081 n = cstr.size;
3103− if (t != TOK_PLCHLDR)
3082+ if (t != TOK_PLCHLDR || tok == TOK_PLCHLDR)
31043083 cstr_cat(&cstr, get_tok_str(t, &cval));
31053084 cstr_ccat(&cstr, '\0');
31063085
31073086 tcc_open_bf(tcc_state, ":paste:", cstr.size);
31083087 memcpy(file->buffer, cstr.data, cstr.size);
31093088 for (;;) {
3110− if (0 == *file->buf_ptr)
3111− break;
31123089 next_nomacro1();
31133090 if (0 == *file->buf_ptr)
31143091 break;
@@ -3119,22 +3096,13 @@ static inline int *macro_twosharps(const int *macro_str) · 4 unmodified lines
31193096 tcc_close();
31203097 cstr_free(&cstr);
31213098 }
3122− if (tok == TOK_TWOSHARPS) {
3123− /* two sharps twosharped together tokenize to two
3124− * sharp tokens, not a twosharp token. */
3125− /* That's fun to say, but is it actually true? GCC
3126− * stringifies #define a # ## # ## # to "## #" (and a
3127− * warning), while we produce "###" (no warning) */
3128− tok_str_add(&macro_str1, '#');
3129− tok = '#';
3130− }
31313099 }
31323100 if (tok != TOK_NOSUBST) {
31333101 tok_str_add2(&macro_str1, tok, &tokc);
31343102 tok = ' ';
31353103 start_of_nosubsts = -1;
3136− } else
3137− tok_str_add2(&macro_str1, tok, &tokc);
3104+ }
3105+ tok_str_add2(&macro_str1, tok, &tokc);
31383106 }
31393107 tok_str_add(&macro_str1, 0);
31403108 return macro_str1.str;
@@ -3153,6 +3121,7 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 12 unmodified lines
31533121 int t, spc;
31543122 CValue cval;
31553123 struct macro_level ml;
3124+ int force_blank;
31563125 int gnucomma_index = -1;
31573126
31583127 /* first scan for '##' operator handling */
@@ -3162,6 +3131,7 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 3 unmodified lines
31623131 if (macro_str1)
31633132 ptr = macro_str1;
31643133 spc = 0;
3134+ force_blank = 0;
31653135
31663136 while (1) {
31673137 /* NOTE: ptr == NULL can only happen if tokens are read from
@@ -3207,11 +3177,18 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 39 unmodified lines
32073177 macro_ptr = ml.p;
32083178 if (can_read_stream && *can_read_stream == &ml)
32093179 *can_read_stream = ml.prev;
3180+ if (parse_flags & PARSE_FLAG_SPACES)
3181+ force_blank = 1;
32103182 if (old_len == tok_str->len)
32113183 tok_str_add(tok_str, TOK_PLCHLDR);
32123184 } else {
32133185 no_subst:
3214− if (!check_space(t, &spc))
3186+ if (force_blank) {
3187+ tok_str_add(tok_str, ' ');
3188+ spc = 1;
3189+ force_blank = 0;
3190+ }
3191+ if (!check_space(t, &spc))
32153192 tok_str_add2(tok_str, t, &cval);
32163193 }
32173194 if (gnucomma_index != -1) {

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