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 Aug 4 11:24:25 2016
|
---|
13 | // Update Count : 21
|
---|
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 | acceptAll( functionDecl->get_oldDecls(), *this );
|
---|
38 | maybeAccept( functionDecl->get_statements(), *this );
|
---|
39 | }
|
---|
40 |
|
---|
41 | void Visitor::handleAggregateDecl( AggregateDecl *aggregateDecl ) {
|
---|
42 | acceptAll( aggregateDecl->get_parameters(), *this );
|
---|
43 | acceptAll( aggregateDecl->get_members(), *this );
|
---|
44 | }
|
---|
45 |
|
---|
46 | void Visitor::visit( StructDecl *aggregateDecl ) {
|
---|
47 | handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
|
---|
48 | }
|
---|
49 |
|
---|
50 | void Visitor::visit( UnionDecl *aggregateDecl ) {
|
---|
51 | handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
|
---|
52 | }
|
---|
53 |
|
---|
54 | void Visitor::visit( EnumDecl *aggregateDecl ) {
|
---|
55 | handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
|
---|
56 | }
|
---|
57 |
|
---|
58 | void Visitor::visit( TraitDecl *aggregateDecl ) {
|
---|
59 | handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
|
---|
60 | }
|
---|
61 |
|
---|
62 | void Visitor::handleNamedTypeDecl( NamedTypeDecl *typeDecl ) {
|
---|
63 | acceptAll( typeDecl->get_parameters(), *this );
|
---|
64 | acceptAll( typeDecl->get_assertions(), *this );
|
---|
65 | maybeAccept( typeDecl->get_base(), *this );
|
---|
66 | }
|
---|
67 |
|
---|
68 | void Visitor::visit( TypeDecl *typeDecl ) {
|
---|
69 | handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) );
|
---|
70 | }
|
---|
71 |
|
---|
72 | void Visitor::visit( TypedefDecl *typeDecl ) {
|
---|
73 | handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) );
|
---|
74 | }
|
---|
75 |
|
---|
76 | void Visitor::visit( CompoundStmt *compoundStmt ) {
|
---|
77 | acceptAll( compoundStmt->get_kids(), *this );
|
---|
78 | }
|
---|
79 |
|
---|
80 | void Visitor::visit( ExprStmt *exprStmt ) {
|
---|
81 | maybeAccept( exprStmt->get_expr(), *this );
|
---|
82 | }
|
---|
83 |
|
---|
84 | void Visitor::visit( AsmStmt *asmStmt ) {
|
---|
85 | maybeAccept( asmStmt->get_instruction(), *this );
|
---|
86 | acceptAll( asmStmt->get_output(), *this );
|
---|
87 | acceptAll( asmStmt->get_input(), *this );
|
---|
88 | acceptAll( asmStmt->get_clobber(), *this );
|
---|
89 | }
|
---|
90 |
|
---|
91 | void Visitor::visit( IfStmt *ifStmt ) {
|
---|
92 | maybeAccept( ifStmt->get_condition(), *this );
|
---|
93 | maybeAccept( ifStmt->get_thenPart(), *this );
|
---|
94 | maybeAccept( ifStmt->get_elsePart(), *this );
|
---|
95 | }
|
---|
96 |
|
---|
97 | void Visitor::visit( WhileStmt *whileStmt ) {
|
---|
98 | maybeAccept( whileStmt->get_condition(), *this );
|
---|
99 | maybeAccept( whileStmt->get_body(), *this );
|
---|
100 | }
|
---|
101 |
|
---|
102 | void Visitor::visit( ForStmt *forStmt ) {
|
---|
103 | acceptAll( forStmt->get_initialization(), *this );
|
---|
104 | maybeAccept( forStmt->get_condition(), *this );
|
---|
105 | maybeAccept( forStmt->get_increment(), *this );
|
---|
106 | maybeAccept( forStmt->get_body(), *this );
|
---|
107 | }
|
---|
108 |
|
---|
109 | void Visitor::visit( SwitchStmt *switchStmt ) {
|
---|
110 | maybeAccept( switchStmt->get_condition(), *this );
|
---|
111 | acceptAll( switchStmt->get_statements(), *this );
|
---|
112 | }
|
---|
113 |
|
---|
114 | void Visitor::visit( CaseStmt *caseStmt ) {
|
---|
115 | maybeAccept( caseStmt->get_condition(), *this );
|
---|
116 | acceptAll( caseStmt->get_statements(), *this );
|
---|
117 | }
|
---|
118 |
|
---|
119 | void Visitor::visit( BranchStmt *branchStmt ) {
|
---|
120 | }
|
---|
121 |
|
---|
122 | void Visitor::visit( ReturnStmt *returnStmt ) {
|
---|
123 | maybeAccept( returnStmt->get_expr(), *this );
|
---|
124 | }
|
---|
125 |
|
---|
126 | void Visitor::visit( TryStmt *tryStmt ) {
|
---|
127 | maybeAccept( tryStmt->get_block(), *this );
|
---|
128 | acceptAll( tryStmt->get_catchers(), *this );
|
---|
129 | }
|
---|
130 |
|
---|
131 | void Visitor::visit( CatchStmt *catchStmt ) {
|
---|
132 | maybeAccept( catchStmt->get_decl(), *this );
|
---|
133 | maybeAccept( catchStmt->get_body(), *this );
|
---|
134 | }
|
---|
135 |
|
---|
136 | void Visitor::visit( FinallyStmt *finalStmt ) {
|
---|
137 | maybeAccept( finalStmt->get_block(), *this );
|
---|
138 | }
|
---|
139 |
|
---|
140 | void Visitor::visit( NullStmt *nullStmt ) {
|
---|
141 | }
|
---|
142 |
|
---|
143 | void Visitor::visit( DeclStmt *declStmt ) {
|
---|
144 | maybeAccept( declStmt->get_decl(), *this );
|
---|
145 | }
|
---|
146 |
|
---|
147 | void Visitor::visit( ImplicitCtorDtorStmt *impCtorDtorStmt ) {
|
---|
148 | maybeAccept( impCtorDtorStmt->get_callStmt(), *this );
|
---|
149 | }
|
---|
150 |
|
---|
151 | void Visitor::visit( ApplicationExpr *applicationExpr ) {
|
---|
152 | maybeAccept( applicationExpr->get_result(), *this );
|
---|
153 | maybeAccept( applicationExpr->get_function(), *this );
|
---|
154 | acceptAll( applicationExpr->get_args(), *this );
|
---|
155 | }
|
---|
156 |
|
---|
157 | void Visitor::visit( UntypedExpr *untypedExpr ) {
|
---|
158 | maybeAccept( untypedExpr->get_result(), *this );
|
---|
159 | acceptAll( untypedExpr->get_args(), *this );
|
---|
160 | }
|
---|
161 |
|
---|
162 | void Visitor::visit( NameExpr *nameExpr ) {
|
---|
163 | maybeAccept( nameExpr->get_result(), *this );
|
---|
164 | }
|
---|
165 |
|
---|
166 | void Visitor::visit( AddressExpr *addressExpr ) {
|
---|
167 | maybeAccept( addressExpr->get_result(), *this );
|
---|
168 | maybeAccept( addressExpr->get_arg(), *this );
|
---|
169 | }
|
---|
170 |
|
---|
171 | void Visitor::visit( LabelAddressExpr *labAddressExpr ) {
|
---|
172 | maybeAccept( labAddressExpr->get_result(), *this );
|
---|
173 | maybeAccept( labAddressExpr->get_arg(), *this );
|
---|
174 | }
|
---|
175 |
|
---|
176 | void Visitor::visit( CastExpr *castExpr ) {
|
---|
177 | maybeAccept( castExpr->get_result(), *this );
|
---|
178 | maybeAccept( castExpr->get_arg(), *this );
|
---|
179 | }
|
---|
180 |
|
---|
181 | void Visitor::visit( UntypedMemberExpr *memberExpr ) {
|
---|
182 | maybeAccept( memberExpr->get_result(), *this );
|
---|
183 | maybeAccept( memberExpr->get_aggregate(), *this );
|
---|
184 | maybeAccept( memberExpr->get_member(), *this );
|
---|
185 | }
|
---|
186 |
|
---|
187 | void Visitor::visit( MemberExpr *memberExpr ) {
|
---|
188 | maybeAccept( memberExpr->get_result(), *this );
|
---|
189 | maybeAccept( memberExpr->get_aggregate(), *this );
|
---|
190 | }
|
---|
191 |
|
---|
192 | void Visitor::visit( VariableExpr *variableExpr ) {
|
---|
193 | maybeAccept( variableExpr->get_result(), *this );
|
---|
194 | }
|
---|
195 |
|
---|
196 | void Visitor::visit( ConstantExpr *constantExpr ) {
|
---|
197 | maybeAccept( constantExpr->get_result(), *this );
|
---|
198 | maybeAccept( constantExpr->get_constant(), *this );
|
---|
199 | }
|
---|
200 |
|
---|
201 | void Visitor::visit( SizeofExpr *sizeofExpr ) {
|
---|
202 | maybeAccept( sizeofExpr->get_result(), *this );
|
---|
203 | if ( sizeofExpr->get_isType() ) {
|
---|
204 | maybeAccept( sizeofExpr->get_type(), *this );
|
---|
205 | } else {
|
---|
206 | maybeAccept( sizeofExpr->get_expr(), *this );
|
---|
207 | }
|
---|
208 | }
|
---|
209 |
|
---|
210 | void Visitor::visit( AlignofExpr *alignofExpr ) {
|
---|
211 | maybeAccept( alignofExpr->get_result(), *this );
|
---|
212 | if ( alignofExpr->get_isType() ) {
|
---|
213 | maybeAccept( alignofExpr->get_type(), *this );
|
---|
214 | } else {
|
---|
215 | maybeAccept( alignofExpr->get_expr(), *this );
|
---|
216 | }
|
---|
217 | }
|
---|
218 |
|
---|
219 | void Visitor::visit( UntypedOffsetofExpr *offsetofExpr ) {
|
---|
220 | maybeAccept( offsetofExpr->get_result(), *this );
|
---|
221 | maybeAccept( offsetofExpr->get_type(), *this );
|
---|
222 | }
|
---|
223 |
|
---|
224 | void Visitor::visit( OffsetofExpr *offsetofExpr ) {
|
---|
225 | maybeAccept( offsetofExpr->get_result(), *this );
|
---|
226 | maybeAccept( offsetofExpr->get_type(), *this );
|
---|
227 | maybeAccept( offsetofExpr->get_member(), *this );
|
---|
228 | }
|
---|
229 |
|
---|
230 | void Visitor::visit( OffsetPackExpr *offsetPackExpr ) {
|
---|
231 | maybeAccept( offsetPackExpr->get_result(), *this );
|
---|
232 | maybeAccept( offsetPackExpr->get_type(), *this );
|
---|
233 | }
|
---|
234 |
|
---|
235 | void Visitor::visit( AttrExpr *attrExpr ) {
|
---|
236 | maybeAccept( attrExpr->get_result(), *this );
|
---|
237 | if ( attrExpr->get_isType() ) {
|
---|
238 | maybeAccept( attrExpr->get_type(), *this );
|
---|
239 | } else {
|
---|
240 | maybeAccept( attrExpr->get_expr(), *this );
|
---|
241 | }
|
---|
242 | }
|
---|
243 |
|
---|
244 | void Visitor::visit( LogicalExpr *logicalExpr ) {
|
---|
245 | maybeAccept( logicalExpr->get_result(), *this );
|
---|
246 | maybeAccept( logicalExpr->get_arg1(), *this );
|
---|
247 | maybeAccept( logicalExpr->get_arg2(), *this );
|
---|
248 | }
|
---|
249 |
|
---|
250 | void Visitor::visit( ConditionalExpr *conditionalExpr ) {
|
---|
251 | maybeAccept( conditionalExpr->get_result(), *this );
|
---|
252 | maybeAccept( conditionalExpr->get_arg1(), *this );
|
---|
253 | maybeAccept( conditionalExpr->get_arg2(), *this );
|
---|
254 | maybeAccept( conditionalExpr->get_arg3(), *this );
|
---|
255 | }
|
---|
256 |
|
---|
257 | void Visitor::visit( CommaExpr *commaExpr ) {
|
---|
258 | maybeAccept( commaExpr->get_result(), *this );
|
---|
259 | maybeAccept( commaExpr->get_arg1(), *this );
|
---|
260 | maybeAccept( commaExpr->get_arg2(), *this );
|
---|
261 | }
|
---|
262 |
|
---|
263 | void Visitor::visit( TypeExpr *typeExpr ) {
|
---|
264 | maybeAccept( typeExpr->get_result(), *this );
|
---|
265 | maybeAccept( typeExpr->get_type(), *this );
|
---|
266 | }
|
---|
267 |
|
---|
268 | void Visitor::visit( AsmExpr *asmExpr ) {
|
---|
269 | maybeAccept( asmExpr->get_inout(), *this );
|
---|
270 | maybeAccept( asmExpr->get_constraint(), *this );
|
---|
271 | maybeAccept( asmExpr->get_operand(), *this );
|
---|
272 | }
|
---|
273 |
|
---|
274 | void Visitor::visit( ImplicitCopyCtorExpr *impCpCtorExpr ) {
|
---|
275 | maybeAccept( impCpCtorExpr->get_result(), *this );
|
---|
276 | maybeAccept( impCpCtorExpr->get_callExpr(), *this );
|
---|
277 | acceptAll( impCpCtorExpr->get_tempDecls(), *this );
|
---|
278 | acceptAll( impCpCtorExpr->get_returnDecls(), *this );
|
---|
279 | acceptAll( impCpCtorExpr->get_dtors(), *this );
|
---|
280 | }
|
---|
281 |
|
---|
282 | void Visitor::visit( ConstructorExpr * ctorExpr ) {
|
---|
283 | maybeAccept( ctorExpr->get_result(), *this );
|
---|
284 | maybeAccept( ctorExpr->get_callExpr(), *this );
|
---|
285 | }
|
---|
286 |
|
---|
287 | void Visitor::visit( CompoundLiteralExpr *compLitExpr ) {
|
---|
288 | maybeAccept( compLitExpr->get_result(), *this );
|
---|
289 | maybeAccept( compLitExpr->get_type(), *this );
|
---|
290 | maybeAccept( compLitExpr->get_initializer(), *this );
|
---|
291 | }
|
---|
292 |
|
---|
293 | void Visitor::visit( UntypedValofExpr *valofExpr ) {
|
---|
294 | maybeAccept( valofExpr->get_result(), *this );
|
---|
295 | maybeAccept( valofExpr->get_body(), *this );
|
---|
296 | }
|
---|
297 |
|
---|
298 | void Visitor::visit( RangeExpr *rangeExpr ) {
|
---|
299 | maybeAccept( rangeExpr->get_low(), *this );
|
---|
300 | maybeAccept( rangeExpr->get_high(), *this );
|
---|
301 | }
|
---|
302 |
|
---|
303 | void Visitor::visit( UntypedTupleExpr *tupleExpr ) {
|
---|
304 | maybeAccept( tupleExpr->get_result(), *this );
|
---|
305 | acceptAll( tupleExpr->get_exprs(), *this );
|
---|
306 | }
|
---|
307 |
|
---|
308 | void Visitor::visit( TupleExpr *tupleExpr ) {
|
---|
309 | maybeAccept( tupleExpr->get_result(), *this );
|
---|
310 | acceptAll( tupleExpr->get_exprs(), *this );
|
---|
311 | }
|
---|
312 |
|
---|
313 | void Visitor::visit( TupleIndexExpr *tupleExpr ) {
|
---|
314 | maybeAccept( tupleExpr->get_result(), *this );
|
---|
315 | maybeAccept( tupleExpr->get_tuple(), *this );
|
---|
316 | }
|
---|
317 |
|
---|
318 | void Visitor::visit( MemberTupleExpr *tupleExpr ) {
|
---|
319 | maybeAccept( tupleExpr->get_result(), *this );
|
---|
320 | maybeAccept( tupleExpr->get_member(), *this );
|
---|
321 | maybeAccept( tupleExpr->get_aggregate(), *this );
|
---|
322 | }
|
---|
323 |
|
---|
324 | void Visitor::visit( TupleAssignExpr *assignExpr ) {
|
---|
325 | maybeAccept( assignExpr->get_result(), *this );
|
---|
326 | maybeAccept( assignExpr->get_stmtExpr(), *this );
|
---|
327 | }
|
---|
328 |
|
---|
329 | void Visitor::visit( StmtExpr *stmtExpr ) {
|
---|
330 | maybeAccept( stmtExpr->get_result(), *this );
|
---|
331 | maybeAccept( stmtExpr->get_statements(), *this );
|
---|
332 | acceptAll( stmtExpr->get_returnDecls(), *this );
|
---|
333 | acceptAll( stmtExpr->get_dtors(), *this );
|
---|
334 | }
|
---|
335 |
|
---|
336 | void Visitor::visit( UniqueExpr *uniqueExpr ) {
|
---|
337 | maybeAccept( uniqueExpr->get_result(), *this );
|
---|
338 | maybeAccept( uniqueExpr->get_expr(), *this );
|
---|
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 | void Visitor::visit( SingleInit *singleInit ) {
|
---|
425 | singleInit->get_value()->accept( *this );
|
---|
426 | }
|
---|
427 |
|
---|
428 | void Visitor::visit( ListInit *listInit ) {
|
---|
429 | acceptAll( listInit->get_designators(), *this );
|
---|
430 | acceptAll( listInit->get_initializers(), *this );
|
---|
431 | }
|
---|
432 |
|
---|
433 | void Visitor::visit( ConstructorInit *ctorInit ) {
|
---|
434 | maybeAccept( ctorInit->get_ctor(), *this );
|
---|
435 | maybeAccept( ctorInit->get_dtor(), *this );
|
---|
436 | maybeAccept( ctorInit->get_init(), *this );
|
---|
437 | }
|
---|
438 |
|
---|
439 | void Visitor::visit( Subrange *subrange ) {}
|
---|
440 |
|
---|
441 | void Visitor::visit( Constant *constant ) {}
|
---|
442 | // Local Variables: //
|
---|
443 | // tab-width: 4 //
|
---|
444 | // mode: c++ //
|
---|
445 | // compile-command: "make install" //
|
---|
446 | // End: //
|
---|