ref: 113870ab619a3ca19dd9e524c43c9a347f5e3895
parent: 886bd49d93db4ea06014b50df0827f3788584259
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Jul 10 08:18:05 EDT 2014
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.
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -428,8 +428,10 @@
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:
@@ -436,47 +438,41 @@
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;
}
--
⑨