changeset 67:254a0c576114

argument type list
author kono
date Mon, 24 Feb 2003 00:59:30 +0900
parents 0b068058dd67
children 0266905063b5
files .gdbinit Changes Makefile conv/c.c mc-parse.c mc-tree.c mc.h
diffstat 7 files changed, 445 insertions(+), 219 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Sat Feb 22 01:32:47 2003 +0900
+++ b/.gdbinit	Mon Feb 24 00:59:30 2003 +0900
@@ -12,6 +12,6 @@
 regs
 x/1i $eip
 end
-b error
 b errmsg
-r -s test/arg.c
+r -s -ob00.s -Cc mc-parse.c
+
--- a/Changes	Sat Feb 22 01:32:47 2003 +0900
+++ b/Changes	Mon Feb 24 00:59:30 2003 +0900
@@ -1194,6 +1194,7 @@
 これと同じようにするならば、regiterの使用数を最初に調べる必要が
 あるのだけど、one path compiler である micro-C では、それは
 できない。したがって、enter は後ろでする方が良い。
+
 Mon Jan 20 18:25:27 JST 2003
 
 3年間さわってないのかよ。何やってんだ?
@@ -1700,3 +1701,26 @@
 
 まぁいいけど.. chk を無視しているところが結構あるんですけど。
 jmp,enter,leave ...
+
+Sat Feb 22 13:05:04 JST 2003
+
+type の印刷かぁ...
+
+conv 系は大半はdefault convが呼ばれる。なので、c.c
+っていうよりは、default.cだよね。必要なところだけ、
+自分で代入すると言う方法が良いだろう。その方が
+ヘッダも一つで済むし。もちろん、object 指向なら
+簡単なんだが...
+
+
+Sun Feb 23 19:47:41 JST 2003
+
+struct のtypeを印刷するんだけど、一回印刷したら、あとは印刷
+しない方が良い。逆に毎回書くなら、tag名type名は、いらないの
+か。
+
+とするとtypeの解釈はやめてndeclで処理する? 印刷では、それで
+いいわけだけど。
+
+このタイプの印刷だと再帰型は印刷が終了しないんじゃないか?
+しないね。
--- a/Makefile	Sat Feb 22 01:32:47 2003 +0900
+++ b/Makefile	Mon Feb 24 00:59:30 2003 +0900
@@ -14,15 +14,23 @@
 	$(CC) -g mc-parse.o mc-codegen.o mc-code-ia32.o \
 		mc-tree.o $(CONVERTER) -o $@
 
+conv/conv.h: conv_func.tbl
+	perl conv_func.pl
+conv/convdef.h: conv_func.tbl
+	perl conv_func.pl
+
 tar :
 	make clean
 	tar cBf - . | gzip > ../comp.tgz 
 
 depend :
-	makedepend mc-parse.c mc-nop-386.c mc-tree.c
+	makedepend mc-code-ia32.c mc-code.h mc-codegen.c mc-codegen.h \
+		mc-parse.c mc-tree.c mc.h \
+	    conv/c.c conv/c.h conv/c2cbc.c conv/c2cbc.h conv/cbc2c.c \
+	    conv/cbc2c.h conv/conv.h conv/convdef.h conv/null.c conv/null.h
 
 clean :
-	-rm -f *.s *.o mc mc1 a.out *~ core* */*.o
+	-rm -f *.s *.o mc mc1 a.out *~ core* */*.o *.bak
 
 mc1 : b00.s b01.s mc-codegen.o mc-tree.o $CONVERTER
 	$(CC) -g -o $@ $(PRINTF) b00.s b01.s mc-codegen.o mc-tree.o $CONVERTER
@@ -38,8 +46,60 @@
 diff :  b00.s b01.s b10.s b11.s
 	-diff b00.s b10.s
 	-diff b01.s b11.s
+
 # DO NOT DELETE
 
