scc

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

commit f6970279c96254b3407c1d0f2ade3342c26b87b6
parent 510b4fad0f6339b629f25bad6b02037ae4b7d8af
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  8 Sep 2015 18:15:13 +0200

Fix define()

After the last symbol table rewritten, define in cpp was not working,
because the semantic of the table was totally different. Symbols are
not ever declared with lookup(), a explicit call to install is needed.
For the same reason, it is also necesary check in iden() if we are in
cppmode, because in other case we can call to nextsym() in all the
symbols defined in the preprocessor.

Diffstat:
Mcc1/cpp.c | 2+-
Mcc1/lex.c | 3++-
Mcc1/tests/test015.c | 6++++--
3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -340,7 +340,7 @@ define(void) warn("'%s' redefined", yytext); free(sym->u.s); } else { - sym = lookup(NS_CPP, yytext); + sym = install(NS_CPP, sym); sym->flags |= ISDECLARED; } diff --git a/cc1/lex.c b/cc1/lex.c @@ -431,7 +431,8 @@ iden(void) * it is not a correct macro call, so try to find * another definition. */ - sym = nextsym(sym, namespace); + if (lexmode != CPPMODE) + sym = nextsym(sym, namespace); } yylval.sym = sym; if (sym->flags & ISCONSTANT) diff --git a/cc1/tests/test015.c b/cc1/tests/test015.c @@ -2,7 +2,7 @@ name: TEST015 description: Stress namespace mechanism output: -test015.c:25: error: label 's' already defined +test015.c:60: error: label 's' already defined S8 s2 ( M9 I s @@ -30,7 +30,6 @@ L2 ???? */ -#line 1 typedef struct s s; struct s { @@ -42,9 +41,12 @@ struct s { } s; } s2; +#define s s + int main(void) { +#undef s goto s; struct s s; {