scc

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

commit b5a07a8e256269a057c0143c8f61f131d038eb44
parent 2adcda7668e73c5fd1471f0766fd6fd3ba8d638b
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 28 Sep 2015 23:13:39 +0200

Remove delmacro()

Delmacro() is not needed at all, because its work is already done by
killsym, which is more generic.

Diffstat:
Mcc1/cc1.h | 2+-
Mcc1/cpp.c | 10+++++-----
Mcc1/symbol.c | 25++++++-------------------
3 files changed, 12 insertions(+), 25 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -346,7 +346,7 @@ extern Symbol *install(int ns, Symbol *sym); extern Symbol *newsym(int ns); extern void pushctx(void), popctx(void); extern void ikeywords(void); -extern void delmacro(Symbol *sym); +extern void killsym(Symbol *sym); extern Symbol *newlabel(void); /* stmt.c */ diff --git a/cc1/cpp.c b/cc1/cpp.c @@ -241,7 +241,7 @@ substitute: input->p = input->begin = begin; if (!(sym->flags & ISDECLARED)) - delmacro(sym); + killsym(sym); return 1; } @@ -342,7 +342,7 @@ define(void) free(sym->u.s); } else { sym = install(NS_CPP, sym); - sym->flags |= ISDECLARED; + sym->flags |= ISDECLARED|ISSTRING; } namespace = NS_IDEN; /* Avoid polution in NS_CPP */ @@ -357,7 +357,7 @@ define(void) return; delete: - delmacro(sym); + killsym(sym); } void @@ -531,7 +531,7 @@ ifclause(int negate, int isifdef) next(); status = (sym->flags & ISDECLARED) != 0; if (!status) - delmacro(sym); + killsym(sym); } else { /* TODO: catch recovery here */ if ((expr = iconstexpr()) == NULL) { @@ -614,7 +614,7 @@ undef(void) error("no macro name given in #undef directive"); return; } - delmacro(yylval.sym); + killsym(yylval.sym); next(); } diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -76,7 +76,7 @@ pushctx(void) error("too much nested blocks"); } -static void +void killsym(Symbol *sym) { short f; @@ -87,14 +87,14 @@ killsym(Symbol *sym) free(sym->u.s); if (sym->ns == NS_TAG) sym->type->defined = 0; - if ((name = sym->name) != NULL) { - unlinkhash(sym); + unlinkhash(sym); + if ((name = sym->name) != NULL && sym->ns != NS_CPP) { if ((f & (ISUSED|ISGLOBAL|ISDECLARED)) == ISDECLARED) warn("'%s' defined but not used", name); if ((f & ISDEFINED) == 0 && sym->ns == NS_LABEL) errorp("label '%s' is not defined", name); - free(name); } + free(name); free(sym); } @@ -168,7 +168,6 @@ linksym(Symbol *sym) { Symbol *p, *prev; - sym->flags |= ISDECLARED; switch (sym->ns) { case NS_CPP: return sym; @@ -198,7 +197,6 @@ linkhash(Symbol *sym) Symbol **h, *p, *prev; h = &htab[hash(sym->name)]; - for (prev = p = *h; p; prev = p, p = p->hash) { if (p->ctx <= sym->ctx) break; @@ -214,16 +212,14 @@ linkhash(Symbol *sym) if (sym->ns != NS_CPP) sym->id = newid(); + sym->flags |= ISDECLARED; return linksym(sym); } Symbol * newsym(int ns) { - Symbol *sym; - - sym = linksym(allocsym(ns, NULL)); - return sym; + return linksym(allocsym(ns, NULL)); } Symbol * @@ -253,15 +249,6 @@ lookup(int ns, char *name) return allocsym(ns, name); } -void -delmacro(Symbol *sym) -{ - unlinkhash(sym); - free(sym->name); - free(sym->u.s); - free(sym); -} - Symbol * nextsym(Symbol *sym, int ns) {