source: src/SynTree/Visitor.cc @ 6d49ea3

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 6d49ea3 was 6d49ea3, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

second attempt, add declarations into if conditional

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