commit 6b911721fbe864d1966a471c6b0f111ea5083aaf
Author: Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Tue Jul 21 21:11:35 2015 +0200
Commit: Roberto E. Vargas Caballero <[email protected]>
CommitDate: Tue Jul 21 21:11:35 2015 +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.
diff --git a/cc1/symbol.c b/cc1/symbol.c
index 0734a27..6e38406 100644
--- 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;
}