scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit d5570660a7452191e33dc3d8817efc6ebd6c20e9
parent 12da403dac1d4581566efa3a72e98b04dd828395
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  8 Jul 2014 14:41:20 +0200

Simplify enumdcl

This commit removes one indentation level and removes non needed
gotos.

Diffstat:
cc1/decl.c | 46+++++++++++++++++++---------------------------
1 file changed, 19 insertions(+), 27 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -358,39 +358,31 @@ enumdcl(void) register Type *tp; Symbol *sym; int val = 0; - char *err; next(); tp = newtag(ENUM); - if (yytoken != ';') { - expect('{'); - if (tp->defined) - goto redefined; - tp->defined = 1; - while (yytoken != '}') { - if (yytoken != IDEN) - goto iden_expected; - sym = newiden(); - sym->type = inttype; - if (accept('=')) - initializer(inttype); - sym->u.i = val++; - newfield(tp, sym); - if (!accept(',')) - break; - } - expect('}'); + if (yytoken == ';') + return tp; + + expect('{'); + if (tp->defined) + error("redefinition of enumeration '%s'", yytext); + tp->defined = 1; + while (yytoken != '}') { + if (yytoken != IDEN) + error("identifier expected"); + sym = newiden(); + sym->type = inttype; + if (accept('=')) + initializer(inttype); + sym->u.i = val++; + newfield(tp, sym); + if (!accept(',')) + break; } + expect('}'); return tp; - -redefined: - err = "redefinition of enumeration '%s'"; - goto error; -iden_expected: - err = "identifier expected"; -error: - error(err, yytext); } void