source: translator/SynTree/Visitor.h@ d3d8c3f

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since d3d8c3f was 51b73452, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

initial commit

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/*
2 * This file is part of the Cforall project
3 *
4 * $Id: Visitor.h,v 1.23 2005/08/29 20:59:27 rcbilson Exp $
5 *
6 */
7
8#ifndef VISITOR_H
9#define VISITOR_H
10
11#include "SynTree.h"
12#include "SemanticError.h"
13#include "CompilerError.h"
14
15
16class Visitor
17{
18protected:
19 Visitor();
20 virtual ~Visitor();
21
22public:
23 virtual void visit(ObjectDecl *objectDecl);
24 virtual void visit(FunctionDecl *functionDecl);
25 virtual void visit(StructDecl *aggregateDecl);
26 virtual void visit(UnionDecl *aggregateDecl);
27 virtual void visit(EnumDecl *aggregateDecl);
28 virtual void visit(ContextDecl *aggregateDecl);
29 virtual void visit(TypeDecl *typeDecl);
30 virtual void visit(TypedefDecl *typeDecl);
31
32 virtual void visit(CompoundStmt *compoundStmt);
33 virtual void visit(ExprStmt *exprStmt);
34 virtual void visit(IfStmt *ifStmt);
35 virtual void visit(WhileStmt *whileStmt);
36 virtual void visit(ForStmt *forStmt);
37 virtual void visit(SwitchStmt *switchStmt);
38 virtual void visit(ChooseStmt *switchStmt);
39 virtual void visit(FallthruStmt *switchStmt);
40 virtual void visit(CaseStmt *caseStmt);
41 virtual void visit(BranchStmt *branchStmt);
42 virtual void visit(ReturnStmt *returnStmt);
43 virtual void visit(TryStmt *tryStmt);
44 virtual void visit(CatchStmt *catchStmt);
45 virtual void visit(FinallyStmt *finallyStmt);
46 virtual void visit(NullStmt *nullStmt);
47 virtual void visit(DeclStmt *declStmt);
48
49 virtual void visit(ApplicationExpr *applicationExpr);
50 virtual void visit(UntypedExpr *untypedExpr);
51 virtual void visit(NameExpr *nameExpr);
52 virtual void visit(CastExpr *castExpr);
53 virtual void visit(AddressExpr *addressExpr);
54 virtual void visit(LabelAddressExpr *labAddressExpr);
55 virtual void visit(UntypedMemberExpr *memberExpr);
56 virtual void visit(MemberExpr *memberExpr);
57 virtual void visit(VariableExpr *variableExpr);
58 virtual void visit(ConstantExpr *constantExpr);
59 virtual void visit(SizeofExpr *sizeofExpr);
60 virtual void visit(AttrExpr *attrExpr);
61 virtual void visit(LogicalExpr *logicalExpr);
62 virtual void visit(ConditionalExpr *conditionalExpr);
63 virtual void visit(CommaExpr *commaExpr);
64 virtual void visit(TupleExpr *tupleExpr);
65 virtual void visit(SolvedTupleExpr *tupleExpr);
66 virtual void visit(TypeExpr *typeExpr);
67 virtual void visit(UntypedValofExpr *valofExpr);
68
69 virtual void visit(VoidType *basicType);
70 virtual void visit(BasicType *basicType);
71 virtual void visit(PointerType *pointerType);
72 virtual void visit(ArrayType *arrayType);
73 virtual void visit(FunctionType *functionType);
74 virtual void visit(StructInstType *aggregateUseType);
75 virtual void visit(UnionInstType *aggregateUseType);
76 virtual void visit(EnumInstType *aggregateUseType);
77 virtual void visit(ContextInstType *aggregateUseType);
78 virtual void visit(TypeInstType *aggregateUseType);
79 virtual void visit(TupleType *tupleType);
80 virtual void visit(TypeofType *typeofType);
81 virtual void visit(AttrType *attrType);
82
83 virtual void visit(MemberInit *memberInit);
84 virtual void visit(ElementInit *elementInit);
85 virtual void visit(SingleInit *singleInit);
86 virtual void visit(ListInit *listInit);
87
88 virtual void visit(Subrange *subrange);
89
90 virtual void visit(Constant *constant);
91
92private:
93 virtual void visit(AggregateDecl *aggregateDecl);
94 virtual void visit(NamedTypeDecl *typeDecl);
95 virtual void visit(ReferenceToType *aggregateUseType);
96};
97
98template< typename TreeType, typename VisitorType >
99inline void
100maybeAccept( TreeType *tree, VisitorType &visitor )
101{
102 if( tree ) {
103 tree->accept( visitor );
104 }
105}
106
107template< typename Container, typename VisitorType >
108inline void
109acceptAll( Container &container, VisitorType &visitor )
110{
111 SemanticError errors;
112 for( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
113 try {
114 if( *i ) {
115 (*i)->accept( visitor );
116 }
117 } catch( SemanticError &e ) {
118 errors.append( e );
119 }
120 }
121 if( !errors.isEmpty() ) {
122 throw errors;
123 }
124}
125
126template< typename Container, typename VisitorType >
127void
128acceptAllFold( Container &container, VisitorType &visitor, VisitorType &around )
129{
130 SemanticError errors;
131 for( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
132 try {
133 if( *i ) {
134 VisitorType *v = new VisitorType;
135 (*i)->accept( *v );
136
137 typename Container::iterator nxt = i; nxt++; // forward_iterator
138 if( nxt == container.end() )
139 visitor += *v;
140 else
141 visitor += *v + around;
142
143 delete v;
144 }
145 } catch( SemanticError &e ) {
146 errors.append( e );
147 }
148 }
149 if( !errors.isEmpty() ) {
150 throw errors;
151 }
152}
153
154
155#endif /* #ifndef VISITOR_H */
156
157
158/*
159 Local Variables:
160 mode: c++
161 End:
162*/
Note: See TracBrowser for help on using the repository browser.