commit 4feeded5c41b279f3e1f3d96d0878c9adb9c52ee parent 2f1a6880fb5e5d5408c217809ff203a9b942a9b4 Author: Roberto E. Vargas Caballero <k0ga@shike2.com> Date: Sat, 8 Mar 2014 20:28:33 +0100 add newtag() function Centralize where tag names are generated, so the error control is done only in a place. Diffstat:
M | decl.c | | | 19 | ++++++++++++------- |
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/decl.c b/decl.c @@ -64,6 +64,14 @@ directdcl(register struct ctype *tp, unsigned char ns) } } +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,17 +91,14 @@ aggregate(register struct ctype *tp) *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; }