scc

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

commit c41400e10b2d33c1b1e5d1900add4cd17b34c7f0
parent 6f2043e9eb7f2eb1a4ab6d4ac58d59f2e36f77a6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  8 Jul 2014 14:19:48 +0200

Simplify extdecl function

This function had an in that was not necessary. This change
remove it and also remove the non needed gotos of error handling.

Diffstat:
Mcc1/decl.c | 77++++++++++++++++++++++++++++++++++-------------------------------------------
1 file changed, 34 insertions(+), 43 deletions(-)

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