shithub: scc

Download patch

ref: b2fc11b3d2e07e84e2868f5aab8319612257855c
parent: ec0bbf93d441cac0db795007d80b1dcdc32e91d0
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Mar 17 03:42:06 EDT 2014

Fix order of evaluation in declarators

Declarations must be evaluated in reverse order of the expressions
in the same form, so we need a queue instead of a stack, so the
recursive function was not correct.

--- a/decl.c
+++ b/decl.c
@@ -90,24 +90,41 @@
 error:	error(err, yytext);
 }
 
+/* TODO: Add a token2 field in yylval to avoid yylval.sym->u.c */
+
 static struct dcldata*
 declarator0(struct dcldata *dp, uint8_t ns, int8_t flags)
 {
-	if (accept('*')) {
-		register uint8_t qlf = 0;
-		while (yytoken == TQUALIFIER) {
+	uint8_t buffer[NR_DECLARATORS];
+	register uint8_t *bp, n, qlf;
+
+	bp = buffer;
+	for (n = 0; accept('*'); ++n) {
+		if (n == NR_DECLARATORS)
+			goto too_much_declarators;
+		qlf = 0;
+		if (yytoken == TQUALIFIER) {
 			qlf |= yylval.sym->u.c;
 			next();
 		}
-		dp = declarator0(dp, ns, flags);
+		*bp++ = qlf;
+	}
+
+	dp = directdcl(dp, ns, flags);
+
+	bp = buffer;
+	while (n--) {
 		if (dp->op == 255)
-			error("too much declarators");
+			goto too_much_declarators;
 		dp->op = PTR;
-		dp->u.qlf = qlf;
-		return dp + 1;
-	} else {
-		return directdcl(dp, ns, TQUALIFIER);
+		dp->u.qlf = *bp++;
+		++dp;
 	}
+
+	return dp;
+
+too_much_declarators:
+	error("too much declarators");
 }
 
 static struct symbol *