scc

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

commit 6b911721fbe864d1966a471c6b0f111ea5083aaf
parent 10945b12361ca806d3d80c424063418331669947
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 21 Jul 2015 21:11:35 +0200

Use symbol identifiers only in install()

install() is called when a semantic symbol is stored in the hash
table, so it is the better place to assign the identifiers to
the symbols, because if we do it in newsym then we will use an
id for every temporal symbol whose id is not used.

Diffstat:
Mcc1/symbol.c | 24++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -103,7 +103,8 @@ duptype(Type *base) Type *tp = xmalloc(sizeof(*tp)); *tp = *base; - tp->id = (curctx) ? ++localcnt : ++globalcnt; + if (tp->op == ARY) + tp->id = (curctx) ? ++localcnt : ++globalcnt; return tp; } @@ -113,8 +114,8 @@ newsym(unsigned ns) Symbol *sym; sym = malloc(sizeof(*sym)); - if ((sym->ns = ns) != NS_CPP) - sym->id = (curctx) ? ++localcnt : ++globalcnt; + sym->id = 0; + sym->ns = ns; sym->ctx = curctx; sym->token = IDEN; sym->flags = ISDEFINED; @@ -199,14 +200,18 @@ install(unsigned ns) if (yylval.sym->flags & ISDEFINED) return NULL; yylval.sym->flags |= ISDEFINED; - return yylval.sym; + sym = yylval.sym; + } else { + sym = newsym(ns); + sym->name = xstrdup(yytext); + h = &htab[hash(yytext)]; + sym->hash = *h; + *h = sym; } - sym = newsym(ns); - sym->name = xstrdup(yytext); - h = &htab[hash(yytext)]; - sym->hash = *h; - *h = sym; + if (sym->ns != NS_CPP) + sym->id = (curctx) ? ++localcnt : ++globalcnt; + return sym; } @@ -281,5 +286,4 @@ ikeywords(void) } ns = NS_CPPCLAUSES; } - globalcnt = 0; }