changeset 870:e3de6b70abe9

struct initialization by function
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 01 Apr 2014 09:47:38 +0900
parents 11add9567972
children 662e2b778fc2
files mc-parse.c test/tmp7.c
diffstat 2 files changed, 26 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mc-parse.c	Tue Apr 01 09:14:52 2014 +0900
+++ b/mc-parse.c	Tue Apr 01 09:47:38 2014 +0900
@@ -1558,14 +1558,13 @@
 #define LOCAL_STRUCT_INIT_STATIC 1
 
 static int
-decl_data_1(int type,int v,int offset)
+decl_data_1(int type0,int v,int offset)
 {
-    int t;
+    int t = type0;
 
     // casted initializer    (sturct hoge){.a=3,.b=c,...}
-
-    getsym(0);
     if (sym==LPAR) {
+        getsym(0);
 	offset = decl_data_1(type,v,offset);
 	checksym(RPAR);
     } else if (typeid(sym)) {
@@ -1575,7 +1574,17 @@
 	if (inmode)
 	    offset = list4(CAST,offset,t,type);
     } else {
-	return 0;
+        int mode_save = mode;
+ 	int e=expr1();
+	mode = mode_save;
+	if (inmode) {
+	    offset = list3(DECL_DATA,e,type);
+	    type=t;
+	    return offset;
+	}
+ 	offset = assign_data(e,t,v,offset);
+ 	type=t;
+	return offset;
     }
     return offset;
 }
@@ -1598,11 +1607,13 @@
     if (sym==LC) {
 	mode = STAT;
 	getsym(0);
-    } else if (sym==LPAR) {
+    } else {
 	// have to be a value, no comma cascading values
         //    .__tcp_lhash_lock = (rwlock_t) { },
         // We cannot distinguish this case and cascading comma here.
         // Do it more upper syntactical node;
+        int par = (sym==LPAR);
+        if (par) getsym(0);
 	if (inmode) {
 	    int offset1=decl_data_1(car(t1),v,0);
 	    offset1 = reverse0(offset1);
@@ -1610,11 +1621,9 @@
 	    return offset;
 	}  else {
 	    offset=decl_data_1(car(t1),v,offset);
-	    if (!offset) checksym(RPAR);
+	    if (!offset && par ) checksym(RPAR);
 	    return offset;
 	}
-    } else {
-	error(SIERR);
     }
     mode=SFDINIT;
     while(1) {
--- a/test/tmp7.c	Tue Apr 01 09:14:52 2014 +0900
+++ b/test/tmp7.c	Tue Apr 01 09:47:38 2014 +0900
@@ -56,7 +56,7 @@
 	a2.b[1]=555;
 	return a2;
 }
-INLINE void main6();
+INLINE void main6(); INLINE void main7();
 
 INLINE void
 main1(struct aa a1)
@@ -166,3 +166,10 @@
 }
 
 
+INLINE void
+main7(struct aa a1)
+{
+    struct aa b = main0(0xff);
+    printf("#0065:main7 b.a[55] %d\n",b.a[55]);
+}
+