shithub: scc

Download patch

ref: e33b5c0c4f3d7abd9ab3db4334ba8fa54addd8d1
parent: 50bfc145d470d78dfe38594a3a94123375c3a66a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Oct 28 17:37:10 EDT 2013

Move decision of when a declaration is vaid to specifier

A statement is a declaration if it has a specifier or type, or
it is a global declaration without specifier and type. We were
checking all the possible conditions about specifiers in specifier(),
so it is a better place than decl() where check it.

--- a/decl.c
+++ b/decl.c
@@ -207,10 +207,14 @@
 			}
 			/* it is not a type name */
 		default:
-			if (!tp)
-				return NULL;
-			if (!tp->type) {
+			if (!tp) {
+				if (curctx != CTX_OUTER || yytoken != IDEN)
+					return NULL;
+				tp = ctype(tp, INT);
 				warn(options.implicit,
+					"data definition has no type or storage class");
+			} else if (!tp->type) {
+				warn(options.implicit,
 			             "type defaults to 'int' in declaration");
 				tp->type = INT;
 			}
@@ -316,14 +320,10 @@
 	register struct ctype *base;
 	struct node *np;
 
-repeat: if (!(base = specifier())) {
-		if (curctx != CTX_OUTER || yytoken != IDEN)
-			return NULL;
-		base = newctype();
-		base->type = INT;
-		warn(options.implicit,
-		     "data definition has no type or storage class");
-	} else if (accept(';')) {
+repeat: if (!(base = specifier()))
+		return NULL;
+
+	if (accept(';')) {
 		register unsigned char type = base->type;
 
 		switch (type) {
--