shithub: scc

Download patch

ref: d5999e4023f08294856780febf26edcb4f1cb37f
parent: 9e97f6d8b18b7334e1f45e09e3a27c59989d2c86
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Jan 20 07:41:50 EST 2016

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.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -386,6 +386,7 @@
 
 /* init.c */
 extern void initializer(Symbol *sym, Type *tp);
+extern Node *initlist(Type *tp);
 
 /* cpp.c */
 extern void icpp(void);
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -820,13 +820,15 @@
 	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");
--- a/cc1/init.c
+++ b/cc1/init.c
@@ -87,8 +87,6 @@
 	return ip;
 }
 
-static Node *initlist(Type *tp);
-
 static Node *
 initialize(Type *tp)
 {
@@ -188,7 +186,7 @@
 	}
 }
 
-static Node *
+Node *
 initlist(Type *tp)
 {
 	Init in;