annotate mc-tree.c @ 562:0a156c491f81

*** empty log message ***
author kono
date Mon, 09 Jan 2006 20:06:02 +0900
parents 464e7480395c
children 588bb765b301
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[] = {
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
27 {DOTS,"...",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
28 {LMACRO,"lmacro",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
29 {FMACRO,"fmacro",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
30 {KONST,"const",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
31 {DEFINED,"defined",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
32 {ENVIRONMENT,"environment",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
33 {CODE,"code",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
34 {REGISTER,"register",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
35 {VOID,"void",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
36 {EXTRN,"extern",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
37 {SHORT,"short",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
38 {LONG,"long",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
39 {TYPE,"type",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
40 {SIZEOF,"sizeof",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
41 {TYPEDEF,"typedef",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
42 {FLABEL,"flabel",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
43 {BLABEL,"blabel",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
44 {MACRO,"macro",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
45 {STRING,"string",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
46 {IDENT,"ident",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
47 {FIELD,"field",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
48 {TAG,"tag",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
49 {RESERVE,"reserve",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
50 {DEFAULT,"default",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
51 {CASE,"case",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
52 {SWITCH,"switch",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
53 {WHILE,"while",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
54 {DO,"do",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
55 {FOR,"for",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
56 {ELSE,"else",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
57 {IF,"if",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
58 {CONTINUE,"continue",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
59 {BREAK,"break",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
60 {RETURN,"return",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
61 {GOTO,"goto",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
62 {STATIC,"static",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
63 {EMPTY,"empty",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
64 {FUNCTION,"function","t"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
65 {UNION,"union",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
66 {STRUCT,"struct","vt"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
67 {ARRAY,"array","tv"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
68 {POINTER,"pointer","t"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
69 {UNSIGNED,"unsigned",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
70 {CHAR,"char",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
71 {INT,"int",""},
37
412ad2e6c2a2 struct copy
kono
parents: 33
diff changeset
72
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
73 {GVAR,"gvar","vs"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
74 {RGVAR,"rgvar","vs"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
75 {CRGVAR,"crgvar","vs"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
76 {LVAR,"lvar","v"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
77 {RLVAR,"rlvar","v"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
78 {CRLVAR,"crlvar","v"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
79 {CONST,"const","v"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
80 {FNAME,"fname","n"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
81 {MUL,"*","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
82 {RINDIRECT,"rindirect","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
83 {CRINDIRECT,"crindirect","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
84 {BAND,"&","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
85 {MINUS,"-","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
86 {LNOT,"!","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
87 {BNOT,"~","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
88 {INC,"++",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
89 {POSTINC,"postinc","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
90 {PREINC,"preinc","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
91 {CPOSTINC,"cpostinc","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
92 {CPREINC,"cpreinc","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
93 {DEC,"--",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
94 {DIV,"/","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
95 {UDIV,"/","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
96 {MUL,"*","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
97 {UMUL,"*","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
98 {MOD,"%","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
99 {UMOD,"%","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
100 {ADD,"+","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
101 {SUB,"-","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
102 {RSHIFT,">>","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
103 {URSHIFT,">>","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
104 {LSHIFT,"<<","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
105 {ULSHIFT,"<<","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
106 {GT,">","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
107 {UGT,">","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
108 {GE,">=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
109 {UGE,">=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
110 {LT,"<","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
111 {ULT,"<","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
112 {LE,"<=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
113 {ULE,"<=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
114 {EQ,"==","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
115 {NEQ,"!=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
116 {BAND,"&","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
117 {EOR,"^","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
118 {BOR,"|","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
119 {LAND,"&&","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
120 {LOR,"||","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
121 {COND,"cond","eee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
122 {ASSOP,"assop","eev"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
123 {CASSOP,"cassop","eev"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
124 {COMMA,",","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
125 {LPAR,"(",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
126 {RPAR,")",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
127 {LBRA,"[",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
128 {RBRA,"]",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
129 {LC,"{",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
130 {RC,"}",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
131 {COLON,":","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
132 {SM,";",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
133 {PERIOD,".",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
134 {ARROW,"->",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
135 {SASS,"sass",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
136 {RSTRUCT,"rstruct",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
137 {AS+MUL,"*=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
138 {AS+UMUL,"*=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
139 {AS+DIV,"/=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
140 {AS+UDIV,"/=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
141 {AS+MOD,"%=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
142 {AS+UMOD,"%=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
143 {AS+ADD,"+=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
144 {AS+MINUS,"-=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
145 {AS+RSHIFT,">>=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
146 {AS+URSHIFT,">>=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
147 {AS+LSHIFT,"<<=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
148 {AS+ULSHIFT,"<<=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
149 {AS+BAND,"&=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
150 {AS+EOR,"^=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
151 {AS+BOR,"|=","ee"},
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
152 };
d35df41eac69 Initial revision
kono
parents:
diff changeset
153
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
154 void
50
kono
parents: 37
diff changeset
155 tree_print_t(int e,int t)
kono
parents: 37
diff changeset
156 {
kono
parents: 37
diff changeset
157 printf("# type: ");
kono
parents: 37
diff changeset
158 tree_print(t);
kono
parents: 37
diff changeset
159 printf("expr: ");
kono
parents: 37
diff changeset
160 tree_print(e);
kono
parents: 37
diff changeset
161 printf("\n");
kono
parents: 37
diff changeset
162 }
kono
parents: 37
diff changeset
163
kono
parents: 37
diff changeset
164 void
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
165 tree_print(int e)
d35df41eac69 Initial revision
kono
parents:
diff changeset
166 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
167 printf("* generate code on type:\n* ");
d35df41eac69 Initial revision
kono
parents:
diff changeset
168 tree_parse(type);
d35df41eac69 Initial revision
kono
parents:
diff changeset
169 printf("\n* expr:\n* ");
d35df41eac69 Initial revision
kono
parents:
diff changeset
170 tree_parse(e);
d35df41eac69 Initial revision
kono
parents:
diff changeset
171 printf("\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
172 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
173
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
174 static
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
175 int tree_level;
d35df41eac69 Initial revision
kono
parents:
diff changeset
176
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
177 void
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
178 tree_parse(int e)
d35df41eac69 Initial revision
kono
parents:
diff changeset
179 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
180 tree_node_type *t;
d35df41eac69 Initial revision
kono
parents:
diff changeset
181 int i,j;
d35df41eac69 Initial revision
kono
parents:
diff changeset
182 char *s;
d35df41eac69 Initial revision
kono
parents:
diff changeset
183
d35df41eac69 Initial revision
kono
parents:
diff changeset
184 if(e<0) {
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
185 t=find_node(e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
186 if(t->tree_type==e) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
187 for(j=0;j<tree_level;j++) putchar(' ');
254a0c576114 argument type list
kono
parents: 50
diff changeset
188 printf("list(%s)",t->tree_name);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
189 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
190 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
191 i = car(e);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
192 t=find_node(e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
193 if(t->tree_type==i) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
194 tree_level++;
254a0c576114 argument type list
kono
parents: 50
diff changeset
195 for(j=0;j<tree_level;j++) putchar(' ');
254a0c576114 argument type list
kono
parents: 50
diff changeset
196 printf("list(%s",t->tree_name);
254a0c576114 argument type list
kono
parents: 50
diff changeset
197 for(i=1,s=t->tree_args;*s;s++,i++) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
198 switch(*s) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
199 case 'e':
254a0c576114 argument type list
kono
parents: 50
diff changeset
200 case 't':
254a0c576114 argument type list
kono
parents: 50
diff changeset
201 printf(",\n*");
254a0c576114 argument type list
kono
parents: 50
diff changeset
202 tree_parse(heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
203 case 'v':
254a0c576114 argument type list
kono
parents: 50
diff changeset
204 printf(",%d",heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
205 case 'n':
254a0c576114 argument type list
kono
parents: 50
diff changeset
206 printf(",%s",((NMTBL *)heap[e+i])->nm); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
207 case 's':
254a0c576114 argument type list
kono
parents: 50
diff changeset
208 printf(",%s",(char *)heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
209 case 'i':
254a0c576114 argument type list
kono
parents: 50
diff changeset
210 printf(",%d",heap[e+i]); break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
211 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
212 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
213 tree_level--;
254a0c576114 argument type list
kono
parents: 50
diff changeset
214 printf(")");
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
215 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
216 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
217 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
218
254a0c576114 argument type list
kono
parents: 50
diff changeset
219 tree_node_type *
254a0c576114 argument type list
kono
parents: 50
diff changeset
220 find_node(int e) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
221 int e1,e2;
254a0c576114 argument type list
kono
parents: 50
diff changeset
222 int first=0;
254a0c576114 argument type list
kono
parents: 50
diff changeset
223 int last=sizeof(tree_nodes)/sizeof(tree_node_type);
254a0c576114 argument type list
kono
parents: 50
diff changeset
224 e2=-1;
254a0c576114 argument type list
kono
parents: 50
diff changeset
225 while (first!=last) {
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
226 #if 0
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
227 e1 = (first+last)/2;
254a0c576114 argument type list
kono
parents: 50
diff changeset
228 if(e2==e1)
254a0c576114 argument type list
kono
parents: 50
diff changeset
229 return 0;
254a0c576114 argument type list
kono
parents: 50
diff changeset
230 e2=e1;
254a0c576114 argument type list
kono
parents: 50
diff changeset
231 if (tree_nodes[e1].tree_type>e)
254a0c576114 argument type list
kono
parents: 50
diff changeset
232 last = e1;
254a0c576114 argument type list
kono
parents: 50
diff changeset
233 else if (tree_nodes[e1].tree_type==e)
254a0c576114 argument type list
kono
parents: 50
diff changeset
234 break;
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 first = e1;
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
237 #else
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
238 if (tree_nodes[first].tree_type==e)
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
239 break;
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
240 first++;
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
241 #endif
67
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 */