shithub: scc

Download patch

ref: 804ee8287281ddb95bf676825021f944a6fbe398
parent: 4292e620e8f4305403a0ef59a7b41b48354314be
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Jun 29 06:55:40 EDT 2012

Split decl into decl and listdcl

This split improves the code because simplify the logic of the different
warnings (we don't need to use the nd variable for counting the number of
declarations).

--- a/decl.c
+++ b/decl.c
@@ -119,41 +119,44 @@
 		pushtype(*bp);
 }
 
+static void listdcl(register struct ctype *cp)
+{
+	register  struct type *tp;
+
+	do {
+		declarator();
+		tp = decl_type(cp->base);
+		if (!tp) {
+			warning_error(user_opt.implicit_int,
+				      "type defaults to 'int' in declaration of '%s'",
+				      yytext);
+		}
+		if (tp->op == FTN && yytoken == '{') {
+			compound();
+			return;
+		}
+	} while (accept(','));
+}
+
 unsigned char decl(void)
 {
-	auto struct ctype ctype;
-	auto struct type *tp;
-	auto unsigned char nd = 0;
+	static struct ctype ctype;
 
 	if (accept(';'))
 		return 1;
 	if (!spec(&ctype)) {
-		if (nested_level == 0)
-			warning("data definition has no type or storage class");
-		else
+		if (nested_level != 0)
 			return 0;
+		warning("data definition has no type or storage class");
 	}
-	if (yytoken != ';') {
-		do {
-			declarator();
-			tp = decl_type(ctype.base);
-			if (!tp) {
-				warning_error(user_opt.implicit_int,
-					      "type defaults to 'int' in declaration of '%s'",
-					      yytext);
-			}
-			if (tp->op == FTN && yytoken == '{') {
-				compound();
-				return;
-			}
-			++nd;
-		} while (accept(','));
-	}
-	expect(';');
-	if (nd == 0) {
+	if (yytoken == ';') {
 		warning_error(user_opt.useless_typename,
 			      "useless type name in empty declaration");
+	} else {
+		listdcl(&ctype);
 	}
+	expect(';');
+
 	return 1;
 }
 
--