source: src/SynTree/Visitor.cc@ 948b0c8

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 948b0c8 was a5f0529, checked in by Andrew Beach <ajbeach@…>, 8 years ago

Virtual casts have been added. They still require a lot of hand coded support to work but for simple cases it should be enough.

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