# HG changeset patch # User kono # Date 1136280526 -32400 # Node ID 25e61d68c54537d9ff5c1ee6abcae189ac2d9159 # Parent 650717de878b18039d4b24c8a993c7c5a6293c13 struct member init (inline) diff -r 650717de878b -r 25e61d68c545 .gdbinit --- a/.gdbinit Tue Jan 03 15:40:57 2006 +0900 +++ b/.gdbinit Tue Jan 03 18:28:46 2006 +0900 @@ -45,4 +45,4 @@ # run -s test/code-gen-inline.c # run -s -DINLINE=inline test/basic.c # run -s test/too-long-argument.c -# run -s test/strinit.c +run -s test/strinit.c diff -r 650717de878b -r 25e61d68c545 mc-codegen.c --- a/mc-codegen.c Tue Jan 03 15:40:57 2006 +0900 +++ b/mc-codegen.c Tue Jan 03 18:28:46 2006 +0900 @@ -768,7 +768,7 @@ case ADDRESS: e = cadr(e); return (car(e)==GVAR||car(e)==FNAME||car(e)==LVAR); - case STRING: + case STRING: case GVAR: case CONST: case LCONST: case FCONST: case DCONST: return 1; default: @@ -2767,6 +2767,7 @@ /* Struct fields name lists are in the struct type or tag. */ /* Only name in the table is used. Do not set n->ty! */ /* Struct field may volatile... where do I put? list2(VOLATILE,type)? */ + /* disp is pushded and reset in sdecl */ if (type0>0 && car(type0)==BIT_FIELD) { bit_field_disp=sbit_f; // default is 0, recover only here. // type = list4(BIT_FIELD,value type, @@ -2787,6 +2788,7 @@ if (n!=&null_nptr) fields = list4(type,fields,(int)(n->nm),disp); } else if (mode==GUDECL||mode==LUDECL) { // union + /* disp is pushded and reset in sdecl */ if (type0>0 && car(type0)==BIT_FIELD) { cadr(caddr(type0)) = 0; sz = size(cadr(type0)); } else { @@ -2841,6 +2843,7 @@ disp += sz; return n; case GUDECL: case LUDECL: // union + /* In union case, disp contains max size of the member */ if (disp < sz) disp = sz; return n; case GTDECL: // typedef @@ -3065,9 +3068,13 @@ But some one may take it's address. We have to generate assign. */ ass = assign_expr0( + inmode?( + offset? + list3(ADD,list3(n->sc,n->dsp,(int)n),list2(CONST,offset)): + list3(n->sc,n->dsp,(int)n)): (n->sc==REGISTER||n->sc==DREGISTER||n->sc==FREGISTER||n->sc==LREGISTER)? - list3(n->sc,n->dsp,(int)n): - list3(n->sc,n->dsp+offset,(int)n), + list3(n->sc,n->dsp,(int)n): + list3(n->sc,n->dsp+offset,(int)n), e,t,type); init_vars = list2(ass,init_vars); } else if(mode==STADECL) { diff -r 650717de878b -r 25e61d68c545 mc-inline.c --- a/mc-inline.c Tue Jan 03 15:40:57 2006 +0900 +++ b/mc-inline.c Tue Jan 03 18:28:46 2006 +0900 @@ -1080,7 +1080,7 @@ // should contain correct argument variable name // if (anptr) printf("## var %s\n",anptr->nm); // else printf("## var 0\n"); - g_expr_u(assign_expr0(arg,e4,t,t)); + g_expr_u(assign_expr0(arg,e4,anptr->ty,t)); } narg ++; fargtype = cadr(fargtype); diff -r 650717de878b -r 25e61d68c545 mc-parse.c --- a/mc-parse.c Tue Jan 03 15:40:57 2006 +0900 +++ b/mc-parse.c Tue Jan 03 18:28:46 2006 +0900 @@ -1345,7 +1345,7 @@ static void decl_data_field(int type,NMTBL *n,int offset) { - int t1,t2; + int t1,t2,period=0; int foffset; int mode_save=mode; int type0=type_value(type); @@ -1359,17 +1359,19 @@ if (sym==LC) getsym(0); while(1) { if (sym==PERIOD) { /* struct/union field initializaer */ + period=1; getsym(0); if (sym==IDENT) { t2 = search_struct_type(type,nptr->nm,&foffset); getsym(0); if (sym==ASS) { - decl_data(t2,n,foffset,0); + decl_data(t2,n,offset+foffset,0); } else error(INERR); } else error(INERR); } else { + if(period) error(INERR); if(!t1) break; // empty field case (it can happen...) // next decl_data must skip getsym offset = decl_data(car(t1),n,offset,1); /* alignment? */ @@ -1406,7 +1408,12 @@ decl_data_field(type,nptr0,offset); // do struct assignment before flushed assignment expression init_vars = list2( - list4(STASS,list3(LVAR,n->dsp+offset,0), + list4(STASS, + inmode?( + offset? + list3(ADD,list3(IVAR,n->dsp,0),list2(CONST,offset)): + list3(IVAR,n->dsp,0)): + list3(LVAR,n->dsp+offset,0), list3(RSTRUCT,list3(GVAR,0,(int)nptr0),sz),sz), init_vars); flush_delayed_decl_data(nptr0); @@ -1585,12 +1592,14 @@ bit_field_disp=0; if (sdecl_f) conv->sdecl_(s); if (getsym(TAG) == IDENT) { + /* struct tag name */ nptr0 = nptr; gnptr0 = gnptr; if (sdecl_f) conv->id_(sym,nptr); if (getsym(0) == LC) { + /* struct define case */ if (sdecl_f) conv->lc_(); - if(nptr0->sc == EMPTY) nptr0=gnptr0; + if (nptr0->sc == EMPTY) nptr0=gnptr0; if (nptr0->sc!=TAG && nptr0->sc != EMPTY) error(DCERR); nptr0->sc = TAG; nptr0->ty = list4(s,-1,0,(int)nptr0); @@ -1599,7 +1608,7 @@ cadr((type0 = nptr0->ty))=disp; /* type0 = list4(s,disp,fields,0); now ... */ } else { - /* struct tag name */ + /* struct reference case */ if(nptr0->sc == EMPTY) nptr0=gnptr0; if(nptr0->sc == EMPTY) nptr0->sc = TAG; if(nptr0->sc != TAG) error(TYERR); @@ -1611,6 +1620,7 @@ type0 = list4(s,disp,fields,(int)nptr0); } } else if(sym==LC) { + /* no tag name */ if (sdecl_f) conv->lc_(); sdecl_field(); type0 = list4(s,disp,fields,0); @@ -3423,11 +3433,12 @@ smode = mode; type = t; nptr0=new_static_name("__lstruct",'_'); - nptr0->next = local_static_list; local_static_list = nptr0; - nptr0->sc = GVAR; + mode=STADECL; + def(nptr0,0); + // nptr0->next = local_static_list; local_static_list = nptr0; + // nptr0->sc = GVAR; + // nptr0->ty = type; e1 = size(type); - nptr0->ty = type; - mode=STADECL; decl_data_field(type,nptr0,0); checksym(RC); e1 = list3(RSTRUCT,list3(GVAR,0,(int)nptr0),e1);