Mercurial > hg > CbC > old > device
changeset 70:2e84590720a6
typedef name
author | kono |
---|---|
date | Mon, 24 Feb 2003 11:42:53 +0900 |
parents | dba8d111b7a0 |
children | be313430f90b |
files | Changes conv/c.c mc-parse.c mc-tree.c mc.h |
diffstat | 5 files changed, 57 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Mon Feb 24 10:13:29 2003 +0900 +++ b/Changes Mon Feb 24 11:42:53 2003 +0900 @@ -1730,3 +1730,12 @@ strings の\nなどを元に戻す必要がある。 なんか括弧がわやになってるな。 + +Mon Feb 24 11:02:07 JST 2003 + +typedef されたタイプは、そちらを使う方が良い。 +けど、情報が失われてしまっているので、 +どこかにとっておかないとだめだね。dsp ? + +うーむ、これはなかなか難しい。全サーチ +してもいいんじゃないかな。遅いけど。
--- a/conv/c.c Mon Feb 24 10:13:29 2003 +0900 +++ b/conv/c.c Mon Feb 24 11:42:53 2003 +0900 @@ -348,12 +348,16 @@ void return_end_(){ + fprintf(vout,";"); } - void return_type_(int t,NMTBL *nptr,int cont){ if (cont) { + while (t>0&&car(t)==POINTER) { + fprintf(vout,"*"); + t=cadr(t); + } if(nptr) fprintf(vout,"%s",nptr->nm); while (t>0&&car(t)==ARRAY) { if(caddr(t)==0) @@ -397,6 +401,12 @@ } void +sdecl_(int s) +{ + fprintf(vout,s==UNION?"union ":"struct "); +} + +void while_(){ fprintf(vout,"while ("); }
--- a/mc-parse.c Mon Feb 24 10:13:29 2003 +0900 +++ b/mc-parse.c Mon Feb 24 11:42:53 2003 +0900 @@ -356,6 +356,8 @@ { NMTBL *n; int t; + int typedef_f=0; + if (mode==GDECL) typedefed=0; if(sym==STATIC) { if(mode==LDECL) { @@ -380,6 +382,7 @@ conv->extern_(); stmode=EXTRN; } else if(sym==TYPEDEF) { + typedef_f=1; if(mode==GDECL) { getsym(); conv->typedef_(); @@ -393,7 +396,7 @@ } if((t=typespec())==0) return; if(sym==SM) { - conv->return_type_(t,0,0); + conv->return_type_(t,0,typedef_f); conv->sm_(); return; } type=t; @@ -410,7 +413,7 @@ fdecl(n); return; } else error(TYERR); } - conv->return_type_(type,n,0); + conv->return_type_(type,n,typedef_f);typedef_f=0; def(n); while(sym==COMMA) { conv->comma_(); @@ -467,10 +470,12 @@ if(sym==IDENT) { if(nptr->sc==TYPE) { t=nptr->ty; + typedefed=list2((int)nptr,typedefed); getsym(); break; } else if(nptr->sc==EMPTY && gnptr->sc==TYPE) { t=gnptr->ty; + typedefed=list2((int)gnptr,typedefed); getsym(); break; } @@ -952,10 +957,13 @@ mode=(s==STRUCT?LSDECL:LUDECL); sdisp=disp; disp=0; + conv->sdecl_(s); if (getsym() == IDENT) { nptr0 = nptr; gnptr0 = gnptr; + conv->id_(sym,nptr); if (getsym() == LC) { + conv->lc_(); if (nptr0->sc != EMPTY) error(DCERR); nptr0->sc = TAG; tags = 0; @@ -964,6 +972,7 @@ decl(); tags = list3(type,tags,(int)nptr); } + conv->rc_(); getsym(); tags=reverse0(tags); heap[nptr0->ty+2]=tags; @@ -978,11 +987,13 @@ } type0 = list4(s,disp,tags,(int)nptr0); } else if(sym==LC) { + conv->lc_(); tags = 0; while(getsym() != RC) { decl(); tags = list3(type,tags,(int)nptr); } + conv->rc_(); getsym(); tags=reverse0(tags); type0 = list4(s,disp,tags,0); @@ -1018,6 +1029,7 @@ n->dsp = -n->dsp-caddr(t); } conv->code_(fnptr,arglist); + typedefed=0; /* local variable declaration */ stmode=0; mode=STAT; @@ -1062,6 +1074,7 @@ fnptr->dsp=reverse0(fnptr->dsp); } fdecl_struct(fnptr->ty); + typedefed=0; conv->function_(fnptr,arglist); conv->lc_(); disp=0; init_vars=0;
--- a/mc-tree.c Mon Feb 24 10:13:29 2003 +0900 +++ b/mc-tree.c Mon Feb 24 11:42:53 2003 +0900 @@ -284,11 +284,27 @@ fprintf(out,"%s",tn->tree_name); } +NMTBL * +typedef_search(type) +{ + int t = typedefed; + while(t) { + if (((NMTBL*)car(t))->ty==type) + return (NMTBL*)car(t); + t=cadr(t); + } + return 0; +} + void type_print(int type,NMTBL *n,FILE *out) { int t; tree_node_type *tn; - if (type<0) { + NMTBL *td; + + if(typedefed && (td=typedef_search(type))) { + fprintf(out,"%s ",td->nm); + } else if (type<0) { t=type; if (!(tn=find_node(t))) { error(-1); return; } fprintf(out,"%s ",tn->tree_name); @@ -306,7 +322,10 @@ return; } else if(t==ARRAY) { type_print(cadr(type),n,out); - fprintf(out,"[%d]",caddr(type)); + if (caddr(type)) + fprintf(out,"[%d]",caddr(type)); + else + fprintf(out,"[]"); return; } else if(t==POINTER) { t=cadr(type);
--- a/mc.h Mon Feb 24 10:13:29 2003 +0900 +++ b/mc.h Mon Feb 24 11:42:53 2003 +0900 @@ -207,6 +207,7 @@ EXTERN NMTBL ntable[GSYMS+LSYMS]; EXTERN NMTBL *nptr,*gnptr; EXTERN NMTBL *fnptr; +EXTERN int typedefed; EXTERN struct {int fd,ln;char *name0;FILE *fcb;} *filep,filestack[FILES]; EXTERN char cheap[CHEAPSIZE];