annotate mc-tree.c @ 573:3de2ae36c7e5 more-strict-error

*** empty log message ***
author kono
date Fri, 13 Jan 2006 01:55:33 +0900
parents 25f431685d80
children 94d3a8c1b3e8
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",""},
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
38 {USHORT,"unsigned short",""},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
39 {LONG,"long",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
40 {TYPE,"type",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
41 {SIZEOF,"sizeof",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
42 {TYPEDEF,"typedef",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
43 {FLABEL,"flabel",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
44 {BLABEL,"blabel",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
45 {MACRO,"macro",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
46 {STRING,"string",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
47 {IDENT,"ident",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
48 {FIELD,"field",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
49 {TAG,"tag",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
50 {RESERVE,"reserve",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
51 {DEFAULT,"default",""},
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
52 {ATTRIBUTE,"attribute",""},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
53 {CASE,"case",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
54 {SWITCH,"switch",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
55 {WHILE,"while",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
56 {DO,"do",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
57 {FOR,"for",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
58 {ELSE,"else",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
59 {IF,"if",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
60 {CONTINUE,"continue",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
61 {BREAK,"break",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
62 {RETURN,"return",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
63 {GOTO,"goto",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
64 {STATIC,"static",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
65 {EMPTY,"empty",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
66 {FUNCTION,"function","t"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
67 {UNION,"union",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
68 {STRUCT,"struct","vt"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
69 {ARRAY,"array","tv"},
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
70 {POINTER,"*","t"},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
71 {UNSIGNED,"unsigned",""},
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
72 {INLINE,"inline",""},
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
73 {SIGNED,"signed",""},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
74 {CHAR,"char",""},
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
75 {UCHAR,"unsigned char",""},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
76 {INT,"int",""},
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
77 {FLOAT,"float",""},
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
78 {DOUBLE,"double",""},
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
79 {LONGLONG,"long long",""},
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
80 {ULONGLONG,"unsigned long long",""},
37
412ad2e6c2a2 struct copy
kono
parents: 33
diff changeset
81
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
82 {GVAR,"gvar","vs"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
83 {RGVAR,"rgvar","vs"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
84 {CRGVAR,"crgvar","vs"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
85 {LVAR,"lvar","v"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
86 {RLVAR,"rlvar","v"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
87 {CRLVAR,"crlvar","v"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
88 {CONST,"const","v"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
89 {FNAME,"fname","n"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
90 {MUL,"*","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
91 {RINDIRECT,"rindirect","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
92 {CRINDIRECT,"crindirect","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
93 {BAND,"&","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
94 {MINUS,"-","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
95 {LNOT,"!","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
96 {BNOT,"~","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
97 {INC,"++",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
98 {POSTINC,"postinc","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
99 {PREINC,"preinc","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
100 {CPOSTINC,"cpostinc","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
101 {CPREINC,"cpreinc","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
102 {DEC,"--",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
103 {DIV,"/","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
104 {UDIV,"/","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
105 {MUL,"*","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
106 {UMUL,"*","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
107 {MOD,"%","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
108 {UMOD,"%","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
109 {ADD,"+","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
110 {SUB,"-","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
111 {RSHIFT,">>","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
112 {URSHIFT,">>","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
113 {LSHIFT,"<<","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
114 {ULSHIFT,"<<","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
115 {GT,">","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
116 {UGT,">","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
117 {GE,">=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
118 {UGE,">=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
119 {LT,"<","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
120 {ULT,"<","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
121 {LE,"<=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
122 {ULE,"<=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
123 {EQ,"==","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
124 {NEQ,"!=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
125 {BAND,"&","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
126 {EOR,"^","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
127 {BOR,"|","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
128 {LAND,"&&","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
129 {LOR,"||","ee"},
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
130 {COND,"?","eee"},
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
131 {ASS,"=","ee"},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
132 {ASSOP,"assop","eev"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
133 {CASSOP,"cassop","eev"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
134 {COMMA,",","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
135 {LPAR,"(",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
136 {RPAR,")",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
137 {LBRA,"[",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
138 {RBRA,"]",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
139 {LC,"{",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
140 {RC,"}",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
141 {COLON,":","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
142 {SM,";",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
143 {PERIOD,".",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
144 {ARROW,"->",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
145 {SASS,"sass",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
146 {RSTRUCT,"rstruct",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
147 {AS+MUL,"*=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
148 {AS+UMUL,"*=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
149 {AS+DIV,"/=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
150 {AS+UDIV,"/=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
151 {AS+MOD,"%=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
152 {AS+UMOD,"%=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
153 {AS+ADD,"+=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
154 {AS+MINUS,"-=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
155 {AS+RSHIFT,">>=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
156 {AS+URSHIFT,">>=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
157 {AS+LSHIFT,"<<=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
158 {AS+ULSHIFT,"<<=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
159 {AS+BAND,"&=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
160 {AS+EOR,"^=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
161 {AS+BOR,"|=","ee"},
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
162 };
d35df41eac69 Initial revision
kono
parents:
diff changeset
163
564
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
164 static int
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
165 attr_print(int t)
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
166 {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
167 while (t>0 && car(t)==ATTRIBUTE) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
168 switch (caddr(t)) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
169 case KONST: printf( "const"); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
170 case VOLATILE: printf( "volatile"); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
171 case RESTRICT: printf( "restrict"); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
172 case INLINE: printf( "inline"); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
173 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
174 t = cadr(t);
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
175 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
176 return t;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
177 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
178
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
179 void
50
kono
parents: 37
diff changeset
180 tree_print_t(int e,int t)
kono
parents: 37
diff changeset
181 {
kono
parents: 37
diff changeset
182 printf("# type: ");
kono
parents: 37
diff changeset
183 tree_print(t);
kono
parents: 37
diff changeset
184 printf("expr: ");
kono
parents: 37
diff changeset
185 tree_print(e);
kono
parents: 37
diff changeset
186 printf("\n");
kono
parents: 37
diff changeset
187 }
kono
parents: 37
diff changeset
188
kono
parents: 37
diff changeset
189 void
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
190 tree_print(int e)
d35df41eac69 Initial revision
kono
parents:
diff changeset
191 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
192 printf("* generate code on type:\n* ");
d35df41eac69 Initial revision
kono
parents:
diff changeset
193 tree_parse(type);
d35df41eac69 Initial revision
kono
parents:
diff changeset
194 printf("\n* expr:\n* ");
d35df41eac69 Initial revision
kono
parents:
diff changeset
195 tree_parse(e);
d35df41eac69 Initial revision
kono
parents:
diff changeset
196 printf("\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
197 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
198
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
199 static
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
200 int tree_level;
d35df41eac69 Initial revision
kono
parents:
diff changeset
201
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
202 void
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
203 tree_parse(int e)
d35df41eac69 Initial revision
kono
parents:
diff changeset
204 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
205 tree_node_type *t;
d35df41eac69 Initial revision
kono
parents:
diff changeset
206 int i,j;
d35df41eac69 Initial revision
kono
parents:
diff changeset
207 char *s;
d35df41eac69 Initial revision
kono
parents:
diff changeset
208
d35df41eac69 Initial revision
kono
parents:
diff changeset
209 if(e<0) {
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
210 t=find_node(e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
211 if(t->tree_type==e) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
212 for(j=0;j<tree_level;j++) putchar(' ');
254a0c576114 argument type list
kono
parents: 50
diff changeset
213 printf("list(%s)",t->tree_name);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
214 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
215 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
216 i = car(e);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
217 t=find_node(e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
218 if(t->tree_type==i) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
219 tree_level++;
254a0c576114 argument type list
kono
parents: 50
diff changeset
220 for(j=0;j<tree_level;j++) putchar(' ');
254a0c576114 argument type list
kono
parents: 50
diff changeset
221 printf("list(%s",t->tree_name);
254a0c576114 argument type list
kono
parents: 50
diff changeset
222 for(i=1,s=t->tree_args;*s;s++,i++) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
223 switch(*s) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
224 case 'e':
254a0c576114 argument type list
kono
parents: 50
diff changeset
225 case 't':
254a0c576114 argument type list
kono
parents: 50
diff changeset
226 printf(",\n*");
254a0c576114 argument type list
kono
parents: 50
diff changeset
227 tree_parse(heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
228 case 'v':
254a0c576114 argument type list
kono
parents: 50
diff changeset
229 printf(",%d",heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
230 case 'n':
254a0c576114 argument type list
kono
parents: 50
diff changeset
231 printf(",%s",((NMTBL *)heap[e+i])->nm); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
232 case 's':
254a0c576114 argument type list
kono
parents: 50
diff changeset
233 printf(",%s",(char *)heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
234 case 'i':
254a0c576114 argument type list
kono
parents: 50
diff changeset
235 printf(",%d",heap[e+i]); break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
236 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
237 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
238 tree_level--;
254a0c576114 argument type list
kono
parents: 50
diff changeset
239 printf(")");
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
240 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
241 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
242 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
243
254a0c576114 argument type list
kono
parents: 50
diff changeset
244 tree_node_type *
254a0c576114 argument type list
kono
parents: 50
diff changeset
245 find_node(int e) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
246 int e1,e2;
254a0c576114 argument type list
kono
parents: 50
diff changeset
247 int first=0;
254a0c576114 argument type list
kono
parents: 50
diff changeset
248 int last=sizeof(tree_nodes)/sizeof(tree_node_type);
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
249 // e2=-1;
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
250 e2=e%200;
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
251 e1=0;
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
252 while (first!=last) {
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
253 #if 0
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
254 e1 = (first+last)/2;
254a0c576114 argument type list
kono
parents: 50
diff changeset
255 if(e2==e1)
254a0c576114 argument type list
kono
parents: 50
diff changeset
256 return 0;
254a0c576114 argument type list
kono
parents: 50
diff changeset
257 e2=e1;
254a0c576114 argument type list
kono
parents: 50
diff changeset
258 if (tree_nodes[e1].tree_type>e)
254a0c576114 argument type list
kono
parents: 50
diff changeset
259 last = e1;
254a0c576114 argument type list
kono
parents: 50
diff changeset
260 else if (tree_nodes[e1].tree_type==e)
254a0c576114 argument type list
kono
parents: 50
diff changeset
261 break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
262 else if (tree_nodes[e1].tree_type<e)
254a0c576114 argument type list
kono
parents: 50
diff changeset
263 first = e1;
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
264 #else
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
265 if (tree_nodes[first].tree_type==e2)
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
266 return &tree_nodes[first];
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
267 first++;
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
268 #endif
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
269 }
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
270 fprintf(stderr,"Unknown ID %d [%d]in find note\n",e2,e);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
271 return &tree_nodes[e1];
254a0c576114 argument type list
kono
parents: 50
diff changeset
272 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
273
254a0c576114 argument type list
kono
parents: 50
diff changeset
274 void struct_type_print(int type,FILE *out)
254a0c576114 argument type list
kono
parents: 50
diff changeset
275 {
254a0c576114 argument type list
kono
parents: 50
diff changeset
276 NMTBL *n;
254a0c576114 argument type list
kono
parents: 50
diff changeset
277 int tags;
254a0c576114 argument type list
kono
parents: 50
diff changeset
278 if((n=(NMTBL*)cadddr(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
279 fprintf(out,"%s ",n->nm);
254a0c576114 argument type list
kono
parents: 50
diff changeset
280 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
281 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
282 if((tags=caddr(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
283 fprintf(out,"{");
254a0c576114 argument type list
kono
parents: 50
diff changeset
284 while(tags) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
285 n=(NMTBL*)caddr(tags);
254a0c576114 argument type list
kono
parents: 50
diff changeset
286 type_print(car(tags),n,out);
254a0c576114 argument type list
kono
parents: 50
diff changeset
287 fprintf(out,";");
254a0c576114 argument type list
kono
parents: 50
diff changeset
288 tags = cadr(tags);
254a0c576114 argument type list
kono
parents: 50
diff changeset
289 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
290 fprintf(out,"}");
254a0c576114 argument type list
kono
parents: 50
diff changeset
291 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
292 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
293
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
294 void function_type_print1(int type,NMTBL *n,FILE *out,int cont)
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
295 {
254a0c576114 argument type list
kono
parents: 50
diff changeset
296 int args;
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
297 type_print1(cadr(type),0,out,cont);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
298 if(n) fprintf(out," %s",n->nm);
254a0c576114 argument type list
kono
parents: 50
diff changeset
299 fprintf(out,"(");
254a0c576114 argument type list
kono
parents: 50
diff changeset
300 if((args=caddr(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
301 while (args) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
302 type_print(car(args),0,out);
254a0c576114 argument type list
kono
parents: 50
diff changeset
303 args=cadr(args);
254a0c576114 argument type list
kono
parents: 50
diff changeset
304 if (args) fprintf(out,",");
254a0c576114 argument type list
kono
parents: 50
diff changeset
305 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
306 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
307 fprintf(out,")");
254a0c576114 argument type list
kono
parents: 50
diff changeset
308 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
309
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
310 void function_type_print(int type,NMTBL *n,FILE *out)
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
311 {
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
312 function_type_print1(type,n,out,0);
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
313 }
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
314
68
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
315 void sym_print(int sym,FILE *out)
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
316 {
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
317 tree_node_type *tn;
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
318 if (!(tn=find_node(sym))) { error(-1); return; }
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
319 fprintf(out,"%s",tn->tree_name);
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
320 }
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
321
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
322 NMTBL *
468
464e7480395c *** empty log message ***
kono
parents: 327
diff changeset
323 typedef_search(int t,int type)
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
324 {
2e84590720a6 typedef name
kono
parents: 69
diff changeset
325 while(t) {
2e84590720a6 typedef name
kono
parents: 69
diff changeset
326 if (((NMTBL*)car(t))->ty==type)
2e84590720a6 typedef name
kono
parents: 69
diff changeset
327 return (NMTBL*)car(t);
2e84590720a6 typedef name
kono
parents: 69
diff changeset
328 t=cadr(t);
2e84590720a6 typedef name
kono
parents: 69
diff changeset
329 }
2e84590720a6 typedef name
kono
parents: 69
diff changeset
330 return 0;
2e84590720a6 typedef name
kono
parents: 69
diff changeset
331 }
2e84590720a6 typedef name
kono
parents: 69
diff changeset
332
564
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
333 static void n_attr_print(int attr, FILE *out)
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
334 {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
335 for(;attr;attr=cadr(attr)) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
336 switch(car(attr)) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
337 case INLINE: fprintf(out,"inline "); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
338 case CONST: fprintf(out,"const "); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
339 case VOLATILE: fprintf(out,"const "); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
340 case RESTRICT: fprintf(out,"const "); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
341 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
342 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
343 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
344
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
345 void type_print1(int type,NMTBL *n,FILE *out,int cont)
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
346 {
254a0c576114 argument type list
kono
parents: 50
diff changeset
347 int t;
254a0c576114 argument type list
kono
parents: 50
diff changeset
348 tree_node_type *tn;
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
349 NMTBL *td;
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
350 int args;
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
351
564
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
352 if (n) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
353 if (n->attr) n_attr_print(n->attr,out);
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
354 while(type>0 && car(type)==ATTRIBUTE) type=cadr(type);
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
355 } else
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
356 type = attr_print(type);
75
92dcf107a837 c code output
kono
parents: 74
diff changeset
357 if(type>0&&(td=typedef_search(typedefed,type))) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
358 if (!cont)
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
359 fprintf(out,"%s ",td->nm);
75
92dcf107a837 c code output
kono
parents: 74
diff changeset
360 } else if(type>0&&(td=typedef_search(gtypedefed,type))) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
361 if (!cont)
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
362 fprintf(out,"%s ",td->nm);
2e84590720a6 typedef name
kono
parents: 69
diff changeset
363 } else if (type<0) {
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
364 t=type;
254a0c576114 argument type list
kono
parents: 50
diff changeset
365 if (!(tn=find_node(t))) { error(-1); return; }
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
366 if (!cont)
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
367 fprintf(out,"%s ",tn->tree_name);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
368 } else if ((t=car(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
369 if (!(tn=find_node(t))) { error(-1); return; }
254a0c576114 argument type list
kono
parents: 50
diff changeset
370 if(t==STRUCT||t==UNION) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
371 if (!cont) {
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
372 fprintf(out,"%s ",tn->tree_name);
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
373 struct_type_print(type,out);
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
374 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
375 } else if(t==CODE) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
376 if (!cont) {
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
377 fprintf(out,"%s ",tn->tree_name);
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
378 }
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
379 function_type_print1(type,n,out,cont);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
380 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
381 } else if(t==FUNCTION) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
382 function_type_print1(type,n,out,cont);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
383 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
384 } else if(t==ARRAY) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
385 type_print1(cadr(type),n,out,cont);
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
386 if (caddr(type))
2e84590720a6 typedef name
kono
parents: 69
diff changeset
387 fprintf(out,"[%d]",caddr(type));
2e84590720a6 typedef name
kono
parents: 69
diff changeset
388 else
2e84590720a6 typedef name
kono
parents: 69
diff changeset
389 fprintf(out,"[]");
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
390 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
391 } else if(t==POINTER) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
392 t=cadr(type);
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
393 if(t<0) {
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
394 type_print1(t,0,out,cont);
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
395 fprintf(out,"*");
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
396 } else if(car(t)==FUNCTION) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
397 type_print1(cadr(t),0,out,cont);
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
398 fprintf(out,"(*");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
399 if(n) fprintf(out,"%s",n->nm);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
400 fprintf(out,")");
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
401 fprintf(out,"(");
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
402 if((args=caddr(t))) {
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
403 while (args) {
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
404 type_print(car(args),0,out);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
405 args=cadr(args);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
406 if (args) fprintf(out,",");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
407 }
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
408 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
409 fprintf(out,")");
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
410 return;
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
411 } else if(car(t)==ARRAY) {
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
412 fprintf(out,"(*");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
413 type_print(cadr(t),n,out);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
414 if (caddr(type))
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
415 fprintf(out,")[%d]",caddr(type));
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
416 else
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
417 fprintf(out,")[]");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
418 return;
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
419 } else {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
420 type_print1(t,0,out,cont);
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
421 fprintf(out,"*");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
422 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
423 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
424 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
425 if(n) fprintf(out,"%s",n->nm);
254a0c576114 argument type list
kono
parents: 50
diff changeset
426 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
427
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
428 void type_print(int type,NMTBL *n,FILE *out)
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
429 {
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
430 type_print1(type,n,out,0);
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
431 }
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
432
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
433 /* end */