annotate mc-tree.c @ 72:3b5d293cea36

type def etc
author kono
date Mon, 24 Feb 2003 16:04:30 +0900
parents 2e84590720a6
children 6de658ae384c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
0529f5abe9d0 *** empty log message ***
kono
parents: 0
diff changeset
1 /* Micro-C tree print routine */
0529f5abe9d0 *** empty log message ***
kono
parents: 0
diff changeset
2 /* $Id$ */
0529f5abe9d0 *** empty log message ***
kono
parents: 0
diff changeset
3
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
4 #define EXTERN /**/
d35df41eac69 Initial revision
kono
parents:
diff changeset
5 #include "mc.h"
d35df41eac69 Initial revision
kono
parents:
diff changeset
6
d35df41eac69 Initial revision
kono
parents:
diff changeset
7 typedef
d35df41eac69 Initial revision
kono
parents:
diff changeset
8 struct tree_node {
d35df41eac69 Initial revision
kono
parents:
diff changeset
9 int tree_type;
d35df41eac69 Initial revision
kono
parents:
diff changeset
10 char *tree_name;
d35df41eac69 Initial revision
kono
parents:
diff changeset
11 char *tree_args;
d35df41eac69 Initial revision
kono
parents:
diff changeset
12 } tree_node_type;
d35df41eac69 Initial revision
kono
parents:
diff changeset
13
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
14 extern void tree_print(int e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
15 extern void tree_parse(int e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
16 extern void tree_print_t(int e,int t);
254a0c576114 argument type list
kono
parents: 50
diff changeset
17 static tree_node_type * find_node(int e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
18 extern void type_print(int type,NMTBL *n,FILE *out);
68
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
19 extern void sym_print(int type,FILE *out);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
20
254a0c576114 argument type list
kono
parents: 50
diff changeset
21 /* ascendant order for binary search */
254a0c576114 argument type list
kono
parents: 50
diff changeset
22
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
23 static
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
24 tree_node_type tree_nodes[] = {
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
25 {(-45),"...",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
26 {(-44),"lmacro",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
27 {(-43),"fmacro",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
28 {(-42),"konst",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
29 {(-41),"defined",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
30 {(-40),"environment",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
31 {(-39),"code",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
32 {(-38),"register",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
33 {(-37),"void",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
34 {(-36),"extern",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
35 {(-35),"short",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
36 {(-34),"long",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
37 {(-33),"type",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
38 {(-32),"sizeof",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
39 {(-31),"typedef",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
40 {(-30),"flabel",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
41 {(-29),"blabel",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
42 {(-28),"macro",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
43 {(-27),"string",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
44 {(-26),"ident",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
45 {(-25),"field",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
46 {(-24),"tag",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
47 {(-23),"reserve",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
48 {(-22),"default",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
49 {(-21),"case",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
50 {(-20),"switch",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
51 {(-19),"while",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
52 {(-18),"do",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
53 {(-17),"for",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
54 {(-16),"else",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
55 {(-15),"if",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
56 {(-14),"continue",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
57 {(-13),"break",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
58 {(-12),"return",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
59 {(-11),"goto",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
60 {(-10),"static",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
61 {(-9),"empty",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
62 {(-8),"function","t"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
63 {(-7),"union",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
64 {(-6),"struct","vt"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
65 {(-5),"array","tv"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
66 {(-4),"pointer","t"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
67 {(-3),"unsigned",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
68 {(-2),"char",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
69 {(-1),"int",""},
37
412ad2e6c2a2 struct copy
kono
parents: 33
diff changeset
70
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
71 {1,"gvar","vs"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
72 {2,"rgvar","vs"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
73 {3,"crgvar","vs"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
74 {4,"lvar","v"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
75 {5,"rlvar","v"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
76 {6,"crlvar","v"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
77 {7,"const","v"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
78 {8,"fname","n"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
79 {9,"*","e"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
80 {10,"rindirect","e"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
81 {11,"crindirect","e"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
82 {12,"&","e"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
83 {13,"-","e"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
84 {14,"!","e"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
85 {15,"~","e"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
86 {16,"++",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
87 {17,"postinc","e"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
88 {18,"preinc","e"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
89 {19,"cpostinc","e"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
90 {20,"cpreinc","e"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
91 {21,"--",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
92 {22,"cpostdec","e"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
93 {23,"cpredec","e"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
94 {24,"*","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
95 {25,"*","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
96 {26,"/","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
97 {27,"/","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
98 {28,"%","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
99 {29,"%","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
100 {30,"+","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
101 {31,"-","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
102 {32,">>","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
103 {33,">>","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
104 {34,"<<","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
105 {35,"<<","ee"},
69
dba8d111b7a0 c output
kono
parents: 68
diff changeset
106 {36,">","ee"},
dba8d111b7a0 c output
kono
parents: 68
diff changeset
107 {37,">","ee"},
dba8d111b7a0 c output
kono
parents: 68
diff changeset
108 {38,">=","ee"},
dba8d111b7a0 c output
kono
parents: 68
diff changeset
109 {39,">=","ee"},
dba8d111b7a0 c output
kono
parents: 68
diff changeset
110 {40,"<","ee"},
dba8d111b7a0 c output
kono
parents: 68
diff changeset
111 {41,"<","ee"},
dba8d111b7a0 c output
kono
parents: 68
diff changeset
112 {42,"<=","ee"},
dba8d111b7a0 c output
kono
parents: 68
diff changeset
113 {43,"<=","ee"},
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
114 {44,"==","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
115 {45,"!=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
116 {46,"&","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
117 {47,"^","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
118 {48,"|","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
119 {49,"&&","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
120 {50,"||","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
121 {51,"cond","eee"},
69
dba8d111b7a0 c output
kono
parents: 68
diff changeset
122 {52," = ","ee"},
dba8d111b7a0 c output
kono
parents: 68
diff changeset
123 {53," = ","ee"},
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
124 {54,"assop","eev"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
125 {55,"cassop","eev"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
126 {56,",","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
127 {57,"(",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
128 {58,")",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
129 {59,"[",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
130 {60,"]",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
131 {61,"{",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
132 {62,"}",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
133 {63,":","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
134 {64,";",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
135 {65,".",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
136 {66,"->",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
137 {67,"cname",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
138 {68,"sass",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
139 {69,"rstruct",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
140 {100,"=",""},
254a0c576114 argument type list
kono
parents: 50
diff changeset
141 {124,"*=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
142 {125,"*=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
143 {126,"/=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
144 {127,"/=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
145 {128,"%=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
146 {129,"%=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
147 {130,"+=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
148 {131,"-=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
149 {132,">>=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
150 {133,">>=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
151 {134,"<<=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
152 {135,"<<=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
153 {146,"&=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
154 {147,"^=","ee"},
254a0c576114 argument type list
kono
parents: 50
diff changeset
155 {148,"|=","ee"},
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
156 };
d35df41eac69 Initial revision
kono
parents:
diff changeset
157
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
158 void
50
kono
parents: 37
diff changeset
159 tree_print_t(int e,int t)
kono
parents: 37
diff changeset
160 {
kono
parents: 37
diff changeset
161 printf("# type: ");
kono
parents: 37
diff changeset
162 tree_print(t);
kono
parents: 37
diff changeset
163 printf("expr: ");
kono
parents: 37
diff changeset
164 tree_print(e);
kono
parents: 37
diff changeset
165 printf("\n");
kono
parents: 37
diff changeset
166 }
kono
parents: 37
diff changeset
167
kono
parents: 37
diff changeset
168 void
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
169 tree_print(int e)
d35df41eac69 Initial revision
kono
parents:
diff changeset
170 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
171 printf("* generate code on type:\n* ");
d35df41eac69 Initial revision
kono
parents:
diff changeset
172 tree_parse(type);
d35df41eac69 Initial revision
kono
parents:
diff changeset
173 printf("\n* expr:\n* ");
d35df41eac69 Initial revision
kono
parents:
diff changeset
174 tree_parse(e);
d35df41eac69 Initial revision
kono
parents:
diff changeset
175 printf("\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
176 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
177
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
178 static
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
179 int tree_level;
d35df41eac69 Initial revision
kono
parents:
diff changeset
180
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
181 void
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
182 tree_parse(int e)
d35df41eac69 Initial revision
kono
parents:
diff changeset
183 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
184 tree_node_type *t;
d35df41eac69 Initial revision
kono
parents:
diff changeset
185 int i,j;
d35df41eac69 Initial revision
kono
parents:
diff changeset
186 char *s;
d35df41eac69 Initial revision
kono
parents:
diff changeset
187
d35df41eac69 Initial revision
kono
parents:
diff changeset
188 if(e<0) {
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
189 t=find_node(e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
190 if(t->tree_type==e) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
191 for(j=0;j<tree_level;j++) putchar(' ');
254a0c576114 argument type list
kono
parents: 50
diff changeset
192 printf("list(%s)",t->tree_name);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
193 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
194 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
195 i = car(e);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
196 t=find_node(e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
197 if(t->tree_type==i) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
198 tree_level++;
254a0c576114 argument type list
kono
parents: 50
diff changeset
199 for(j=0;j<tree_level;j++) putchar(' ');
254a0c576114 argument type list
kono
parents: 50
diff changeset
200 printf("list(%s",t->tree_name);
254a0c576114 argument type list
kono
parents: 50
diff changeset
201 for(i=1,s=t->tree_args;*s;s++,i++) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
202 switch(*s) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
203 case 'e':
254a0c576114 argument type list
kono
parents: 50
diff changeset
204 case 't':
254a0c576114 argument type list
kono
parents: 50
diff changeset
205 printf(",\n*");
254a0c576114 argument type list
kono
parents: 50
diff changeset
206 tree_parse(heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
207 case 'v':
254a0c576114 argument type list
kono
parents: 50
diff changeset
208 printf(",%d",heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
209 case 'n':
254a0c576114 argument type list
kono
parents: 50
diff changeset
210 printf(",%s",((NMTBL *)heap[e+i])->nm); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
211 case 's':
254a0c576114 argument type list
kono
parents: 50
diff changeset
212 printf(",%s",(char *)heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
213 case 'i':
254a0c576114 argument type list
kono
parents: 50
diff changeset
214 printf(",%d",heap[e+i]); break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
215 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
216 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
217 tree_level--;
254a0c576114 argument type list
kono
parents: 50
diff changeset
218 printf(")");
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
219 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
220 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
221 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
222
254a0c576114 argument type list
kono
parents: 50
diff changeset
223 tree_node_type *
254a0c576114 argument type list
kono
parents: 50
diff changeset
224 find_node(int e) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
225 int e1,e2;
254a0c576114 argument type list
kono
parents: 50
diff changeset
226 int first=0;
254a0c576114 argument type list
kono
parents: 50
diff changeset
227 int last=sizeof(tree_nodes)/sizeof(tree_node_type);
254a0c576114 argument type list
kono
parents: 50
diff changeset
228 e2=-1;
254a0c576114 argument type list
kono
parents: 50
diff changeset
229 while (first!=last) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
230 e1 = (first+last)/2;
254a0c576114 argument type list
kono
parents: 50
diff changeset
231 if(e2==e1)
254a0c576114 argument type list
kono
parents: 50
diff changeset
232 return 0;
254a0c576114 argument type list
kono
parents: 50
diff changeset
233 e2=e1;
254a0c576114 argument type list
kono
parents: 50
diff changeset
234 if (tree_nodes[e1].tree_type>e)
254a0c576114 argument type list
kono
parents: 50
diff changeset
235 last = e1;
254a0c576114 argument type list
kono
parents: 50
diff changeset
236 else if (tree_nodes[e1].tree_type==e)
254a0c576114 argument type list
kono
parents: 50
diff changeset
237 break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
238 else if (tree_nodes[e1].tree_type<e)
254a0c576114 argument type list
kono
parents: 50
diff changeset
239 first = e1;
254a0c576114 argument type list
kono
parents: 50
diff changeset
240 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
241 return &tree_nodes[e1];
254a0c576114 argument type list
kono
parents: 50
diff changeset
242 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
243
254a0c576114 argument type list
kono
parents: 50
diff changeset
244 void struct_type_print(int type,FILE *out)
254a0c576114 argument type list
kono
parents: 50
diff changeset
245 {
254a0c576114 argument type list
kono
parents: 50
diff changeset
246 NMTBL *n;
254a0c576114 argument type list
kono
parents: 50
diff changeset
247 int tags;
254a0c576114 argument type list
kono
parents: 50
diff changeset
248 if((n=(NMTBL*)cadddr(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
249 fprintf(out,"%s ",n->nm);
254a0c576114 argument type list
kono
parents: 50
diff changeset
250 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
251 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
252 if((tags=caddr(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
253 fprintf(out,"{");
254a0c576114 argument type list
kono
parents: 50
diff changeset
254 while(tags) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
255 n=(NMTBL*)caddr(tags);
254a0c576114 argument type list
kono
parents: 50
diff changeset
256 type_print(car(tags),n,out);
254a0c576114 argument type list
kono
parents: 50
diff changeset
257 fprintf(out,";");
254a0c576114 argument type list
kono
parents: 50
diff changeset
258 tags = cadr(tags);
254a0c576114 argument type list
kono
parents: 50
diff changeset
259 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
260 fprintf(out,"}");
254a0c576114 argument type list
kono
parents: 50
diff changeset
261 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
262 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
263
254a0c576114 argument type list
kono
parents: 50
diff changeset
264 void function_type_print(int type,NMTBL *n,FILE *out)
254a0c576114 argument type list
kono
parents: 50
diff changeset
265 {
254a0c576114 argument type list
kono
parents: 50
diff changeset
266 int args;
254a0c576114 argument type list
kono
parents: 50
diff changeset
267 type_print(cadr(type),0,out);
254a0c576114 argument type list
kono
parents: 50
diff changeset
268 if(n) fprintf(out," %s",n->nm);
254a0c576114 argument type list
kono
parents: 50
diff changeset
269 fprintf(out,"(");
254a0c576114 argument type list
kono
parents: 50
diff changeset
270 if((args=caddr(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
271 while (args) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
272 type_print(car(args),0,out);
254a0c576114 argument type list
kono
parents: 50
diff changeset
273 args=cadr(args);
254a0c576114 argument type list
kono
parents: 50
diff changeset
274 if (args) fprintf(out,",");
254a0c576114 argument type list
kono
parents: 50
diff changeset
275 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
276 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
277 fprintf(out,")");
254a0c576114 argument type list
kono
parents: 50
diff changeset
278 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
279
68
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
280 void sym_print(int sym,FILE *out)
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
281 {
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
282 tree_node_type *tn;
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
283 if (!(tn=find_node(sym))) { error(-1); return; }
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
284 fprintf(out,"%s",tn->tree_name);
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
285 }
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
286
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
287 NMTBL *
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
288 typedef_search(t,type)
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
289 {
2e84590720a6 typedef name
kono
parents: 69
diff changeset
290 while(t) {
2e84590720a6 typedef name
kono
parents: 69
diff changeset
291 if (((NMTBL*)car(t))->ty==type)
2e84590720a6 typedef name
kono
parents: 69
diff changeset
292 return (NMTBL*)car(t);
2e84590720a6 typedef name
kono
parents: 69
diff changeset
293 t=cadr(t);
2e84590720a6 typedef name
kono
parents: 69
diff changeset
294 }
2e84590720a6 typedef name
kono
parents: 69
diff changeset
295 return 0;
2e84590720a6 typedef name
kono
parents: 69
diff changeset
296 }
2e84590720a6 typedef name
kono
parents: 69
diff changeset
297
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
298 void type_print(int type,NMTBL *n,FILE *out)
254a0c576114 argument type list
kono
parents: 50
diff changeset
299 {
254a0c576114 argument type list
kono
parents: 50
diff changeset
300 int t;
254a0c576114 argument type list
kono
parents: 50
diff changeset
301 tree_node_type *tn;
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
302 NMTBL *td;
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
303 int args;
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
304
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
305 if((td=typedef_search(typedefed,type))) {
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
306 fprintf(out,"%s ",td->nm);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
307 } else if((td=typedef_search(gtypedefed,type))) {
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
308 fprintf(out,"%s ",td->nm);
2e84590720a6 typedef name
kono
parents: 69
diff changeset
309 } else if (type<0) {
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
310 t=type;
254a0c576114 argument type list
kono
parents: 50
diff changeset
311 if (!(tn=find_node(t))) { error(-1); return; }
254a0c576114 argument type list
kono
parents: 50
diff changeset
312 fprintf(out,"%s ",tn->tree_name);
254a0c576114 argument type list
kono
parents: 50
diff changeset
313 } else if ((t=car(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
314 if (!(tn=find_node(t))) { error(-1); return; }
254a0c576114 argument type list
kono
parents: 50
diff changeset
315 if(t==STRUCT||t==UNION) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
316 fprintf(out,"%s ",tn->tree_name);
254a0c576114 argument type list
kono
parents: 50
diff changeset
317 struct_type_print(type,out);
254a0c576114 argument type list
kono
parents: 50
diff changeset
318 } else if(t==CODE) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
319 fprintf(out,"%s ",tn->tree_name);
254a0c576114 argument type list
kono
parents: 50
diff changeset
320 function_type_print(type,n,out);
254a0c576114 argument type list
kono
parents: 50
diff changeset
321 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
322 } else if(t==FUNCTION) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
323 function_type_print(type,n,out);
254a0c576114 argument type list
kono
parents: 50
diff changeset
324 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
325 } else if(t==ARRAY) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
326 type_print(cadr(type),n,out);
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
327 if (caddr(type))
2e84590720a6 typedef name
kono
parents: 69
diff changeset
328 fprintf(out,"[%d]",caddr(type));
2e84590720a6 typedef name
kono
parents: 69
diff changeset
329 else
2e84590720a6 typedef name
kono
parents: 69
diff changeset
330 fprintf(out,"[]");
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
331 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
332 } else if(t==POINTER) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
333 t=cadr(type);
254a0c576114 argument type list
kono
parents: 50
diff changeset
334 if(car(t)==FUNCTION) {
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
335 type_print(cadr(t),0,out);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
336 fprintf(out,"(*");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
337 if(n) fprintf(out,"%s",n->nm);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
338 fprintf(out,")");
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
339 fprintf(out,"(");
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
340 if((args=caddr(t))) {
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
341 while (args) {
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
342 type_print(car(args),0,out);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
343 args=cadr(args);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
344 if (args) fprintf(out,",");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
345 }
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
346 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
347 fprintf(out,")");
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
348 return;
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
349 } else if(car(t)==ARRAY) {
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
350 fprintf(out,"(*");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
351 type_print(cadr(t),n,out);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
352 if (caddr(type))
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
353 fprintf(out,")[%d]",caddr(type));
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
354 else
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
355 fprintf(out,")[]");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
356 return;
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
357 } else {
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
358 type_print(t,0,out);
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
359 fprintf(out,"*");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
360 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
361 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
362 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
363 if(n) fprintf(out,"%s",n->nm);
254a0c576114 argument type list
kono
parents: 50
diff changeset
364 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
365
254a0c576114 argument type list
kono
parents: 50
diff changeset
366 /* end */