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