1 | // |
---|
2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
3 | // |
---|
4 | // The contents of this file are covered under the licence agreement in the |
---|
5 | // file "LICENCE" distributed with Cforall. |
---|
6 | // |
---|
7 | // Visitor.cc -- |
---|
8 | // |
---|
9 | // Author : Richard C. Bilson |
---|
10 | // Created On : Mon May 18 07:44:20 2015 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Thu Feb 16 15:01:25 2017 |
---|
13 | // Update Count : 23 |
---|
14 | // |
---|
15 | |
---|
16 | #include <cassert> |
---|
17 | #include "Visitor.h" |
---|
18 | #include "Initializer.h" |
---|
19 | #include "Statement.h" |
---|
20 | #include "Type.h" |
---|
21 | #include "Declaration.h" |
---|
22 | #include "Expression.h" |
---|
23 | #include "Constant.h" |
---|
24 | |
---|
25 | Visitor::Visitor() {} |
---|
26 | |
---|
27 | Visitor::~Visitor() {} |
---|
28 | |
---|
29 | void Visitor::visit( ObjectDecl *objectDecl ) { |
---|
30 | maybeAccept( objectDecl->get_type(), *this ); |
---|
31 | maybeAccept( objectDecl->get_init(), *this ); |
---|
32 | maybeAccept( objectDecl->get_bitfieldWidth(), *this ); |
---|
33 | } |
---|
34 | |
---|
35 | void Visitor::visit( FunctionDecl *functionDecl ) { |
---|
36 | maybeAccept( functionDecl->get_functionType(), *this ); |
---|
37 | maybeAccept( functionDecl->get_statements(), *this ); |
---|
38 | } |
---|
39 | |
---|
40 | void Visitor::handleAggregateDecl( AggregateDecl *aggregateDecl ) { |
---|
41 | acceptAll( aggregateDecl->get_parameters(), *this ); |
---|
42 | acceptAll( aggregateDecl->get_members(), *this ); |
---|
43 | } |
---|
44 | |
---|
45 | void Visitor::visit( StructDecl *aggregateDecl ) { |
---|
46 | handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) ); |
---|
47 | } |
---|
48 | |
---|
49 | void Visitor::visit( UnionDecl *aggregateDecl ) { |
---|
50 | handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) ); |
---|
51 | } |
---|
52 | |
---|
53 | void Visitor::visit( EnumDecl *aggregateDecl ) { |
---|
54 | handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) ); |
---|
55 | } |
---|
56 | |
---|
57 | void Visitor::visit( TraitDecl *aggregateDecl ) { |
---|
58 | handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) ); |
---|
59 | } |
---|
60 | |
---|
61 | void Visitor::handleNamedTypeDecl( NamedTypeDecl *typeDecl ) { |
---|
62 | acceptAll( typeDecl->get_parameters(), *this ); |
---|
63 | acceptAll( typeDecl->get_assertions(), *this ); |
---|
64 | maybeAccept( typeDecl->get_base(), *this ); |
---|
65 | } |
---|
66 | |
---|
67 | void Visitor::visit( TypeDecl *typeDecl ) { |
---|
68 | handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) ); |
---|
69 | } |
---|
70 | |
---|
71 | void Visitor::visit( TypedefDecl *typeDecl ) { |
---|
72 | handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) ); |
---|
73 | } |
---|
74 | |
---|
75 | void Visitor::visit( AsmDecl *asmDecl ) { |
---|
76 | maybeAccept( asmDecl->get_stmt(), *this ); |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | void Visitor::visit( CompoundStmt *compoundStmt ) { |
---|
81 | acceptAll( compoundStmt->get_kids(), *this ); |
---|
82 | } |
---|
83 | |
---|
84 | void Visitor::visit( ExprStmt *exprStmt ) { |
---|
85 | maybeAccept( exprStmt->get_expr(), *this ); |
---|
86 | } |
---|
87 | |
---|
88 | void Visitor::visit( AsmStmt *asmStmt ) { |
---|
89 | maybeAccept( asmStmt->get_instruction(), *this ); |
---|
90 | acceptAll( asmStmt->get_output(), *this ); |
---|
91 | acceptAll( asmStmt->get_input(), *this ); |
---|
92 | acceptAll( asmStmt->get_clobber(), *this ); |
---|
93 | } |
---|
94 | |
---|
95 | void Visitor::visit( IfStmt *ifStmt ) { |
---|
96 | maybeAccept( ifStmt->get_condition(), *this ); |
---|
97 | maybeAccept( ifStmt->get_thenPart(), *this ); |
---|
98 | maybeAccept( ifStmt->get_elsePart(), *this ); |
---|
99 | } |
---|
100 | |
---|
101 | void Visitor::visit( WhileStmt *whileStmt ) { |
---|
102 | maybeAccept( whileStmt->get_condition(), *this ); |
---|
103 | maybeAccept( whileStmt->get_body(), *this ); |
---|
104 | } |
---|
105 | |
---|
106 | void Visitor::visit( ForStmt *forStmt ) { |
---|
107 | acceptAll( forStmt->get_initialization(), *this ); |
---|
108 | maybeAccept( forStmt->get_condition(), *this ); |
---|
109 | maybeAccept( forStmt->get_increment(), *this ); |
---|
110 | maybeAccept( forStmt->get_body(), *this ); |
---|
111 | } |
---|
112 | |
---|
113 | void Visitor::visit( SwitchStmt *switchStmt ) { |
---|
114 | maybeAccept( switchStmt->get_condition(), *this ); |
---|
115 | acceptAll( switchStmt->get_statements(), *this ); |
---|
116 | } |
---|
117 | |
---|
118 | void Visitor::visit( CaseStmt *caseStmt ) { |
---|
119 | maybeAccept( caseStmt->get_condition(), *this ); |
---|
120 | acceptAll( caseStmt->get_statements(), *this ); |
---|
121 | } |
---|
122 | |
---|
123 | void Visitor::visit( BranchStmt *branchStmt ) { |
---|
124 | } |
---|
125 | |
---|
126 | void Visitor::visit( ReturnStmt *returnStmt ) { |
---|
127 | maybeAccept( returnStmt->get_expr(), *this ); |
---|
128 | } |
---|
129 | |
---|
130 | void Visitor::visit( TryStmt *tryStmt ) { |
---|
131 | maybeAccept( tryStmt->get_block(), *this ); |
---|
132 | acceptAll( tryStmt->get_catchers(), *this ); |
---|
133 | } |
---|
134 | |
---|
135 | void Visitor::visit( CatchStmt *catchStmt ) { |
---|
136 | maybeAccept( catchStmt->get_decl(), *this ); |
---|
137 | maybeAccept( catchStmt->get_body(), *this ); |
---|
138 | } |
---|
139 | |
---|
140 | void Visitor::visit( FinallyStmt *finalStmt ) { |
---|
141 | maybeAccept( finalStmt->get_block(), *this ); |
---|
142 | } |
---|
143 | |
---|
144 | void Visitor::visit( NullStmt *nullStmt ) { |
---|
145 | } |
---|
146 | |
---|
147 | void Visitor::visit( DeclStmt *declStmt ) { |
---|
148 | maybeAccept( declStmt->get_decl(), *this ); |
---|
149 | } |
---|
150 | |
---|
151 | void Visitor::visit( ImplicitCtorDtorStmt *impCtorDtorStmt ) { |
---|
152 | maybeAccept( impCtorDtorStmt->get_callStmt(), *this ); |
---|
153 | } |
---|
154 | |
---|
155 | |
---|
156 | void Visitor::visit( ApplicationExpr *applicationExpr ) { |
---|
157 | maybeAccept( applicationExpr->get_result(), *this ); |
---|
158 | maybeAccept( applicationExpr->get_function(), *this ); |
---|
159 | acceptAll( applicationExpr->get_args(), *this ); |
---|
160 | } |
---|
161 | |
---|
162 | void Visitor::visit( UntypedExpr *untypedExpr ) { |
---|
163 | maybeAccept( untypedExpr->get_result(), *this ); |
---|
164 | acceptAll( untypedExpr->get_args(), *this ); |
---|
165 | } |
---|
166 | |
---|
167 | void Visitor::visit( NameExpr *nameExpr ) { |
---|
168 | maybeAccept( nameExpr->get_result(), *this ); |
---|
169 | } |
---|
170 | |
---|
171 | void Visitor::visit( AddressExpr *addressExpr ) { |
---|
172 | maybeAccept( addressExpr->get_result(), *this ); |
---|
173 | maybeAccept( addressExpr->get_arg(), *this ); |
---|
174 | } |
---|
175 | |
---|
176 | void Visitor::visit( LabelAddressExpr *labAddressExpr ) { |
---|
177 | maybeAccept( labAddressExpr->get_result(), *this ); |
---|
178 | maybeAccept( labAddressExpr->get_arg(), *this ); |
---|
179 | } |
---|
180 | |
---|
181 | void Visitor::visit( CastExpr *castExpr ) { |
---|
182 | maybeAccept( castExpr->get_result(), *this ); |
---|
183 | maybeAccept( castExpr->get_arg(), *this ); |
---|
184 | } |
---|
185 | |
---|
186 | void Visitor::visit( UntypedMemberExpr *memberExpr ) { |
---|
187 | maybeAccept( memberExpr->get_result(), *this ); |
---|
188 | maybeAccept( memberExpr->get_aggregate(), *this ); |
---|
189 | maybeAccept( memberExpr->get_member(), *this ); |
---|
190 | } |
---|
191 | |
---|
192 | void Visitor::visit( MemberExpr *memberExpr ) { |
---|
193 | maybeAccept( memberExpr->get_result(), *this ); |
---|
194 | maybeAccept( memberExpr->get_aggregate(), *this ); |
---|
195 | } |
---|
196 | |
---|
197 | void Visitor::visit( VariableExpr *variableExpr ) { |
---|
198 | maybeAccept( variableExpr->get_result(), *this ); |
---|
199 | } |
---|
200 | |
---|
201 | void Visitor::visit( ConstantExpr *constantExpr ) { |
---|
202 | maybeAccept( constantExpr->get_result(), *this ); |
---|
203 | maybeAccept( constantExpr->get_constant(), *this ); |
---|
204 | } |
---|
205 | |
---|
206 | void Visitor::visit( SizeofExpr *sizeofExpr ) { |
---|
207 | maybeAccept( sizeofExpr->get_result(), *this ); |
---|
208 | if ( sizeofExpr->get_isType() ) { |
---|
209 | maybeAccept( sizeofExpr->get_type(), *this ); |
---|
210 | } else { |
---|
211 | maybeAccept( sizeofExpr->get_expr(), *this ); |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | void Visitor::visit( AlignofExpr *alignofExpr ) { |
---|
216 | maybeAccept( alignofExpr->get_result(), *this ); |
---|
217 | if ( alignofExpr->get_isType() ) { |
---|
218 | maybeAccept( alignofExpr->get_type(), *this ); |
---|
219 | } else { |
---|
220 | maybeAccept( alignofExpr->get_expr(), *this ); |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | void Visitor::visit( UntypedOffsetofExpr *offsetofExpr ) { |
---|
225 | maybeAccept( offsetofExpr->get_result(), *this ); |
---|
226 | maybeAccept( offsetofExpr->get_type(), *this ); |
---|
227 | } |
---|
228 | |
---|
229 | void Visitor::visit( OffsetofExpr *offsetofExpr ) { |
---|
230 | maybeAccept( offsetofExpr->get_result(), *this ); |
---|
231 | maybeAccept( offsetofExpr->get_type(), *this ); |
---|
232 | maybeAccept( offsetofExpr->get_member(), *this ); |
---|
233 | } |
---|
234 | |
---|
235 | void Visitor::visit( OffsetPackExpr *offsetPackExpr ) { |
---|
236 | maybeAccept( offsetPackExpr->get_result(), *this ); |
---|
237 | maybeAccept( offsetPackExpr->get_type(), *this ); |
---|
238 | } |
---|
239 | |
---|
240 | void Visitor::visit( AttrExpr *attrExpr ) { |
---|
241 | maybeAccept( attrExpr->get_result(), *this ); |
---|
242 | if ( attrExpr->get_isType() ) { |
---|
243 | maybeAccept( attrExpr->get_type(), *this ); |
---|
244 | } else { |
---|
245 | maybeAccept( attrExpr->get_expr(), *this ); |
---|
246 | } |
---|
247 | } |
---|
248 | |
---|
249 | void Visitor::visit( LogicalExpr *logicalExpr ) { |
---|
250 | maybeAccept( logicalExpr->get_result(), *this ); |
---|
251 | maybeAccept( logicalExpr->get_arg1(), *this ); |
---|
252 | maybeAccept( logicalExpr->get_arg2(), *this ); |
---|
253 | } |
---|
254 | |
---|
255 | void Visitor::visit( ConditionalExpr *conditionalExpr ) { |
---|
256 | maybeAccept( conditionalExpr->get_result(), *this ); |
---|
257 | maybeAccept( conditionalExpr->get_arg1(), *this ); |
---|
258 | maybeAccept( conditionalExpr->get_arg2(), *this ); |
---|
259 | maybeAccept( conditionalExpr->get_arg3(), *this ); |
---|
260 | } |
---|
261 | |
---|
262 | void Visitor::visit( CommaExpr *commaExpr ) { |
---|
263 | maybeAccept( commaExpr->get_result(), *this ); |
---|
264 | maybeAccept( commaExpr->get_arg1(), *this ); |
---|
265 | maybeAccept( commaExpr->get_arg2(), *this ); |
---|
266 | } |
---|
267 | |
---|
268 | void Visitor::visit( TypeExpr *typeExpr ) { |
---|
269 | maybeAccept( typeExpr->get_result(), *this ); |
---|
270 | maybeAccept( typeExpr->get_type(), *this ); |
---|
271 | } |
---|
272 | |
---|
273 | void Visitor::visit( AsmExpr *asmExpr ) { |
---|
274 | maybeAccept( asmExpr->get_inout(), *this ); |
---|
275 | maybeAccept( asmExpr->get_constraint(), *this ); |
---|
276 | maybeAccept( asmExpr->get_operand(), *this ); |
---|
277 | } |
---|
278 | |
---|
279 | void Visitor::visit( ImplicitCopyCtorExpr *impCpCtorExpr ) { |
---|
280 | maybeAccept( impCpCtorExpr->get_result(), *this ); |
---|
281 | maybeAccept( impCpCtorExpr->get_callExpr(), *this ); |
---|
282 | acceptAll( impCpCtorExpr->get_tempDecls(), *this ); |
---|
283 | acceptAll( impCpCtorExpr->get_returnDecls(), *this ); |
---|
284 | acceptAll( impCpCtorExpr->get_dtors(), *this ); |
---|
285 | } |
---|
286 | |
---|
287 | void Visitor::visit( ConstructorExpr * ctorExpr ) { |
---|
288 | maybeAccept( ctorExpr->get_result(), *this ); |
---|
289 | maybeAccept( ctorExpr->get_callExpr(), *this ); |
---|
290 | } |
---|
291 | |
---|
292 | void Visitor::visit( CompoundLiteralExpr *compLitExpr ) { |
---|
293 | maybeAccept( compLitExpr->get_result(), *this ); |
---|
294 | maybeAccept( compLitExpr->get_type(), *this ); |
---|
295 | maybeAccept( compLitExpr->get_initializer(), *this ); |
---|
296 | } |
---|
297 | |
---|
298 | void Visitor::visit( UntypedValofExpr *valofExpr ) { |
---|
299 | maybeAccept( valofExpr->get_result(), *this ); |
---|
300 | maybeAccept( valofExpr->get_body(), *this ); |
---|
301 | } |
---|
302 | |
---|
303 | void Visitor::visit( RangeExpr *rangeExpr ) { |
---|
304 | maybeAccept( rangeExpr->get_low(), *this ); |
---|
305 | maybeAccept( rangeExpr->get_high(), *this ); |
---|
306 | } |
---|
307 | |
---|
308 | void Visitor::visit( UntypedTupleExpr *tupleExpr ) { |
---|
309 | maybeAccept( tupleExpr->get_result(), *this ); |
---|
310 | acceptAll( tupleExpr->get_exprs(), *this ); |
---|
311 | } |
---|
312 | |
---|
313 | void Visitor::visit( TupleExpr *tupleExpr ) { |
---|
314 | maybeAccept( tupleExpr->get_result(), *this ); |
---|
315 | acceptAll( tupleExpr->get_exprs(), *this ); |
---|
316 | } |
---|
317 | |
---|
318 | void Visitor::visit( TupleIndexExpr *tupleExpr ) { |
---|
319 | maybeAccept( tupleExpr->get_result(), *this ); |
---|
320 | maybeAccept( tupleExpr->get_tuple(), *this ); |
---|
321 | } |
---|
322 | |
---|
323 | void Visitor::visit( MemberTupleExpr *tupleExpr ) { |
---|
324 | maybeAccept( tupleExpr->get_result(), *this ); |
---|
325 | maybeAccept( tupleExpr->get_member(), *this ); |
---|
326 | maybeAccept( tupleExpr->get_aggregate(), *this ); |
---|
327 | } |
---|
328 | |
---|
329 | void Visitor::visit( TupleAssignExpr *assignExpr ) { |
---|
330 | maybeAccept( assignExpr->get_result(), *this ); |
---|
331 | maybeAccept( assignExpr->get_stmtExpr(), *this ); |
---|
332 | } |
---|
333 | |
---|
334 | void Visitor::visit( StmtExpr *stmtExpr ) { |
---|
335 | maybeAccept( stmtExpr->get_result(), *this ); |
---|
336 | maybeAccept( stmtExpr->get_statements(), *this ); |
---|
337 | acceptAll( stmtExpr->get_returnDecls(), *this ); |
---|
338 | acceptAll( stmtExpr->get_dtors(), *this ); |
---|
339 | } |
---|
340 | |
---|
341 | void Visitor::visit( UniqueExpr *uniqueExpr ) { |
---|
342 | maybeAccept( uniqueExpr->get_result(), *this ); |
---|
343 | maybeAccept( uniqueExpr->get_expr(), *this ); |
---|
344 | } |
---|
345 | |
---|
346 | |
---|
347 | void Visitor::visit( VoidType *voidType ) { |
---|
348 | acceptAll( voidType->get_forall(), *this ); |
---|
349 | } |
---|
350 | |
---|
351 | void Visitor::visit( BasicType *basicType ) { |
---|
352 | acceptAll( basicType->get_forall(), *this ); |
---|
353 | } |
---|
354 | |
---|
355 | void Visitor::visit( PointerType *pointerType ) { |
---|
356 | acceptAll( pointerType->get_forall(), *this ); |
---|
357 | maybeAccept( pointerType->get_base(), *this ); |
---|
358 | } |
---|
359 | |
---|
360 | void Visitor::visit( ArrayType *arrayType ) { |
---|
361 | acceptAll( arrayType->get_forall(), *this ); |
---|
362 | maybeAccept( arrayType->get_dimension(), *this ); |
---|
363 | maybeAccept( arrayType->get_base(), *this ); |
---|
364 | } |
---|
365 | |
---|
366 | void Visitor::visit( FunctionType *functionType ) { |
---|
367 | acceptAll( functionType->get_forall(), *this ); |
---|
368 | acceptAll( functionType->get_returnVals(), *this ); |
---|
369 | acceptAll( functionType->get_parameters(), *this ); |
---|
370 | } |
---|
371 | |
---|
372 | void Visitor::handleReferenceToType( ReferenceToType *aggregateUseType ) { |
---|
373 | acceptAll( aggregateUseType->get_forall(), *this ); |
---|
374 | acceptAll( aggregateUseType->get_parameters(), *this ); |
---|
375 | } |
---|
376 | |
---|
377 | void Visitor::visit( StructInstType *aggregateUseType ) { |
---|
378 | handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
379 | } |
---|
380 | |
---|
381 | void Visitor::visit( UnionInstType *aggregateUseType ) { |
---|
382 | handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
383 | } |
---|
384 | |
---|
385 | void Visitor::visit( EnumInstType *aggregateUseType ) { |
---|
386 | handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
387 | } |
---|
388 | |
---|
389 | void Visitor::visit( TraitInstType *aggregateUseType ) { |
---|
390 | handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
391 | acceptAll( aggregateUseType->get_members(), *this ); |
---|
392 | } |
---|
393 | |
---|
394 | void Visitor::visit( TypeInstType *aggregateUseType ) { |
---|
395 | handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
396 | } |
---|
397 | |
---|
398 | void Visitor::visit( TupleType *tupleType ) { |
---|
399 | acceptAll( tupleType->get_forall(), *this ); |
---|
400 | acceptAll( tupleType->get_types(), *this ); |
---|
401 | } |
---|
402 | |
---|
403 | void Visitor::visit( TypeofType *typeofType ) { |
---|
404 | assert( typeofType->get_expr() ); |
---|
405 | typeofType->get_expr()->accept( *this ); |
---|
406 | } |
---|
407 | |
---|
408 | void Visitor::visit( AttrType *attrType ) { |
---|
409 | if ( attrType->get_isType() ) { |
---|
410 | assert( attrType->get_type() ); |
---|
411 | attrType->get_type()->accept( *this ); |
---|
412 | } else { |
---|
413 | assert( attrType->get_expr() ); |
---|
414 | attrType->get_expr()->accept( *this ); |
---|
415 | } // if |
---|
416 | } |
---|
417 | |
---|
418 | void Visitor::visit( VarArgsType *varArgsType ) { |
---|
419 | acceptAll( varArgsType->get_forall(), *this ); |
---|
420 | } |
---|
421 | |
---|
422 | void Visitor::visit( ZeroType *zeroType ) { |
---|
423 | acceptAll( zeroType->get_forall(), *this ); |
---|
424 | } |
---|
425 | |
---|
426 | void Visitor::visit( OneType *oneType ) { |
---|
427 | acceptAll( oneType->get_forall(), *this ); |
---|
428 | } |
---|
429 | |
---|
430 | |
---|
431 | void Visitor::visit( SingleInit *singleInit ) { |
---|
432 | singleInit->get_value()->accept( *this ); |
---|
433 | } |
---|
434 | |
---|
435 | void Visitor::visit( ListInit *listInit ) { |
---|
436 | acceptAll( listInit->get_designators(), *this ); |
---|
437 | acceptAll( listInit->get_initializers(), *this ); |
---|
438 | } |
---|
439 | |
---|
440 | void Visitor::visit( ConstructorInit *ctorInit ) { |
---|
441 | maybeAccept( ctorInit->get_ctor(), *this ); |
---|
442 | maybeAccept( ctorInit->get_dtor(), *this ); |
---|
443 | maybeAccept( ctorInit->get_init(), *this ); |
---|
444 | } |
---|
445 | |
---|
446 | |
---|
447 | void Visitor::visit( Subrange *subrange ) {} |
---|
448 | |
---|
449 | |
---|
450 | void Visitor::visit( Constant *constant ) {} |
---|
451 | // Local Variables: // |
---|
452 | // tab-width: 4 // |
---|
453 | // mode: c++ // |
---|
454 | // compile-command: "make install" // |
---|
455 | // End: // |
---|