History

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

Sorry about that. This should definitely fix Sergey's issue.

Philip committed 11 years ago

Commit 27ec4f61 parent 3b4c42c1 file · +43 −19Browse files

Unified · Split

tccpp.c+43−19
@@ -2890,7 +2890,7 @@ static int macro_subst_tok(TokenString *tok_str, · 2889 unmodified lines
28902890 p = macro_ptr;
28912891 while (is_space(t = *p) || TOK_LINEFEED == t) {
28922892 if (saved_parse_flags & PARSE_FLAG_SPACES)
2893− tok_str_add(&ws_str, t);
2893+ tok_str_add(&ws_str, t);
28942894 ++p;
28952895 }
28962896 if (t == 0 && can_read_stream) {
@@ -2927,7 +2927,8 @@ static int macro_subst_tok(TokenString *tok_str, · 30 unmodified lines
29272927 break;
29282928 ch = ' ';
29292929 }
2930− tok_str_add(&ws_str, ch);
2930+ if (saved_parse_flags & PARSE_FLAG_SPACES)
2931+ tok_str_add(&ws_str, ch);
29312932 cinp();
29322933 }
29332934 t = ch;
@@ -2995,8 +2996,30 @@ static int macro_subst_tok(TokenString *tok_str, · 61 unmodified lines
29952996 else
29962997 break;
29972998 }
2998− if (tok != ',')
2999− expect(",");
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+ }
30003023 next_nomacro();
30013024 }
30023025 if (sa) {
@@ -3006,6 +3029,7 @@ static int macro_subst_tok(TokenString *tok_str, · 3 unmodified lines
30063029
30073030 /* now subst each arg */
30083031 mstr = macro_arg_subst(nested_list, mstr, args);
3032+ free_memory:
30093033 /* free memory */
30103034 sa = args;
30113035 while (sa) {
@@ -3057,8 +3081,6 @@ static inline int *macro_twosharps(const int *macro_str) · 45 unmodified lines
30573081 TOK_GET(&tok, &ptr, &tokc);
30583082 if (tok == 0)
30593083 break;
3060− if (tok == TOK_TWOSHARPS)
3061− continue;
30623084 if (tok == TOK_NOSUBST && start_of_nosubsts < 0)
30633085 start_of_nosubsts = macro_str1.len;
30643086 while (*ptr == TOK_TWOSHARPS) {
@@ -3078,13 +3100,15 @@ static inline int *macro_twosharps(const int *macro_str) · 13 unmodified lines
30783100 if (tok != TOK_PLCHLDR)
30793101 cstr_cat(&cstr, get_tok_str(tok, &tokc));
30803102 n = cstr.size;
3081− if (t != TOK_PLCHLDR || tok == TOK_PLCHLDR)
3103+ if (t != TOK_PLCHLDR)
30823104 cstr_cat(&cstr, get_tok_str(t, &cval));
30833105 cstr_ccat(&cstr, '\0');
30843106
30853107 tcc_open_bf(tcc_state, ":paste:", cstr.size);
30863108 memcpy(file->buffer, cstr.data, cstr.size);
30873109 for (;;) {
3110+ if (0 == *file->buf_ptr)
3111+ break;
30883112 next_nomacro1();
30893113 if (0 == *file->buf_ptr)
30903114 break;
@@ -3095,13 +3119,22 @@ static inline int *macro_twosharps(const int *macro_str) · 4 unmodified lines
30953119 tcc_close();
30963120 cstr_free(&cstr);
30973121 }
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+ }
30983131 }
30993132 if (tok != TOK_NOSUBST) {
31003133 tok_str_add2(&macro_str1, tok, &tokc);
31013134 tok = ' ';
31023135 start_of_nosubsts = -1;
3103− }
3104− tok_str_add2(&macro_str1, tok, &tokc);
3136+ } else
3137+ tok_str_add2(&macro_str1, tok, &tokc);
31053138 }
31063139 tok_str_add(&macro_str1, 0);
31073140 return macro_str1.str;
@@ -3120,7 +3153,6 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 12 unmodified lines
31203153 int t, spc;
31213154 CValue cval;
31223155 struct macro_level ml;
3123− int force_blank;
31243156 int gnucomma_index = -1;
31253157
31263158 /* first scan for '##' operator handling */
@@ -3130,7 +3162,6 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 3 unmodified lines
31303162 if (macro_str1)
31313163 ptr = macro_str1;
31323164 spc = 0;
3133− force_blank = 0;
31343165
31353166 while (1) {
31363167 /* NOTE: ptr == NULL can only happen if tokens are read from
@@ -3176,18 +3207,11 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 39 unmodified lines
31763207 macro_ptr = ml.p;
31773208 if (can_read_stream && *can_read_stream == &ml)
31783209 *can_read_stream = ml.prev;
3179− if (parse_flags & PARSE_FLAG_SPACES)
3180− force_blank = 1;
31813210 if (old_len == tok_str->len)
31823211 tok_str_add(tok_str, TOK_PLCHLDR);
31833212 } else {
31843213 no_subst:
3185− if (force_blank) {
3186− tok_str_add(tok_str, ' ');
3187− spc = 1;
3188− force_blank = 0;
3189− }
3190− if (!check_space(t, &spc))
3214+ if (!check_space(t, &spc))
31913215 tok_str_add2(tok_str, t, &cval);
31923216 }
31933217 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