source: src/SynTree/Visitor.cc @ 906e24d

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 906e24d was 906e24d, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

replace results list on Expressions with a single Type field

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