changeset 879:528595192871

partial struct init in GDECL
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 03 Apr 2014 10:34:02 +0900
parents 9745d517f113
children 5313ed059cee
files mc-codegen.c mc-parse.c test/strinit.c
diffstat 3 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mc-codegen.c	Wed Apr 02 20:37:53 2014 +0900
+++ b/mc-codegen.c	Thu Apr 03 10:34:02 2014 +0900
@@ -3572,6 +3572,7 @@
 	n->sc = nsc;
 	n->dsp = ndsp;
 	set_ctmode(n,ctmode);
+    case SFDINIT:  
 	return n;
     default:
 	error(DCERR);
@@ -3983,6 +3984,7 @@
     }
     switch (mode) {
     case GDECL:
+	if (car(e)==RSTRUCT) break; // already done
 	if (!is_const(e)) error(INERR);
  	emit_data(e,t,n);
 	break;
--- a/mc-parse.c	Wed Apr 02 20:37:53 2014 +0900
+++ b/mc-parse.c	Thu Apr 03 10:34:02 2014 +0900
@@ -1581,18 +1581,18 @@
 	getsym(0);
     } else if (sym != PERIOD ) {
 	 // have to be a value, no comma cascading values
-         int mode_save = mode;
+         // int mode_save = mode;
          int stype = type;
-         mode=STAT;
+         //  mode=STAT;  do it in GDECL mode
          //  expr1 may contain (sturct hoge){...}. it will call local_struct_static. tell him about offset
          local_struct_offset = offset;  
          int e=expr1();
-         mode = mode_save;
+         // mode = mode_save;
          int t2 = type;
          type = stype;
          if (size(t2)==size(type0)) {
              // direct assingn case , including (struct hoge){ ... } 
-             if (inmode) {
+             if (inmode || mode==SFDINIT) {
                  return e;
              }
              type = type0;
@@ -1675,7 +1675,7 @@
     //  if initialization contains expressions,
     //  we cannot do it in STADECL, but we can assign later in this mode
     if (inmode) error(-1);
-    if (local_nptr)  {
+    if (local_nptr || mode==SFDINIT)  {
         decl_data_field(type,v,local_struct_offset);
         return;
     }
--- a/test/strinit.c	Wed Apr 02 20:37:53 2014 +0900
+++ b/test/strinit.c	Thu Apr 03 10:34:02 2014 +0900
@@ -38,10 +38,10 @@
 struct temp temp4 = { 1,2,3,4,5,6,7};
 struct temp temp7 = { 1,2,3,4,{5,6},7};
 
-#if 0
+#if 1
 struct temp temp10 = {
-   .m = (struct hoge){},    // not allowed in global
-   .c = (int)&b,
+    .m = (struct hoge){ .k = 3 },    // not allowed in mc
+    // .c = (int)&b,                 // int/long trancation is not allowed in global
 };
 #endif