Mercurial > hg > CbC > old > device
changeset 564:25f431685d80
*** empty log message ***
author | kono |
---|---|
date | Tue, 10 Jan 2006 16:30:43 +0900 |
parents | 588bb765b301 |
children | dbe0b9ac9f53 |
files | Changes conv/c.c conv/c.h conv/null.c conv/null.h conv_func.tbl mc-macro.c mc-parse.c mc-tree.c |
diffstat | 9 files changed, 98 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Tue Jan 10 10:28:55 2006 +0900 +++ b/Changes Tue Jan 10 16:30:43 2006 +0900 @@ -8139,3 +8139,12 @@ それをdefaultにするべきか? inline のst_switch は、もっと賢くあるべき。 + +Tue Jan 10 11:30:33 JST 2006 + +parse tree base で変換するなら、binop を通すのはまずい。 + +binop では、式と型の組みで持たないとだめ? その方が +良いはず。 + +う、あっさり、converter も動いたか。
--- a/conv/c.c Tue Jan 10 10:28:55 2006 +0900 +++ b/conv/c.c Tue Jan 10 16:30:43 2006 +0900 @@ -25,7 +25,7 @@ open_(char *s) { char *p; - p = make_filename_with_extension(s,".cc"); + p = make_filename_with_extension(s,"cc"); #if 1 vout = fopen(p,"w"); #else @@ -194,7 +194,7 @@ void function_(NMTBL *n,int cont){ int args; - type_print1(n->ty,0,vout,cont); + type_print1(cadr(n->ty),0,vout,cont); fprintf(vout,"%s(",n->nm); args=n->dsp; while(args) { @@ -226,7 +226,8 @@ void id_(int sym,NMTBL *nptr){ - fprintf(vout,"%s",nptr->nm); + char *p = nptr->nm; + for(;*p && *p!='.';p++) fputc(*p,vout); } void @@ -236,7 +237,10 @@ while((c=*s++)) { if(c=='\n') fprintf(vout,"\\n"); else if(c=='\r') fprintf(vout,"\\r"); + else if(c=='\t') fprintf(vout,"\\t"); else if(c=='\e') fprintf(vout,"\\e"); + else if(c=='"') fprintf(vout,"\\\""); + else if(c=='\\') fprintf(vout,"\\\\"); else if(!(' '<=c&&c<=0x7f)) fprintf(vout,"\\%03o",c); else fprintf(vout,"%c",c); } @@ -392,6 +396,11 @@ } void +type_(int t){ + type_print(t,0,vout); +} + +void sdecl_(int s) { fprintf(vout,s==UNION?"union ":"struct ");
--- a/conv/c.h Tue Jan 10 10:28:55 2006 +0900 +++ b/conv/c.h Tue Jan 10 16:30:43 2006 +0900 @@ -71,6 +71,7 @@ &switch_body_, &switch_end_, &typedef_, + &type_, &while_, &while_body_, &while_end_,
--- a/conv/null.c Tue Jan 10 10:28:55 2006 +0900 +++ b/conv/null.c Tue Jan 10 16:30:43 2006 +0900 @@ -271,6 +271,10 @@ { } static void +type_() +{ } + +static void while_() { }
--- a/conv/null.h Tue Jan 10 10:28:55 2006 +0900 +++ b/conv/null.h Tue Jan 10 16:30:43 2006 +0900 @@ -71,6 +71,7 @@ &switch_body_, &switch_end_, &typedef_, + &type_, &while_, &while_body_, &while_end_,
--- a/conv_func.tbl Tue Jan 10 10:28:55 2006 +0900 +++ b/conv_func.tbl Tue Jan 10 16:30:43 2006 +0900 @@ -64,6 +64,7 @@ void switch_body_(); void switch_end_(); void typedef_(); +void type_(); void while_(); void while_body_(); void while_end_();
--- a/mc-macro.c Tue Jan 10 10:28:55 2006 +0900 +++ b/mc-macro.c Tue Jan 10 16:30:43 2006 +0900 @@ -60,7 +60,10 @@ macropp = cheap->ptr; // append result override, working cheap, but it's OK. mappend0(reverse0(macrop),¯opp); - cheap->ptr[-1] ='\n'; // makes some tokenize happy + // cheap->ptr[-1] ='\n'; // makes some tokenize happy + // ## macro_result needs \n at end + cheap->ptr[-1] = 0; // makes some tokenize happy + t = cheap->ptr-2; cheap->ptr[0] =0; cheap = increment_cheap(cheap,¯opp); while (mconcat) { @@ -82,13 +85,17 @@ } *t++=0; // evaluate generated result again -if (lsrc) printf("### %s",macropp); +if (lsrc) { + printf("### %s\n",macropp); + if (t[-2]!='\n') putchar('\n'); +} macrop=macro_eval(macrop,macropp,0); cheap = reset_cheap(&scheap); macropp = cheap->ptr; // will not override evaled list mappend0(reverse0(macrop),¯opp); - cheap->ptr[-1] ='\n'; + // cheap->ptr[-1] ='\n'; + cheap->ptr[-1] =0; cheap->ptr[0] =0; cheap = increment_cheap(cheap,¯opp); } @@ -96,7 +103,10 @@ // genrated macro will be overwrited by cheap, but it's OK, again mconcat = 0; set_lfree(slfree); - if (lsrc && !asmf && nptrm->sc==FMACRO) gen_comment(macropp); + if (lsrc && !asmf && nptrm->sc==FMACRO) { + gen_comment(macropp); + if (t[-2]!='\n') putchar('\n'); + } // push previous chptr, and change it to the generate macro chptrsave = glist2((int)chptr,chptrsave); chsave = glist2(ch,chsave);
--- a/mc-parse.c Tue Jan 10 10:28:55 2006 +0900 +++ b/mc-parse.c Tue Jan 10 16:30:43 2006 +0900 @@ -863,6 +863,7 @@ parse = list4(ST_DECL,parse,(int)n,list3(mode,stmode,ctmode)); } if (sym==ASS && n!=&null_nptr) { + conv->op_(sym); decl_data(type,n,0,0); data_closing(n); } while(sym==COMMA) { @@ -882,6 +883,7 @@ parse = list4(ST_DECL,parse,(int)n,list3(mode,stmode,ctmode)); } if (sym==ASS && n!=&null_nptr) { + conv->op_(sym); decl_data(type,n,0,0);data_closing(n); } } @@ -1570,6 +1572,7 @@ return offset; } else if (t0>0 && (t1 = car(t0)) && t1==ARRAY) { if (sym==LC) { + conv->lc_(); conv->decl_data_begin_(); mode = mode_save; t1 = cadr(t); @@ -1581,6 +1584,7 @@ continue; } else if (sym==RC) { conv->decl_data_end_(); + conv->rc_(); if (caddr(t)==0) { /* size not defined */ caddr(t)=i+1; /* define array size */ } else if (caddr(t)!=i+1) { /* size match? */ @@ -2558,11 +2562,13 @@ getsym(0); // we have to make it global? c = cexpr(expr(1)); - if (!inmode && cst) + if (!inmode && cst) { clist |= (cadr(csvalue1)==c); - else + conv->case_(list2(c,0),0); + } else { clist=glist3(c,clist,inmode?0:l); - conv->case_(0,0); + conv->case_(clist,0); + } checksym(COLON); } if (cst && !clist) return; @@ -2936,11 +2942,12 @@ /* C expression */ extern int -expr(int noconv) +expr(int noconv) // noconv=1 suppress convsion output { int r; conv->noconv_(noconv); r=rvalue(expr0()); + if (noconv) conv->conv_(); return r; } @@ -3368,10 +3375,13 @@ case SIZEOF: conv->prefix_(sym); if(getsym(0)==LPAR) { + conv->lpar_(); if(typeid(getsym(0))) { - e=list2(CONST,size(typename())); + e=list2(CONST,size(t=typename())); type=INT; checksym(RPAR); + conv->type_(t); + conv->rpar_(); return e; } else { e=expr0(); @@ -3392,6 +3402,7 @@ error(TYERR); } } + conv->rpar_(); } } else expr13(); @@ -3652,12 +3663,13 @@ if(typeid(sym)) { t=typename(); - conv->return_type_(t,0,0); + conv->type_(t,0,0); conv->rpar_(); checksym(RPAR); if (sym==LC && (t>0 && (car(t)==STRUCT||car(t)==UNION))) { // initializer // q->lock = (spinlock_t) { }; + conv->lc_(); smode = mode; type = t; nptr0=new_static_name("__lstruct",'_'); @@ -3665,6 +3677,7 @@ def(nptr0,0); e1 = size(type); decl_data_field(type,nptr0,0); + conv->rc_(); checksym(RC); e1 = list3(RSTRUCT,list3(GVAR,0,(int)nptr0),e1); mode = smode; @@ -3707,8 +3720,8 @@ } } else { e1=expr0(); - conv->rpar_(); } + conv->rpar_(); checksym(RPAR); break; default:error(EXERR); e1=list2(CONST,0); @@ -3901,12 +3914,16 @@ { int t; int sctmode=ctmode; + int sd = sdecl_f; + sdecl_f = 0; ctmode=0; + sdecl_f = 0; type=t=typespec(); // undefine case? ctmode = sctmode; ndecl0(); reverse(t); + sdecl_f = sd; return type; }
--- a/mc-tree.c Tue Jan 10 10:28:55 2006 +0900 +++ b/mc-tree.c Tue Jan 10 16:30:43 2006 +0900 @@ -161,6 +161,21 @@ {AS+BOR,"|=","ee"}, }; +static int +attr_print(int t) +{ + while (t>0 && car(t)==ATTRIBUTE) { + switch (caddr(t)) { + case KONST: printf( "const"); break; + case VOLATILE: printf( "volatile"); break; + case RESTRICT: printf( "restrict"); break; + case INLINE: printf( "inline"); break; + } + t = cadr(t); + } + return t; +} + void tree_print_t(int e,int t) { @@ -315,6 +330,18 @@ return 0; } +static void n_attr_print(int attr, FILE *out) +{ + for(;attr;attr=cadr(attr)) { + switch(car(attr)) { + case INLINE: fprintf(out,"inline "); break; + case CONST: fprintf(out,"const "); break; + case VOLATILE: fprintf(out,"const "); break; + case RESTRICT: fprintf(out,"const "); break; + } + } +} + void type_print1(int type,NMTBL *n,FILE *out,int cont) { int t; @@ -322,6 +349,11 @@ NMTBL *td; int args; + if (n) { + if (n->attr) n_attr_print(n->attr,out); + while(type>0 && car(type)==ATTRIBUTE) type=cadr(type); + } else + type = attr_print(type); if(type>0&&(td=typedef_search(typedefed,type))) { if (!cont) fprintf(out,"%s ",td->nm);