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