[hackers] [scc] Use the value of constant expressions in array sizes || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 21 Jul 2015 18:25:00 +0200 (CEST)

commit 36fb5f2f51f08b9c78c31277f7ef9475608fb4ab
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Jul 21 18:21:11 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Jul 21 18:21:11 2015 +0200

    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.

diff --git a/cc1/decl.c b/cc1/decl.c
index 0dfc62b..c809c9a 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
_AT_@ -39,15 +39,20 @@ queue(struct dcldata *dp, unsigned op, short nelem, void *data)
 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);
Received on Tue Jul 21 2015 - 18:25:00 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 21 2015 - 18:36:10 CEST