source: src/SynTree/Visitor.cc @ dc2e7e0

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since dc2e7e0 was dc2e7e0, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

add ImplicitCopyCtorExpr? returnDecls to Visitor, Mutator, print

  • Property mode set to 100644
File size: 11.4 KB
RevLine 
[0dd3a2f]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//
[71f4e4f]7// Visitor.cc --
[0dd3a2f]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[71f4e4f]11// Last Modified By : Rob Schluntz
[dc2e7e0]12// Last Modified On : Mon Apr 18 17:30:10 2016
[71f4e4f]13// Update Count     : 18
[0dd3a2f]14//
15
[51b7345]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
[d9a0e76]25Visitor::Visitor() {}
[51b7345]26
[d9a0e76]27Visitor::~Visitor() {}
[51b7345]28
[0dd3a2f]29void Visitor::visit( ObjectDecl *objectDecl ) {
30        maybeAccept( objectDecl->get_type(), *this );
31        maybeAccept( objectDecl->get_init(), *this );
32        maybeAccept( objectDecl->get_bitfieldWidth(), *this );
[51b7345]33}
34
[0dd3a2f]35void Visitor::visit( FunctionDecl *functionDecl ) {
36        maybeAccept( functionDecl->get_functionType(), *this );
37        acceptAll( functionDecl->get_oldDecls(), *this );
38        maybeAccept( functionDecl->get_statements(), *this );
[51b7345]39}
40
[0dd3a2f]41void Visitor::visit( AggregateDecl *aggregateDecl ) {
42        acceptAll( aggregateDecl->get_parameters(), *this );
43        acceptAll( aggregateDecl->get_members(), *this );
[51b7345]44}
45
[0dd3a2f]46void Visitor::visit( StructDecl *aggregateDecl ) {
47        visit( static_cast< AggregateDecl* >( aggregateDecl ) );
[51b7345]48}
49
[0dd3a2f]50void Visitor::visit( UnionDecl *aggregateDecl ) {
51        visit( static_cast< AggregateDecl* >( aggregateDecl ) );
[51b7345]52}
53
[0dd3a2f]54void Visitor::visit( EnumDecl *aggregateDecl ) {
55        visit( static_cast< AggregateDecl* >( aggregateDecl ) );
[51b7345]56}
57
[4040425]58void Visitor::visit( TraitDecl *aggregateDecl ) {
[0dd3a2f]59        visit( static_cast< AggregateDecl* >( aggregateDecl ) );
[51b7345]60}
61
[0dd3a2f]62void Visitor::visit( NamedTypeDecl *typeDecl ) {
63        acceptAll( typeDecl->get_parameters(), *this );
64        acceptAll( typeDecl->get_assertions(), *this );
65        maybeAccept( typeDecl->get_base(), *this );
[51b7345]66}
67
[0dd3a2f]68void Visitor::visit( TypeDecl *typeDecl ) {
69        visit( static_cast< NamedTypeDecl* >( typeDecl ) );
[51b7345]70}
71
[0dd3a2f]72void Visitor::visit( TypedefDecl *typeDecl ) {
73        visit( static_cast< NamedTypeDecl* >( typeDecl ) );
[51b7345]74}
75
[0dd3a2f]76void Visitor::visit( CompoundStmt *compoundStmt ) {
77        acceptAll( compoundStmt->get_kids(), *this );
[51b7345]78}
79
[0dd3a2f]80void Visitor::visit( ExprStmt *exprStmt ) {
81        maybeAccept( exprStmt->get_expr(), *this );
[51b7345]82}
83
[7f5566b]84void 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
[0dd3a2f]91void Visitor::visit( IfStmt *ifStmt ) {
92        maybeAccept( ifStmt->get_condition(), *this );
93        maybeAccept( ifStmt->get_thenPart(), *this );
94        maybeAccept( ifStmt->get_elsePart(), *this );
[51b7345]95}
96
[0dd3a2f]97void Visitor::visit( WhileStmt *whileStmt ) {
98        maybeAccept( whileStmt->get_condition(), *this );
99        maybeAccept( whileStmt->get_body(), *this );
[51b7345]100}
101
[0dd3a2f]102void Visitor::visit( ForStmt *forStmt ) {
[145f1fc]103        acceptAll( forStmt->get_initialization(), *this );
[0dd3a2f]104        maybeAccept( forStmt->get_condition(), *this );
105        maybeAccept( forStmt->get_increment(), *this );
106        maybeAccept( forStmt->get_body(), *this );
[51b7345]107}
108
[0dd3a2f]109void Visitor::visit( SwitchStmt *switchStmt ) {
110        maybeAccept( switchStmt->get_condition(), *this );
111        acceptAll( switchStmt->get_branches(), *this );
[51b7345]112}
113
[0dd3a2f]114void Visitor::visit( ChooseStmt *switchStmt ) {
115        maybeAccept( switchStmt->get_condition(), *this );
116        acceptAll( switchStmt->get_branches(), *this );
[51b7345]117}
118
[a08ba92]119void Visitor::visit( FallthruStmt *fallthruStmt ) {}
[51b7345]120
[0dd3a2f]121void Visitor::visit( CaseStmt *caseStmt ) {
122        maybeAccept( caseStmt->get_condition(), *this );
123        acceptAll( caseStmt->get_statements(), *this );
[51b7345]124}
125
[0dd3a2f]126void Visitor::visit( BranchStmt *branchStmt ) {
[51b7345]127}
128
[0dd3a2f]129void Visitor::visit( ReturnStmt *returnStmt ) {
130        maybeAccept( returnStmt->get_expr(), *this );
[51b7345]131}
132
[0dd3a2f]133void Visitor::visit( TryStmt *tryStmt ) {
134        maybeAccept( tryStmt->get_block(), *this );
135        acceptAll( tryStmt->get_catchers(), *this );
[51b7345]136}
137
[0dd3a2f]138void Visitor::visit( CatchStmt *catchStmt ) {
139        maybeAccept( catchStmt->get_decl(), *this );
140        maybeAccept( catchStmt->get_body(), *this );
[51b7345]141}
142
[0dd3a2f]143void Visitor::visit( FinallyStmt *finalStmt ) {
144        maybeAccept( finalStmt->get_block(), *this );
[51b7345]145}
146
[0dd3a2f]147void Visitor::visit( NullStmt *nullStmt ) {
[51b7345]148}
149
[0dd3a2f]150void Visitor::visit( DeclStmt *declStmt ) {
151        maybeAccept( declStmt->get_decl(), *this );
[51b7345]152}
153
[0dd3a2f]154void Visitor::visit( ApplicationExpr *applicationExpr ) {
155        acceptAll( applicationExpr->get_results(), *this );
156        maybeAccept( applicationExpr->get_function(), *this );
157        acceptAll( applicationExpr->get_args(), *this );
[51b7345]158}
159
[0dd3a2f]160void Visitor::visit( UntypedExpr *untypedExpr ) {
161        acceptAll( untypedExpr->get_results(), *this );
162        acceptAll( untypedExpr->get_args(), *this );
[51b7345]163}
164
[0dd3a2f]165void Visitor::visit( NameExpr *nameExpr ) {
166        acceptAll( nameExpr->get_results(), *this );
[51b7345]167}
168
[0dd3a2f]169void Visitor::visit( AddressExpr *addressExpr ) {
170        acceptAll( addressExpr->get_results(), *this );
171        maybeAccept( addressExpr->get_arg(), *this );
[51b7345]172}
173
[0dd3a2f]174void Visitor::visit( LabelAddressExpr *labAddressExpr ) {
175        acceptAll( labAddressExpr->get_results(), *this );
176        maybeAccept( labAddressExpr->get_arg(), *this );
[51b7345]177}
178
[0dd3a2f]179void Visitor::visit( CastExpr *castExpr ) {
180        acceptAll( castExpr->get_results(), *this );
181        maybeAccept( castExpr->get_arg(), *this );
[51b7345]182}
183
[0dd3a2f]184void Visitor::visit( UntypedMemberExpr *memberExpr ) {
185        acceptAll( memberExpr->get_results(), *this );
186        maybeAccept( memberExpr->get_aggregate(), *this );
[51b7345]187}
188
[0dd3a2f]189void Visitor::visit( MemberExpr *memberExpr ) {
190        acceptAll( memberExpr->get_results(), *this );
191        maybeAccept( memberExpr->get_aggregate(), *this );
[51b7345]192}
193
[0dd3a2f]194void Visitor::visit( VariableExpr *variableExpr ) {
195        acceptAll( variableExpr->get_results(), *this );
[51b7345]196}
197
[0dd3a2f]198void Visitor::visit( ConstantExpr *constantExpr ) {
199        acceptAll( constantExpr->get_results(), *this );
200        maybeAccept( constantExpr->get_constant(), *this );
[51b7345]201}
202
[0dd3a2f]203void Visitor::visit( SizeofExpr *sizeofExpr ) {
204        acceptAll( sizeofExpr->get_results(), *this );
205        if ( sizeofExpr->get_isType() ) {
206                maybeAccept( sizeofExpr->get_type(), *this );
207        } else {
208                maybeAccept( sizeofExpr->get_expr(), *this );
209        }
[51b7345]210}
211
[47534159]212void Visitor::visit( AlignofExpr *alignofExpr ) {
213        acceptAll( alignofExpr->get_results(), *this );
214        if ( alignofExpr->get_isType() ) {
215                maybeAccept( alignofExpr->get_type(), *this );
216        } else {
217                maybeAccept( alignofExpr->get_expr(), *this );
218        }
219}
220
[2a4b088]221void Visitor::visit( UntypedOffsetofExpr *offsetofExpr ) {
222        acceptAll( offsetofExpr->get_results(), *this );
223        maybeAccept( offsetofExpr->get_type(), *this );
224}
225
[25a054f]226void Visitor::visit( OffsetofExpr *offsetofExpr ) {
227        acceptAll( offsetofExpr->get_results(), *this );
228        maybeAccept( offsetofExpr->get_type(), *this );
229        maybeAccept( offsetofExpr->get_member(), *this );
230}
231
[afc1045]232void Visitor::visit( OffsetPackExpr *offsetPackExpr ) {
233        acceptAll( offsetPackExpr->get_results(), *this );
234        maybeAccept( offsetPackExpr->get_type(), *this );
235}
236
[0dd3a2f]237void Visitor::visit( AttrExpr *attrExpr ) {
238        acceptAll( attrExpr->get_results(), *this );
239        if ( attrExpr->get_isType() ) {
240                maybeAccept( attrExpr->get_type(), *this );
241        } else {
242                maybeAccept( attrExpr->get_expr(), *this );
243        }
[51b7345]244}
245
[0dd3a2f]246void Visitor::visit( LogicalExpr *logicalExpr ) {
247        acceptAll( logicalExpr->get_results(), *this );
248        maybeAccept( logicalExpr->get_arg1(), *this );
249        maybeAccept( logicalExpr->get_arg2(), *this );
[51b7345]250}
251
[0dd3a2f]252void Visitor::visit( ConditionalExpr *conditionalExpr ) {
253        acceptAll( conditionalExpr->get_results(), *this );
254        maybeAccept( conditionalExpr->get_arg1(), *this );
255        maybeAccept( conditionalExpr->get_arg2(), *this );
256        maybeAccept( conditionalExpr->get_arg3(), *this );
[51b7345]257}
258
[0dd3a2f]259void Visitor::visit( CommaExpr *commaExpr ) {
260        acceptAll( commaExpr->get_results(), *this );
261        maybeAccept( commaExpr->get_arg1(), *this );
262        maybeAccept( commaExpr->get_arg2(), *this );
[51b7345]263}
264
[0dd3a2f]265void Visitor::visit( TupleExpr *tupleExpr ) {
266        acceptAll( tupleExpr->get_results(), *this );
267        acceptAll( tupleExpr->get_exprs(), *this );
[51b7345]268}
269
[0dd3a2f]270void Visitor::visit( SolvedTupleExpr *tupleExpr ) {
271        acceptAll( tupleExpr->get_results(), *this );
272        acceptAll( tupleExpr->get_exprs(), *this );
[51b7345]273}
274
[0dd3a2f]275void Visitor::visit( TypeExpr *typeExpr ) {
276        acceptAll( typeExpr->get_results(), *this );
277        maybeAccept( typeExpr->get_type(), *this );
[51b7345]278}
279
[7f5566b]280void Visitor::visit( AsmExpr *asmExpr ) {
281        maybeAccept( asmExpr->get_inout(), *this );
282        maybeAccept( asmExpr->get_constraint(), *this );
283        maybeAccept( asmExpr->get_operand(), *this );
284}
285
[db4ecc5]286void Visitor::visit( ImplicitCopyCtorExpr *impCpCtorExpr ) {
287        maybeAccept( impCpCtorExpr->get_callExpr(), *this );
288        acceptAll( impCpCtorExpr->get_copyCtors(), *this );
289        acceptAll( impCpCtorExpr->get_tempDecls(), *this );
[dc2e7e0]290        acceptAll( impCpCtorExpr->get_returnDecls(), *this );
[db4ecc5]291}
292
[0dd3a2f]293void Visitor::visit( UntypedValofExpr *valofExpr ) {
294        acceptAll( valofExpr->get_results(), *this );
295        maybeAccept( valofExpr->get_body(), *this );
[51b7345]296}
297
[630a82a]298void Visitor::visit( CompoundLiteralExpr *compLitExpr ) {
299        acceptAll( compLitExpr->get_results(), *this );
300        maybeAccept( compLitExpr->get_type(), *this );
301        maybeAccept( compLitExpr->get_initializer(), *this );
302}
303
[0dd3a2f]304void Visitor::visit( VoidType *voidType ) {
305        acceptAll( voidType->get_forall(), *this );
[51b7345]306}
307
[0dd3a2f]308void Visitor::visit( BasicType *basicType ) {
309        acceptAll( basicType->get_forall(), *this );
[51b7345]310}
311
[0dd3a2f]312void Visitor::visit( PointerType *pointerType ) {
313        acceptAll( pointerType->get_forall(), *this );
314        maybeAccept( pointerType->get_base(), *this );
[51b7345]315}
316
[0dd3a2f]317void Visitor::visit( ArrayType *arrayType ) {
318        acceptAll( arrayType->get_forall(), *this );
319        maybeAccept( arrayType->get_dimension(), *this );
320        maybeAccept( arrayType->get_base(), *this );
[51b7345]321}
322
[0dd3a2f]323void Visitor::visit( FunctionType *functionType ) {
324        acceptAll( functionType->get_forall(), *this );
325        acceptAll( functionType->get_returnVals(), *this );
326        acceptAll( functionType->get_parameters(), *this );
[51b7345]327}
328
[0dd3a2f]329void Visitor::visit( ReferenceToType *aggregateUseType ) {
330        acceptAll( aggregateUseType->get_forall(), *this );
331        acceptAll( aggregateUseType->get_parameters(), *this );
[51b7345]332}
333
[0dd3a2f]334void Visitor::visit( StructInstType *aggregateUseType ) {
[7f5566b]335        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
[51b7345]336}
337
[0dd3a2f]338void Visitor::visit( UnionInstType *aggregateUseType ) {
[7f5566b]339        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
[51b7345]340}
341
[0dd3a2f]342void Visitor::visit( EnumInstType *aggregateUseType ) {
[7f5566b]343        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
[51b7345]344}
345
[4040425]346void Visitor::visit( TraitInstType *aggregateUseType ) {
[7f5566b]347        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
[0dd3a2f]348        acceptAll( aggregateUseType->get_members(), *this );
[51b7345]349}
350
[0dd3a2f]351void Visitor::visit( TypeInstType *aggregateUseType ) {
[7f5566b]352        visit( static_cast< ReferenceToType * >( aggregateUseType ) );
[51b7345]353}
354
[0dd3a2f]355void Visitor::visit( TupleType *tupleType ) {
356        acceptAll( tupleType->get_forall(), *this );
357        acceptAll( tupleType->get_types(), *this );
[51b7345]358}
359
[0dd3a2f]360void Visitor::visit( TypeofType *typeofType ) {
361        assert( typeofType->get_expr() );
362        typeofType->get_expr()->accept( *this );
[51b7345]363}
364
[0dd3a2f]365void Visitor::visit( AttrType *attrType ) {
366        if ( attrType->get_isType() ) {
367                assert( attrType->get_type() );
368                attrType->get_type()->accept( *this );
369        } else {
370                assert( attrType->get_expr() );
371                attrType->get_expr()->accept( *this );
372        } // if
[51b7345]373}
374
[44b7088]375void Visitor::visit( VarArgsType *varArgsType ) {
376        acceptAll( varArgsType->get_forall(), *this );
377}
378
[0dd3a2f]379void Visitor::visit( SingleInit *singleInit ) {
380        singleInit->get_value()->accept( *this );
[51b7345]381}
382
[0dd3a2f]383void Visitor::visit( ListInit *listInit ) {
384        acceptAll( listInit->get_designators(), *this );
385        acceptAll( listInit->get_initializers(), *this );
[51b7345]386}
387
[71f4e4f]388void Visitor::visit( ConstructorInit *ctorInit ) {
389        maybeAccept( ctorInit->get_ctor(), *this );
390        maybeAccept( ctorInit->get_init(), *this );
391}
392
[0dd3a2f]393void Visitor::visit( Subrange *subrange ) {}
[51b7345]394
[0dd3a2f]395void Visitor::visit( Constant *constant ) {}
396// Local Variables: //
397// tab-width: 4 //
398// mode: c++ //
399// compile-command: "make install" //
400// End: //
Note: See TracBrowser for help on using the repository browser.