# HG changeset patch # User Shinji KONO # Date 1396488842 -32400 # Node ID 5285951928715c5c5dd5212ec401725b38f4fd87 # Parent 9745d517f11368cb58b4a8c0d575a23bb4590789 partial struct init in GDECL diff -r 9745d517f113 -r 528595192871 mc-codegen.c --- 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; diff -r 9745d517f113 -r 528595192871 mc-parse.c --- 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; } diff -r 9745d517f113 -r 528595192871 test/strinit.c --- 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