ref: 6b911721fbe864d1966a471c6b0f111ea5083aaf
parent: 10945b12361ca806d3d80c424063418331669947
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Jul 21 17:11:35 EDT 2015
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.
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -103,7 +103,8 @@
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 @@
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 @@
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 @@
}
ns = NS_CPPCLAUSES;
}
- globalcnt = 0;
}