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 : Andrew Beach |
---|
12 | // Last Modified On : Thu Jun 8 16:31:00 2017 |
---|
13 | // Update Count : 25 |
---|
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 | maybeAccept( typeDecl->get_init(), *this ); |
---|
70 | } |
---|
71 | |
---|
72 | void Visitor::visit( TypedefDecl *typeDecl ) { |
---|
73 | handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) ); |
---|
74 | } |
---|
75 | |
---|
76 | void Visitor::visit( AsmDecl *asmDecl ) { |
---|
77 | maybeAccept( asmDecl->get_stmt(), *this ); |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | void Visitor::visit( CompoundStmt *compoundStmt ) { |
---|
82 | acceptAll( compoundStmt->get_kids(), *this ); |
---|
83 | } |
---|
84 | |
---|
85 | void Visitor::visit( ExprStmt *exprStmt ) { |
---|
86 | maybeAccept( exprStmt->get_expr(), *this ); |
---|
87 | } |
---|
88 | |
---|
89 | void Visitor::visit( AsmStmt *asmStmt ) { |
---|
90 | maybeAccept( asmStmt->get_instruction(), *this ); |
---|
91 | acceptAll( asmStmt->get_output(), *this ); |
---|
92 | acceptAll( asmStmt->get_input(), *this ); |
---|
93 | acceptAll( asmStmt->get_clobber(), *this ); |
---|
94 | } |
---|
95 | |
---|
96 | void Visitor::visit( IfStmt *ifStmt ) { |
---|
97 | maybeAccept( ifStmt->get_condition(), *this ); |
---|
98 | maybeAccept( ifStmt->get_thenPart(), *this ); |
---|
99 | maybeAccept( ifStmt->get_elsePart(), *this ); |
---|
100 | } |
---|
101 | |
---|
102 | void Visitor::visit( WhileStmt *whileStmt ) { |
---|
103 | maybeAccept( whileStmt->get_condition(), *this ); |
---|
104 | maybeAccept( whileStmt->get_body(), *this ); |
---|
105 | } |
---|
106 | |
---|
107 | void Visitor::visit( ForStmt *forStmt ) { |
---|
108 | acceptAll( forStmt->get_initialization(), *this ); |
---|
109 | maybeAccept( forStmt->get_condition(), *this ); |
---|
110 | maybeAccept( forStmt->get_increment(), *this ); |
---|
111 | maybeAccept( forStmt->get_body(), *this ); |
---|
112 | } |
---|
113 | |
---|
114 | void Visitor::visit( SwitchStmt *switchStmt ) { |
---|
115 | maybeAccept( switchStmt->get_condition(), *this ); |
---|
116 | acceptAll( switchStmt->get_statements(), *this ); |
---|
117 | } |
---|
118 | |
---|
119 | void Visitor::visit( CaseStmt *caseStmt ) { |
---|
120 | maybeAccept( caseStmt->get_condition(), *this ); |
---|
121 | acceptAll( caseStmt->get_statements(), *this ); |
---|
122 | } |
---|
123 | |
---|
124 | void Visitor::visit( __attribute__((unused)) BranchStmt *branchStmt ) { |
---|
125 | } |
---|
126 | |
---|
127 | void Visitor::visit( ReturnStmt *returnStmt ) { |
---|
128 | maybeAccept( returnStmt->get_expr(), *this ); |
---|
129 | } |
---|
130 | |
---|
131 | void Visitor::visit( ThrowStmt * throwStmt ) { |
---|
132 | maybeAccept( throwStmt->get_expr(), *this ); |
---|
133 | maybeAccept( throwStmt->get_target(), *this ); |
---|
134 | } |
---|
135 | |
---|
136 | void Visitor::visit( TryStmt *tryStmt ) { |
---|
137 | maybeAccept( tryStmt->get_block(), *this ); |
---|
138 | acceptAll( tryStmt->get_catchers(), *this ); |
---|
139 | } |
---|
140 | |
---|
141 | void Visitor::visit( CatchStmt *catchStmt ) { |
---|
142 | maybeAccept( catchStmt->get_decl(), *this ); |
---|
143 | maybeAccept( catchStmt->get_body(), *this ); |
---|
144 | } |
---|
145 | |
---|
146 | void Visitor::visit( FinallyStmt *finalStmt ) { |
---|
147 | maybeAccept( finalStmt->get_block(), *this ); |
---|
148 | } |
---|
149 | |
---|
150 | void Visitor::visit( __attribute__((unused)) NullStmt *nullStmt ) { |
---|
151 | } |
---|
152 | |
---|
153 | void Visitor::visit( DeclStmt *declStmt ) { |
---|
154 | maybeAccept( declStmt->get_decl(), *this ); |
---|
155 | } |
---|
156 | |
---|
157 | void Visitor::visit( ImplicitCtorDtorStmt *impCtorDtorStmt ) { |
---|
158 | maybeAccept( impCtorDtorStmt->get_callStmt(), *this ); |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | void Visitor::visit( ApplicationExpr *applicationExpr ) { |
---|
163 | maybeAccept( applicationExpr->get_result(), *this ); |
---|
164 | maybeAccept( applicationExpr->get_function(), *this ); |
---|
165 | acceptAll( applicationExpr->get_args(), *this ); |
---|
166 | } |
---|
167 | |
---|
168 | void Visitor::visit( UntypedExpr *untypedExpr ) { |
---|
169 | maybeAccept( untypedExpr->get_result(), *this ); |
---|
170 | acceptAll( untypedExpr->get_args(), *this ); |
---|
171 | } |
---|
172 | |
---|
173 | void Visitor::visit( NameExpr *nameExpr ) { |
---|
174 | maybeAccept( nameExpr->get_result(), *this ); |
---|
175 | } |
---|
176 | |
---|
177 | void Visitor::visit( AddressExpr *addressExpr ) { |
---|
178 | maybeAccept( addressExpr->get_result(), *this ); |
---|
179 | maybeAccept( addressExpr->get_arg(), *this ); |
---|
180 | } |
---|
181 | |
---|
182 | void Visitor::visit( LabelAddressExpr *labAddressExpr ) { |
---|
183 | maybeAccept( labAddressExpr->get_result(), *this ); |
---|
184 | maybeAccept( labAddressExpr->get_arg(), *this ); |
---|
185 | } |
---|
186 | |
---|
187 | void Visitor::visit( CastExpr *castExpr ) { |
---|
188 | maybeAccept( castExpr->get_result(), *this ); |
---|
189 | maybeAccept( castExpr->get_arg(), *this ); |
---|
190 | } |
---|
191 | |
---|
192 | void Visitor::visit( UntypedMemberExpr *memberExpr ) { |
---|
193 | maybeAccept( memberExpr->get_result(), *this ); |
---|
194 | maybeAccept( memberExpr->get_aggregate(), *this ); |
---|
195 | maybeAccept( memberExpr->get_member(), *this ); |
---|
196 | } |
---|
197 | |
---|
198 | void Visitor::visit( MemberExpr *memberExpr ) { |
---|
199 | maybeAccept( memberExpr->get_result(), *this ); |
---|
200 | maybeAccept( memberExpr->get_aggregate(), *this ); |
---|
201 | } |
---|
202 | |
---|
203 | void Visitor::visit( VariableExpr *variableExpr ) { |
---|
204 | maybeAccept( variableExpr->get_result(), *this ); |
---|
205 | } |
---|
206 | |
---|
207 | void Visitor::visit( ConstantExpr *constantExpr ) { |
---|
208 | maybeAccept( constantExpr->get_result(), *this ); |
---|
209 | maybeAccept( constantExpr->get_constant(), *this ); |
---|
210 | } |
---|
211 | |
---|
212 | void Visitor::visit( SizeofExpr *sizeofExpr ) { |
---|
213 | maybeAccept( sizeofExpr->get_result(), *this ); |
---|
214 | if ( sizeofExpr->get_isType() ) { |
---|
215 | maybeAccept( sizeofExpr->get_type(), *this ); |
---|
216 | } else { |
---|
217 | maybeAccept( sizeofExpr->get_expr(), *this ); |
---|
218 | } |
---|
219 | } |
---|
220 | |
---|
221 | void Visitor::visit( AlignofExpr *alignofExpr ) { |
---|
222 | maybeAccept( alignofExpr->get_result(), *this ); |
---|
223 | if ( alignofExpr->get_isType() ) { |
---|
224 | maybeAccept( alignofExpr->get_type(), *this ); |
---|
225 | } else { |
---|
226 | maybeAccept( alignofExpr->get_expr(), *this ); |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | void Visitor::visit( UntypedOffsetofExpr *offsetofExpr ) { |
---|
231 | maybeAccept( offsetofExpr->get_result(), *this ); |
---|
232 | maybeAccept( offsetofExpr->get_type(), *this ); |
---|
233 | } |
---|
234 | |
---|
235 | void Visitor::visit( OffsetofExpr *offsetofExpr ) { |
---|
236 | maybeAccept( offsetofExpr->get_result(), *this ); |
---|
237 | maybeAccept( offsetofExpr->get_type(), *this ); |
---|
238 | maybeAccept( offsetofExpr->get_member(), *this ); |
---|
239 | } |
---|
240 | |
---|
241 | void Visitor::visit( OffsetPackExpr *offsetPackExpr ) { |
---|
242 | maybeAccept( offsetPackExpr->get_result(), *this ); |
---|
243 | maybeAccept( offsetPackExpr->get_type(), *this ); |
---|
244 | } |
---|
245 | |
---|
246 | void Visitor::visit( AttrExpr *attrExpr ) { |
---|
247 | maybeAccept( attrExpr->get_result(), *this ); |
---|
248 | if ( attrExpr->get_isType() ) { |
---|
249 | maybeAccept( attrExpr->get_type(), *this ); |
---|
250 | } else { |
---|
251 | maybeAccept( attrExpr->get_expr(), *this ); |
---|
252 | } |
---|
253 | } |
---|
254 | |
---|
255 | void Visitor::visit( LogicalExpr *logicalExpr ) { |
---|
256 | maybeAccept( logicalExpr->get_result(), *this ); |
---|
257 | maybeAccept( logicalExpr->get_arg1(), *this ); |
---|
258 | maybeAccept( logicalExpr->get_arg2(), *this ); |
---|
259 | } |
---|
260 | |
---|
261 | void Visitor::visit( ConditionalExpr *conditionalExpr ) { |
---|
262 | maybeAccept( conditionalExpr->get_result(), *this ); |
---|
263 | maybeAccept( conditionalExpr->get_arg1(), *this ); |
---|
264 | maybeAccept( conditionalExpr->get_arg2(), *this ); |
---|
265 | maybeAccept( conditionalExpr->get_arg3(), *this ); |
---|
266 | } |
---|
267 | |
---|
268 | void Visitor::visit( CommaExpr *commaExpr ) { |
---|
269 | maybeAccept( commaExpr->get_result(), *this ); |
---|
270 | maybeAccept( commaExpr->get_arg1(), *this ); |
---|
271 | maybeAccept( commaExpr->get_arg2(), *this ); |
---|
272 | } |
---|
273 | |
---|
274 | void Visitor::visit( TypeExpr *typeExpr ) { |
---|
275 | maybeAccept( typeExpr->get_result(), *this ); |
---|
276 | maybeAccept( typeExpr->get_type(), *this ); |
---|
277 | } |
---|
278 | |
---|
279 | void Visitor::visit( AsmExpr *asmExpr ) { |
---|
280 | maybeAccept( asmExpr->get_inout(), *this ); |
---|
281 | maybeAccept( asmExpr->get_constraint(), *this ); |
---|
282 | maybeAccept( asmExpr->get_operand(), *this ); |
---|
283 | } |
---|
284 | |
---|
285 | void Visitor::visit( ImplicitCopyCtorExpr *impCpCtorExpr ) { |
---|
286 | maybeAccept( impCpCtorExpr->get_result(), *this ); |
---|
287 | maybeAccept( impCpCtorExpr->get_callExpr(), *this ); |
---|
288 | acceptAll( impCpCtorExpr->get_tempDecls(), *this ); |
---|
289 | acceptAll( impCpCtorExpr->get_returnDecls(), *this ); |
---|
290 | acceptAll( impCpCtorExpr->get_dtors(), *this ); |
---|
291 | } |
---|
292 | |
---|
293 | void Visitor::visit( ConstructorExpr * ctorExpr ) { |
---|
294 | maybeAccept( ctorExpr->get_result(), *this ); |
---|
295 | maybeAccept( ctorExpr->get_callExpr(), *this ); |
---|
296 | } |
---|
297 | |
---|
298 | void Visitor::visit( CompoundLiteralExpr *compLitExpr ) { |
---|
299 | maybeAccept( compLitExpr->get_result(), *this ); |
---|
300 | maybeAccept( compLitExpr->get_initializer(), *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( TupleAssignExpr *assignExpr ) { |
---|
324 | maybeAccept( assignExpr->get_result(), *this ); |
---|
325 | maybeAccept( assignExpr->get_stmtExpr(), *this ); |
---|
326 | } |
---|
327 | |
---|
328 | void Visitor::visit( StmtExpr *stmtExpr ) { |
---|
329 | maybeAccept( stmtExpr->get_result(), *this ); |
---|
330 | maybeAccept( stmtExpr->get_statements(), *this ); |
---|
331 | acceptAll( stmtExpr->get_returnDecls(), *this ); |
---|
332 | acceptAll( stmtExpr->get_dtors(), *this ); |
---|
333 | } |
---|
334 | |
---|
335 | void Visitor::visit( UniqueExpr *uniqueExpr ) { |
---|
336 | maybeAccept( uniqueExpr->get_result(), *this ); |
---|
337 | maybeAccept( uniqueExpr->get_expr(), *this ); |
---|
338 | } |
---|
339 | |
---|
340 | |
---|
341 | void Visitor::visit( VoidType *voidType ) { |
---|
342 | acceptAll( voidType->get_forall(), *this ); |
---|
343 | } |
---|
344 | |
---|
345 | void Visitor::visit( BasicType *basicType ) { |
---|
346 | acceptAll( basicType->get_forall(), *this ); |
---|
347 | } |
---|
348 | |
---|
349 | void Visitor::visit( PointerType *pointerType ) { |
---|
350 | acceptAll( pointerType->get_forall(), *this ); |
---|
351 | maybeAccept( pointerType->get_base(), *this ); |
---|
352 | } |
---|
353 | |
---|
354 | void Visitor::visit( ArrayType *arrayType ) { |
---|
355 | acceptAll( arrayType->get_forall(), *this ); |
---|
356 | maybeAccept( arrayType->get_dimension(), *this ); |
---|
357 | maybeAccept( arrayType->get_base(), *this ); |
---|
358 | } |
---|
359 | |
---|
360 | void Visitor::visit( FunctionType *functionType ) { |
---|
361 | acceptAll( functionType->get_forall(), *this ); |
---|
362 | acceptAll( functionType->get_returnVals(), *this ); |
---|
363 | acceptAll( functionType->get_parameters(), *this ); |
---|
364 | } |
---|
365 | |
---|
366 | void Visitor::handleReferenceToType( ReferenceToType *aggregateUseType ) { |
---|
367 | acceptAll( aggregateUseType->get_forall(), *this ); |
---|
368 | acceptAll( aggregateUseType->get_parameters(), *this ); |
---|
369 | } |
---|
370 | |
---|
371 | void Visitor::visit( StructInstType *aggregateUseType ) { |
---|
372 | handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
373 | } |
---|
374 | |
---|
375 | void Visitor::visit( UnionInstType *aggregateUseType ) { |
---|
376 | handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
377 | } |
---|
378 | |
---|
379 | void Visitor::visit( EnumInstType *aggregateUseType ) { |
---|
380 | handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
381 | } |
---|
382 | |
---|
383 | void Visitor::visit( TraitInstType *aggregateUseType ) { |
---|
384 | handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
385 | acceptAll( aggregateUseType->get_members(), *this ); |
---|
386 | } |
---|
387 | |
---|
388 | void Visitor::visit( TypeInstType *aggregateUseType ) { |
---|
389 | handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) ); |
---|
390 | } |
---|
391 | |
---|
392 | void Visitor::visit( TupleType *tupleType ) { |
---|
393 | acceptAll( tupleType->get_forall(), *this ); |
---|
394 | acceptAll( tupleType->get_types(), *this ); |
---|
395 | } |
---|
396 | |
---|
397 | void Visitor::visit( TypeofType *typeofType ) { |
---|
398 | assert( typeofType->get_expr() ); |
---|
399 | typeofType->get_expr()->accept( *this ); |
---|
400 | } |
---|
401 | |
---|
402 | void Visitor::visit( AttrType *attrType ) { |
---|
403 | if ( attrType->get_isType() ) { |
---|
404 | assert( attrType->get_type() ); |
---|
405 | attrType->get_type()->accept( *this ); |
---|
406 | } else { |
---|
407 | assert( attrType->get_expr() ); |
---|
408 | attrType->get_expr()->accept( *this ); |
---|
409 | } // if |
---|
410 | } |
---|
411 | |
---|
412 | void Visitor::visit( VarArgsType *varArgsType ) { |
---|
413 | acceptAll( varArgsType->get_forall(), *this ); |
---|
414 | } |
---|
415 | |
---|
416 | void Visitor::visit( ZeroType *zeroType ) { |
---|
417 | acceptAll( zeroType->get_forall(), *this ); |
---|
418 | } |
---|
419 | |
---|
420 | void Visitor::visit( OneType *oneType ) { |
---|
421 | acceptAll( oneType->get_forall(), *this ); |
---|
422 | } |
---|
423 | |
---|
424 | |
---|
425 | void Visitor::visit( SingleInit *singleInit ) { |
---|
426 | singleInit->get_value()->accept( *this ); |
---|
427 | } |
---|
428 | |
---|
429 | void Visitor::visit( ListInit *listInit ) { |
---|
430 | acceptAll( listInit->get_designators(), *this ); |
---|
431 | acceptAll( listInit->get_initializers(), *this ); |
---|
432 | } |
---|
433 | |
---|
434 | void Visitor::visit( ConstructorInit *ctorInit ) { |
---|
435 | maybeAccept( ctorInit->get_ctor(), *this ); |
---|
436 | maybeAccept( ctorInit->get_dtor(), *this ); |
---|
437 | maybeAccept( ctorInit->get_init(), *this ); |
---|
438 | } |
---|
439 | |
---|
440 | |
---|
441 | void Visitor::visit( __attribute__((unused)) Subrange *subrange ) {} |
---|
442 | |
---|
443 | |
---|
444 | void Visitor::visit( __attribute__((unused)) Constant *constant ) {} |
---|
445 | // Local Variables: // |
---|
446 | // tab-width: 4 // |
---|
447 | // mode: c++ // |
---|
448 | // compile-command: "make install" // |
---|
449 | // End: // |
---|