ref: 0916935c02c6513acbb0f36d625c7cb25315236f
parent: bd3704ba7221b1432934c82a3ec6181849d8ebd8
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Aug 8 14:35:13 EDT 2015
Remove dependence between install() and yylval.sym Install() is always called after a call to lookup(), so yylval.sym is always a correct Symbol related to the value of yytext. This condition makes hard use install() in some cases, so this patch adds a new parameter to install that is the Symbol to be installed.
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -297,7 +297,7 @@
extern void dumpstab(char *msg);
extern Symbol *lookup(unsigned ns);
extern Symbol *nextsym(Symbol *sym, unsigned ns);
-extern Symbol *install(unsigned ns);
+extern Symbol *install(unsigned ns, Symbol *sym);
extern Symbol *newsym(unsigned ns);
extern void pushctx(void), popctx(void);
extern void ikeywords(void);
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -143,7 +143,7 @@
/* TODO: check type of the function */
/* TODO: check function is not redefined */
if (yytoken == IDEN || yytoken == TYPEIDEN) {
- if ((sym = install(ns)) == NULL)
+ if ((sym = install(ns, yylval.sym)) == NULL)
error("redeclaration of '%s'", yytext);
next();
} else {
@@ -333,7 +333,7 @@
case TYPEIDEN:
sym = yylval.sym;
if ((sym->flags & ISDEFINED) == 0)
- install(NS_TAG);
+ install(NS_TAG, yylval.sym);
next();
break;
default:
@@ -394,7 +394,7 @@
for (val = 0; yytoken != ')'; ++val) {
if (yytoken != IDEN)
unexpected();
- if ((sym = install(NS_IDEN)) == NULL) {
+ if ((sym = install(NS_IDEN, yylval.sym)) == NULL) {
error("'%s' redeclared as different kind of symbol",
yytext);
}
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -185,25 +185,19 @@
}
Symbol *
-install(unsigned ns)
+install(unsigned ns, Symbol *sym)
{
- Symbol *sym, **h;
- /*
- * install() is always called after a call to lookup(), so
- * yylval.sym always points to a symbol with yytext name.
- * if the symbol is an undefined symbol and in the same
- * context, then it was generated in the previous lookup()
- * call. If the symbol is defined and in the same context
- * then there is a redefinition
- */
- if (yylval.sym->ctx == curctx) {
- if (yylval.sym->flags & ISDEFINED)
+ if (sym->ctx == curctx) {
+ if (sym->flags & ISDEFINED)
return NULL;
- yylval.sym->flags |= ISDEFINED;
+ sym->flags |= ISDEFINED;
sym = yylval.sym;
} else {
+ char *name = sym->name;
+ Symbol **h;
+
sym = newsym(ns);
- sym->name = xstrdup(yytext);
+ sym->name = xstrdup(name);
h = &htab[hash(yytext)];
sym->hash = *h;
*h = sym;