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

This reverts commit 27ec4f67a3.

Sorry about that, I included changes which are still being tested, by
accident.
master
Philip 2015-05-02 20:30:07 +00:00
parent 27ec4f67a3
commit 929d171f47
1 changed files with 17 additions and 40 deletions

57
tccpp.c
View File

@ -2996,30 +2996,8 @@ static int macro_subst_tok(TokenString *tok_str,
else else
break; break;
} }
/* if (tok != ',')
* #define f(a) f(a) expect(",");
* #define h f(r
* h 5)
*/
if (tok != ',') {
/* Argh! Not a macro invocation after all, at this
* point, so put everything back onto mstr that's
* been skipped since we saw the '(' )*/
tok_str_new(&str);
tok_str_add(&str, mtok);
tok_str_add(&str, '(');
for (sa = s->next; sa; sa = sa->next) {
int *p = sa->d;
while (p && *p) {
tok_str_add(&str, *p);
p++;
}
mstr = str.str;
/* leak memory */;
mstr_allocated = 0;
goto free_memory;
}
}
next_nomacro(); next_nomacro();
} }
if (sa) { if (sa) {
@ -3029,7 +3007,6 @@ static int macro_subst_tok(TokenString *tok_str,
/* now subst each arg */ /* now subst each arg */
mstr = macro_arg_subst(nested_list, mstr, args); mstr = macro_arg_subst(nested_list, mstr, args);
free_memory:
/* free memory */ /* free memory */
sa = args; sa = args;
while (sa) { while (sa) {
@ -3081,6 +3058,8 @@ static inline int *macro_twosharps(const int *macro_str)
TOK_GET(&tok, &ptr, &tokc); TOK_GET(&tok, &ptr, &tokc);
if (tok == 0) if (tok == 0)
break; break;
if (tok == TOK_TWOSHARPS)
continue;
if (tok == TOK_NOSUBST && start_of_nosubsts < 0) if (tok == TOK_NOSUBST && start_of_nosubsts < 0)
start_of_nosubsts = macro_str1.len; start_of_nosubsts = macro_str1.len;
while (*ptr == TOK_TWOSHARPS) { while (*ptr == TOK_TWOSHARPS) {
@ -3100,15 +3079,13 @@ static inline int *macro_twosharps(const int *macro_str)
if (tok != TOK_PLCHLDR) if (tok != TOK_PLCHLDR)
cstr_cat(&cstr, get_tok_str(tok, &tokc)); cstr_cat(&cstr, get_tok_str(tok, &tokc));
n = cstr.size; n = cstr.size;
if (t != TOK_PLCHLDR) if (t != TOK_PLCHLDR || tok == TOK_PLCHLDR)
cstr_cat(&cstr, get_tok_str(t, &cval)); cstr_cat(&cstr, get_tok_str(t, &cval));
cstr_ccat(&cstr, '\0'); cstr_ccat(&cstr, '\0');
tcc_open_bf(tcc_state, ":paste:", cstr.size); tcc_open_bf(tcc_state, ":paste:", cstr.size);
memcpy(file->buffer, cstr.data, cstr.size); memcpy(file->buffer, cstr.data, cstr.size);
for (;;) { for (;;) {
if (0 == *file->buf_ptr)
break;
next_nomacro1(); next_nomacro1();
if (0 == *file->buf_ptr) if (0 == *file->buf_ptr)
break; break;
@ -3119,22 +3096,13 @@ static inline int *macro_twosharps(const int *macro_str)
tcc_close(); tcc_close();
cstr_free(&cstr); cstr_free(&cstr);
} }
if (tok == TOK_TWOSHARPS) {
/* two sharps twosharped together tokenize to two
* sharp tokens, not a twosharp token. */
/* That's fun to say, but is it actually true? GCC
* stringifies #define a # ## # ## # to "## #" (and a
* warning), while we produce "###" (no warning) */
tok_str_add(&macro_str1, '#');
tok = '#';
}
} }
if (tok != TOK_NOSUBST) { if (tok != TOK_NOSUBST) {
tok_str_add2(&macro_str1, tok, &tokc); tok_str_add2(&macro_str1, tok, &tokc);
tok = ' '; tok = ' ';
start_of_nosubsts = -1; start_of_nosubsts = -1;
} else }
tok_str_add2(&macro_str1, tok, &tokc); tok_str_add2(&macro_str1, tok, &tokc);
} }
tok_str_add(&macro_str1, 0); tok_str_add(&macro_str1, 0);
return macro_str1.str; return macro_str1.str;
@ -3153,6 +3121,7 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list,
int t, spc; int t, spc;
CValue cval; CValue cval;
struct macro_level ml; struct macro_level ml;
int force_blank;
int gnucomma_index = -1; int gnucomma_index = -1;
/* first scan for '##' operator handling */ /* first scan for '##' operator handling */
@ -3162,6 +3131,7 @@ static void macro_subst(TokenString *tok_str, Sym **nested_list,
if (macro_str1) if (macro_str1)
ptr = macro_str1; ptr = macro_str1;
spc = 0; spc = 0;
force_blank = 0;
while (1) { while (1) {
/* NOTE: ptr == NULL can only happen if tokens are read from /* 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,
macro_ptr = ml.p; macro_ptr = ml.p;
if (can_read_stream && *can_read_stream == &ml) if (can_read_stream && *can_read_stream == &ml)
*can_read_stream = ml.prev; *can_read_stream = ml.prev;
if (parse_flags & PARSE_FLAG_SPACES)
force_blank = 1;
if (old_len == tok_str->len) if (old_len == tok_str->len)
tok_str_add(tok_str, TOK_PLCHLDR); tok_str_add(tok_str, TOK_PLCHLDR);
} else { } else {
no_subst: no_subst:
if (!check_space(t, &spc)) if (force_blank) {
tok_str_add(tok_str, ' ');
spc = 1;
force_blank = 0;
}
if (!check_space(t, &spc))
tok_str_add2(tok_str, t, &cval); tok_str_add2(tok_str, t, &cval);
} }
if (gnucomma_index != -1) { if (gnucomma_index != -1) {