annotate mc-tree.c @ 669:1530b1a636ac

ato mouchotto...
author kono
date Wed, 02 May 2007 15:31:38 +0900
parents 3e1dba5758d8
children f536897fa3cb
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 */
607
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
2
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
3 /************************************************************************
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
4 ** Copyright (C) 2006 Shinji Kono
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
5 ** 連絡先: 琉球大学情報工学科 河野 真治
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
6 ** (E-Mail Address: kono@ie.u-ryukyu.ac.jp)
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
7 **
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
8 ** このソースのいかなる複写,改変,修正も許諾します。ただし、
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
9 ** その際には、誰が貢献したを示すこの部分を残すこと。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
10 ** 再配布や雑誌の付録などの問い合わせも必要ありません。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
11 ** 営利利用も上記に反しない範囲で許可します。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
12 ** バイナリの配布の際にはversion messageを保存することを条件とします。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
13 ** このプログラムについては特に何の保証もしない、悪しからず。
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
14 **
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
15 ** Everyone is permitted to do anything on this program
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
16 ** including copying, modifying, improving,
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
17 ** as long as you don't try to pretend that you wrote it.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
18 ** i.e., the above copyright notice has to appear in all copies.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
19 ** Binary distribution requires original version messages.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
20 ** You don't have to ask before copying, redistribution or publishing.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
21 ** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
e055df7c1082 *** empty log message ***
kono
parents: 599
diff changeset
22 ***********************************************************************/
1
0529f5abe9d0 *** empty log message ***
kono
parents: 0
diff changeset
23
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 81
diff changeset
24 #include <stdio.h>
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
25 #include "mc.h"
327
da2e3f2d127d macro/codegen reorganization
kono
parents: 81
diff changeset
26 #include "mc-parse.h"
596
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
27 #include "mc-codegen.h"
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
28
d35df41eac69 Initial revision
kono
parents:
diff changeset
29 typedef
d35df41eac69 Initial revision
kono
parents:
diff changeset
30 struct tree_node {
d35df41eac69 Initial revision
kono
parents:
diff changeset
31 int tree_type;
d35df41eac69 Initial revision
kono
parents:
diff changeset
32 char *tree_name;
d35df41eac69 Initial revision
kono
parents:
diff changeset
33 char *tree_args;
d35df41eac69 Initial revision
kono
parents:
diff changeset
34 } tree_node_type;
d35df41eac69 Initial revision
kono
parents:
diff changeset
35
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
36 extern void tree_print(int e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
37 extern void tree_parse(int e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
38 extern void tree_print_t(int e,int t);
254a0c576114 argument type list
kono
parents: 50
diff changeset
39 static tree_node_type * find_node(int e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
40 extern void type_print(int type,NMTBL *n,FILE *out);
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
41 extern void type_print1(int type,NMTBL *n,FILE *out,int cont);
68
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
42 extern void sym_print(int type,FILE *out);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
43
254a0c576114 argument type list
kono
parents: 50
diff changeset
44 /* ascendant order for binary search */
254a0c576114 argument type list
kono
parents: 50
diff changeset
45
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
46 static
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
47 tree_node_type tree_nodes[] = {
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
48 {DOTS,"...",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
49 {LMACRO,"lmacro",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
50 {FMACRO,"fmacro",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
51 {KONST,"const",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
52 {DEFINED,"defined",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
53 {ENVIRONMENT,"environment",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
54 {CODE,"code",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
55 {REGISTER,"register",""},
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
56 {ASM,"__asm__",""},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
57 {VOID,"void",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
58 {EXTRN,"extern",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
59 {SHORT,"short",""},
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
60 {USHORT,"unsigned short",""},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
61 {LONG,"long",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
62 {TYPE,"type",""},
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
63 {VOLATILE,"volatile",""},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
64 {SIZEOF,"sizeof",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
65 {TYPEDEF,"typedef",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
66 {FLABEL,"flabel",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
67 {BLABEL,"blabel",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
68 {MACRO,"macro",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
69 {STRING,"string",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
70 {IDENT,"ident",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
71 {FIELD,"field",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
72 {TAG,"tag",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
73 {RESERVE,"reserve",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
74 {DEFAULT,"default",""},
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
75 {ATTRIBUTE,"__attribute__",""},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
76 {CASE,"case",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
77 {SWITCH,"switch",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
78 {WHILE,"while",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
79 {DO,"do",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
80 {FOR,"for",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
81 {ELSE,"else",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
82 {IF,"if",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
83 {CONTINUE,"continue",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
84 {BREAK,"break",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
85 {RETURN,"return",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
86 {GOTO,"goto",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
87 {STATIC,"static",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
88 {EMPTY,"empty",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
89 {FUNCTION,"function","t"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
90 {UNION,"union",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
91 {STRUCT,"struct","vt"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
92 {ARRAY,"array","tv"},
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
93 {POINTER,"*","t"},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
94 {UNSIGNED,"unsigned",""},
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
95 {INLINE,"inline",""},
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
96 {SIGNED,"signed",""},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
97 {CHAR,"char",""},
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
98 {UCHAR,"unsigned char",""},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
99 {INT,"int",""},
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
100 {FLOAT,"float",""},
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
101 {DOUBLE,"double",""},
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
102 {LONGLONG,"long long",""},
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
103 {ULONGLONG,"unsigned long long",""},
37
412ad2e6c2a2 struct copy
kono
parents: 33
diff changeset
104
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
105 {GVAR,"gvar","vs"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
106 {RGVAR,"rgvar","vs"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
107 {CRGVAR,"crgvar","vs"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
108 {LVAR,"lvar","v"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
109 {RLVAR,"rlvar","v"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
110 {CRLVAR,"crlvar","v"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
111 {CONST,"const","v"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
112 {FNAME,"fname","n"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
113 {MUL,"*","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
114 {RINDIRECT,"rindirect","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
115 {CRINDIRECT,"crindirect","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
116 {BAND,"&","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
117 {MINUS,"-","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
118 {LNOT,"!","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
119 {BNOT,"~","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
120 {INC,"++",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
121 {POSTINC,"postinc","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
122 {PREINC,"preinc","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
123 {CPOSTINC,"cpostinc","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
124 {CPREINC,"cpreinc","e"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
125 {DEC,"--",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
126 {DIV,"/","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
127 {UDIV,"/","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
128 {MUL,"*","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
129 {UMUL,"*","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
130 {MOD,"%","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
131 {UMOD,"%","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
132 {ADD,"+","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
133 {SUB,"-","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
134 {RSHIFT,">>","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
135 {URSHIFT,">>","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
136 {LSHIFT,"<<","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
137 {ULSHIFT,"<<","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
138 {GT,">","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
139 {UGT,">","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
140 {GE,">=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
141 {UGE,">=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
142 {LT,"<","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
143 {ULT,"<","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
144 {LE,"<=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
145 {ULE,"<=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
146 {EQ,"==","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
147 {NEQ,"!=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
148 {BAND,"&","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
149 {EOR,"^","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
150 {BOR,"|","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
151 {LAND,"&&","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
152 {LOR,"||","ee"},
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
153 {COND,"?","eee"},
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
154 {ASS,"=","ee"},
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
155 {ASSOP,"assop","eev"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
156 {CASSOP,"cassop","eev"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
157 {COMMA,",","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
158 {LPAR,"(",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
159 {RPAR,")",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
160 {LBRA,"[",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
161 {RBRA,"]",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
162 {LC,"{",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
163 {RC,"}",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
164 {COLON,":","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
165 {SM,";",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
166 {PERIOD,".",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
167 {ARROW,"->",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
168 {SASS,"sass",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
169 {RSTRUCT,"rstruct",""},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
170 {AS+MUL,"*=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
171 {AS+UMUL,"*=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
172 {AS+DIV,"/=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
173 {AS+UDIV,"/=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
174 {AS+MOD,"%=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
175 {AS+UMOD,"%=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
176 {AS+ADD,"+=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
177 {AS+MINUS,"-=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
178 {AS+RSHIFT,">>=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
179 {AS+URSHIFT,">>=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
180 {AS+LSHIFT,"<<=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
181 {AS+ULSHIFT,"<<=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
182 {AS+BAND,"&=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
183 {AS+EOR,"^=","ee"},
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
184 {AS+BOR,"|=","ee"},
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
185 };
d35df41eac69 Initial revision
kono
parents:
diff changeset
186
564
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
187 static int
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
188 attr_print(int t)
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
189 {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
190 while (t>0 && car(t)==ATTRIBUTE) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
191 switch (caddr(t)) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
192 case KONST: printf( "const"); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
193 case VOLATILE: printf( "volatile"); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
194 case RESTRICT: printf( "restrict"); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
195 case INLINE: printf( "inline"); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
196 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
197 t = cadr(t);
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
198 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
199 return t;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
200 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
201
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
202 void
50
kono
parents: 37
diff changeset
203 tree_print_t(int e,int t)
kono
parents: 37
diff changeset
204 {
kono
parents: 37
diff changeset
205 printf("# type: ");
kono
parents: 37
diff changeset
206 tree_print(t);
kono
parents: 37
diff changeset
207 printf("expr: ");
kono
parents: 37
diff changeset
208 tree_print(e);
kono
parents: 37
diff changeset
209 printf("\n");
kono
parents: 37
diff changeset
210 }
kono
parents: 37
diff changeset
211
kono
parents: 37
diff changeset
212 void
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
213 tree_print(int e)
d35df41eac69 Initial revision
kono
parents:
diff changeset
214 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
215 printf("* generate code on type:\n* ");
d35df41eac69 Initial revision
kono
parents:
diff changeset
216 tree_parse(type);
d35df41eac69 Initial revision
kono
parents:
diff changeset
217 printf("\n* expr:\n* ");
d35df41eac69 Initial revision
kono
parents:
diff changeset
218 tree_parse(e);
d35df41eac69 Initial revision
kono
parents:
diff changeset
219 printf("\n");
d35df41eac69 Initial revision
kono
parents:
diff changeset
220 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
221
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
222 static
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
223 int tree_level;
d35df41eac69 Initial revision
kono
parents:
diff changeset
224
18
df7fa8cee67b pass -Wall
kono
parents: 1
diff changeset
225 void
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
226 tree_parse(int e)
d35df41eac69 Initial revision
kono
parents:
diff changeset
227 {
d35df41eac69 Initial revision
kono
parents:
diff changeset
228 tree_node_type *t;
d35df41eac69 Initial revision
kono
parents:
diff changeset
229 int i,j;
d35df41eac69 Initial revision
kono
parents:
diff changeset
230 char *s;
d35df41eac69 Initial revision
kono
parents:
diff changeset
231
d35df41eac69 Initial revision
kono
parents:
diff changeset
232 if(e<0) {
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
233 t=find_node(e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
234 if(t->tree_type==e) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
235 for(j=0;j<tree_level;j++) putchar(' ');
254a0c576114 argument type list
kono
parents: 50
diff changeset
236 printf("list(%s)",t->tree_name);
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
237 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
238 } else {
d35df41eac69 Initial revision
kono
parents:
diff changeset
239 i = car(e);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
240 t=find_node(e);
254a0c576114 argument type list
kono
parents: 50
diff changeset
241 if(t->tree_type==i) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
242 tree_level++;
254a0c576114 argument type list
kono
parents: 50
diff changeset
243 for(j=0;j<tree_level;j++) putchar(' ');
254a0c576114 argument type list
kono
parents: 50
diff changeset
244 printf("list(%s",t->tree_name);
254a0c576114 argument type list
kono
parents: 50
diff changeset
245 for(i=1,s=t->tree_args;*s;s++,i++) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
246 switch(*s) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
247 case 'e':
254a0c576114 argument type list
kono
parents: 50
diff changeset
248 case 't':
254a0c576114 argument type list
kono
parents: 50
diff changeset
249 printf(",\n*");
254a0c576114 argument type list
kono
parents: 50
diff changeset
250 tree_parse(heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
251 case 'v':
254a0c576114 argument type list
kono
parents: 50
diff changeset
252 printf(",%d",heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
253 case 'n':
254a0c576114 argument type list
kono
parents: 50
diff changeset
254 printf(",%s",((NMTBL *)heap[e+i])->nm); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
255 case 's':
254a0c576114 argument type list
kono
parents: 50
diff changeset
256 printf(",%s",(char *)heap[e+i]); break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
257 case 'i':
254a0c576114 argument type list
kono
parents: 50
diff changeset
258 printf(",%d",heap[e+i]); break;
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
259 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
260 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
261 tree_level--;
254a0c576114 argument type list
kono
parents: 50
diff changeset
262 printf(")");
0
d35df41eac69 Initial revision
kono
parents:
diff changeset
263 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
264 }
d35df41eac69 Initial revision
kono
parents:
diff changeset
265 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
266
254a0c576114 argument type list
kono
parents: 50
diff changeset
267 tree_node_type *
254a0c576114 argument type list
kono
parents: 50
diff changeset
268 find_node(int e) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
269 int e1,e2;
254a0c576114 argument type list
kono
parents: 50
diff changeset
270 int first=0;
254a0c576114 argument type list
kono
parents: 50
diff changeset
271 int last=sizeof(tree_nodes)/sizeof(tree_node_type);
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
272 // e2=-1;
599
df04bc5fd5fe *** empty log message ***
kono
parents: 596
diff changeset
273 e2=OP(e);
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
274 e1=0;
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
275 while (first!=last) {
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
276 #if 0
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
277 e1 = (first+last)/2;
254a0c576114 argument type list
kono
parents: 50
diff changeset
278 if(e2==e1)
254a0c576114 argument type list
kono
parents: 50
diff changeset
279 return 0;
254a0c576114 argument type list
kono
parents: 50
diff changeset
280 e2=e1;
254a0c576114 argument type list
kono
parents: 50
diff changeset
281 if (tree_nodes[e1].tree_type>e)
254a0c576114 argument type list
kono
parents: 50
diff changeset
282 last = e1;
254a0c576114 argument type list
kono
parents: 50
diff changeset
283 else if (tree_nodes[e1].tree_type==e)
254a0c576114 argument type list
kono
parents: 50
diff changeset
284 break;
254a0c576114 argument type list
kono
parents: 50
diff changeset
285 else if (tree_nodes[e1].tree_type<e)
254a0c576114 argument type list
kono
parents: 50
diff changeset
286 first = e1;
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
287 #else
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
288 if (tree_nodes[first].tree_type==e2)
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
289 return &tree_nodes[first];
562
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
290 first++;
0a156c491f81 *** empty log message ***
kono
parents: 468
diff changeset
291 #endif
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
292 }
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
293 fprintf(stderr,"Unknown ID %d [%d]in find note\n",e2,e);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
294 return &tree_nodes[e1];
254a0c576114 argument type list
kono
parents: 50
diff changeset
295 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
296
254a0c576114 argument type list
kono
parents: 50
diff changeset
297 void struct_type_print(int type,FILE *out)
254a0c576114 argument type list
kono
parents: 50
diff changeset
298 {
254a0c576114 argument type list
kono
parents: 50
diff changeset
299 NMTBL *n;
254a0c576114 argument type list
kono
parents: 50
diff changeset
300 int tags;
254a0c576114 argument type list
kono
parents: 50
diff changeset
301 if((n=(NMTBL*)cadddr(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
302 fprintf(out,"%s ",n->nm);
254a0c576114 argument type list
kono
parents: 50
diff changeset
303 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
304 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
305 if((tags=caddr(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
306 fprintf(out,"{");
254a0c576114 argument type list
kono
parents: 50
diff changeset
307 while(tags) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
308 n=(NMTBL*)caddr(tags);
254a0c576114 argument type list
kono
parents: 50
diff changeset
309 type_print(car(tags),n,out);
254a0c576114 argument type list
kono
parents: 50
diff changeset
310 fprintf(out,";");
254a0c576114 argument type list
kono
parents: 50
diff changeset
311 tags = cadr(tags);
254a0c576114 argument type list
kono
parents: 50
diff changeset
312 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
313 fprintf(out,"}");
254a0c576114 argument type list
kono
parents: 50
diff changeset
314 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
315 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
316
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
317 void function_type_print1(int type,NMTBL *n,FILE *out,int cont)
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
318 {
254a0c576114 argument type list
kono
parents: 50
diff changeset
319 int args;
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
320 type_print1(cadr(type),0,out,cont);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
321 if(n) fprintf(out," %s",n->nm);
254a0c576114 argument type list
kono
parents: 50
diff changeset
322 fprintf(out,"(");
254a0c576114 argument type list
kono
parents: 50
diff changeset
323 if((args=caddr(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
324 while (args) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
325 type_print(car(args),0,out);
254a0c576114 argument type list
kono
parents: 50
diff changeset
326 args=cadr(args);
254a0c576114 argument type list
kono
parents: 50
diff changeset
327 if (args) fprintf(out,",");
254a0c576114 argument type list
kono
parents: 50
diff changeset
328 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
329 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
330 fprintf(out,")");
254a0c576114 argument type list
kono
parents: 50
diff changeset
331 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
332
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
333 void function_type_print(int type,NMTBL *n,FILE *out)
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
334 {
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
335 function_type_print1(type,n,out,0);
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
336 }
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
337
68
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
338 void sym_print(int sym,FILE *out)
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
339 {
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
340 tree_node_type *tn;
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
341 if (!(tn=find_node(sym))) { error(-1); return; }
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
342 fprintf(out,"%s",tn->tree_name);
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
343 }
0266905063b5 *** empty log message ***
kono
parents: 67
diff changeset
344
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
345 NMTBL *
468
464e7480395c *** empty log message ***
kono
parents: 327
diff changeset
346 typedef_search(int t,int type)
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
347 {
2e84590720a6 typedef name
kono
parents: 69
diff changeset
348 while(t) {
2e84590720a6 typedef name
kono
parents: 69
diff changeset
349 if (((NMTBL*)car(t))->ty==type)
2e84590720a6 typedef name
kono
parents: 69
diff changeset
350 return (NMTBL*)car(t);
2e84590720a6 typedef name
kono
parents: 69
diff changeset
351 t=cadr(t);
2e84590720a6 typedef name
kono
parents: 69
diff changeset
352 }
2e84590720a6 typedef name
kono
parents: 69
diff changeset
353 return 0;
2e84590720a6 typedef name
kono
parents: 69
diff changeset
354 }
2e84590720a6 typedef name
kono
parents: 69
diff changeset
355
564
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
356 static void n_attr_print(int attr, FILE *out)
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
357 {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
358 for(;attr;attr=cadr(attr)) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
359 switch(car(attr)) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
360 case INLINE: fprintf(out,"inline "); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
361 case CONST: fprintf(out,"const "); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
362 case VOLATILE: fprintf(out,"const "); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
363 case RESTRICT: fprintf(out,"const "); break;
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
364 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
365 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
366 }
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
367
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
368 void type_print1(int type,NMTBL *n,FILE *out,int cont)
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
369 {
254a0c576114 argument type list
kono
parents: 50
diff changeset
370 int t;
254a0c576114 argument type list
kono
parents: 50
diff changeset
371 tree_node_type *tn;
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
372 NMTBL *td;
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
373 int args;
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
374
564
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
375 if (n) {
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
376 if (n->attr) n_attr_print(n->attr,out);
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
377 while(type>0 && car(type)==ATTRIBUTE) type=cadr(type);
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
378 } else
25f431685d80 *** empty log message ***
kono
parents: 563
diff changeset
379 type = attr_print(type);
75
92dcf107a837 c code output
kono
parents: 74
diff changeset
380 if(type>0&&(td=typedef_search(typedefed,type))) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
381 if (!cont)
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
382 fprintf(out,"%s ",td->nm);
75
92dcf107a837 c code output
kono
parents: 74
diff changeset
383 } else if(type>0&&(td=typedef_search(gtypedefed,type))) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
384 if (!cont)
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
385 fprintf(out,"%s ",td->nm);
2e84590720a6 typedef name
kono
parents: 69
diff changeset
386 } else if (type<0) {
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
387 t=type;
254a0c576114 argument type list
kono
parents: 50
diff changeset
388 if (!(tn=find_node(t))) { error(-1); return; }
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
389 if (!cont)
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
390 fprintf(out,"%s ",tn->tree_name);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
391 } else if ((t=car(type))) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
392 if (!(tn=find_node(t))) { error(-1); return; }
254a0c576114 argument type list
kono
parents: 50
diff changeset
393 if(t==STRUCT||t==UNION) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
394 if (!cont) {
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
395 fprintf(out,"%s ",tn->tree_name);
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
396 struct_type_print(type,out);
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
397 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
398 } else if(t==CODE) {
596
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
399 // if (!cont) { fprintf(out,"%s ",tn->tree_name); }
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
400 function_type_print1(type,n,out,cont);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
401 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
402 } else if(t==FUNCTION) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
403 function_type_print1(type,n,out,cont);
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
404 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
405 } else if(t==ARRAY) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
406 type_print1(cadr(type),n,out,cont);
70
2e84590720a6 typedef name
kono
parents: 69
diff changeset
407 if (caddr(type))
2e84590720a6 typedef name
kono
parents: 69
diff changeset
408 fprintf(out,"[%d]",caddr(type));
2e84590720a6 typedef name
kono
parents: 69
diff changeset
409 else
2e84590720a6 typedef name
kono
parents: 69
diff changeset
410 fprintf(out,"[]");
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
411 return;
254a0c576114 argument type list
kono
parents: 50
diff changeset
412 } else if(t==POINTER) {
254a0c576114 argument type list
kono
parents: 50
diff changeset
413 t=cadr(type);
563
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
414 if(t<0) {
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
415 type_print1(t,0,out,cont);
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
416 fprintf(out,"*");
588bb765b301 *** empty log message ***
kono
parents: 562
diff changeset
417 } else if(car(t)==FUNCTION) {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
418 type_print1(cadr(t),0,out,cont);
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
419 fprintf(out,"(*");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
420 if(n) fprintf(out,"%s",n->nm);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
421 fprintf(out,")");
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
422 fprintf(out,"(");
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
423 if((args=caddr(t))) {
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
424 while (args) {
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
425 type_print(car(args),0,out);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
426 args=cadr(args);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
427 if (args) fprintf(out,",");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
428 }
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
429 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
430 fprintf(out,")");
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
431 return;
596
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
432 } else if(car(t)==CODE) {
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
433 type_print1(cadr(t),0,out,cont);
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
434 fprintf(out,"(*");
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
435 if(n) fprintf(out,"%s",n->nm);
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
436 fprintf(out,")");
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
437 fprintf(out,"(");
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
438 if((args=caddr(t))) {
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
439 while (args) {
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
440 type_print(car(args),0,out);
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
441 args=cadr(args);
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
442 if (args) fprintf(out,",");
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
443 }
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
444 }
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
445 fprintf(out,")");
94d3a8c1b3e8 *** empty log message ***
kono
parents: 564
diff changeset
446 return;
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
447 } else if(car(t)==ARRAY) {
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
448 fprintf(out,"(*");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
449 type_print(cadr(t),n,out);
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
450 if (caddr(type))
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
451 fprintf(out,")[%d]",caddr(type));
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
452 else
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
453 fprintf(out,")[]");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
454 return;
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
455 } else {
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
456 type_print1(t,0,out,cont);
72
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
457 fprintf(out,"*");
3b5d293cea36 type def etc
kono
parents: 70
diff changeset
458 }
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
459 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
460 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
461 if(n) fprintf(out,"%s",n->nm);
254a0c576114 argument type list
kono
parents: 50
diff changeset
462 }
254a0c576114 argument type list
kono
parents: 50
diff changeset
463
74
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
464 void type_print(int type,NMTBL *n,FILE *out)
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
465 {
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
466 type_print1(type,n,out,0);
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
467 }
6de658ae384c *** empty log message ***
kono
parents: 72
diff changeset
468
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
469 /*
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
470 parse tree を印刷する
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
471
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
472 正しく括弧とかを付けるアルゴリズムが不明...
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
473 先読みして、優先順位を判別する必要があるはず。
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
474 */
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
475
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
476 void
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
477 print_expr(int e, FILE *vout)
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
478 {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
479 NMTBL *nptr,*n;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
480
660
3e1dba5758d8 *** empty log message ***
kono
parents: 620
diff changeset
481 if (e==0) {
3e1dba5758d8 *** empty log message ***
kono
parents: 620
diff changeset
482 fprintf(vout,"()");
3e1dba5758d8 *** empty log message ***
kono
parents: 620
diff changeset
483 return;
3e1dba5758d8 *** empty log message ***
kono
parents: 620
diff changeset
484 }
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
485 switch (car(e)%SOP) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
486 case LVAR:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
487 case RLVAR:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
488 if ((nptr = (NMTBL*)caddr(e))) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
489 fprintf(vout,"%s",nptr->nm);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
490 } else {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
491 // anonymous variable
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
492 fprintf(vout,"_%d",caddr(e));
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
493 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
494 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
495 case GVAR:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
496 case RGVAR:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
497 if ((nptr = (NMTBL*)caddr(e))) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
498 fprintf(vout,"%s",nptr->nm);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
499 } else {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
500 // anonymous variable
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
501 fprintf(vout,"_%d",caddr(e));
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
502 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
503 if (cadr(e)) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
504 // offset
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
505 // certainly this is wrong
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
506 fprintf(vout,"+%d",caddr(e));
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
507 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
508 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
509 case REGISTER:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
510 if ((nptr = (NMTBL*)caddr(e))) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
511 fprintf(vout,"%s",nptr->nm);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
512 } else {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
513 // anonymous register variable
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
514 fprintf(vout,"_%d",caddr(e));
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
515 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
516 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
517 case IDENT:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
518 nptr = (NMTBL*)cadr(e);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
519 fprintf(vout,"%s",nptr->nm); break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
520 case CONST:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
521 switch(car(e)) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
522 case CONST:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
523 fprintf(vout,"%d",cadr(e)); break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
524 #if FLOAT_CODE
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
525 case FCONST:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
526 fprintf(vout,"%g",dcadr(e)); break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
527 case DCONST:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
528 fprintf(vout,"%g",dcadr(e)); break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
529 #endif
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
530 #if LONGLONG_CODE
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
531 case LCONST:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
532 fprintf(vout,"%lld",lcadr(e)); break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
533 #endif
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
534 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
535 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
536 case ADDRESS:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
537 if (car(cadr(e))!=STRING) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
538 fprintf(vout,"&");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
539 print_expr(cadr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
540 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
541 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
542 case STRING:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
543 {
620
0e7281ec9007 *** empty log message ***
kono
parents: 609
diff changeset
544 int c; char *s; int i;
0e7281ec9007 *** empty log message ***
kono
parents: 609
diff changeset
545 nptr = (NMTBL*)cadr(e); s = nptr->nm;i=nptr->dsp;
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
546 fprintf(vout,"\"");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
547 while(--i>0) {
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
548 c=*s++;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
549 if(c=='\n') fprintf(vout,"\\n");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
550 else if(c=='\r') fprintf(vout,"\\r");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
551 else if(c=='\t') fprintf(vout,"\\t");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
552 else if(c=='\e') fprintf(vout,"\\e");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
553 else if(c=='"') fprintf(vout,"\\\"");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
554 else if(c=='\\') fprintf(vout,"\\\\");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
555 else if(!(' '<=c&&c<=0x7f)) fprintf(vout,"\\%03o",c);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
556 else fprintf(vout,"%c",c);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
557 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
558 fprintf(vout,"\"");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
559 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
560 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
561 case ARRAY:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
562 print_expr(cadr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
563 fprintf(vout,"[");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
564 print_expr(caddr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
565 fprintf(vout,"]");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
566 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
567 case PERIOD:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
568 print_expr(cadr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
569 n = (NMTBL*)caddr(e);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
570 fprintf(vout,".%s",n->nm);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
571 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
572 case ARROW:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
573 print_expr(cadr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
574 n = (NMTBL*)caddr(e);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
575 fprintf(vout,"->%s",n->nm);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
576 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
577 case INDIRECT:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
578 case RINDIRECT:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
579 fprintf(vout,"*");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
580 print_expr(cadr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
581 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
582 case FNAME:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
583 n = (NMTBL*)cadr(e);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
584 fprintf(vout,"%s",n->nm);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
585 break;
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
586 case ADD:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
587 fprintf(vout,"(");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
588 print_expr(cadr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
589 fprintf(vout,"+");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
590 print_expr(caddr(e),vout);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
591 fprintf(vout,")");
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
592 break;
660
3e1dba5758d8 *** empty log message ***
kono
parents: 620
diff changeset
593 case RSTRUCT:
3e1dba5758d8 *** empty log message ***
kono
parents: 620
diff changeset
594 print_expr(cadr(e),vout);
3e1dba5758d8 *** empty log message ***
kono
parents: 620
diff changeset
595 break;
609
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
596 default:
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
597 error(-1);
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
598 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
599 }
af6b9ae79583 modificatioon for udpcl
kono
parents: 607
diff changeset
600
67
254a0c576114 argument type list
kono
parents: 50
diff changeset
601 /* end */