changeset 873:509a394c5ff9

temp4 passed.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 01 Apr 2014 18:02:03 +0900
parents 11abda130b91
children 3454953b3df0
files mc-parse.c
diffstat 1 files changed, 29 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/mc-parse.c	Tue Apr 01 16:57:16 2014 +0900
+++ b/mc-parse.c	Tue Apr 01 18:02:03 2014 +0900
@@ -1558,27 +1558,6 @@
 #define LOCAL_STRUCT_INIT_STATIC 1
 
 static int
-decl_data_1(int type0,int v,int offset)
-{
-    // casted initializer    (sturct hoge){.a=3,.b=c,...}
-
-    getsym(0);
-    if (sym==LPAR) {
-	offset = decl_data_1(type,v,offset);
-	checksym(RPAR);
-    } else if (typeid(sym)) {
-	int t = typename();
-	checksym(RPAR);
-	offset = decl_data(t,v,offset,1);
-	if (inmode)
-	    offset = list4(CAST,offset,t,type);
-    } else {
-        return 0;
-    }
-    return offset;
-}
-
-static int
 decl_data_field(int type1,int v,int offset)
 {
     int t1,t2,period=0;
@@ -1596,33 +1575,34 @@
     if (sym==LC) {
 	mode = STAT;
 	getsym(0);
-    } else if (sym==LPAR) {
-	// 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;
-	if (inmode) {
-	    int offset1=decl_data_1(car(t1),v,0);
-	    offset1 = reverse0(offset1);
-	    offset=list3(DECL_DATA,offset1,car(t1));
-	}  else {
-	    offset=decl_data_1(car(t1),v,offset);
-            if (!offset) checksym(RPAR);
-	}
-	return offset;
-    } else {
-        int mode_save = mode;
-        int stype = type;
-        mode=STAT;
- 	int e=expr1();
-	mode = mode_save;
-        type = stype;
-	if (inmode) {
-	    offset = list3(DECL_DATA,e,car(t1));
-	    return offset;
-	}
- 	offset = assign_data(e,car(t1),v,offset);
-	return offset;
+    } else if (sym != PERIOD ) {
+	 // have to be a value, no comma cascading values
+         int mode_save = mode;
+         int stype = type;
+         mode=STAT;
+         int e=expr1();
+         mode = mode_save;
+         int t2 = type;
+         type = stype;
+         if (size(t2)==size(type0)) {
+             // direct assingn case , including (struct hoge){ ... } 
+             if (inmode) {
+                 offset = list3(DECL_DATA,e,type0);
+                 return offset;
+             }
+             offset = assign_data(e,type0,v,offset);
+             return offset;
+         }
+         // missing brace case
+         error(SIERR);
+         if (inmode) {
+             offset = list3(DECL_DATA,e,car(t1));
+             return offset;
+         }
+         offset = assign_data(e,car(t1),v,offset);
+         t1 = cadr(t1);
+         if (! ( t1 && sym==COMMA)) return offset;
+         conv->comma_(); getsym(0);  // fall thru
     }
     mode=SFDINIT;
     while(1) {
@@ -1891,6 +1871,7 @@
 	    // decl_data_field(t,n,offset) is called inside;
 	} else
 #endif
+        // we cannot handle direct struct assign ( struct hoge a = f(); ) here, because of missing brace case
 	if (inmode) {
 	    int offset1=decl_data_field(t,v,0);
 	    offset1 = reverse0(offset1);