Mercurial > hg > CbC > old > device
changeset 322:46ac55e8b14c
struct init by cast
author | kono |
---|---|
date | Sat, 19 Jun 2004 11:02:28 +0900 |
parents | 80beb03e5b73 |
children | d5cb084fc3f4 |
files | Changes mc-parse.c test/code-gen.c |
diffstat | 3 files changed, 58 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sat Jun 19 07:11:12 2004 +0900 +++ b/Changes Sat Jun 19 11:02:28 2004 +0900 @@ -5012,3 +5012,14 @@ とか。 + typedef struct __wait_queue wait_queue_t; + + struct __wait_queue { + unsigned int flags; + ... + }; + +って言う感じで typedef の struct が後だしジャンケンされてしまう。 +後ろの struct def は、typedef された型名を知りようがない。うん。 + +
--- a/mc-parse.c Sat Jun 19 07:11:12 2004 +0900 +++ b/mc-parse.c Sat Jun 19 11:02:28 2004 +0900 @@ -960,15 +960,15 @@ } } -char * -new_static_name(char *name) +static char * +new_static_name(char *name,int delimit) { int ndsp; char *p = cheapp; while((*cheapp++ = *name++)); ndsp = ++stat_no; - cheapp[-1] = '.'; + cheapp[-1] = delimit; while(ndsp>0) { *cheapp++ = ndsp%10+'0'; ndsp /= 10; @@ -1028,7 +1028,7 @@ nsc = STATIC; n->sc = nsc; if (stmode==LDECL) { - n->nm = new_static_name(n->nm); + n->nm = new_static_name(n->nm,'.'); } if(sym==ASS) { if (n->dsp==-1) error(-1); // already initialized @@ -1173,7 +1173,6 @@ #define LOCAL_STRUCT_INIT_STATIC 1 -static NMTBL local_struct; static void decl_data_field(int type,NMTBL *n,int offset) @@ -1183,6 +1182,7 @@ int offset0 = offset; int decl_str_init_save = decl_str_init; int mode_save=mode; + NMTBL *nptr0; decl_str_init = 0; if(cadr(type)==-1) { @@ -1192,14 +1192,15 @@ 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; + nptr0=lsearch(new_static_name("__lstruct",'_'),0); + nptr0->sc = GVAR; + e = size(type); + nptr0->ty = type; mode=STADECL; - decl_data_field(type,&local_struct,offset); - e = size(type); + decl_data_field(type,nptr0,offset); init_vars = list2( list4(STASS,list2(LVAR,n->dsp+offset), - list3(RSTRUCT,list2(GVAR,(int)&local_struct),e),e), + list3(RSTRUCT,list2(GVAR,(int)nptr0),e),e), init_vars); return; } @@ -1219,7 +1220,10 @@ } else error(TYERR); /* should be initialization error */ } else { - if(!t1) error(-1); + if(!t1) { + // empty field case (it can happen...) + break; + } // next decl_data must skip getsym offset = decl_data(car(t1),n,offset,1); /* alignment? */ t1 = cadr(t1); @@ -1248,6 +1252,8 @@ decl_str_init = decl_str_init_save; } +// data strucutre initialization + static int decl_data(int t, NMTBL *n,int offset,int skip) { @@ -2191,6 +2197,7 @@ nptr0 = (NMTBL *)cadr(e1); t = nptr0->sc; if (t==EMPTY||t==EXTRN1||t==EXTRN) { + nptr0->sc=EMPTY; nptr0=lsearch(nptr0->nm,0); nptr0->sc = FLABEL; jmp(nptr0->dsp = fwdlabel()); @@ -2242,6 +2249,7 @@ fwddef(nptr->dsp); else if(nptr->sc != EMPTY && nptr->sc != EXTRN1) error(TYERR); + nptr->sc=EMPTY; nptr1=lsearch(nptr->nm,0); nptr1->sc = BLABEL; nptr1->dsp = backdef(); @@ -3034,7 +3042,8 @@ static int expr14(void) { - int e1=0,t,t1; + int e1=0,t,t1,smode; + NMTBL *nptr0; switch(sym) { case IDENT: @@ -3158,6 +3167,21 @@ conv->return_type_(t,0,0); conv->rpar_(); checksym(RPAR); + if (sym==LC && (t>0 && (car(t)==STRUCT||car(t)==UNION))) { + // q->lock = (spinlock_t) { }; + smode = mode; + type = t; + nptr0=lsearch(new_static_name("__lstruct",'_'),0); + nptr0->sc = GVAR; + e1 = size(type); + nptr0->ty = type; + mode=STADECL; + decl_data_field(type,nptr0,0); + checksym(RC); + e1 = list3(RSTRUCT,list2(GVAR,(int)nptr0),e1); + mode = smode; + return e1; + } e1=expr13(); if (integral(t)) { if(t==UNSIGNED) e1=unsigned_value(e1,type);
--- a/test/code-gen.c Sat Jun 19 07:11:12 2004 +0900 +++ b/test/code-gen.c Sat Jun 19 11:02:28 2004 +0900 @@ -35,6 +35,17 @@ printf("code_label done\n"); } +// code_label(int labelno) +void +code_label1() +{ + goto hoge; +hage: + goto hage; +hoge: + printf("code_label1 done\n"); +} + // code_gvar(int e1,int creg) // code_rgvar(int e1,int creg) // code_crgvar(int e1,int creg,int sign,int sz)