scc

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

commit 113870ab619a3ca19dd9e524c43c9a347f5e3895
parent 886bd49d93db4ea06014b50df0827f3788584259
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 10 Jul 2014 12:18:05 +0200

Simplify extdecl

This new version removes a lot of break and gotos, that were not
really needed because the do-while loop was only necessary in one
of the cases of the switch.

Diffstat:
Mcc1/decl.c | 66+++++++++++++++++++++++++++++++-----------------------------------
1 file changed, 31 insertions(+), 35 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -428,55 +428,51 @@ typename(void) void extdecl(void) { - Type *base; + Type *base, *tp; int8_t sclass; + Symbol *sym; + extern Symbol *curfun; switch (yytoken) { case IDEN: case TYPE: case SCLASS: case TQUALIFIER: base = specifier(&sclass); if (sclass == REGISTER || sclass == AUTO) error("incorrect storage class for file-scope declaration"); - if (yytoken != ';') - break; + if (accept(';')) + return; + do { + sym = declarator(base, ID_EXPECTED); + tp = sym->type; + if (!(sclass & STATIC)) + sym->s.isglobal = 1; + if (BTYPE(tp) != FTN) { + sym->s.isstatic = 1; + if (sclass & EXTERN) + ; /* TODO: handle extern */ + else if (accept('=')) + initializer(tp); + emitdcl(sym); + } else if (yytoken == '{') { + curfun = sym; + emitfun(sym); + emitsframe(sym); + context(NULL, NULL, NULL); + emiteframe(); + freesyms(NS_LABEL); + return; + } + } while (accept(',')); /* PASSTHROUGH */ case ';': - goto semicolon; + expect(';'); + return; case '@': next(); emitprint(expr()); - goto semicolon; + expect(';'); + return; default: error("declaration expected"); } - - do { - Symbol *sym = declarator(base, ID_EXPECTED); - Type *tp = sym->type; - - if (!(sclass & STATIC)) - sym->s.isglobal = 1; - if (BTYPE(tp) != FTN) { - sym->s.isstatic = 1; - if (sclass & EXTERN) - ; /* TODO: handle extern */ - else if (accept('=')) - initializer(tp); - emitdcl(sym); - } else if (yytoken == '{') { - extern Symbol *curfun; - - curfun = sym; - emitfun(sym); - emitsframe(sym); - context(NULL, NULL, NULL); - emiteframe(); - freesyms(NS_LABEL); - return; - } - } while (accept(',')); - -semicolon: - expect(';'); - return; }