shithub: scc

Download patch

ref: 6edad19c7b1d3bfda9f38073f950ce914895f63e
parent: 33078464460d0f78f783415d560a27f58dcb39ae
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Jul 8 11:16:39 EDT 2014

Simplify extdecl

Reordering the conditions make the code clearer

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -430,7 +430,6 @@
 {
 	Type *base;
 	int8_t sclass;
-	Symbol *sym;
 
 	switch (yytoken) {
 	case IDEN: case TYPE: case SCLASS: case TQUALIFIER:
@@ -439,6 +438,7 @@
 			error("incorrect storage class for file-scope declaration");
 		if (yytoken != ';')
 			break;
+		/* PASSTHROUGH */
 	case ';':
 		goto semicolon;
 	case '@':
@@ -450,26 +450,12 @@
 	}
 
 	do {
-		Type *tp;
+		Symbol *sym = declarator(base, ID_EXPECTED);
+		Type *tp = sym->type;
 
-		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 {
+		if (BTYPE(tp) != FTN) {
 			sym->s.isstatic = 1;
 			if (sclass & EXTERN)
 				; /* TODO: handle extern */
@@ -476,7 +462,16 @@
 			else if (accept('='))
 				initializer(tp);
 			emitdcl(sym);
+		} else 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(','));
 
@@ -484,3 +479,4 @@
 	expect(';');
 	return;
 }
+