scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit ac1288f4d196d9eb41b35f4d38506e286e6a3212
parent d7dc1a4fbb9f1e8af0fade6cea54855d4f7549c9
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 28 May 2015 11:28:21 +0200

Disable expansion while parsing parameters of macros

Parameters of macros are not expanded, but we called to next(), which
search for macros to expand them.

Diffstat:
Mcc1/cc1.h | 2+-
Mcc1/cpp.c | 6+++++-
Mcc1/lex.c | 15++++++++-------
3 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -308,7 +308,7 @@ extern struct yystype yylval; extern char yytext[]; extern unsigned yytoken; extern unsigned short yylen; -extern int cppoff; +extern int cppoff, disexpand; extern unsigned cppctx; extern Type *voidtype, *pvoidtype, *booltype, diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -18,6 +18,7 @@ static unsigned char ifstatus[NR_COND]; static int paramerr; unsigned cppctx; +int disexpand; static Symbol * defmacro(char *s) @@ -171,8 +172,9 @@ parsepars(char *buffer, char **listp, int nargs) if (ahead() != '(') return 0; - next(); + disexpand = 1; + next(); paramerr = n = 0; argp = buffer; arglen = INPUTSIZ; @@ -182,6 +184,7 @@ parsepars(char *buffer, char **listp, int nargs) parameter(); } while (!paramerr && ++n < NR_MACROARG && yytoken == ','); } + disexpand = 0; if (paramerr) return -1; @@ -194,6 +197,7 @@ parsepars(char *buffer, char **listp, int nargs) macroname, n, nargs); return -1; } + return 1; } diff --git a/cc1/lex.c b/cc1/lex.c @@ -429,26 +429,27 @@ repeat: static unsigned iden(void) { + Symbol *sym; char *p, *t, c; for (p = input->p; isalnum(*p) || *p == '_'; ++p) /* nothing */; input->p = p; tok2str(); - yylval.sym = lookup(lex_ns); - if (yylval.sym->ns == NS_CPP) { - if (yylval.sym != input->macro && expand(yylval.sym)) + yylval.sym = sym = lookup(lex_ns); + if (sym->ns == NS_CPP) { + if (!disexpand && sym != input->macro && expand(sym)) return 0; /* * it is not a correct macro call, so try to find * another definition. This is going to be expensive * but I think it is not going to be a common case. */ - yylval.sym = nextsym(yylval.sym, lex_ns); + sym = nextsym(sym, lex_ns); } - if (yylval.sym->token != IDEN) - yylval.token = yylval.sym->u.token; - return yylval.sym->token; + if (sym->token != IDEN) + yylval.token = sym->u.token; + return sym->token; } static unsigned