Mercurial > hg > CbC > old > device
changeset 897:66f32d0af4d2
local struct initialization target management in decl
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 07 Apr 2014 10:27:12 +0900 |
parents | d712ee10feb7 |
children | c073495301ae |
files | mc-parse.c |
diffstat | 1 files changed, 28 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-parse.c Sun Apr 06 19:20:58 2014 +0900 +++ b/mc-parse.c Mon Apr 07 10:27:12 2014 +0900 @@ -51,7 +51,7 @@ extern double strtod(const char *nptr, char **endptr); #endif -int parse_mode = 0; // generate parse tree for all code +int parse_mode = 1; // generate parse tree for all code static int HEAP_REPORT = 0; static int lfree_type_limit; // debugging purpose @@ -187,6 +187,7 @@ static void statement(int); static int typename(void); static int decl_data_field(int type,int v,int offset); +static int decl_data_def(NMTBL *n, int t, int v,int offset,int skip); static int decl_data(int t, int v,int offset,int skip); static int typeid(int s); extern NMTBL * get_name_from_chptr(); @@ -967,8 +968,7 @@ v = list3n(n->sc,n->dsp,n); if (sym==ASS && n!=&null_nptr) { conv->op_(sym); - local_nptr = n; local_struct_offset = 0; - init = decl_data(type,v,0,0); data_closing(v); + init = decl_data_def(n, type,v,0,0); data_closing(v); } if (inmode && (mode==LDECL||mode==LLDECL||mode==STADECL)) { parse = list5n(ST_DECL,parse,list3(mode,stmode,ctmode),init,n); @@ -990,8 +990,7 @@ v = list3n(n->sc,n->dsp,n); if (sym==ASS && n!=&null_nptr) { conv->op_(sym); - local_nptr = n; local_struct_offset = 0; - init = decl_data(type,v,0,0);data_closing(v); + init = decl_data_def(n, type,v,0,0);data_closing(v); } if (inmode && mode==LDECL) { parse = list5n(ST_DECL,parse, @@ -1728,6 +1727,18 @@ */ static int +decl_data_def(NMTBL *n, int t, int v,int offset,int skip) +{ + NMTBL *slocal_nptr = local_nptr; + local_nptr = n; + int slocal_struct_offset = local_struct_offset ; + int e = decl_data(t,v,offset,skip); + local_struct_offset = slocal_struct_offset ; + local_nptr = slocal_nptr; + return e; +} + +static int decl_data(int t, int v,int offset,int skip) { int t0,t1=0,e,i,mode_save,lc=0; @@ -4145,11 +4156,11 @@ int local_offset; if (mode==GDECL||inmode) { int e2,e3; - e1 = size(type); + int sz = size(type); e2 = list3n(GVAR,0,nptr0); e3 = decl_data_field(type,e2,0); if (!inmode) { - e1 = list3(RSTRUCT,e2,e1); + e1 = list3(RSTRUCT,e2,sz); } else { e1 = reverse0(e3); e1 = list3(DECL_DATA,e1,t); @@ -4157,6 +4168,8 @@ } } else { if (!local_nptr) { + // struct initialization for this variable + // (struct hoge) { .fuga = 5 } local_nptr = nptr0; int smode = mode; mode = LDECL; def(nptr0,0); @@ -4170,16 +4183,23 @@ local_offset = local_struct_offset; int offset = decl_data_field(type,e1,local_struct_offset); if (offset==local_struct_offset) { + // empty case, let's zero clear now int sz = size(type); zfill(e1,offset,sz); local_struct_offset = offset + sz; - } + } else + local_struct_offset = offset; #endif } if (mode==STAT && decl_str_init) gen_delayed_decl_data(e1,local_offset); if (init_vars && mode!=LDECL) { emit_init_vars(); } + if (nptr0==local_nptr) { + // I have created this, sanitize + local_nptr = 0; + local_struct_offset = 0; + } conv->rc_(); checksym(RC); type = t;