equal
deleted
inserted
replaced
42 |
42 |
43 |
43 |
44 #include <unistd.h> |
44 #include <unistd.h> |
45 #include <stdio.h> /* required for NULL */ |
45 #include <stdio.h> /* required for NULL */ |
46 #include "absyntax_utils.hh" |
46 #include "absyntax_utils.hh" |
47 |
47 #include "../absyntax/visitor.hh" |
48 |
48 |
49 |
49 |
50 |
50 |
51 |
51 |
52 |
52 |
53 |
53 |
54 |
54 /*********************************/ |
|
55 /* Class to print a symbol */ |
|
56 /*********************************/ |
|
57 |
|
58 |
|
59 class print_symbol_c: public fcall_visitor_c { |
|
60 public: |
|
61 static void print(symbol_c *symbol); |
|
62 |
|
63 protected: |
|
64 void fcall(symbol_c *symbol); |
|
65 /* AST symbols with extra data have their own specialised methods for printing that data */ |
|
66 void *visit(il_instruction_c *symbol); |
|
67 |
|
68 private: |
|
69 static print_symbol_c *singleton; |
|
70 |
|
71 void dump_symbol(symbol_c* symbol); |
|
72 }; |
55 |
73 |
56 |
74 |
57 |
75 |
58 |
76 |
59 print_symbol_c *print_symbol_c::singleton = NULL; |
77 print_symbol_c *print_symbol_c::singleton = NULL; |
63 if (NULL == singleton) singleton = new print_symbol_c(); |
81 if (NULL == singleton) singleton = new print_symbol_c(); |
64 if (NULL == singleton) ERROR; |
82 if (NULL == singleton) ERROR; |
65 |
83 |
66 symbol->accept(*singleton); |
84 symbol->accept(*singleton); |
67 } |
85 } |
68 |
|
69 |
|
70 |
|
71 |
86 |
72 |
87 |
73 |
88 |
74 |
89 |
75 |
90 |
135 |
150 |
136 |
151 |
137 |
152 |
138 |
153 |
139 |
154 |
140 |
155 /*********************************/ |
141 |
156 /* Class to print an AST */ |
142 |
157 /*********************************/ |
143 |
158 |
|
159 class print_ast_c: public fcall_iterator_visitor_c { |
|
160 public: |
|
161 static void print(symbol_c *symbol); |
|
162 static void print(const char *str); |
|
163 |
|
164 protected: |
|
165 void prefix_fcall(symbol_c *symbol); |
|
166 void suffix_fcall(symbol_c *symbol); |
|
167 |
|
168 private: |
|
169 static print_ast_c *singleton; |
|
170 }; |
144 |
171 |
145 |
172 |
146 |
173 |
147 |
174 |
148 print_ast_c *print_ast_c::singleton = NULL; |
175 print_ast_c *print_ast_c::singleton = NULL; |
153 if (NULL == singleton) ERROR; |
180 if (NULL == singleton) ERROR; |
154 |
181 |
155 symbol->accept(*singleton); |
182 symbol->accept(*singleton); |
156 } |
183 } |
157 |
184 |
|
185 |
|
186 void print_ast_c::print(const char *str) { |
|
187 fprintf(stderr, str); |
|
188 } |
|
189 |
158 |
190 |
159 void print_ast_c::prefix_fcall(symbol_c* symbol) {print_symbol_c::print(symbol);} |
191 void print_ast_c::prefix_fcall(symbol_c* symbol) {print_symbol_c::print(symbol);} |
160 void print_ast_c::suffix_fcall(symbol_c* symbol) {} |
192 void print_ast_c::suffix_fcall(symbol_c* symbol) {} |
161 |
193 |
162 |
194 |
163 |
195 |
164 |
196 |
165 |
197 |
166 |
198 /*********************************/ |
167 |
199 /* The DEBUG class */ |
168 |
200 /*********************************/ |
169 |
201 |
170 |
202 |
171 |
203 |
172 |
204 |
173 |
205 void debug_c::print(const char *str) { |
174 |
206 fprintf(stderr, str); |
175 |
207 } |
176 |
208 |
|
209 void debug_c::print(symbol_c *symbol) { |
|
210 print_symbol_c::print(symbol); |
|
211 } |
|
212 |
|
213 void debug_c::print_ast(symbol_c *symbol) { |
|
214 print_ast_c::print(symbol); |
|
215 } |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |