[hackers] [scc] Remove dependence between install() and yylval.sym || Roberto E. Vargas Caballero
commit 0916935c02c6513acbb0f36d625c7cb25315236f
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sat Aug 8 18:35:13 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sat Aug 8 18:35:13 2015 +0200
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.
diff --git a/cc1/cc1.h b/cc1/cc1.h
index e42b59b..7fd62f8 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
_AT_@ -297,7 +297,7 @@ extern Type *duptype(Type *base);
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);
diff --git a/cc1/decl.c b/cc1/decl.c
index 227848a..5b8d0df 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -143,7 +143,7 @@ directdcl(struct dcldata *dp, unsigned ns)
/* 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 {
_AT_@ -333,7 +333,7 @@ newtag(void)
case TYPEIDEN:
sym = yylval.sym;
if ((sym->flags & ISDEFINED) == 0)
- install(NS_TAG);
+ install(NS_TAG, yylval.sym);
next();
break;
default:
_AT_@ -394,7 +394,7 @@ enumdcl(void)
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);
}
diff --git a/cc1/symbol.c b/cc1/symbol.c
index 7e25a14..93648ec 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
_AT_@ -185,25 +185,19 @@ nextsym(Symbol *sym, unsigned ns)
}
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;
Received on Sat Aug 08 2015 - 23:02:35 CEST
This archive was generated by hypermail 2.3.0
: Sat Aug 08 2015 - 23:12:11 CEST