Mercurial > hg > CbC > old > device
changeset 310:5ae5857ded2c struct-partial-init
struct partial init done.
author | kono |
---|---|
date | Fri, 11 Jun 2004 01:21:35 +0900 |
parents | a86612cf1a19 |
children | 38c9976863b7 |
files | Changes Makefile mc-parse.c |
diffstat | 3 files changed, 21 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Thu Jun 10 19:09:36 2004 +0900 +++ b/Changes Fri Jun 11 01:21:35 2004 +0900 @@ -4867,3 +4867,7 @@ struct partial field init は、できたんだけど、局所変数の場合 は、不定の部分を0にしているみたいね。つまり、static にとって、 コピーしているみたいね。これは標準的なセマンティクスなのかな? + +やっぱり、重複した初期化は許されないのが普通なのか。 + +skipspc()=='.' だとコメントがスキップされない。ふーむ。
--- a/Makefile Thu Jun 10 19:09:36 2004 +0900 +++ b/Makefile Fri Jun 11 01:21:35 2004 +0900 @@ -73,6 +73,7 @@ make check TARGET=test/obsf make check TARGET=test/long make check TARGET=test/tstdarg + make check TARGET=test/strinit make check TARGET=test/code-gen-all #MK =-make MK=
--- a/mc-parse.c Thu Jun 10 19:09:36 2004 +0900 +++ b/mc-parse.c Fri Jun 11 01:21:35 2004 +0900 @@ -16,7 +16,7 @@ static int append3(int p,int a1,int a2); static int binop(int op, int e1, int e2, int t1, int t2); static int cexpr(int e); -static int decl_data(int t, NMTBL *n,int offset); +static int decl_data(int t, NMTBL *n,int offset,int skip); static int digit(char c); static int expr(int); static int expr0(void); @@ -1013,7 +1013,7 @@ if(sym==ASS) { if (n->dsp==-1) error(-1); // already initialized conv->op_(sym); - decl_data(type,n,0); + decl_data(type,n,0,0); emit_data_closing(n); /* gpc is incremented by emit_data */ } else @@ -1091,7 +1091,7 @@ n->dsp = ndsp; if(sym==ASS) { conv->op_(sym); - decl_data(type,n,0); + decl_data(type,n,0,0); } return n; default: @@ -1139,7 +1139,7 @@ (n->sc==REGISTER||n->sc==DREGISTER||n->sc==FREGISTER||n->sc==LREGISTER)? list3(n->sc,n->dsp,(int)n): list2(LVAR,n->dsp+offset), - e,t,t); + e,t,type); init_vars = list2(ass,init_vars); } else if(mode==SFDINIT) { decl_str_init=insert_ascend(decl_str_init, @@ -1170,6 +1170,8 @@ return; } if (mode==LDECL && LOCAL_STRUCT_INIT_STATIC) { + // uninitialized part should be 0. + // local var init cannot postponed because of assign_expr0/type local_struct.nm = new_static_name("_lstrcut"); local_struct.sc = STATIC; mode=STADECL; @@ -1184,21 +1186,22 @@ mode=SFDINIT; t1 = caddr(type); /* list of fields */ while(1) { - if (skipspc()=='.') { /* struct/union field initializaer */ - getsym(0); // skip period + getsym(0); + if (sym==PERIOD) { /* struct/union field initializaer */ getsym(0); if (sym==IDENT) { t1 = search_struct_type(type,nptr->nm,&foffset); getsym(0); if (sym==ASS) { - decl_data(t1,n,foffset); + decl_data(t1,n,foffset,0); } else error(TYERR); /* should be initialization error */ } else error(TYERR); /* should be initialization error */ } else { if(!t1) error(-1); - offset = decl_data(car(t1),n,offset); /* alignment? */ + // next decl_data must skip getsym + offset = decl_data(car(t1),n,offset,1); /* alignment? */ t1 = cadr(t1); } if ( t1 && sym==COMMA) { conv->comma_(); continue; } @@ -1226,14 +1229,14 @@ } static int -decl_data(int t, NMTBL *n,int offset) +decl_data(int t, NMTBL *n,int offset,int skip) { int t1,e,i,mode_save; conv->decl_data_(); mode_save = mode; mode=STAT; - getsym(0); + if (!skip) getsym(0); if (sym==RC) { /* premature end (not necessary?) */ conv->decl_data_end_(); mode = mode_save; @@ -1243,13 +1246,13 @@ mode = mode_save; if(car(e)!=CONST && t==CHAR) error(TYERR); - offset = assign_data(rvalue(e),t,n,offset); + offset = assign_data(e,t,n,offset); type=t; return offset; } else if (t==FLOAT||t==DOUBLE||t==LONGLONG||t==ULONGLONG) { e=expr1(); mode = mode_save; - offset = assign_data(rvalue(e),t,n,offset); + offset = assign_data(e,t,n,offset); type=t; return offset; } else if ((t1 = car(t)) && t1==ARRAY) { @@ -1259,7 +1262,7 @@ t1 = cadr(t); for(i=0;;i++) { if (sym!=RC) - offset=decl_data(t1,n,offset); /* array of some thing */ + offset=decl_data(t1,n,offset,0); /* array of some thing */ if (sym==COMMA) { conv->comma_(); continue;