shithub: scc

Download patch

ref: 38245a0672da52532077f4ae2a49060f2ce67b22
parent: ff9a7ec77a798f1555fa184a1516f3f721943560
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Jul 15 14:35:50 EDT 2014

Simplify logic of directdcl()

directdcl() had a complex logic because sometimes was needed an
identifier, another time was needed not have an identifier, and
another time doesn't matter. This patch solves this problem in
the easy way. Fix the problem in declarator(), where you are not
limited by the recursion.

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -9,6 +9,7 @@
 
 #define ID_EXPECTED     1
 #define ID_ACCEPTED     2
+#define ID_FORBIDDEN    3
 
 struct dcldata {
 	uint8_t op;
@@ -92,18 +93,16 @@
 }
 
 static struct dcldata *
-directdcl(struct dcldata *dp, int8_t flags)
+directdcl(struct dcldata *dp)
 {
 	register Symbol *sym;
 
 	if (accept('(')) {
-		dp = declarator0(dp, flags);
+		dp = declarator0(dp);
 		expect(')');
-	} else if (flags) {
+	} else {
 		if (yytoken == IDEN || yytoken == TYPEIDEN)
 			sym = newiden();
-		else if (flags & ID_EXPECTED)
-			unexpected();
 		else
 			sym = install("", NS_IDEN);
 
@@ -122,7 +121,7 @@
 }
 
 static struct dcldata*
-declarator0(struct dcldata *dp, int8_t flags)
+declarator0(struct dcldata *dp)
 {
 	register uint8_t  n;
 
@@ -131,7 +130,7 @@
 			/* nothing */;
 	}
 
-	dp = directdcl(dp, flags);
+	dp = directdcl(dp);
 
 	while (n--) {
 		if (dp->op == 255)
@@ -153,7 +152,7 @@
 
 	memset(data, 0, sizeof(data));
 	data[NR_DECLARATORS].op = 255;
-	for (bp = declarator0(data, flags); bp >= data; --bp) {
+	for (bp = declarator0(data); bp >= data; --bp) {
 		switch (bp->op) {
 		case PTR:
 			tp = mktype(tp, PTR, 0);
@@ -166,13 +165,15 @@
 			break;
 		case IDEN:
 			sym = bp->u.sym;
+			if (flags == ID_EXPECTED && *sym->name == '\0')
+				error("missed identifier in declaration");
+			if (flags == ID_FORBIDDEN && *sym->name != '\0')
+				error("unexpected identifier in type name");
 			break;
 		}
 	}
 	if (!tp->defined)
 		error("declared variable '%s' of incomplete type", sym->name);
-	if (!sym)
-		sym = &dummy;
 	sym->type = tp;
 	return sym;
 }
@@ -501,7 +502,7 @@
 	tp = specifier(&sclass);
 	if (sclass)
 		error("class storage in type name");
-	sym = declarator(tp, 0);
+	sym = declarator(tp, ID_FORBIDDEN);
 	return  sym->type;
 }