# HG changeset patch # User Shinji KONO # Date 1396428297 -32400 # Node ID 6955ee41688f95d00a52adcc79be6e8f91170e4d # Parent f93bf97bbd1fa1e1ffe855d0f5573a97792b13fe non parse mode struct initialization passed. diff -r f93bf97bbd1f -r 6955ee41688f Changes --- a/Changes Wed Apr 02 12:44:48 2014 +0900 +++ b/Changes Wed Apr 02 17:44:57 2014 +0900 @@ -10011,8 +10011,8 @@ でも、局所構造体はゼロ初期化しなければならないので、local_struct_static が正しいだろう。 ということは、decl_data 側で再帰定義を扱うのが正しいのだろうな。 -local_struct_offset を大域変数にしてやれば良い。 - - - - +local_struct_offset を大域変数にしてやれば良い。(いや、それは難しすぎる) + + + + diff -r f93bf97bbd1f -r 6955ee41688f mc-parse.c --- a/mc-parse.c Wed Apr 02 12:44:48 2014 +0900 +++ b/mc-parse.c Wed Apr 02 17:44:57 2014 +0900 @@ -61,7 +61,8 @@ NMTBL null_nptr; NMTBL *fnptr; // current compiling function NMTBL *nptr,*gnptr; // current name ptr -NMTBL *local_nptr; // local variable initialzation +NMTBL *local_nptr; // local struct initialzation in static area +int local_struct_offset; // local struct initialzation offset static NMTBL *htable0[GSYMS]; // hash table NMTBL **htable = htable0; @@ -1579,6 +1580,8 @@ int mode_save = mode; int stype = type; mode=STAT; + // 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; int t2 = type; @@ -1588,7 +1591,9 @@ if (inmode) { return e; } + type = type0; offset = assign_data(e,type0,v,offset); + type = stype; return offset; } // missing brace case @@ -1596,7 +1601,9 @@ if (inmode) { offset = list4(DECL_DATA_LIST,offset,list3(DECL_DATA,e,t2),car(t1)); } else { + type = car(t1); offset = assign_data(e,car(t1),v,offset); + type = stype; } t1 = cadr(t1); if (! ( t1 && sym==COMMA)) return offset; @@ -1632,10 +1639,10 @@ if(!t1) break; // empty field case (it can happen...) // next decl_data must skip getsym if (inmode) { - int offset1 = decl_data(car(t1),v,0,1); /* alignment? */ + int offset1 = decl_data(car(t1),v,0,1); offset = list4(DECL_DATA_LIST,offset,offset1,car(t1)); } else { - offset = decl_data(car(t1),v,offset,1); /* alignment? */ + offset = decl_data(car(t1),v,offset,1); } t1 = cadr(t1); } @@ -1664,17 +1671,18 @@ // 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) error(-1); + if (local_nptr) { + decl_data_field(type,v,local_struct_offset); + return; + } local_nptr = n; // will be clear in flush + local_struct_offset = offset; mode=STADECL; nptr0=new_static_name("__lstruct",'_'); def(nptr0,0); mode=smode; v0 = list3n(GVAR,0,nptr0); - //nptr0->next = local_static_list; local_static_list = nptr0; - //nptr0->sc = STATIC; - //nptr0->ty = t = type; decl_data_field(type,v0,offset); // do struct assignment before flushed assignment expression init_vars = list2( @@ -1863,7 +1871,7 @@ mode = mode_save; #if LOCAL_STRUCT_INIT_STATIC if(mode==LDECL && !inmode) { - if (offset) error(-1); + local_struct_offset = offset; local_struct_static(v); // change mode to STADECL // decl_data_field(t,n,offset) is called inside; @@ -4230,7 +4238,6 @@ } else { e1 = reverse0(e3); e1 = list3(DECL_DATA,e1,t); - // e1 = list3(RSTRUCT,e2,e1); e1 = list4(CAST,e1,t,t); // only for cast syntax } } else {