-mc-parse.o: mc.h stdio.h
-mc-nop-386.o: mc.h stdio.h
-mc-tree.o: mc.h stdio.h
+mc-code-ia32.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+mc-code-ia32.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+mc-code-ia32.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+mc-code-ia32.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+mc-code-ia32.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+mc-code-ia32.o: conv/conv.h conv/c.h mc-codegen.h
+mc-codegen.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+mc-codegen.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+mc-codegen.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+mc-codegen.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+mc-codegen.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+mc-codegen.o: conv/conv.h conv/c.h mc-codegen.h mc-code.h
+mc-parse.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+mc-parse.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+mc-parse.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+mc-parse.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+mc-parse.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+mc-parse.o: conv/conv.h conv/c.h mc-codegen.h
+mc-tree.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+mc-tree.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+mc-tree.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+mc-tree.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+mc-tree.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+mc-tree.o: conv/conv.h conv/c.h
+mc.o: /usr/include/stdio.h /usr/include/sys/types.h
+mc.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+mc.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+mc.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+mc.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h conv/conv.h
+mc.o: conv/c.h
+conv/c.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+conv/c.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+conv/c.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+conv/c.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+conv/c.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h conv/conv.h
+conv/c.o: conv/c.h conv/convdef.h
+conv/c2cbc.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+conv/c2cbc.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+conv/c2cbc.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+conv/c2cbc.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+conv/c2cbc.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+conv/c2cbc.o: conv/conv.h conv/c.h
+conv/cbc2c.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+conv/cbc2c.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+conv/cbc2c.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+conv/cbc2c.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+conv/cbc2c.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+conv/cbc2c.o: conv/conv.h conv/c.h
+conv/null.o: mc.h /usr/include/stdio.h /usr/include/sys/types.h
+conv/null.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h
+conv/null.o: /usr/include/machine/types.h /usr/include/ppc/types.h
+conv/null.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h
+conv/null.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h
+conv/null.o: conv/conv.h conv/c.h
--- a/conv/c.c	Sat Feb 22 01:32:47 2003 +0900
+++ b/conv/c.c	Mon Feb 24 00:59:30 2003 +0900
@@ -7,8 +7,9 @@
 static FILE *vout;
 
 static void
-comment_(char *s)
+comment_(int c)
 {
+    fprintf(vout,"%c",c);
 }
 
 static void
@@ -39,8 +40,16 @@
 }
 
 void
+case_begin_(int cases,int def){
+    fprintf(vout,"case ");
+}
+
+void
 case_(int cases,int def){
-
+    if (def)
+	fprintf(vout,"default:");
+    else
+	fprintf(vout,":");
 }
 
 void
@@ -55,7 +64,7 @@
 
 void
 comma_(){
-
+    fprintf(vout,",");
 }
 
 void
@@ -90,7 +99,6 @@
 
 void
 def_(NMTBL *n){
-
 }
 
 void
@@ -114,13 +122,8 @@
 }
 
 void
-expr16_end_(){
-
-}
-
-void
 extern_(){
-
+    fprintf(vout,"extern ");
 }
 
 void
@@ -219,13 +222,33 @@
 }
 
 void
+lpar_(){
+    fprintf(vout,"(");
+}
+
+void
+rpar_(){
+    fprintf(vout,")");
+}
+
+void
 lbra_(int sym){
+    fprintf(vout,"[");
+}
 
+void
+rbra_(int sym){
+    fprintf(vout,"]");
 }
 
 void
 lc_(){
+    fprintf(vout,"{");
+}
 
+void
+rc_(){
+    fprintf(vout,"}");
 }
 
 void
@@ -234,11 +257,6 @@
 }
 
 void
-lpar_(){
-
-}
-
-void
 op_(int sym){
 
 }
@@ -254,18 +272,8 @@
 }
 
 void
-rbra_(int sym){
-
-}
-
-void
-rc_(){
-
-}
-
-void
 register_(){
-
+    fprintf(vout,"register ");
 }
 
 void
@@ -278,24 +286,31 @@
 
 }
 
-void
-return_type_(int t){
-
-}
+extern void type_print(int type,NMTBL *nptr,FILE *out);
 
 void
