scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit b1ed9087223b78b86fdbb90ffc858c2c99b02833
parent 55210afb602705a30acb416bc224664ed56dfb67
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 24 Jan 2016 22:37:27 +0100

[cc2] Move newid() to symbol.c

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

Diffstat:
Mcc2/parser.c | 12------------
Mcc2/symbol.c | 5+++++
2 files changed, 5 insertions(+), 12 deletions(-)

diff --git 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 @@ -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;