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