[hackers] [scc] [cc2] Move newid() to symbol.c || Roberto E. Vargas Caballero
commit b1ed9087223b78b86fdbb90ffc858c2c99b02833
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sun Jan 24 22:37:27 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
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
_AT_@ -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)
{
_AT_@ -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
_AT_@ -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;
Received on Mon Jan 25 2016 - 11:00:38 CET
This archive was generated by hypermail 2.3.0
: Mon Jan 25 2016 - 11:12:30 CET