1 | /* |
---|
2 | * This file is part of the Cforall project |
---|
3 | * |
---|
4 | * $Id: Visitor.cc,v 1.30 2005/08/29 20:59:27 rcbilson Exp $ |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #include <cassert> |
---|
9 | #include "Visitor.h" |
---|
10 | #include "Initializer.h" |
---|
11 | #include "Statement.h" |
---|
12 | #include "Type.h" |
---|
13 | #include "Declaration.h" |
---|
14 | #include "Expression.h" |
---|
15 | #include "Constant.h" |
---|
16 | |
---|
17 | |
---|
18 | Visitor::Visitor() |
---|
19 | { |
---|
20 | } |
---|
21 | |
---|
22 | Visitor::~Visitor() |
---|
23 | { |
---|
24 | } |
---|
25 | |
---|
26 | void |
---|
27 | Visitor::visit(ObjectDecl *objectDecl) |
---|
28 | { |
---|
29 | maybeAccept( objectDecl->get_type(), *this ); |
---|
30 | maybeAccept( objectDecl->get_init(), *this ); |
---|
31 | maybeAccept( objectDecl->get_bitfieldWidth(), *this ); |
---|
32 | } |
---|
33 | |
---|
34 | void |
---|
35 | Visitor::visit(FunctionDecl *functionDecl) |
---|
36 | { |
---|
37 | maybeAccept( functionDecl->get_functionType(), *this ); |
---|
38 | acceptAll( functionDecl->get_oldDecls(), *this ); |
---|
39 | maybeAccept( functionDecl->get_statements(), *this ); |
---|
40 | } |
---|
41 | |
---|
42 | void |
---|
43 | Visitor::visit(AggregateDecl *aggregateDecl) |
---|
44 | { |
---|
45 | acceptAll( aggregateDecl->get_parameters(), *this ); |
---|
46 | acceptAll( aggregateDecl->get_members(), *this ); |
---|
47 | } |
---|
48 | |
---|
49 | void |
---|
50 | Visitor::visit(StructDecl *aggregateDecl) |
---|
51 | { |
---|
52 | visit( static_cast< AggregateDecl* >( aggregateDecl ) ); |
---|
53 | } |
---|
54 | |
---|
55 | void |
---|
56 | Visitor::visit(UnionDecl *aggregateDecl) |
---|
57 | { |
---|
58 | visit( static_cast< AggregateDecl* >( aggregateDecl ) ); |
---|
59 | } |
---|
60 | |
---|
61 | void |
---|
62 | Visitor::visit(EnumDecl *aggregateDecl) |
---|
63 | { |
---|
64 | visit( static_cast< AggregateDecl* >( aggregateDecl ) ); |
---|
65 | } |
---|
66 | |
---|
67 | void |
---|
68 | Visitor::visit(ContextDecl *aggregateDecl) |
---|
69 | { |
---|
70 | visit( static_cast< AggregateDecl* >( aggregateDecl ) ); |
---|
71 | } |
---|
72 | |
---|
73 | void |
---|
74 | Visitor::visit(NamedTypeDecl *typeDecl) |
---|
75 | { |
---|
76 | acceptAll( typeDecl->get_parameters(), *this ); |
---|
77 | acceptAll( typeDecl->get_assertions(), *this ); |
---|
78 | maybeAccept( typeDecl->get_base(), *this ); |
---|
79 | } |
---|
80 | |
---|
81 | void |
---|
82 | Visitor::visit(TypeDecl *typeDecl) |
---|
83 | { |
---|
84 | visit( static_cast< NamedTypeDecl* >( typeDecl ) ); |
---|
85 | } |
---|
86 | |
---|
87 | void |
---|
88 | Visitor::visit(TypedefDecl *typeDecl) |
---|
89 | { |
---|
90 | visit( static_cast< NamedTypeDecl* >( typeDecl ) ); |
---|
91 | } |
---|
92 | |
---|
93 | void |
---|
94 | Visitor::visit(CompoundStmt *compoundStmt) |
---|
95 | { |
---|
96 | acceptAll( compoundStmt->get_kids(), *this ); |
---|
97 | } |
---|
98 | |
---|
99 | void |
---|
100 | Visitor::visit(ExprStmt *exprStmt) |
---|
101 | { |
---|
102 | maybeAccept( exprStmt->get_expr(), *this ); |
---|
103 | } |
---|
104 | |
---|
105 | void |
---|
106 | Visitor::visit(IfStmt *ifStmt) |
---|
107 | { |
---|
108 | maybeAccept( ifStmt->get_condition(), *this ); |
---|
109 | maybeAccept( ifStmt->get_thenPart(), *this ); |
---|
110 | maybeAccept( ifStmt->get_elsePart(), *this ); |
---|
111 | } |
---|
112 | |
---|
113 | void |
---|
114 | Visitor::visit(WhileStmt *whileStmt) |
---|
115 | { |
---|
116 | maybeAccept( whileStmt->get_condition(), *this ); |
---|
117 | maybeAccept( whileStmt->get_body(), *this ); |
---|
118 | } |
---|
119 | |
---|
120 | void |
---|
121 | Visitor::visit(ForStmt *forStmt) |
---|
122 | { |
---|
123 | // ForStmt still needs to be fixed |
---|
124 | maybeAccept( forStmt->get_initialization(), *this ); |
---|
125 | maybeAccept( forStmt->get_condition(), *this ); |
---|
126 | maybeAccept( forStmt->get_increment(), *this ); |
---|
127 | maybeAccept( forStmt->get_body(), *this ); |
---|
128 | } |
---|
129 | |
---|
130 | void |
---|
131 | Visitor::visit(SwitchStmt *switchStmt) |
---|
132 | { |
---|
133 | maybeAccept( switchStmt->get_condition(), *this ); |
---|
134 | acceptAll( switchStmt->get_branches(), *this ); |
---|
135 | } |
---|
136 | |
---|
137 | void |
---|
138 | Visitor::visit(ChooseStmt *switchStmt) |
---|
139 | { |
---|
140 | maybeAccept( switchStmt->get_condition(), *this ); |
---|
141 | acceptAll( switchStmt->get_branches(), *this ); |
---|
142 | } |
---|
143 | |
---|
144 | void |
---|
145 | Visitor::visit(FallthruStmt *fallthruStmt){} |
---|
146 | |
---|
147 | void |
---|
148 | Visitor::visit(CaseStmt *caseStmt) |
---|
149 | { |
---|
150 | maybeAccept( caseStmt->get_condition(), *this ); |
---|
151 | acceptAll( caseStmt->get_statements(), *this ); |
---|
152 | } |
---|
153 | |
---|
154 | void |
---|
155 | Visitor::visit(BranchStmt *branchStmt) |
---|
156 | { |
---|
157 | } |
---|
158 | |
---|
159 | void |
---|
160 | Visitor::visit(ReturnStmt *returnStmt) |
---|
161 | { |
---|
162 | maybeAccept( returnStmt->get_expr(), *this ); |
---|
163 | } |
---|
164 | |
---|
165 | void |
---|
166 | Visitor::visit(TryStmt *tryStmt) |
---|
167 | { |
---|
168 | maybeAccept( tryStmt->get_block(), *this ); |
---|
169 | acceptAll( tryStmt->get_catchers(), *this ); |
---|
170 | } |
---|
171 | |
---|
172 | void |
---|
173 | Visitor::visit(CatchStmt *catchStmt) |
---|
174 | { |
---|
175 | maybeAccept( catchStmt->get_decl(), *this ); |
---|
176 | maybeAccept( catchStmt->get_body(), *this ); |
---|
177 | } |
---|
178 | |
---|
179 | void |
---|
180 | Visitor::visit(FinallyStmt *finalStmt) |
---|
181 | { |
---|
182 | maybeAccept( finalStmt->get_block(), *this ); |
---|
183 | } |
---|
184 | |
---|
185 | void |
---|
186 | Visitor::visit(NullStmt *nullStmt) |
---|
187 | { |
---|
188 | } |
---|
189 | |
---|
190 | void |
---|
191 | Visitor::visit(DeclStmt *declStmt) |
---|
192 | { |
---|
193 | maybeAccept( declStmt->get_decl(), *this ); |
---|
194 | } |
---|
195 | |
---|
196 | void |
---|
197 | Visitor::visit(ApplicationExpr *applicationExpr) |
---|
198 | { |
---|
199 | acceptAll( applicationExpr->get_results(), *this ); |
---|
200 | maybeAccept( applicationExpr->get_function(), *this ); |
---|
201 | acceptAll( applicationExpr->get_args(), *this ); |
---|
202 | } |
---|
203 | |
---|
204 | void |
---|
205 | Visitor::visit(UntypedExpr *untypedExpr) |
---|
206 | { |
---|
207 | acceptAll( untypedExpr->get_results(), *this ); |
---|
208 | acceptAll( untypedExpr->get_args(), *this ); |
---|
209 | } |
---|
210 | |
---|
211 | void |
---|
212 | Visitor::visit(NameExpr *nameExpr) |
---|
213 | { |
---|
214 | acceptAll( nameExpr->get_results(), *this ); |
---|
215 | } |
---|
216 | |
---|
217 | void |
---|
218 | Visitor::visit(AddressExpr *addressExpr) |
---|
219 | { |
---|
220 | acceptAll( addressExpr->get_results(), *this ); |
---|
221 | maybeAccept( addressExpr->get_arg(), *this ); |
---|
222 | } |
---|
223 | |
---|
224 | void |
---|
225 | Visitor::visit(LabelAddressExpr *labAddressExpr) |
---|
226 | { |
---|
227 | acceptAll( labAddressExpr->get_results(), *this ); |
---|
228 | maybeAccept( labAddressExpr->get_arg(), *this ); |
---|
229 | } |
---|
230 | |
---|
231 | void |
---|
232 | Visitor::visit(CastExpr *castExpr) |
---|
233 | { |
---|
234 | acceptAll( castExpr->get_results(), *this ); |
---|
235 | maybeAccept( castExpr->get_arg(), *this ); |
---|
236 | } |
---|
237 | |
---|
238 | void |
---|
239 | Visitor::visit(UntypedMemberExpr *memberExpr) |
---|
240 | { |
---|
241 | acceptAll( memberExpr->get_results(), *this ); |
---|
242 | maybeAccept( memberExpr->get_aggregate(), *this ); |
---|
243 | } |
---|
244 | |
---|
245 | void |
---|
246 | Visitor::visit(MemberExpr *memberExpr) |
---|
247 | { |
---|
248 | acceptAll( memberExpr->get_results(), *this ); |
---|
249 | maybeAccept( memberExpr->get_aggregate(), *this ); |
---|
250 | } |
---|
251 | |
---|
252 | void |
---|
253 | Visitor::visit(VariableExpr *variableExpr) |
---|
254 | { |
---|
255 | acceptAll( variableExpr->get_results(), *this ); |
---|
256 | } |
---|
257 | |
---|
258 | void |
---|
259 | Visitor::visit(ConstantExpr *constantExpr) |
---|
260 | { |
---|
261 | acceptAll( constantExpr->get_results(), *this ); |
---|
262 | maybeAccept( constantExpr->get_constant(), *this ); |
---|
263 | } |
---|
264 | |
---|
265 | void |
---|
266 | Visitor::visit(SizeofExpr *sizeofExpr) |
---|
267 | { |
---|
268 | acceptAll( sizeofExpr->get_results(), *this ); |
---|
269 | if( sizeofExpr->get_isType() ) { |
---|
270 | maybeAccept( sizeofExpr->get_type(), *this ); |
---|
271 | } else { |
---|
272 | maybeAccept( sizeofExpr->get_expr(), *this ); |
---|
273 | } |
---|
274 | } |
---|
275 | |
---|
276 | void |
---|
277 | Visitor::visit(AttrExpr *attrExpr) |
---|
278 | { |
---|
279 | acceptAll( attrExpr->get_results(), *this ); |
---|
280 | if( attrExpr->get_isType() ) { |
---|
281 | maybeAccept( attrExpr->get_type(), *this ); |
---|
282 | } else { |
---|
283 | maybeAccept( attrExpr->get_expr(), *this ); |
---|
284 | } |
---|
285 | } |
---|
286 | |
---|
287 | void |
---|
288 | Visitor::visit(LogicalExpr *logicalExpr) |
---|
289 | { |
---|
290 | acceptAll( logicalExpr->get_results(), *this ); |
---|
291 | maybeAccept( logicalExpr->get_arg1(), *this ); |
---|
292 | maybeAccept( logicalExpr->get_arg2(), *this ); |
---|
293 | } |
---|
294 | |
---|
295 | void |
---|
296 | Visitor::visit(ConditionalExpr *conditionalExpr) |
---|
297 | { |
---|
298 | acceptAll( conditionalExpr->get_results(), *this ); |
---|
299 | maybeAccept( conditionalExpr->get_arg1(), *this ); |
---|
300 | maybeAccept( conditionalExpr->get_arg2(), *this ); |
---|
301 | maybeAccept( conditionalExpr->get_arg3(), *this ); |
---|
302 | } |
---|
303 | |
---|
304 | void |
---|
305 | Visitor::visit(CommaExpr *commaExpr) |
---|
306 | { |
---|
307 | acceptAll( commaExpr->get_results(), *this ); |
---|
308 | maybeAccept( commaExpr->get_arg1(), *this ); |
---|
309 | maybeAccept( commaExpr->get_arg2(), *this ); |
---|
310 | } |
---|
311 | |
---|
312 | void |
---|
313 | Visitor::visit(TupleExpr *tupleExpr) |
---|
314 | { |
---|
315 | acceptAll( tupleExpr->get_results(), *this ); |
---|
316 | acceptAll( tupleExpr->get_exprs(), *this ); |
---|
317 | } |
---|
318 | |
---|
319 | void |
---|
320 | Visitor::visit(SolvedTupleExpr *tupleExpr) |
---|
321 | { |
---|
322 | acceptAll( tupleExpr->get_results(), *this ); |
---|
323 | acceptAll( tupleExpr->get_exprs(), *this ); |
---|
324 | } |
---|
325 | |
---|
326 | void |
---|
327 | Visitor::visit(TypeExpr *typeExpr) |
---|
328 | { |
---|
329 | acceptAll( typeExpr->get_results(), *this ); |
---|
330 | maybeAccept( typeExpr->get_type(), *this ); |
---|
331 | } |
---|
332 | |
---|
333 | void |
---|
334 | Visitor::visit(UntypedValofExpr *valofExpr) |
---|
335 | { |
---|
336 | acceptAll( valofExpr->get_results(), *this ); |
---|
337 | maybeAccept( valofExpr->get_body(), *this ); |
---|
338 | } |
---|
339 | |
---|
340 | void |
---|
341 | Visitor::visit(VoidType *voidType) |
---|
342 | { |
---|
343 | acceptAll( voidType->get_forall(), *this ); |
---|
344 | } |
---|
345 | |
---|
346 | void |
---|
347 | Visitor::visit(BasicType *basicType) |
---|
348 | { |
---|
349 | acceptAll( basicType->get_forall(), *this ); |
---|
350 | } |
---|
351 | |
---|
352 | void |
---|
353 | Visitor::visit(PointerType *pointerType) |
---|
354 | { |
---|
355 | acceptAll( pointerType->get_forall(), *this ); |
---|
356 | maybeAccept( pointerType->get_base(), *this ); |
---|
357 | } |
---|
358 | |
---|
359 | void |
---|
360 | Visitor::visit(ArrayType *arrayType) |
---|
361 | { |
---|
362 | acceptAll( arrayType->get_forall(), *this ); |
---|
363 | maybeAccept( arrayType->get_dimension(), *this ); |
---|
364 | maybeAccept( arrayType->get_base(), *this ); |
---|
365 | } |
---|
366 | |
---|
367 | void |
---|
368 | Visitor::visit(FunctionType *functionType) |
---|
369 | { |
---|
370 | acceptAll( functionType->get_forall(), *this ); |
---|
371 | acceptAll( functionType->get_returnVals(), *this ); |
---|
372 | acceptAll( functionType->get_parameters(), *this ); |
---|
373 | } |
---|
374 | |
---|
375 | void |
---|
376 | Visitor::visit(ReferenceToType *aggregateUseType) |
---|
377 | { |
---|
378 | acceptAll( aggregateUseType->get_forall(), *this ); |
---|
379 | acceptAll( aggregateUseType->get_parameters(), *this ); |
---|
380 | } |
---|
381 | |
---|
382 | void |
---|
383 | Visitor::visit(StructInstType *aggregateUseType) |
---|
384 | { |
---|
385 | visit( static_cast< ReferenceToType* >( aggregateUseType ) ); |
---|
386 | } |
---|
387 | |
---|
388 | void |
---|
389 | Visitor::visit(UnionInstType *aggregateUseType) |
---|
390 | { |
---|
391 | visit( static_cast< ReferenceToType* >( aggregateUseType ) ); |
---|
392 | } |
---|
393 | |
---|
394 | void |
---|
395 | Visitor::visit(EnumInstType *aggregateUseType) |
---|
396 | { |
---|
397 | visit( static_cast< ReferenceToType* >( aggregateUseType ) ); |
---|
398 | } |
---|
399 | |
---|
400 | void |
---|
401 | Visitor::visit(ContextInstType *aggregateUseType) |
---|
402 | { |
---|
403 | visit( static_cast< ReferenceToType* >( aggregateUseType ) ); |
---|
404 | acceptAll( aggregateUseType->get_members(), *this ); |
---|
405 | } |
---|
406 | |
---|
407 | void |
---|
408 | Visitor::visit(TypeInstType *aggregateUseType) |
---|
409 | { |
---|
410 | visit( static_cast< ReferenceToType* >( aggregateUseType ) ); |
---|
411 | } |
---|
412 | |
---|
413 | void |
---|
414 | Visitor::visit(TupleType *tupleType) |
---|
415 | { |
---|
416 | acceptAll( tupleType->get_forall(), *this ); |
---|
417 | acceptAll( tupleType->get_types(), *this ); |
---|
418 | } |
---|
419 | |
---|
420 | void |
---|
421 | Visitor::visit(TypeofType *typeofType) |
---|
422 | { |
---|
423 | assert( typeofType->get_expr() ); |
---|
424 | typeofType->get_expr()->accept( *this ); |
---|
425 | } |
---|
426 | |
---|
427 | void |
---|
428 | Visitor::visit(AttrType *attrType) |
---|
429 | { |
---|
430 | if( attrType->get_isType() ) { |
---|
431 | assert( attrType->get_type() ); |
---|
432 | attrType->get_type()->accept( *this ); |
---|
433 | } else { |
---|
434 | assert( attrType->get_expr() ); |
---|
435 | attrType->get_expr()->accept( *this ); |
---|
436 | } |
---|
437 | } |
---|
438 | |
---|
439 | void |
---|
440 | Visitor::visit(MemberInit *memberInit) |
---|
441 | { |
---|
442 | memberInit->get_value()->accept( *this ); |
---|
443 | } |
---|
444 | |
---|
445 | void |
---|
446 | Visitor::visit(ElementInit *elementInit) |
---|
447 | { |
---|
448 | elementInit->get_value()->accept( *this ); |
---|
449 | } |
---|
450 | |
---|
451 | void |
---|
452 | Visitor::visit(SingleInit *singleInit) |
---|
453 | { |
---|
454 | singleInit->get_value()->accept( *this ); |
---|
455 | } |
---|
456 | |
---|
457 | void |
---|
458 | Visitor::visit(ListInit *listInit) |
---|
459 | { |
---|
460 | acceptAll( listInit->get_designators(), *this ); |
---|
461 | acceptAll( listInit->get_initializers(), *this ); |
---|
462 | } |
---|
463 | |
---|
464 | void |
---|
465 | Visitor::visit(Subrange *subrange) |
---|
466 | { |
---|
467 | } |
---|
468 | |
---|
469 | void |
---|
470 | Visitor::visit(Constant *constant) |
---|
471 | { |
---|
472 | } |
---|
473 | |
---|