source: translator/SynTree/Visitor.cc@ 643a2e1

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 643a2e1 was d9a0e76, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

remove Parser.old, add -XCFA to driver, copy ptrdiff_t from stddef.h in preclude, remove casts from initialization constants, adjust formatting

  • Property mode set to 100644
File size: 9.4 KB
Line 
1#include <cassert>
2#include "Visitor.h"
3#include "Initializer.h"
4#include "Statement.h"
5#include "Type.h"
6#include "Declaration.h"
7#include "Expression.h"
8#include "Constant.h"
9
10
11Visitor::Visitor() {}
12
13Visitor::~Visitor() {}
14
15void Visitor::visit(ObjectDecl *objectDecl) {
16 maybeAccept( objectDecl->get_type(), *this );
17 maybeAccept( objectDecl->get_init(), *this );
18 maybeAccept( objectDecl->get_bitfieldWidth(), *this );
19}
20
21void Visitor::visit(FunctionDecl *functionDecl) {
22 maybeAccept( functionDecl->get_functionType(), *this );
23 acceptAll( functionDecl->get_oldDecls(), *this );
24 maybeAccept( functionDecl->get_statements(), *this );
25}
26
27void Visitor::visit(AggregateDecl *aggregateDecl) {
28 acceptAll( aggregateDecl->get_parameters(), *this );
29 acceptAll( aggregateDecl->get_members(), *this );
30}
31
32void Visitor::visit(StructDecl *aggregateDecl) {
33 visit( static_cast< AggregateDecl* >( aggregateDecl ) );
34}
35
36void Visitor::visit(UnionDecl *aggregateDecl) {
37 visit( static_cast< AggregateDecl* >( aggregateDecl ) );
38}
39
40void Visitor::visit(EnumDecl *aggregateDecl) {
41 visit( static_cast< AggregateDecl* >( aggregateDecl ) );
42}
43
44void Visitor::visit(ContextDecl *aggregateDecl) {
45 visit( static_cast< AggregateDecl* >( aggregateDecl ) );
46}
47
48void Visitor::visit(NamedTypeDecl *typeDecl) {
49 acceptAll( typeDecl->get_parameters(), *this );
50 acceptAll( typeDecl->get_assertions(), *this );
51 maybeAccept( typeDecl->get_base(), *this );
52}
53
54void Visitor::visit(TypeDecl *typeDecl) {
55 visit( static_cast< NamedTypeDecl* >( typeDecl ) );
56}
57
58void Visitor::visit(TypedefDecl *typeDecl) {
59 visit( static_cast< NamedTypeDecl* >( typeDecl ) );
60}
61
62void Visitor::visit(CompoundStmt *compoundStmt) {
63 acceptAll( compoundStmt->get_kids(), *this );
64}
65
66void Visitor::visit(ExprStmt *exprStmt) {
67 maybeAccept( exprStmt->get_expr(), *this );
68}
69
70void Visitor::visit(IfStmt *ifStmt) {
71 maybeAccept( ifStmt->get_condition(), *this );
72 maybeAccept( ifStmt->get_thenPart(), *this );
73 maybeAccept( ifStmt->get_elsePart(), *this );
74}
75
76void Visitor::visit(WhileStmt *whileStmt) {
77 maybeAccept( whileStmt->get_condition(), *this );
78 maybeAccept( whileStmt->get_body(), *this );
79}
80
81void Visitor::visit(ForStmt *forStmt) {
82 // ForStmt still needs to be fixed
83 maybeAccept( forStmt->get_initialization(), *this );
84 maybeAccept( forStmt->get_condition(), *this );
85 maybeAccept( forStmt->get_increment(), *this );
86 maybeAccept( forStmt->get_body(), *this );
87}
88
89void Visitor::visit(SwitchStmt *switchStmt) {
90 maybeAccept( switchStmt->get_condition(), *this );
91 acceptAll( switchStmt->get_branches(), *this );
92}
93
94void Visitor::visit(ChooseStmt *switchStmt) {
95 maybeAccept( switchStmt->get_condition(), *this );
96 acceptAll( switchStmt->get_branches(), *this );
97}
98
99void Visitor::visit(FallthruStmt *fallthruStmt){}
100
101void Visitor::visit(CaseStmt *caseStmt) {
102 maybeAccept( caseStmt->get_condition(), *this );
103 acceptAll( caseStmt->get_statements(), *this );
104}
105
106void Visitor::visit(BranchStmt *branchStmt) {
107}
108
109void Visitor::visit(ReturnStmt *returnStmt) {
110 maybeAccept( returnStmt->get_expr(), *this );
111}
112
113void Visitor::visit(TryStmt *tryStmt) {
114 maybeAccept( tryStmt->get_block(), *this );
115 acceptAll( tryStmt->get_catchers(), *this );
116}
117
118void Visitor::visit(CatchStmt *catchStmt) {
119 maybeAccept( catchStmt->get_decl(), *this );
120 maybeAccept( catchStmt->get_body(), *this );
121}
122
123void Visitor::visit(FinallyStmt *finalStmt) {
124 maybeAccept( finalStmt->get_block(), *this );
125}
126
127void Visitor::visit(NullStmt *nullStmt) {
128}
129
130void Visitor::visit(DeclStmt *declStmt) {
131 maybeAccept( declStmt->get_decl(), *this );
132}
133
134void Visitor::visit(ApplicationExpr *applicationExpr) {
135 acceptAll( applicationExpr->get_results(), *this );
136 maybeAccept( applicationExpr->get_function(), *this );
137 acceptAll( applicationExpr->get_args(), *this );
138}
139
140void Visitor::visit(UntypedExpr *untypedExpr) {
141 acceptAll( untypedExpr->get_results(), *this );
142 acceptAll( untypedExpr->get_args(), *this );
143}
144
145void Visitor::visit(NameExpr *nameExpr) {
146 acceptAll( nameExpr->get_results(), *this );
147}
148
149void Visitor::visit(AddressExpr *addressExpr) {
150 acceptAll( addressExpr->get_results(), *this );
151 maybeAccept( addressExpr->get_arg(), *this );
152}
153
154void Visitor::visit(LabelAddressExpr *labAddressExpr) {
155 acceptAll( labAddressExpr->get_results(), *this );
156 maybeAccept( labAddressExpr->get_arg(), *this );
157}
158
159void Visitor::visit(CastExpr *castExpr) {
160 acceptAll( castExpr->get_results(), *this );
161 maybeAccept( castExpr->get_arg(), *this );
162}
163
164void Visitor::visit(UntypedMemberExpr *memberExpr) {
165 acceptAll( memberExpr->get_results(), *this );
166 maybeAccept( memberExpr->get_aggregate(), *this );
167}
168
169void Visitor::visit(MemberExpr *memberExpr) {
170 acceptAll( memberExpr->get_results(), *this );
171 maybeAccept( memberExpr->get_aggregate(), *this );
172}
173
174void Visitor::visit(VariableExpr *variableExpr) {
175 acceptAll( variableExpr->get_results(), *this );
176}
177
178void Visitor::visit(ConstantExpr *constantExpr) {
179 acceptAll( constantExpr->get_results(), *this );
180 maybeAccept( constantExpr->get_constant(), *this );
181}
182
183void Visitor::visit(SizeofExpr *sizeofExpr) {
184 acceptAll( sizeofExpr->get_results(), *this );
185 if ( sizeofExpr->get_isType() ) {
186 maybeAccept( sizeofExpr->get_type(), *this );
187 } else {
188 maybeAccept( sizeofExpr->get_expr(), *this );
189 }
190}
191
192void Visitor::visit(AttrExpr *attrExpr) {
193 acceptAll( attrExpr->get_results(), *this );
194 if ( attrExpr->get_isType() ) {
195 maybeAccept( attrExpr->get_type(), *this );
196 } else {
197 maybeAccept( attrExpr->get_expr(), *this );
198 }
199}
200
201void Visitor::visit(LogicalExpr *logicalExpr) {
202 acceptAll( logicalExpr->get_results(), *this );
203 maybeAccept( logicalExpr->get_arg1(), *this );
204 maybeAccept( logicalExpr->get_arg2(), *this );
205}
206
207void Visitor::visit(ConditionalExpr *conditionalExpr) {
208 acceptAll( conditionalExpr->get_results(), *this );
209 maybeAccept( conditionalExpr->get_arg1(), *this );
210 maybeAccept( conditionalExpr->get_arg2(), *this );
211 maybeAccept( conditionalExpr->get_arg3(), *this );
212}
213
214void Visitor::visit(CommaExpr *commaExpr) {
215 acceptAll( commaExpr->get_results(), *this );
216 maybeAccept( commaExpr->get_arg1(), *this );
217 maybeAccept( commaExpr->get_arg2(), *this );
218}
219
220void Visitor::visit(TupleExpr *tupleExpr) {
221 acceptAll( tupleExpr->get_results(), *this );
222 acceptAll( tupleExpr->get_exprs(), *this );
223}
224
225void Visitor::visit(SolvedTupleExpr *tupleExpr) {
226 acceptAll( tupleExpr->get_results(), *this );
227 acceptAll( tupleExpr->get_exprs(), *this );
228}
229
230void Visitor::visit(TypeExpr *typeExpr) {
231 acceptAll( typeExpr->get_results(), *this );
232 maybeAccept( typeExpr->get_type(), *this );
233}
234
235void Visitor::visit(UntypedValofExpr *valofExpr) {
236 acceptAll( valofExpr->get_results(), *this );
237 maybeAccept( valofExpr->get_body(), *this );
238}
239
240void Visitor::visit(VoidType *voidType) {
241 acceptAll( voidType->get_forall(), *this );
242}
243
244void Visitor::visit(BasicType *basicType) {
245 acceptAll( basicType->get_forall(), *this );
246}
247
248void Visitor::visit(PointerType *pointerType) {
249 acceptAll( pointerType->get_forall(), *this );
250 maybeAccept( pointerType->get_base(), *this );
251}
252
253void Visitor::visit(ArrayType *arrayType) {
254 acceptAll( arrayType->get_forall(), *this );
255 maybeAccept( arrayType->get_dimension(), *this );
256 maybeAccept( arrayType->get_base(), *this );
257}
258
259void Visitor::visit(FunctionType *functionType) {
260 acceptAll( functionType->get_forall(), *this );
261 acceptAll( functionType->get_returnVals(), *this );
262 acceptAll( functionType->get_parameters(), *this );
263}
264
265void Visitor::visit(ReferenceToType *aggregateUseType) {
266 acceptAll( aggregateUseType->get_forall(), *this );
267 acceptAll( aggregateUseType->get_parameters(), *this );
268}
269
270void Visitor::visit(StructInstType *aggregateUseType) {
271 visit( static_cast< ReferenceToType* >( aggregateUseType ) );
272}
273
274void Visitor::visit(UnionInstType *aggregateUseType) {
275 visit( static_cast< ReferenceToType* >( aggregateUseType ) );
276}
277
278void Visitor::visit(EnumInstType *aggregateUseType) {
279 visit( static_cast< ReferenceToType* >( aggregateUseType ) );
280}
281
282void Visitor::visit(ContextInstType *aggregateUseType) {
283 visit( static_cast< ReferenceToType* >( aggregateUseType ) );
284 acceptAll( aggregateUseType->get_members(), *this );
285}
286
287void Visitor::visit(TypeInstType *aggregateUseType) {
288 visit( static_cast< ReferenceToType* >( aggregateUseType ) );
289}
290
291void Visitor::visit(TupleType *tupleType) {
292 acceptAll( tupleType->get_forall(), *this );
293 acceptAll( tupleType->get_types(), *this );
294}
295
296void Visitor::visit(TypeofType *typeofType) {
297 assert( typeofType->get_expr() );
298 typeofType->get_expr()->accept( *this );
299}
300
301void Visitor::visit(AttrType *attrType) {
302 if ( attrType->get_isType() ) {
303 assert( attrType->get_type() );
304 attrType->get_type()->accept( *this );
305 } else {
306 assert( attrType->get_expr() );
307 attrType->get_expr()->accept( *this );
308 }
309}
310
311void Visitor::visit(MemberInit *memberInit) {
312 memberInit->get_value()->accept( *this );
313}
314
315void Visitor::visit(ElementInit *elementInit) {
316 elementInit->get_value()->accept( *this );
317}
318
319void Visitor::visit(SingleInit *singleInit) {
320 singleInit->get_value()->accept( *this );
321}
322
323void Visitor::visit(ListInit *listInit) {
324 acceptAll( listInit->get_designators(), *this );
325 acceptAll( listInit->get_initializers(), *this );
326}
327
328void Visitor::visit(Subrange *subrange) {}
329
330void Visitor::visit(Constant *constant) {}
Note: See TracBrowser for help on using the repository browser.