ref: 4feeded5c41b279f3e1f3d96d0878c9adb9c52ee
parent: 2f1a6880fb5e5d5408c217809ff203a9b942a9b4
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Mar 8 15:28:33 EST 2014
add newtag() function Centralize where tag names are generated, so the error control is done only in a place.
--- a/decl.c
+++ b/decl.c
@@ -64,6 +64,14 @@
}
}
+static unsigned char
+newtag(void)
+{
+ if (nr_tags == NS_TAG + NR_MAXSTRUCTS)
+ error("too much structs/unions/enum defined");
+ return ++nr_tags;
+}
+
static struct symbol *
aggregate(register struct ctype *tp)
{
@@ -83,16 +91,13 @@
*tp = *aux;
} else {
tp->tag = sym->name;
- tp->ns = ++nr_tags;
+ tp->ns = newtag();
sym->ctype = *tp;
}
- next(); /* This way of handling nr_tag */
- } else { /* is incorrect once is incorrect*/
- tp->ns = ++nr_tags; /* it will be incorrect forever*/
+ next();
+ } else {
+ tp->ns = newtag();
}
-
- if (nr_tags == NS_TAG + NR_MAXSTRUCTS)
- error("too much structs/unions/enum defined");
return sym;
}