scc

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

commit c69a4b90cc4b70415cc5ac62d9465b7ec8fdd543
parent 1372160651f5eea2d275bf4509aeec427b6ce5e6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 11 Aug 2015 16:35:18 +0200

Force cpp symbols to be at the beginning of the hash

Cpp symbols have bigger 'priority' than any other symbol,
because they are expanded in a previous stage, so they
must not be hidden by any other symbol.

Diffstat:
Mcc1/cc1.h | 1+
Mcc1/cpp.c | 4++--
Mcc1/symbol.c | 15+++++++++++++++
3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -306,6 +306,7 @@ extern Symbol *install(unsigned ns, Symbol *sym); extern Symbol *newsym(unsigned ns); extern void pushctx(void), popctx(void); extern void ikeywords(void); +extern Symbol *addmacro(void); /* stmt.c */ extern void compound(Symbol *lbreak, Symbol *lcont, Caselist *lswitch); diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -29,7 +29,7 @@ defmacro(char *s) Symbol *sym; strcpy(yytext, s); - sym = lookup(NS_CPP); + sym = addmacro(); sym->flags |= ISDECLARED; return sym; } @@ -330,7 +330,7 @@ define(void) warn("'%s' redefined", yytext); free(sym->u.s); } else if (sym->ns != NS_CPP) { - sym = lookup(NS_CPP); + sym = addmacro(); } sym->flags |= ISDECLARED; diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -1,5 +1,6 @@ #include <inttypes.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -210,6 +211,20 @@ lookup(unsigned ns) } Symbol * +addmacro(void) +{ + unsigned ctx = curctx; + Symbol *sym; + + /* Force cpp symbols to be at the beginning of the hash */ + curctx = UCHAR_MAX; + sym = lookup(NS_CPP); + curctx = ctx; + return sym; +} +} + +Symbol * nextsym(Symbol *sym, unsigned ns) { char *s, *t, c;