commit b1ed9087223b78b86fdbb90ffc858c2c99b02833
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Sun Jan 24 22:37:27 2016 +0100
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Sun Jan 24 22:37:27 2016 +0100

    [cc2] Move newid() to symbol.c
    
    This functionality fits better in symname(), and we avoid
    a dedicated function only to increment a counter.

diff --git a/cc2/parser.c b/cc2/parser.c
index 6fb8028..5d84cfd 100644
--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -143,16 +143,6 @@ pop(void)
        return *--sp;
 }
 
-static unsigned short
-newid(void)
-{
-       static unsigned short id;
-
-       if (++id == 0)
-               error(EIDOVER);
-       return id;
-}
-
 static void
 type(char *token, union tokenop u)
 {
@@ -374,8 +364,6 @@ vardecl(void)
        sym->type = *tp;
        sym->kind = sclass;
        lastsym = sym;
-       if (!name)
-               sym->numid = newid();
 
        if (funpars >= 0) {
                if (funpars == NR_FUNPARAM)
diff --git a/cc2/symbol.c b/cc2/symbol.c
index 2b26eff..16fe8ce 100644
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
@@ -70,9 +70,14 @@ char *
 symname(Symbol *sym)
 {
        static char name[20];
+       static unsigned short id;
 
        if (sym->name)
                return sym->name;
+       if (sym->numid == 0) {
+               if ((sym->numid = ++id) == 0)
+                       error(EIDOVER);
+       }
        sprintf(name, ".%d", sym->numid);
 
        return name;

Reply via email to