annotate mc-tree.c @ 560:d6ff45d719a5 string-shared

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