shithub: scc

Download patch

ref: b1ed9087223b78b86fdbb90ffc858c2c99b02833
parent: 55210afb602705a30acb416bc224664ed56dfb67
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Jan 24 17:37:27 EST 2016

[cc2] Move newid() to symbol.c

This functionality fits better in symname(), and we avoid
a dedicated function only to increment a counter.

--- a/cc2/parser.c
+++ b/cc2/parser.c
@@ -143,16 +143,6 @@
 	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 @@
 	sym->type = *tp;
 	sym->kind = sclass;
 	lastsym = sym;
-	if (!name)
-		sym->numid = newid();
 
 	if (funpars >= 0) {
 		if (funpars == NR_FUNPARAM)
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
@@ -70,9 +70,14 @@
 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;