source: src/SynTree/Visitor.cc @ f522618

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since f522618 was daf1af8, checked in by Andrew Beach <ajbeach@…>, 7 years ago

Added a new ThrowStmt? node to the Syntax Tree.

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