source: src/SynTree/Visitor.cc@ bd098ea

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 bd098ea 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
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
[daf1af8]11// Last Modified By : Andrew Beach
[a5f0529]12// Last Modified On : Mon Jul 24 16:30:00 2017
13// Update Count : 27
[0dd3a2f]14//
15
[ea6332d]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
[51b73452]25#include "Visitor.h"
[ea6332d]26
27class Subrange;
[51b73452]28
[d9a0e76]29Visitor::Visitor() {}
[51b73452]30
[d9a0e76]31Visitor::~Visitor() {}
[51b73452]32
[0dd3a2f]33void Visitor::visit( ObjectDecl *objectDecl ) {
34 maybeAccept( objectDecl->get_type(), *this );
35 maybeAccept( objectDecl->get_init(), *this );
36 maybeAccept( objectDecl->get_bitfieldWidth(), *this );
[51b73452]37}
38
[0dd3a2f]39void Visitor::visit( FunctionDecl *functionDecl ) {
40 maybeAccept( functionDecl->get_functionType(), *this );
41 maybeAccept( functionDecl->get_statements(), *this );
[51b73452]42}
43
[1e1e15b]44void Visitor::handleAggregateDecl( AggregateDecl *aggregateDecl ) {
[0dd3a2f]45 acceptAll( aggregateDecl->get_parameters(), *this );
46 acceptAll( aggregateDecl->get_members(), *this );
[51b73452]47}
48
[0dd3a2f]49void Visitor::visit( StructDecl *aggregateDecl ) {
[1e1e15b]50 handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
[51b73452]51}
52
[0dd3a2f]53void Visitor::visit( UnionDecl *aggregateDecl ) {
[1e1e15b]54 handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
[51b73452]55}
56
[0dd3a2f]57void Visitor::visit( EnumDecl *aggregateDecl ) {
[1e1e15b]58 handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
[51b73452]59}
60
[4040425]61void Visitor::visit( TraitDecl *aggregateDecl ) {
[1e1e15b]62 handleAggregateDecl( static_cast< AggregateDecl* >( aggregateDecl ) );
[51b73452]63}
64
[1e1e15b]65void Visitor::handleNamedTypeDecl( NamedTypeDecl *typeDecl ) {
[0dd3a2f]66 acceptAll( typeDecl->get_parameters(), *this );
67 acceptAll( typeDecl->get_assertions(), *this );
68 maybeAccept( typeDecl->get_base(), *this );
[51b73452]69}
70
[0dd3a2f]71void Visitor::visit( TypeDecl *typeDecl ) {
[1e1e15b]72 handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) );
[67cf18c]73 maybeAccept( typeDecl->get_init(), *this );
[51b73452]74}
75
[0dd3a2f]76void Visitor::visit( TypedefDecl *typeDecl ) {
[1e1e15b]77 handleNamedTypeDecl( static_cast< NamedTypeDecl* >( typeDecl ) );
[51b73452]78}
79
[e994912]80void Visitor::visit( AsmDecl *asmDecl ) {
81 maybeAccept( asmDecl->get_stmt(), *this );
82}
83
84
[0dd3a2f]85void Visitor::visit( CompoundStmt *compoundStmt ) {
86 acceptAll( compoundStmt->get_kids(), *this );
[51b73452]87}
88
[0dd3a2f]89void Visitor::visit( ExprStmt *exprStmt ) {
90 maybeAccept( exprStmt->get_expr(), *this );
[51b73452]91}
92
[7f5566b]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
[0dd3a2f]100void Visitor::visit( IfStmt *ifStmt ) {
101 maybeAccept( ifStmt->get_condition(), *this );
102 maybeAccept( ifStmt->get_thenPart(), *this );
103 maybeAccept( ifStmt->get_elsePart(), *this );
[51b73452]104}
105
[0dd3a2f]106void Visitor::visit( WhileStmt *whileStmt ) {
107 maybeAccept( whileStmt->get_condition(), *this );
108 maybeAccept( whileStmt->get_body(), *this );
[51b73452]109}
110
[0dd3a2f]111void Visitor::visit( ForStmt *forStmt ) {
[145f1fc]112 acceptAll( forStmt->get_initialization(), *this );
[0dd3a2f]113 maybeAccept( forStmt->get_condition(), *this );
114 maybeAccept( forStmt->get_increment(), *this );
115 maybeAccept( forStmt->get_body(), *this );
[51b73452]116}
117
[0dd3a2f]118void Visitor::visit( SwitchStmt *switchStmt ) {
119 maybeAccept( switchStmt->get_condition(), *this );
[8688ce1]120 acceptAll( switchStmt->get_statements(), *this );
[51b73452]121}
122
[0dd3a2f]123void Visitor::visit( CaseStmt *caseStmt ) {
124 maybeAccept( caseStmt->get_condition(), *this );
125 acceptAll( caseStmt->get_statements(), *this );
[51b73452]126}
127
[b3c36f4]128void Visitor::visit( __attribute__((unused)) BranchStmt *branchStmt ) {
[51b73452]129}
130
[0dd3a2f]131void Visitor::visit( ReturnStmt *returnStmt ) {
132 maybeAccept( returnStmt->get_expr(), *this );
[51b73452]133}
134
[daf1af8]135void Visitor::visit( ThrowStmt * throwStmt ) {
136 maybeAccept( throwStmt->get_expr(), *this );
137 maybeAccept( throwStmt->get_target(), *this );
138}
139
[0dd3a2f]140void Visitor::visit( TryStmt *tryStmt ) {
141 maybeAccept( tryStmt->get_block(), *this );
142 acceptAll( tryStmt->get_catchers(), *this );
[25a8631]143 maybeAccept( tryStmt->get_finally(), *this );
[51b73452]144}
145
[0dd3a2f]146void Visitor::visit( CatchStmt *catchStmt ) {
147 maybeAccept( catchStmt->get_decl(), *this );
[25a8631]148 maybeAccept( catchStmt->get_cond(), *this );
[0dd3a2f]149 maybeAccept( catchStmt->get_body(), *this );
[51b73452]150}
151
[0dd3a2f]152void Visitor::visit( FinallyStmt *finalStmt ) {
153 maybeAccept( finalStmt->get_block(), *this );
[51b73452]154}
155
[b3c36f4]156void Visitor::visit( __attribute__((unused)) NullStmt *nullStmt ) {
[51b73452]157}
158
[0dd3a2f]159void Visitor::visit( DeclStmt *declStmt ) {
160 maybeAccept( declStmt->get_decl(), *this );
[51b73452]161}
162
[f1b1e4c]163void Visitor::visit( ImplicitCtorDtorStmt *impCtorDtorStmt ) {
164 maybeAccept( impCtorDtorStmt->get_callStmt(), *this );
165}
166
[e994912]167
[0dd3a2f]168void Visitor::visit( ApplicationExpr *applicationExpr ) {
[906e24d]169 maybeAccept( applicationExpr->get_result(), *this );
[0dd3a2f]170 maybeAccept( applicationExpr->get_function(), *this );
171 acceptAll( applicationExpr->get_args(), *this );
[51b73452]172}
173
[0dd3a2f]174void Visitor::visit( UntypedExpr *untypedExpr ) {
[906e24d]175 maybeAccept( untypedExpr->get_result(), *this );
[0dd3a2f]176 acceptAll( untypedExpr->get_args(), *this );
[51b73452]177}
178
[0dd3a2f]179void Visitor::visit( NameExpr *nameExpr ) {
[906e24d]180 maybeAccept( nameExpr->get_result(), *this );
[51b73452]181}
182
[0dd3a2f]183void Visitor::visit( AddressExpr *addressExpr ) {
[906e24d]184 maybeAccept( addressExpr->get_result(), *this );
[0dd3a2f]185 maybeAccept( addressExpr->get_arg(), *this );
[51b73452]186}
187
[0dd3a2f]188void Visitor::visit( LabelAddressExpr *labAddressExpr ) {
[906e24d]189 maybeAccept( labAddressExpr->get_result(), *this );
[0dd3a2f]190 maybeAccept( labAddressExpr->get_arg(), *this );
[51b73452]191}
192
[0dd3a2f]193void Visitor::visit( CastExpr *castExpr ) {
[906e24d]194 maybeAccept( castExpr->get_result(), *this );
[0dd3a2f]195 maybeAccept( castExpr->get_arg(), *this );
[51b73452]196}
197
[a5f0529]198void Visitor::visit( VirtualCastExpr *castExpr ) {
199 maybeAccept( castExpr->get_result(), *this );
200 maybeAccept( castExpr->get_arg(), *this );
201}
202
[0dd3a2f]203void Visitor::visit( UntypedMemberExpr *memberExpr ) {
[906e24d]204 maybeAccept( memberExpr->get_result(), *this );
[0dd3a2f]205 maybeAccept( memberExpr->get_aggregate(), *this );
[3b58d91]206 maybeAccept( memberExpr->get_member(), *this );
[51b73452]207}
208
[0dd3a2f]209void Visitor::visit( MemberExpr *memberExpr ) {
[906e24d]210 maybeAccept( memberExpr->get_result(), *this );
[0dd3a2f]211 maybeAccept( memberExpr->get_aggregate(), *this );
[51b73452]212}
213
[0dd3a2f]214void Visitor::visit( VariableExpr *variableExpr ) {
[906e24d]215 maybeAccept( variableExpr->get_result(), *this );
[51b73452]216}
217
[0dd3a2f]218void Visitor::visit( ConstantExpr *constantExpr ) {
[906e24d]219 maybeAccept( constantExpr->get_result(), *this );
[0dd3a2f]220 maybeAccept( constantExpr->get_constant(), *this );
[51b73452]221}
222
[0dd3a2f]223void Visitor::visit( SizeofExpr *sizeofExpr ) {
[906e24d]224 maybeAccept( sizeofExpr->get_result(), *this );
[0dd3a2f]225 if ( sizeofExpr->get_isType() ) {
226 maybeAccept( sizeofExpr->get_type(), *this );
227 } else {
228 maybeAccept( sizeofExpr->get_expr(), *this );
229 }
[51b73452]230}
231
[47534159]232void Visitor::visit( AlignofExpr *alignofExpr ) {
[906e24d]233 maybeAccept( alignofExpr->get_result(), *this );
[47534159]234 if ( alignofExpr->get_isType() ) {
235 maybeAccept( alignofExpr->get_type(), *this );
236 } else {
237 maybeAccept( alignofExpr->get_expr(), *this );
238 }
239}
240
[2a4b088]241void Visitor::visit( UntypedOffsetofExpr *offsetofExpr ) {
[906e24d]242 maybeAccept( offsetofExpr->get_result(), *this );
[2a4b088]243 maybeAccept( offsetofExpr->get_type(), *this );
244}
245
[25a054f]246void Visitor::visit( OffsetofExpr *offsetofExpr ) {
[906e24d]247 maybeAccept( offsetofExpr->get_result(), *this );
[25a054f]248 maybeAccept( offsetofExpr->get_type(), *this );
249 maybeAccept( offsetofExpr->get_member(), *this );
250}
251
[afc1045]252void Visitor::visit( OffsetPackExpr *offsetPackExpr ) {
[906e24d]253 maybeAccept( offsetPackExpr->get_result(), *this );
[afc1045]254 maybeAccept( offsetPackExpr->get_type(), *this );
255}
256
[0dd3a2f]257void Visitor::visit( AttrExpr *attrExpr ) {
[906e24d]258 maybeAccept( attrExpr->get_result(), *this );
[0dd3a2f]259 if ( attrExpr->get_isType() ) {
260 maybeAccept( attrExpr->get_type(), *this );
261 } else {
262 maybeAccept( attrExpr->get_expr(), *this );
263 }
[51b73452]264}
265
[0dd3a2f]266void Visitor::visit( LogicalExpr *logicalExpr ) {
[906e24d]267 maybeAccept( logicalExpr->get_result(), *this );
[0dd3a2f]268 maybeAccept( logicalExpr->get_arg1(), *this );
269 maybeAccept( logicalExpr->get_arg2(), *this );
[51b73452]270}
271
[0dd3a2f]272void Visitor::visit( ConditionalExpr *conditionalExpr ) {
[906e24d]273 maybeAccept( conditionalExpr->get_result(), *this );
[0dd3a2f]274 maybeAccept( conditionalExpr->get_arg1(), *this );
275 maybeAccept( conditionalExpr->get_arg2(), *this );
276 maybeAccept( conditionalExpr->get_arg3(), *this );
[51b73452]277}
278
[0dd3a2f]279void Visitor::visit( CommaExpr *commaExpr ) {
[906e24d]280 maybeAccept( commaExpr->get_result(), *this );
[0dd3a2f]281 maybeAccept( commaExpr->get_arg1(), *this );
282 maybeAccept( commaExpr->get_arg2(), *this );
[51b73452]283}
284
[0dd3a2f]285void Visitor::visit( TypeExpr *typeExpr ) {
[906e24d]286 maybeAccept( typeExpr->get_result(), *this );
[0dd3a2f]287 maybeAccept( typeExpr->get_type(), *this );
[51b73452]288}
289
[7f5566b]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
[db4ecc5]296void Visitor::visit( ImplicitCopyCtorExpr *impCpCtorExpr ) {
[907eccb]297 maybeAccept( impCpCtorExpr->get_result(), *this );
[db4ecc5]298 maybeAccept( impCpCtorExpr->get_callExpr(), *this );
299 acceptAll( impCpCtorExpr->get_tempDecls(), *this );
[dc2e7e0]300 acceptAll( impCpCtorExpr->get_returnDecls(), *this );
[d5556a3]301 acceptAll( impCpCtorExpr->get_dtors(), *this );
[db4ecc5]302}
303
[b6fe7e6]304void Visitor::visit( ConstructorExpr * ctorExpr ) {
[906e24d]305 maybeAccept( ctorExpr->get_result(), *this );
[b6fe7e6]306 maybeAccept( ctorExpr->get_callExpr(), *this );
[51b73452]307}
308
[630a82a]309void Visitor::visit( CompoundLiteralExpr *compLitExpr ) {
[906e24d]310 maybeAccept( compLitExpr->get_result(), *this );
[630a82a]311 maybeAccept( compLitExpr->get_initializer(), *this );
312}
313
[8688ce1]314void Visitor::visit( RangeExpr *rangeExpr ) {
315 maybeAccept( rangeExpr->get_low(), *this );
316 maybeAccept( rangeExpr->get_high(), *this );
317}
318
[907eccb]319void Visitor::visit( UntypedTupleExpr *tupleExpr ) {
320 maybeAccept( tupleExpr->get_result(), *this );
321 acceptAll( tupleExpr->get_exprs(), *this );
322}
323
[6eb8948]324void Visitor::visit( TupleExpr *tupleExpr ) {
[aa8f9df]325 maybeAccept( tupleExpr->get_result(), *this );
[6eb8948]326 acceptAll( tupleExpr->get_exprs(), *this );
327}
328
[3b58d91]329void Visitor::visit( TupleIndexExpr *tupleExpr ) {
[aa8f9df]330 maybeAccept( tupleExpr->get_result(), *this );
[3b58d91]331 maybeAccept( tupleExpr->get_tuple(), *this );
332}
333
[6eb8948]334void Visitor::visit( TupleAssignExpr *assignExpr ) {
[aa8f9df]335 maybeAccept( assignExpr->get_result(), *this );
[d5556a3]336 maybeAccept( assignExpr->get_stmtExpr(), *this );
[3b58d91]337}
338
[6eb8948]339void Visitor::visit( StmtExpr *stmtExpr ) {
[aa8f9df]340 maybeAccept( stmtExpr->get_result(), *this );
[6eb8948]341 maybeAccept( stmtExpr->get_statements(), *this );
[d5556a3]342 acceptAll( stmtExpr->get_returnDecls(), *this );
343 acceptAll( stmtExpr->get_dtors(), *this );
[3b58d91]344}
345
[3c13c03]346void Visitor::visit( UniqueExpr *uniqueExpr ) {
347 maybeAccept( uniqueExpr->get_result(), *this );
348 maybeAccept( uniqueExpr->get_expr(), *this );
349}
350
[e4d829b]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
[e994912]363
[0dd3a2f]364void Visitor::visit( VoidType *voidType ) {
365 acceptAll( voidType->get_forall(), *this );
[51b73452]366}
367
[0dd3a2f]368void Visitor::visit( BasicType *basicType ) {
369 acceptAll( basicType->get_forall(), *this );
[51b73452]370}
371
[0dd3a2f]372void Visitor::visit( PointerType *pointerType ) {
373 acceptAll( pointerType->get_forall(), *this );
374 maybeAccept( pointerType->get_base(), *this );
[51b73452]375}
376
[0dd3a2f]377void Visitor::visit( ArrayType *arrayType ) {
378 acceptAll( arrayType->get_forall(), *this );
379 maybeAccept( arrayType->get_dimension(), *this );
380 maybeAccept( arrayType->get_base(), *this );
[51b73452]381}
382
[0dd3a2f]383void Visitor::visit( FunctionType *functionType ) {
384 acceptAll( functionType->get_forall(), *this );
385 acceptAll( functionType->get_returnVals(), *this );
386 acceptAll( functionType->get_parameters(), *this );
[51b73452]387}
388
[1e1e15b]389void Visitor::handleReferenceToType( ReferenceToType *aggregateUseType ) {
[0dd3a2f]390 acceptAll( aggregateUseType->get_forall(), *this );
391 acceptAll( aggregateUseType->get_parameters(), *this );
[51b73452]392}
393
[0dd3a2f]394void Visitor::visit( StructInstType *aggregateUseType ) {
[1e1e15b]395 handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
[51b73452]396}
397
[0dd3a2f]398void Visitor::visit( UnionInstType *aggregateUseType ) {
[1e1e15b]399 handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
[51b73452]400}
401
[0dd3a2f]402void Visitor::visit( EnumInstType *aggregateUseType ) {
[1e1e15b]403 handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
[51b73452]404}
405
[4040425]406void Visitor::visit( TraitInstType *aggregateUseType ) {
[1e1e15b]407 handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
[0dd3a2f]408 acceptAll( aggregateUseType->get_members(), *this );
[51b73452]409}
410
[0dd3a2f]411void Visitor::visit( TypeInstType *aggregateUseType ) {
[1e1e15b]412 handleReferenceToType( static_cast< ReferenceToType * >( aggregateUseType ) );
[51b73452]413}
414
[0dd3a2f]415void Visitor::visit( TupleType *tupleType ) {
416 acceptAll( tupleType->get_forall(), *this );
417 acceptAll( tupleType->get_types(), *this );
[62423350]418 acceptAll( tupleType->get_members(), *this );
[51b73452]419}
420
[0dd3a2f]421void Visitor::visit( TypeofType *typeofType ) {
422 assert( typeofType->get_expr() );
423 typeofType->get_expr()->accept( *this );
[51b73452]424}
425
[0dd3a2f]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
[51b73452]434}
435
[44b7088]436void Visitor::visit( VarArgsType *varArgsType ) {
437 acceptAll( varArgsType->get_forall(), *this );
438}
439
[89e6ffc]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
[e4d829b]448void Visitor::visit( Designation * designation ) {
449 acceptAll( designation->get_designators(), *this );
450}
[e994912]451
[0dd3a2f]452void Visitor::visit( SingleInit *singleInit ) {
453 singleInit->get_value()->accept( *this );
[51b73452]454}
455
[0dd3a2f]456void Visitor::visit( ListInit *listInit ) {
[e4d829b]457 acceptAll( listInit->get_designations(), *this );
[0dd3a2f]458 acceptAll( listInit->get_initializers(), *this );
[51b73452]459}
460
[71f4e4f]461void Visitor::visit( ConstructorInit *ctorInit ) {
462 maybeAccept( ctorInit->get_ctor(), *this );
[d5556a3]463 maybeAccept( ctorInit->get_dtor(), *this );
[71f4e4f]464 maybeAccept( ctorInit->get_init(), *this );
465}
466
[e994912]467
[b3c36f4]468void Visitor::visit( __attribute__((unused)) Subrange *subrange ) {}
[51b73452]469
[e994912]470
[b3c36f4]471void Visitor::visit( __attribute__((unused)) Constant *constant ) {}
[0dd3a2f]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.