scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 36fb5f2f51f08b9c78c31277f7ef9475608fb4ab
parent 149b464dcae2f20abdfed12cf9f7f78ed7596772
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 21 Jul 2015 18:21:11 +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.

Diffstat:
Mcc1/decl.c | 11++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/cc1/decl.c b/cc1/decl.c @@ -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);