[hackers] [scc] Use symbol identifiers only in install() || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 21 Jul 2015 21:14:01 +0200 (CEST)

commit 6b911721fbe864d1966a471c6b0f111ea5083aaf
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Jul 21 21:11:35 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
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
_AT_@ -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;
 }
 
_AT_@ -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;
_AT_@ -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;
 }
 
_AT_@ -281,5 +286,4 @@ ikeywords(void)
                 }
                 ns = NS_CPPCLAUSES;
         }
- globalcnt = 0;
 }
Received on Tue Jul 21 2015 - 21:14:01 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 21 2015 - 21:24:09 CEST