# HG changeset patch # User kono # Date 1046070270 -32400 # Node ID 3b5d293cea36e0a4a5b4306582168e3533663f98 # Parent be313430f90b19fcb47d2c1852f84c5dd3596516 type def etc diff -r be313430f90b -r 3b5d293cea36 Changes --- a/Changes Mon Feb 24 11:59:26 2003 +0900 +++ b/Changes Mon Feb 24 16:04:30 2003 +0900 @@ -1739,3 +1739,10 @@ うーむ、これはなかなか難しい。全サーチ してもいいんじゃないかな。遅いけど。 +少なくともgnptrで定義されたものはサーチすべきでしょう。 + +indirect function type の表現がなぁ.... + +sdecl ではconv を行うので、type_print ではsdeclを経由した場合に +表示を行ってはいけない。 + diff -r be313430f90b -r 3b5d293cea36 conv/c.c --- a/conv/c.c Mon Feb 24 11:59:26 2003 +0900 +++ b/conv/c.c Mon Feb 24 16:04:30 2003 +0900 @@ -132,17 +132,17 @@ void dowhile_(){ - + fprintf(vout,"do"); } void dowhile_cond_(){ - + fprintf(vout,"while("); } void dowhile_end_(){ - + fprintf(vout,");"); } int @@ -194,6 +194,7 @@ function_(NMTBL *n,int args){ type_print(n->ty,0,vout); fprintf(vout,"%s(",n->nm); + args=reverse0(args); while(args) { n=(NMTBL *)car(args); type_print(n->ty,n,vout); @@ -210,7 +211,7 @@ void goto_(){ - + fprintf(vout,"goto"); } void @@ -283,7 +284,7 @@ void label_(){ - + fprintf(vout,"%s:",nptr->nm); } void @@ -354,6 +355,13 @@ void return_type_(int t,NMTBL *nptr,int cont){ if (cont) { + /* type print に cont の機能を持たせるべきだよね + cont の場合は、配列/関数/ポインタまでは無視する(?) + (int(*)) a,*b; みたいな場合は? (えぇ?) + ってことは、context で、どこまで表示したかを覚えて + おく必要がある? もっとも自分で表示してしまった + はずだから、それを覚えていれば良いだけだけどね。 + */ while (t>0&&car(t)==POINTER) { fprintf(vout,"*"); t=cadr(t); @@ -366,6 +374,11 @@ fprintf(vout,"[%d]",caddr(t)); t=cadr(t); } + if (t>0&&car(t)==FUNCTION) { + fprintf(vout,"("); + type_print(cadr(t),0,vout); + fprintf(vout,")"); + } } else type_print(t,nptr,vout); } diff -r be313430f90b -r 3b5d293cea36 mc-parse.c --- a/mc-parse.c Mon Feb 24 11:59:26 2003 +0900 +++ b/mc-parse.c Mon Feb 24 16:04:30 2003 +0900 @@ -98,6 +98,7 @@ Converter *conv = &c_converter; static char *ccout = 0; +static int stypedecl; int main(int argc, char **argv) @@ -356,7 +357,6 @@ { NMTBL *n; int t; - int typedef_f=0; if (mode==GDECL) typedefed=0; if(sym==STATIC) { @@ -382,7 +382,6 @@ conv->extern_(); stmode=EXTRN; } else if(sym==TYPEDEF) { - typedef_f=1; if(mode==GDECL) { getsym(); conv->typedef_(); @@ -396,7 +395,7 @@ } if((t=typespec())==0) return; if(sym==SM) { - conv->return_type_(t,0,typedef_f); + conv->return_type_(t,0,stypedecl); conv->sm_(); return; } type=t; @@ -413,7 +412,7 @@ fdecl(n); return; } else error(TYERR); } - conv->return_type_(type,n,typedef_f);typedef_f=0; + conv->return_type_(type,n,stypedecl); def(n); while(sym==COMMA) { conv->comma_(); @@ -438,6 +437,7 @@ typespec(void) { int t; + stypedecl = 0; while (sym==KONST) { getsym(); @@ -470,12 +470,12 @@ if(sym==IDENT) { if(nptr->sc==TYPE) { t=nptr->ty; - typedefed=list2((int)nptr,typedefed); + typedefed=glist2((int)nptr,typedefed); getsym(); break; } else if(nptr->sc==EMPTY && gnptr->sc==TYPE) { t=gnptr->ty; - typedefed=list2((int)gnptr,typedefed); + gtypedefed=glist2((int)gnptr,gtypedefed); getsym(); break; } @@ -999,6 +999,7 @@ type0 = list4(s,disp,tags,0); } else error(DCERR); + stypedecl=1; disp=sdisp; mode=smode; return type0; @@ -1312,6 +1313,7 @@ if(sym==SM) { bexpr(e,1,clabel); lfree=slfree; + conv->sm_(); getsym(); } else { bexpr(e,0,blabel); @@ -1349,11 +1351,11 @@ bexpr(expr(0),1,l); lfree=slfree; checksym(RPAR); + conv->dowhile_end_(); checksym(SM); fwddef(blabel); clabel=scontinue; blabel=sbreak; - conv->dowhile_end_(); } static void @@ -1372,16 +1374,20 @@ gexpr(expr(0)); checksym(SM); conv->for1_(); + } else { + conv->for1_(); + getsym(); } - else getsym(); lfree=slfree; l=backdef(); if(sym!=SM) { bexpr(expr(0),0,blabel); checksym(SM); conv->for2_(); + } else { + conv->for2_(); + getsym(); } - else getsym(); lfree=slfree; if(sym==RPAR) { clabel=l; @@ -1598,9 +1604,9 @@ error(TYERR); nptr->sc = BLABEL; nptr->dsp = backdef(); + conv->label_(); getsym(); checksym(COLON); - conv->label_(); } int @@ -2092,10 +2098,11 @@ conv->lpar_(); if(typeid(getsym())) { t=typename(); + conv->return_type_(t,0,0); + conv->rpar_(); checksym(RPAR); e1=expr13(); type=t; - conv->rpar_(); return e1; } e1=expr0(); diff -r be313430f90b -r 3b5d293cea36 mc-tree.c --- a/mc-tree.c Mon Feb 24 11:59:26 2003 +0900 +++ b/mc-tree.c Mon Feb 24 16:04:30 2003 +0900 @@ -285,9 +285,8 @@ } NMTBL * -typedef_search(type) +typedef_search(t,type) { - int t = typedefed; while(t) { if (((NMTBL*)car(t))->ty==type) return (NMTBL*)car(t); @@ -301,8 +300,11 @@ int t; tree_node_type *tn; NMTBL *td; + int args; - if(typedefed && (td=typedef_search(type))) { + if((td=typedef_search(typedefed,type))) { + fprintf(out,"%s ",td->nm); + } else if((td=typedef_search(gtypedefed,type))) { fprintf(out,"%s ",td->nm); } else if (type<0) { t=type; @@ -330,12 +332,32 @@ } else if(t==POINTER) { t=cadr(type); if(car(t)==FUNCTION) { + type_print(cadr(t),0,out); + fprintf(out,"(*"); + if(n) fprintf(out,"%s",n->nm); + fprintf(out,")"); fprintf(out,"("); - type_print(t,0,out); + if((args=caddr(t))) { + while (args) { + type_print(car(args),0,out); + args=cadr(args); + if (args) fprintf(out,","); + } + } fprintf(out,")"); - } else + return; + } else if(car(t)==ARRAY) { + fprintf(out,"(*"); + type_print(cadr(t),n,out); + if (caddr(type)) + fprintf(out,")[%d]",caddr(type)); + else + fprintf(out,")[]"); + return; + } else { type_print(t,0,out); - fprintf(out,"*"); + fprintf(out,"*"); + } } } if(n) fprintf(out,"%s",n->nm); diff -r be313430f90b -r 3b5d293cea36 mc.h --- a/mc.h Mon Feb 24 11:59:26 2003 +0900 +++ b/mc.h Mon Feb 24 16:04:30 2003 +0900 @@ -207,7 +207,7 @@ EXTERN NMTBL ntable[GSYMS+LSYMS]; EXTERN NMTBL *nptr,*gnptr; EXTERN NMTBL *fnptr; -EXTERN int typedefed; +EXTERN int typedefed,gtypedefed; EXTERN struct {int fd,ln;char *name0;FILE *fcb;} *filep,filestack[FILES]; EXTERN char cheap[CHEAPSIZE];