shithub: scc

Download patch

ref: 943fc19936e423b3c349ceea154e4eb6465cc556
parent: 427363d83864c086fbaf836bc412c451c87cc49d
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Jun 5 16:18:00 EDT 2012

Unifying implicit int testing

Before of this patch the implicit int testing was done in two separate
places. After this it is easier locate the place where you can find the condition.

--- a/decl.c
+++ b/decl.c
@@ -125,21 +125,23 @@
 		case UNION:	/* TODO */
 		case ENUM:	/* TODO */
 		default:
-			if (tqlf) {
-				if (t == NULL) {
-					warning_error(user_opt.implicit_int,
-						      "type defaults to 'int' "
-						      "in declaration of '%s'",
-						      yytext);
-					t = T_INT;
-				}
+			if (t) {
+				return t;
+			} else if (tqlf) {
 				if (tqlf & T_CONST)	  pushtype(CONST);
 				if (tqlf & T_RESTRICTED)  pushtype(RESTRICTED);
 				if (tqlf & T_VOLATILE)	  pushtype(VOLATILE);
-				t = decl_type(t);
+				return decl_type(t);
+			} else if (nested_level == 0 && yytoken == IDENTIFIER) {
+				warning_error(user_opt.implicit_int,
+					      "type defaults to 'int' "
+					      "in declaration of '%s'",
+					      yytext);
+				return T_INT;
+			} else if (nested_level == 0) {
+				error("declaration expected");
 			}
-			puts("leaving especifier");
-			return t;
+			return NULL;
 		}
 	check_type:
 		if (nt == F_LONG) {
@@ -239,22 +241,8 @@
 	auto unsigned char nd = 0;
 
 	puts("decl");
-	tbase = specifier();
-
-	if (!tbase) {
-		if (nested_level != 0) {
-			puts("leaving decl");
-			return 0;
-		}
-		if (yytoken == IDENTIFIER) {
-			warning_error(user_opt.implicit_int,
-				      "type defaults to 'int' "
-				      "in declaration of '%s'", yytext);
-			tbase = T_INT;
-		} else {
-			error("declaration expected");
-		}
-	}
+	if (!(tbase = specifier()))
+		return 0;
 	if (yytoken != ';') {
 		do {
 			declarator();
@@ -261,8 +249,7 @@
 			tp = decl_type(tbase);
 			if (isfunction(tp) && yytoken == '{') {
 				compound();
-				puts("leaving decl");
-				return 1;
+				goto leaving;
 			}
 			++nd;
 		} while (accept(','));
@@ -273,7 +260,7 @@
 		warning_error(user_opt.useless_typename,
 			      "useless type name in empty declaration");
 	}
-
+leaving:
 	puts("leaving decl");
 	return 1;
 }
@@ -281,4 +268,3 @@
 void type_name()
 {
 }
-
--- a/syntax.h
+++ b/syntax.h
@@ -5,5 +5,5 @@
 
 extern void compound(void);
 extern void expr(void);
-unsigned char decl(void);
+extern unsigned char decl(void);
 #endif