-rpar_(){
-
+return_type_(int t,NMTBL *nptr,int cont){
+    if (cont) {
+	if(nptr) fprintf(vout,"%s",nptr->nm);
+	while (t>0&&car(t)==ARRAY) {
+	    if(caddr(t)==0)
+		fprintf(vout,"[]");
+	    else
+		fprintf(vout,"[%d]",caddr(t));
+	    t=cadr(t);
+	}
+    } else
+	type_print(t,nptr,vout);
 }
 
 void
 sm_(){
-
+    fprintf(vout,";");
 }
 
 void
 static_(){
-
+    fprintf(vout,"static ");
 }
 
 void
@@ -315,7 +330,7 @@
 
 void
 typedef_(){
-
+    fprintf(vout,"typedef ");
 }
 
 void
--- a/mc-parse.c	Sat Feb 22 01:32:47 2003 +0900
+++ b/mc-parse.c	Mon Feb 24 00:59:30 2003 +0900
@@ -310,6 +310,7 @@
 	ccout=0;
     }
     opening(filep->name0);
+    conv->open_(filep->name0);
 }
 
 static void
@@ -389,8 +390,8 @@
 		error(DCERR);
     }
     if((t=typespec())==0) return;
-    conv->return_type_(t);
     if(sym==SM) {
+	conv->return_type_(t,0,0);
 	conv->sm_(); return;
     }
     type=t;
@@ -408,6 +409,7 @@
 	} else error(TYERR);
     }
     def(n);
+    conv->return_type_(type,n,0);
     while(sym==COMMA) {	
 	conv->comma_();
 	getsym();
@@ -417,6 +419,7 @@
 	if(n == &null_nptr) error(DCERR); 
 	/* if(args) error(DCERR); */
 	def(n);
+	conv->return_type_(type,n,1);
     }
     if(sym!=SM) error(DCERR);
     conv->sm_();
@@ -547,16 +550,17 @@
 		    adecl(n);
 		    stmode=0;
 		    n->sc=EMPTY;
-		    type=list3(CODE,type,cadr(n->ty));
+		    type=list3(CODE,type,n->dsp);
 		    return n;
 		} else {
 		    n->sc=FUNCTION;
 		    n->dsp=0;
+		    n->ty=type;
 		    adecl(n);
 		    n->sc=EMPTY;
 		}
 	    }
-	    type=list3(FUNCTION,type,cadr(n->ty));
+	    type=list3(FUNCTION,type,n->dsp);
 	} else 
 	    return n;
     }
@@ -575,20 +579,19 @@
     fnptr=n;
     sreg_var=reg_var;
     reg_var=0;
-    n->dsp=0;
     smode = mode;
     mode=ADECL;
     args = 0;
+    n->dsp=0;
     arglist = 0;
     for(;;) {	
 	if(sym==IDENT && nptr->sc!=TYPE) {
-	    rplacad(n->ty,glist2(INT,cadr(n->ty)));
 	    def(nptr);
 	    getsym();
 	    if(sym==RPAR) break;
 	} else {
 	    if(sym==DOTS) {
-		rplacad(n->ty,glist2(INT,cadr(n->ty)));
+		n->dsp=list2(DOTS,n->dsp);
 		getsym();
 		break;
 	    } 
@@ -601,16 +604,18 @@
 		type=t;
 		arg=decl0();
 		reverse(t);
-		if (arg != &null_nptr) { /* no varname typespec only */
-		    def(arg);
-		}
+		if (arg != &null_nptr) { 
+		    if (smode==GDECL) 
+			def(arg);
+		} else 
+		    n->dsp=list2(type,n->dsp);
 	    }
-	    rplacad(n->ty,glist2(t,cadr(n->ty)));
 	    if(sym==RPAR) break;
 	} 
 	if (sym!=COMMA) error(DCERR); 
 	getsym();
     }
+    n->dsp=reverse0(n->dsp);
     checksym(RPAR);
     mode=smode;
     reg_var=sreg_var;
