scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit d5999e4023f08294856780febf26edcb4f1cb37f
parent 9e97f6d8b18b7334e1f45e09e3a27c59989d2c86
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 20 Jan 2016 12:41:50 +0100

Add support for compound literal in expr.c

The support is not yet complete because initilist() is wrong.
We do not support designator lists, and we fail to decide
when an initializator is missing the braces. At this point
it works for C90 initializers, but it fails when there is
some compound literal.

Diffstat:
cc1/cc1.h | 1+
cc1/expr.c | 8+++++---
cc1/init.c | 4+---
3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -386,6 +386,7 @@ extern bool cmpnode(Node *np, TUINT val); /* init.c */ extern void initializer(Symbol *sym, Type *tp); +extern Node *initlist(Type *tp); /* cpp.c */ extern void icpp(void); diff --git a/cc1/expr.c b/cc1/expr.c @@ -820,13 +820,15 @@ cast(void) case TQUALIFIER: case TYPE: tp = typename(); + expect(')'); + + if (yytoken == '{') + return initlist(tp); + switch (tp->op) { case ARY: error("cast specify an array type"); - case FTN: - error("cast specify a function type"); default: - expect(')'); lp = cast(); if ((rp = convert(lp, tp, 1)) == NULL) error("bad type convertion requested"); diff --git a/cc1/init.c b/cc1/init.c @@ -87,8 +87,6 @@ designation(Init *ip) return ip; } -static Node *initlist(Type *tp); - static Node * initialize(Type *tp) { @@ -188,7 +186,7 @@ newdesig(Init *ip, Node *np) } } -static Node * +Node * initlist(Type *tp) { Init in;