shithub: scc

Download patch

ref: 36fb5f2f51f08b9c78c31277f7ef9475608fb4ab
parent: 149b464dcae2f20abdfed12cf9f7f78ed7596772
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Jul 21 14:21:11 EDT 2015

Use the value of constant expressions in array sizes

At this point we can reduce addition operators, so we can take
the value of the constant expression and use it for the size
of the array.

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -39,15 +39,20 @@
 static struct dcldata *
 arydcl(struct dcldata *dp)
 {
-	Node *np = NULL;
+	Node *np;
+	TINT n;
 
 	expect('[');
 	np = (yytoken != ']') ? constexpr() : NULL;
 	expect(']');
+
 	/*
-	 * TODO: Evaluate np.
+	 * TODO: check that the type of the constant expression
+	 * is the correct, that in this case should be int
 	 */
-	return queue(dp, ARY, 0, NULL);
+	n = (np == NULL) ? 0 : np->sym->u.i;
+
+	return queue(dp, ARY, n, NULL);
 }
 
 static Symbol *parameter(void);