@@ -671,11 +676,11 @@
 {
     int sz,nsc,ndsp,t;
 
+    conv->def_(n);
     if (n==0) {
 	n=free_nptr();
 	n->nm = "_";
     }
-    conv->def_(n);
     nsc=ndsp=0;
     if(car(type)==FUNCTION) {	
 	if (n->sc==EXTRN || (mode==GDECL)) {
@@ -737,6 +742,7 @@
 	break;
     case ADECL:
 	arglist = list3((int)n,arglist,0);
+	fnptr->dsp=list2(type,fnptr->dsp);
 	if (stmode==REGISTER && reg_var <MAX_REGISTER_VAR &&
 	    !(type!=CHAR && !scalar(type))) {
 	    n->sc = REGISTER;
@@ -950,10 +956,10 @@
 	    if (nptr0->sc != EMPTY) error(DCERR);
 	    nptr0->sc = TAG;
 	    tags = 0;
-	    nptr0->ty = list3(s,-1,tags);
+	    nptr0->ty = list4(s,-1,tags,(int)nptr0);
 	    while (getsym() != RC) {
 		decl();
-		tags = list2(type,tags);
+		tags = list3(type,tags,(int)nptr);
 	    }
 	    getsym();
 	    tags=reverse0(tags);
@@ -967,16 +973,16 @@
 	    tags = caddr(nptr0->ty);
 	    disp = cadr(nptr0->ty);
 	}
-	type0 = list3(s,disp,tags);
+	type0 = list4(s,disp,tags,(int)nptr0);
     } else if(sym==LC) {	
 	tags = 0;
 	while(getsym() != RC) {
 	    decl();
-	    tags = list2(type,tags);
+	    tags = list3(type,tags,(int)nptr);
 	}
 	getsym();
 	tags=reverse0(tags);
-	type0 = list3(s,disp,tags);
+	type0 = list4(s,disp,tags,0);
     }
     else error(DCERR);
     disp=sdisp;
@@ -1044,10 +1050,13 @@
     reg_var=0;
     fcheck(n);
     mode=ADECL;
-    if (sym!=LC) { args=0; arglist = 0; }
-    while (sym!=LC) { /* argument declaration !ANSI */
-	stmode=0;
-	decl(); getsym();
+    if (sym!=LC) { 
+	args=0; arglist = 0; fnptr->dsp=0;
+	while (sym!=LC) { /* argument declaration !ANSI */
+	    stmode=0;
+	    decl(); getsym();
+	}
+	fnptr->dsp=reverse0(fnptr->dsp);
     }
     fdecl_struct(fnptr->ty);
     conv->function_(fnptr,arglist);
@@ -1090,7 +1099,7 @@
     int type_save,mode_save,t,sz;
     NMTBL *n;
 
-    t = car(fntype);
+    t = fntype;
     if (!scalar(t) && (car(t)==STRUCT||car(t)==UNION)) {
 	mode_save = mode;
 	mode=ADECL;
@@ -1107,7 +1116,7 @@
 	    n->dsp += sz;
 	}
 	arglist = reverse0(arglist);
-	if ((t=size(car(fntype)))==-1) error(TYERR);
+	if ((t=size(fntype))==-1) error(TYERR);
 	else {
 	    args = 0;
 	    def(&str_ret);
@@ -1124,13 +1133,13 @@
 fcheck(NMTBL *n)
 {
     if(!(mode==GDECL||mode==ADECL)||car(type)!=FUNCTION) error(DCERR);
-    if(n->sc==FUNCTION) compatible(car(n->ty),cadr(type));
+    if(n->sc==FUNCTION) compatible(n->ty,cadr(type));
     else {
 	if(n->sc!=EMPTY) 
 	    error(DCERR);
 	else {
 	    n->sc=FUNCTION;
-	    n->ty=glist2(cadr(type),0); /* arglist? */
+	    n->ty=cadr(type);
 	}
     }
 }
@@ -1432,6 +1441,7 @@
     c=0;
     slfree=lfree;
     while(sym==CASE) {	
+	conv->case_begin_(c,0);
 	getsym();
 	c=list2(cexpr(expr()),c);
 	conv->case_(c,0);
@@ -1994,19 +2004,19 @@
 	case FLABEL: case BLABEL:
 	case FUNCTION: case CODE:
 	    e1=list2(FNAME,(int)nptr);
-	    type=list3(nptr->sc,car(nptr->ty),cadr(nptr->ty));
+	    type=list3(nptr->sc,nptr->ty,nptr->dsp);
 	    getsym();
 	    break;
 	case EMPTY:
 	    if(getsym()==LPAR) {	
 		nptr->sc = FUNCTION;
-		nptr->ty= glist2(INT,0);
+		nptr->ty= INT;
 		type= list3(FUNCTION,INT,0);
 		e1=expr15(list2(FNAME,(int)nptr));
 		break;
 	    } else {
 		e1=list2(FNAME,(int)nptr);
-		type=list3(nptr->sc,nptr->ty,0);
+		type=list3(nptr->sc,nptr->ty,nptr->dsp);
 		break;
 	    }
 	default:error(UDERR);
@@ -2501,6 +2511,7 @@
 	    *macropp =0;
 	    lfree = slfree;
 	    if (lsrc && !asmf && nptrm->sc==FMACRO) gen_comment(macro_buf);
+	    macropp[-1] =0;
 	    chptrsave = chptr;
 	    chsave = ch = chptr[-1];
 	    chptr = macro_buf;
@@ -2812,8 +2823,10 @@
 static int
 skipspc(void)
 {
-    while(ch=='\t'||ch=='\n'||ch==' '||ch=='\r') 
+    while(ch=='\t'||ch=='\n'||ch==' '||ch=='\r') {
+	conv->comment_(ch);
 	getch();
+    }
     return ch;
 }
 
@@ -3305,7 +3318,7 @@
 
     switch (mode) {
 	case GDECL: case GSDECL: case GUDECL: case GTDECL:
-	case MDECL:
+	case MDECL: case ADECL:
 	e=gfree;
 	gfree+=n;
 	break;
--- a/mc-tree.c	Sat Feb 22 01:32:47 2003 +0900
+++ b/mc-tree.c	Mon Feb 24 00:59:30 2003 +0900
@@ -3,9 +3,6 @@
 
 #define EXTERN /**/
 #include "mc.h"
-extern void tree_print(int e);
-extern void tree_parse(int e);
-extern void tree_print_t(int e,int t);
 
 typedef
 struct tree_node {
@@ -14,123 +11,147 @@
     char *tree_args;
 } tree_node_type;
 
+extern void tree_print(int e);
+extern void tree_parse(int e);
+extern void tree_print_t(int e,int t);
+static tree_node_type * find_node(int e);
+extern void type_print(int type,NMTBL *n,FILE *out);
+
+/* ascendant order for binary search */
+
 static
 tree_node_type tree_nodes[] = {
-    {(-1),"INT",""},
-    {(-2),"CHAR",""},
-    {(-3),"UNSIGNED",""},
-    {(-4),"POINTER","t"},
-    {(-5),"ARRAY","tv"},
-    {(-6),"STRUCT","vt"},
-    {(-7),"UNION",""},
-    {(-8),"FUNCTION","t"},
-    {(-9),"EMPTY",""},
-    {(-10),"STATIC",""},
-    {(-11),"GOTO",""},
-    {(-12),"RETURN",""},
-    {(-13),"BREAK",""},
-    {(-14),"CONTINUE",""},
-    {(-15),"IF",""},
-    {(-16),"ELSE",""},
-    {(-17),"FOR",""},
-    {(-18),"DO",""},
-    {(-19),"WHILE",""},
-    {(-20),"SWITCH",""},
-    {(-21),"CASE",""},
-    {(-22),"DEFAULT",""},
-    {(-23),"RESERVE",""},
-    {(-24),"TAG",""},
-    {(-25),"FIELD",""},
-    {(-26),"IDENT",""},
-    {(-27),"STRING",""},
-    {(-28),"MACRO",""},
-    {(-29),"BLABEL",""},
-    {(-30),"FLABEL",""},
-    {(-31),"TYPEDEF",""},
-    {(-32),"SIZEOF",""},
-    {(-33),"TYPE",""},
-    {(-34),"LONG",""},
-    {(-35),"SHORT",""},
-    {(-36),"EXTERN",""},
-    {(-37),"VOID",""},
-    {(-38),"REGISTER",""},
-    {(-39),"CODE",""},
-    {(-40),"ENVIRONMENT",""},
-    {(-41),"DEFINED",""},
-    {(-42),"KONST",""},
-    {(-43),"FMACRO",""},
-    {(-44),"LMACRO",""},
+    {(-45),"...",""},
+    {(-44),"lmacro",""},
+    {(-43),"fmacro",""},
+    {(-42),"konst",""},
+    {(-41),"defined",""},
+    {(-40),"environment",""},
+    {(-39),"code",""},
+    {(-38),"register",""},
+    {(-37),"void",""},
+    {(-36),"extern",""},
+    {(-35),"short",""},
+    {(-34),"long",""},
+    {(-33),"type",""},
+    {(-32),"sizeof",""},
+    {(-31),"typedef",""},
+    {(-30),"flabel",""},
+    {(-29),"blabel",""},
+    {(-28),"macro",""},
+    {(-27),"string",""},
+    {(-26),"ident",""},
+    {(-25),"field",""},
+    {(-24),"tag",""},
+    {(-23),"reserve",""},
+    {(-22),"default",""},
+    {(-21),"case",""},
+    {(-20),"switch",""},
+    {(-19),"while",""},
+    {(-18),"do",""},
+    {(-17),"for",""},
+    {(-16),"else",""},
+    {(-15),"if",""},
+    {(-14),"continue",""},
+    {(-13),"break",""},
+    {(-12),"return",""},
+    {(-11),"goto",""},
+    {(-10),"static",""},
+    {(-9),"empty",""},
+    {(-8),"function","t"},
+    {(-7),"union",""},
+    {(-6),"struct","vt"},
+    {(-5),"array","tv"},
+    {(-4),"pointer","t"},
+    {(-3),"unsigned",""},
+    {(-2),"char",""},
+    {(-1),"int",""},
 
-    {1,"GVAR","vs"},
-    {2,"RGVAR","vs"},
-    {3,"CRGVAR","vs"},
-    {4,"LVAR","v"},
-    {5,"RLVAR","v"},
-    {6,"CRLVAR","v"},
-    {7,"CONST","v"},
-    {8,"FNAME","n"},
-    {9,"INDIRECT","e"},
-    {10,"RINDIRECT","e"},
-    {11,"CRINDIRECT","e"},
-    {12,"ADDRESS","e"},
-    {13,"MINUS","e"},
-    {14,"LNOT","e"},
-    {15,"BNOT","e"},
-    {16,"INC",""},
-    {17,"POSTINC","e"},
-    {18,"PREINC","e"},
-    {19,"CPOSTINC","e"},
-    {20,"CPREINC","e"},
-    {21,"DEC",""},
-    {22,"CPOSTDEC","e"},
-    {23,"CPREDEC","e"},
-    {24,"MUL","ee"},
-    {25,"UMUL","ee"},
-    {26,"DIV","ee"},
-    {27,"UDIV","ee"},
-    {28,"MOD","ee"},
-    {29,"UMOD","ee"},
-    {30,"ADD","ee"},
-    {31,"SUB","ee"},
-    {32,"RSHIFT","ee"},
-    {33,"URSHIFT","ee"},
-    {34,"LSHIFT","ee"},
-    {35,"ULSHIFT","ee"},
-    {36,"GT","ee"},
-    {37,"UGT","ee"},
-    {38,"GE","ee"},
-    {39,"UGE","ee"},
-    {40,"LT","ee"},
-    {41,"ULT","ee"},
-    {42,"LE","ee"},
-    {43,"ULE","ee"},
-    {44,"EQ","ee"},
-    {45,"NEQ","ee"},
-    {46,"BAND","ee"},
-    {47,"EOR","ee"},
-    {48,"BOR","ee"},
-    {49,"LAND","ee"},
-    {50,"LOR","ee"},
-    {51,"COND","eee"},
-    {52,"ASS","ee"},
-    {53,"CASS","ee"},
-    {54,"ASSOP","eev"},
-    {55,"CASSOP","eev"},
-    {56,"COMMA","ee"},
-    {57,"LPAR",""},
-    {58,"RPAR",""},
-    {59,"LBRA",""},
-    {60,"RBRA",""},
-    {61,"LC",""},
-    {62,"RC",""},
-    {63,"COLON","ee"},
-    {64,"SM",""},
-    {65,"PERIOD",""},
-    {66,"ARROW",""},
-    {67,"CNAME",""},
-    {68,"SASS",""},
-    {69,"DOTS",""},
-    {100,"AS",""}
+    {1,"gvar","vs"},
+    {2,"rgvar","vs"},
+    {3,"crgvar","vs"},
+    {4,"lvar","v"},
+    {5,"rlvar","v"},
+    {6,"crlvar","v"},
+    {7,"const","v"},
+    {8,"fname","n"},
+    {9,"*","e"},
+    {10,"rindirect","e"},
+    {11,"crindirect","e"},
+    {12,"&","e"},
+    {13,"-","e"},
+    {14,"!","e"},
+    {15,"~","e"},
+    {16,"++",""},
+    {17,"postinc","e"},
+    {18,"preinc","e"},
+    {19,"cpostinc","e"},
+    {20,"cpreinc","e"},
+    {21,"--",""},
+    {22,"cpostdec","e"},
+    {23,"cpredec","e"},
+    {24,"*","ee"},
+    {25,"*","ee"},
+    {26,"/","ee"},
+    {27,"/","ee"},
+    {28,"%","ee"},
+    {29,"%","ee"},
+    {30,"+","ee"},
+    {31,"-","ee"},
+    {32,">>","ee"},
+    {33,">>","ee"},
+    {34,"<<","ee"},
+    {35,"<<","ee"},
+    {36,"gt","ee"},
+    {37,"ugt","ee"},
+    {38,"ge","ee"},
+    {39,"uge","ee"},
+    {40,"lt","ee"},
+    {41,"ult","ee"},
+    {42,"le","ee"},
+    {43,"ule","ee"},
+    {44,"==","ee"},
+    {45,"!=","ee"},
+    {46,"&","ee"},
+    {47,"^","ee"},
+    {48,"|","ee"},
+    {49,"&&","ee"},
+    {50,"||","ee"},
+    {51,"cond","eee"},
+    {52,"ass","ee"},
+    {53,"cass","ee"},
+    {54,"assop","eev"},
+    {55,"cassop","eev"},
+    {56,",","ee"},
+    {57,"(",""},
+    {58,")",""},
+    {59,"[",""},
+    {60,"]",""},
+    {61,"{",""},
+    {62,"}",""},
+    {63,":","ee"},
+    {64,";",""},
+    {65,".",""},
+    {66,"->",""},
+    {67,"cname",""},
+    {68,"sass",""},
+    {69,"rstruct",""},
+    {100,"=",""},
+    {124,"*=","ee"},
+    {125,"*=","ee"},
+    {126,"/=","ee"},
+    {127,"/=","ee"},
+    {128,"%=","ee"},
+    {129,"%=","ee"},
+    {130,"+=","ee"},
+    {131,"-=","ee"},
+    {132,">>=","ee"},
+    {133,">>=","ee"},
+    {134,"<<=","ee"},
+    {135,"<<=","ee"},
+    {146,"&=","ee"},
+    {147,"^=","ee"},
+    {148,"|=","ee"},
 };
 
 void
@@ -164,40 +185,133 @@
     char *s;
 
     if(e<0) {
-	for(t=tree_nodes;t->tree_type!=100;t++) {
-	    if(t->tree_type==e) {
-		for(j=0;j<tree_level;j++) putchar(' ');
-		printf("list(%s)",t->tree_name);
-		break;
-	    }
+	t=find_node(e);
+	if(t->tree_type==e) {
+	    for(j=0;j<tree_level;j++) putchar(' ');
+	    printf("list(%s)",t->tree_name);
 	}
     } else {
 	i = car(e);
-	for(t=tree_nodes;t->tree_type!=100;t++) {
-	    if(t->tree_type==i) {
-		tree_level++;
-		for(j=0;j<tree_level;j++) putchar(' ');
-		printf("list(%s",t->tree_name);
-		for(i=1,s=t->tree_args;*s;s++,i++) {
-		    switch(*s) {
-		    case 'e':
-		    case 't':
-			printf(",\n*");
-			tree_parse(heap[e+i]); break;
-		    case 'v':
-			printf(",%d",heap[e+i]); break;
-		    case 'n':
-			printf(",%s",((NMTBL *)heap[e+i])->nm); break;
-		    case 's':
-			printf(",%s",(char *)heap[e+i]); break;
-		    case 'i':
-			printf(",%d",heap[e+i]); break;
-		    }
+	t=find_node(e);
+	if(t->tree_type==i) {
+	    tree_level++;
+	    for(j=0;j<tree_level;j++) putchar(' ');
+	    printf("list(%s",t->tree_name);
+	    for(i=1,s=t->tree_args;*s;s++,i++) {
+		switch(*s) {
+		case 'e':
+		case 't':
+		    printf(",\n*");
+		    tree_parse(heap[e+i]); break;
+		case 'v':
+		    printf(",%d",heap[e+i]); break;
+		case 'n':
+		    printf(",%s",((NMTBL *)heap[e+i])->nm); break;
+		case 's':
+		    printf(",%s",(char *)heap[e+i]); break;
+		case 'i':
+		    printf(",%d",heap[e+i]); break;
 		}
-		tree_level--;
-		printf(")");
-		break;
 	    }
+	    tree_level--;
+	    printf(")");
 	}
     }
 }
+
+tree_node_type *
+find_node(int e) {
+    int e1,e2;
+    int first=0;
+    int last=sizeof(tree_nodes)/sizeof(tree_node_type);
+    e2=-1;
+    while (first!=last) {
+	e1 = (first+last)/2;
+	if(e2==e1) 
+	    return 0;
+	e2=e1;
+	if (tree_nodes[e1].tree_type>e)
+	    last = e1;
+	else if (tree_nodes[e1].tree_type==e)
+	    break;
+	else if (tree_nodes[e1].tree_type<e)
+	    first = e1;
+    }
+    return &tree_nodes[e1];
+}
+
+void struct_type_print(int type,FILE *out)
+{
+    NMTBL *n;
+    int tags;
+    if((n=(NMTBL*)cadddr(type))) {
+	fprintf(out,"%s ",n->nm);
+	return;
+    }
+    if((tags=caddr(type))) {
+	fprintf(out,"{");
+	while(tags) {
+	    n=(NMTBL*)caddr(tags);
+	    type_print(car(tags),n,out);
+	    fprintf(out,";");
+	    tags = cadr(tags);
+	}
+	fprintf(out,"}");
+    }
+}
+
+void function_type_print(int type,NMTBL *n,FILE *out)
+{
+    int args;
+    type_print(cadr(type),0,out);
+    if(n) fprintf(out," %s",n->nm);
+    fprintf(out,"(");
+    if((args=caddr(type))) {
+	while (args) {
+	    type_print(car(args),0,out);
+	    args=cadr(args);
+	    if (args) fprintf(out,",");
+	}
+    }
+    fprintf(out,")");
+}
+
+void type_print(int type,NMTBL *n,FILE *out)
+{
+    int t; 
+    tree_node_type *tn;
+    if (type<0) {
+	t=type;
+	if (!(tn=find_node(t))) { error(-1); return; }
+	fprintf(out,"%s ",tn->tree_name);
+    } else if ((t=car(type))) {
+	if (!(tn=find_node(t))) { error(-1); return; }
+	if(t==STRUCT||t==UNION) {
+	    fprintf(out,"%s ",tn->tree_name);
+	    struct_type_print(type,out);
+	} else if(t==CODE) {
+	    fprintf(out,"%s ",tn->tree_name);
+	    function_type_print(type,n,out);
+	    return;
+	} else if(t==FUNCTION) {
+	    function_type_print(type,n,out);
+	    return;
+	} else if(t==ARRAY) {
+	    type_print(cadr(type),n,out);
+	    fprintf(out,"[%d]",caddr(type));
+	    return;
+	} else if(t==POINTER) {
+	    t=cadr(type);
+	    if(car(t)==FUNCTION) {
+		fprintf(out,"(");
+		type_print(t,0,out);
+		fprintf(out,")");
+	    } else
+		type_print(t,0,out);
+	    fprintf(out,"*");
+	}
+    }
+    if(n) fprintf(out,"%s",n->nm);
+}
+
+/* end */
--- a/mc.h	Sat Feb 22 01:32:47 2003 +0900
+++ b/mc.h	Mon Feb 24 00:59:30 2003 +0900
@@ -56,6 +56,7 @@
 #define KONST	(-42)
 #define FMACRO	(-43)
 #define LMACRO	(-44)
+#define DOTS	(-45)
 
 #define TOP	0
 #define GDECL	1
@@ -140,8 +141,7 @@
 #define ARROW	66
 #define CNAME	67
 #define SASS	68
-#define DOTS	69
-#define RSTRUCT	70
+#define RSTRUCT	69
 
 #define US	1
 #define AS	100