scc

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

commit e7f022e3a196d7473765f5f456da2e19057a7e82
parent c69a4b90cc4b70415cc5ac62d9465b7ec8fdd543
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 11 Aug 2015 17:27:15 +0200

Free cpp symbols after undefining them

Due to the previous data structures used it was hard to free
symbols out of popctx(), but cpp symbols are not anymore in any list.
They are in the hash table (and usually at the beginning of the
collision list), so it is very easy to free them now.

Diffstat:
Mcc1/cc1.h | 1+
Mcc1/cpp.c | 6++----
Mcc1/symbol.c | 8++++++++
3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -307,6 +307,7 @@ extern Symbol *newsym(unsigned ns); extern void pushctx(void), popctx(void); extern void ikeywords(void); extern Symbol *addmacro(void); +extern void delmacro(Symbol *sym); /* stmt.c */ extern void compound(Symbol *lbreak, Symbol *lcont, Caselist *lswitch); diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -531,16 +531,14 @@ elif(void) static void undef(void) { - Symbol *sym; - if (cppoff) return; if (yytoken != IDEN) { error("no macro name given in #undef directive"); return; } - sym = lookup(NS_CPP); - sym->flags &= ~ISDECLARED; + if (yylval.sym->ns == NS_CPP) + delmacro(yylval.sym); next(); } diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -222,6 +222,14 @@ addmacro(void) curctx = ctx; return sym; } + +void +delmacro(Symbol *sym) +{ + unlinkhash(sym); + free(sym->name); + free(sym->u.s); + free(sym); } Symbol *