source: src/SynTree/Visitor.h @ add7117

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

Merge branch 'master' into tuples

Conflicts:

src/ResolvExpr/AlternativeFinder.cc
src/ResolvExpr/AlternativeFinder.h

  • Property mode set to 100644
File size: 5.7 KB
Line 
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//
7// Visitor.h --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Wed Aug  3 17:01:50 2016
13// Update Count     : 9
14//
15
16#ifndef VISITOR_H
17#define VISITOR_H
18
19#include "SynTree.h"
20#include "Common/SemanticError.h"
21#include "Common/CompilerError.h"
22
23class Visitor {
24  protected:
25        Visitor();
26        virtual ~Visitor();
27  public:
28        virtual void visit( ObjectDecl *objectDecl );
29        virtual void visit( FunctionDecl *functionDecl );
30        virtual void visit( StructDecl *aggregateDecl );
31        virtual void visit( UnionDecl *aggregateDecl );
32        virtual void visit( EnumDecl *aggregateDecl );
33        virtual void visit( TraitDecl *aggregateDecl );
34        virtual void visit( TypeDecl *typeDecl );
35        virtual void visit( TypedefDecl *typeDecl );
36
37        virtual void visit( CompoundStmt *compoundStmt );
38        virtual void visit( ExprStmt *exprStmt );
39        virtual void visit( AsmStmt *asmStmt );
40        virtual void visit( IfStmt *ifStmt );
41        virtual void visit( WhileStmt *whileStmt );
42        virtual void visit( ForStmt *forStmt );
43        virtual void visit( SwitchStmt *switchStmt );
44        virtual void visit( CaseStmt *caseStmt );
45        virtual void visit( BranchStmt *branchStmt );
46        virtual void visit( ReturnStmt *returnStmt );
47        virtual void visit( TryStmt *tryStmt );
48        virtual void visit( CatchStmt *catchStmt );
49        virtual void visit( FinallyStmt *finallyStmt );
50        virtual void visit( NullStmt *nullStmt );
51        virtual void visit( DeclStmt *declStmt );
52        virtual void visit( ImplicitCtorDtorStmt *impCtorDtorStmt );
53
54        virtual void visit( ApplicationExpr *applicationExpr );
55        virtual void visit( UntypedExpr *untypedExpr );
56        virtual void visit( NameExpr *nameExpr );
57        virtual void visit( CastExpr *castExpr );
58        virtual void visit( AddressExpr *addressExpr );
59        virtual void visit( LabelAddressExpr *labAddressExpr );
60        virtual void visit( UntypedMemberExpr *memberExpr );
61        virtual void visit( MemberExpr *memberExpr );
62        virtual void visit( VariableExpr *variableExpr );
63        virtual void visit( ConstantExpr *constantExpr );
64        virtual void visit( SizeofExpr *sizeofExpr );
65        virtual void visit( AlignofExpr *alignofExpr );
66        virtual void visit( UntypedOffsetofExpr *offsetofExpr );
67        virtual void visit( OffsetofExpr *offsetofExpr );
68        virtual void visit( OffsetPackExpr *offsetPackExpr );
69        virtual void visit( AttrExpr *attrExpr );
70        virtual void visit( LogicalExpr *logicalExpr );
71        virtual void visit( ConditionalExpr *conditionalExpr );
72        virtual void visit( CommaExpr *commaExpr );
73        virtual void visit( TupleExpr *tupleExpr );
74        virtual void visit( SolvedTupleExpr *tupleExpr );
75        virtual void visit( TypeExpr *typeExpr );
76        virtual void visit( AsmExpr *asmExpr );
77        virtual void visit( ImplicitCopyCtorExpr *impCpCtorExpr );
78        virtual void visit( ConstructorExpr * ctorExpr );
79        virtual void visit( CompoundLiteralExpr *compLitExpr );
80        virtual void visit( UntypedValofExpr *valofExpr );
81        virtual void visit( RangeExpr *rangeExpr );
82        virtual void visit( TupleIndexExpr *tupleExpr );
83        virtual void visit( MemberTupleExpr *tupleExpr );
84        virtual void visit( MultipleAssignExpr *assignExpr );
85        virtual void visit( MassAssignExpr *assignExpr );
86
87        virtual void visit( VoidType *basicType );
88        virtual void visit( BasicType *basicType );
89        virtual void visit( PointerType *pointerType );
90        virtual void visit( ArrayType *arrayType );
91        virtual void visit( FunctionType *functionType );
92        virtual void visit( StructInstType *aggregateUseType );
93        virtual void visit( UnionInstType *aggregateUseType );
94        virtual void visit( EnumInstType *aggregateUseType );
95        virtual void visit( TraitInstType *aggregateUseType );
96        virtual void visit( TypeInstType *aggregateUseType );
97        virtual void visit( TupleType *tupleType );
98        virtual void visit( TypeofType *typeofType );
99        virtual void visit( AttrType *attrType );
100        virtual void visit( VarArgsType *varArgsType );
101
102        virtual void visit( SingleInit *singleInit );
103        virtual void visit( ListInit *listInit );
104        virtual void visit( ConstructorInit *ctorInit );
105
106        virtual void visit( Subrange *subrange );
107
108        virtual void visit( Constant *constant );
109  private:
110        virtual void handleAggregateDecl( AggregateDecl *aggregateDecl );
111        virtual void handleNamedTypeDecl( NamedTypeDecl *typeDecl );
112        virtual void handleReferenceToType( ReferenceToType *aggregateUseType );
113};
114
115template< typename TreeType, typename VisitorType >
116inline void maybeAccept( TreeType *tree, VisitorType &visitor ) {
117        if ( tree ) {
118                tree->accept( visitor );
119        }
120}
121
122template< typename Container, typename VisitorType >
123inline void acceptAll( Container &container, VisitorType &visitor ) {
124        SemanticError errors;
125        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
126                try {
127                        if ( *i ) {
128                                (*i)->accept( visitor );
129                        }
130                } catch( SemanticError &e ) {
131                        errors.append( e );
132                }
133        }
134        if ( ! errors.isEmpty() ) {
135                throw errors;
136        }
137}
138
139template< typename Container, typename VisitorType >
140void acceptAllFold( Container &container, VisitorType &visitor, VisitorType &around ) {
141        SemanticError errors;
142        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
143                try {
144                        if ( *i ) {
145                                VisitorType *v = new VisitorType;
146                                (*i)->accept( *v );
147
148                                typename Container::iterator nxt = i; nxt++; // forward_iterator
149                                if ( nxt == container.end() )
150                                        visitor += *v;
151                                else
152                                        visitor += *v + around;
153
154                                delete v;
155                        } // if
156                } catch( SemanticError &e ) {
157                        errors.append( e );
158                } // try
159        } // for
160        if ( ! errors.isEmpty() ) {
161                throw errors;
162        } // if
163}
164
165#endif // VISITOR_H
166
167// Local Variables: //
168// tab-width: 4 //
169// mode: c++ //
170// compile-command: "make install" //
171// End: //
Note: See TracBrowser for help on using the repository browser.