annotate mc-tree.c @ 67:254a0c576114

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