source: src/SynTree/Visitor.cc@ 6ac5223

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since 6ac5223 was ea6332d, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Big header cleaning pass - commit 3

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