This reverts commit 27ec4f67a33a354c8f377dd4a5b42491c2b43beb. Sorry about that, I included changes which are still being tested, by accident.
Unified · Split
| @@ -2996,30 +2996,8 @@ static int macro_subst_tok(TokenString *tok_str, · 2995 unmodified lines | |||
| 2996 | else | 2996 | else |
| 2997 | break; | 2997 | break; |
| 2998 | } | 2998 | } |
| 2999 | /* | 2999 | if (tok != ',') |
| 3000 | * #define f(a) f(a) | 3000 | expect(","); |
| 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 | } | ||
| 3023 | next_nomacro(); | 3001 | next_nomacro(); |
| 3024 | } | 3002 | } |
| 3025 | if (sa) { | 3003 | if (sa) { |
| @@ -3029,7 +3007,6 @@ static int macro_subst_tok(TokenString *tok_str, · 3 unmodified lines | |||
| 3029 | 3007 | ||
| 3030 | /* now subst each arg */ | 3008 | /* now subst each arg */ |
| 3031 | mstr = macro_arg_subst(nested_list, mstr, args); | 3009 | mstr = macro_arg_subst(nested_list, mstr, args); |
| 3032 | free_memory: | ||
| 3033 | /* free memory */ | 3010 | /* free memory */ |
| 3034 | sa = args; | 3011 | sa = args; |
| 3035 | while (sa) { | 3012 | while (sa) { |
| @@ -3081,6 +3058,8 @@ static inline int *macro_twosharps(const int *macro_str) · 45 unmodified lines | |||
| 3081 | TOK_GET(&tok, &ptr, &tokc); | 3058 | TOK_GET(&tok, &ptr, &tokc); |
| 3082 | if (tok == 0) | 3059 | if (tok == 0) |
| 3083 | break; | 3060 | break; |
| 3061 | if (tok == TOK_TWOSHARPS) | ||
| 3062 | continue; | ||
| 3084 | if (tok == TOK_NOSUBST && start_of_nosubsts < 0) | 3063 | if (tok == TOK_NOSUBST && start_of_nosubsts < 0) |
| 3085 | start_of_nosubsts = macro_str1.len; | 3064 | start_of_nosubsts = macro_str1.len; |
| 3086 | while (*ptr == TOK_TWOSHARPS) { | 3065 | while (*ptr == TOK_TWOSHARPS) { |
| @@ -3100,15 +3079,13 @@ static inline int *macro_twosharps(const int *macro_str) · 13 unmodified lines | |||
| 3100 | if (tok != TOK_PLCHLDR) | 3079 | if (tok != TOK_PLCHLDR) |
| 3101 | cstr_cat(&cstr, get_tok_str(tok, &tokc)); | 3080 | cstr_cat(&cstr, get_tok_str(tok, &tokc)); |
| 3102 | n = cstr.size; | 3081 | n = cstr.size; |
| 3103 | if (t != TOK_PLCHLDR) | 3082 | if (t != TOK_PLCHLDR || tok == TOK_PLCHLDR) |
| 3104 | cstr_cat(&cstr, get_tok_str(t, &cval)); | 3083 | cstr_cat(&cstr, get_tok_str(t, &cval)); |
| 3105 | cstr_ccat(&cstr, '\0'); | 3084 | cstr_ccat(&cstr, '\0'); |
| 3106 | 3085 | ||
| 3107 | tcc_open_bf(tcc_state, ":paste:", cstr.size); | 3086 | tcc_open_bf(tcc_state, ":paste:", cstr.size); |
| 3108 | memcpy(file->buffer, cstr.data, cstr.size); | 3087 | memcpy(file->buffer, cstr.data, cstr.size); |
| 3109 | for (;;) { | 3088 | for (;;) { |
| 3110 | if (0 == *file->buf_ptr) | ||
| 3111 | break; | ||
| 3112 | next_nomacro1(); | 3089 | next_nomacro1(); |
| 3113 | if (0 == *file->buf_ptr) | 3090 | if (0 == *file->buf_ptr) |
| 3114 | break; | 3091 | break; |
| @@ -3119,22 +3096,13 @@ static inline int *macro_twosharps(const int *macro_str) · 4 unmodified lines | |||
| 3119 | tcc_close(); | 3096 | tcc_close(); |
| 3120 | cstr_free(&cstr); | 3097 | cstr_free(&cstr); |
| 3121 | } | 3098 | } |
| 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(¯o_str1, '#'); | ||
| 3129 | tok = '#'; | ||
| 3130 | } | ||
| 3131 | } | 3099 | } |
| 3132 | if (tok != TOK_NOSUBST) { | 3100 | if (tok != TOK_NOSUBST) { |
| 3133 | tok_str_add2(¯o_str1, tok, &tokc); | 3101 | tok_str_add2(¯o_str1, tok, &tokc); |
| 3134 | tok = ' '; | 3102 | tok = ' '; |
| 3135 | start_of_nosubsts = -1; | 3103 | start_of_nosubsts = -1; |
| 3136 | } else | 3104 | } |
| 3137 | tok_str_add2(¯o_str1, tok, &tokc); | 3105 | tok_str_add2(¯o_str1, tok, &tokc); |
| 3138 | } | 3106 | } |
| 3139 | tok_str_add(¯o_str1, 0); | 3107 | tok_str_add(¯o_str1, 0); |
| 3140 | return macro_str1.str; | 3108 | return macro_str1.str; |
| @@ -3153,6 +3121,7 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 12 unmodified lines | |||
| 3153 | int t, spc; | 3121 | int t, spc; |
| 3154 | CValue cval; | 3122 | CValue cval; |
| 3155 | struct macro_level ml; | 3123 | struct macro_level ml; |
| 3124 | int force_blank; | ||
| 3156 | int gnucomma_index = -1; | 3125 | int gnucomma_index = -1; |
| 3157 | 3126 | ||
| 3158 | /* first scan for '##' operator handling */ | 3127 | /* first scan for '##' operator handling */ |
| @@ -3162,6 +3131,7 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list, · 3 unmodified lines | |||
| 3162 | if (macro_str1) | 3131 | if (macro_str1) |
| 3163 | ptr = macro_str1; | 3132 | ptr = macro_str1; |
| 3164 | spc = 0; | 3133 | spc = 0; |
| 3134 | force_blank = 0; | ||
| 3165 | 3135 | ||
| 3166 | while (1) { | 3136 | while (1) { |
| 3167 | /* NOTE: ptr == NULL can only happen if tokens are read from | 3137 | /* 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 | |||
| 3207 | macro_ptr = ml.p; | 3177 | macro_ptr = ml.p; |
| 3208 | if (can_read_stream && *can_read_stream == &ml) | 3178 | if (can_read_stream && *can_read_stream == &ml) |
| 3209 | *can_read_stream = ml.prev; | 3179 | *can_read_stream = ml.prev; |
| 3180 | if (parse_flags & PARSE_FLAG_SPACES) | ||
| 3181 | force_blank = 1; | ||
| 3210 | if (old_len == tok_str->len) | 3182 | if (old_len == tok_str->len) |
| 3211 | tok_str_add(tok_str, TOK_PLCHLDR); | 3183 | tok_str_add(tok_str, TOK_PLCHLDR); |
| 3212 | } else { | 3184 | } else { |
| 3213 | no_subst: | 3185 | 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)) | ||
| 3215 | tok_str_add2(tok_str, t, &cval); | 3192 | tok_str_add2(tok_str, t, &cval); |
| 3216 | } | 3193 | } |
| 3217 | if (gnucomma_index != -1) { | 3194 | if (gnucomma_index != -1) { |