1 | /* |
---|
2 | * This file is part of the Cforall project |
---|
3 | * |
---|
4 | * $Id: Mutator.cc,v 1.30 2005/08/29 20:59:25 rcbilson Exp $ |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #include <cassert> |
---|
9 | #include "Mutator.h" |
---|
10 | #include "Initializer.h" |
---|
11 | #include "Statement.h" |
---|
12 | #include "Type.h" |
---|
13 | #include "Declaration.h" |
---|
14 | #include "Expression.h" |
---|
15 | #include "Constant.h" |
---|
16 | #include "utility.h" |
---|
17 | |
---|
18 | Mutator::Mutator() |
---|
19 | { |
---|
20 | } |
---|
21 | |
---|
22 | Mutator::~Mutator() |
---|
23 | { |
---|
24 | } |
---|
25 | |
---|
26 | ObjectDecl* |
---|
27 | Mutator::mutate(ObjectDecl *objectDecl) |
---|
28 | { |
---|
29 | objectDecl->set_type( maybeMutate( objectDecl->get_type(), *this ) ); |
---|
30 | objectDecl->set_init( maybeMutate( objectDecl->get_init(), *this ) ); |
---|
31 | objectDecl->set_bitfieldWidth( maybeMutate( objectDecl->get_bitfieldWidth(), *this ) ); |
---|
32 | return objectDecl; |
---|
33 | } |
---|
34 | |
---|
35 | DeclarationWithType* |
---|
36 | Mutator::mutate(FunctionDecl *functionDecl) |
---|
37 | { |
---|
38 | functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) ); |
---|
39 | mutateAll( functionDecl->get_oldDecls(), *this ); |
---|
40 | functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) ); |
---|
41 | return functionDecl; |
---|
42 | } |
---|
43 | |
---|
44 | Declaration* |
---|
45 | Mutator::handleAggregateDecl(AggregateDecl *aggregateDecl) |
---|
46 | { |
---|
47 | mutateAll( aggregateDecl->get_parameters(), *this ); |
---|
48 | mutateAll( aggregateDecl->get_members(), *this ); |
---|
49 | return aggregateDecl; |
---|
50 | } |
---|
51 | |
---|
52 | Declaration* |
---|
53 | Mutator::mutate(StructDecl *aggregateDecl) |
---|
54 | { |
---|
55 | handleAggregateDecl( aggregateDecl ); |
---|
56 | return aggregateDecl; |
---|
57 | } |
---|
58 | |
---|
59 | Declaration* |
---|
60 | Mutator::mutate(UnionDecl *aggregateDecl) |
---|
61 | { |
---|
62 | handleAggregateDecl( aggregateDecl ); |
---|
63 | return aggregateDecl; |
---|
64 | } |
---|
65 | |
---|
66 | Declaration* |
---|
67 | Mutator::mutate(EnumDecl *aggregateDecl) |
---|
68 | { |
---|
69 | handleAggregateDecl( aggregateDecl ); |
---|
70 | return aggregateDecl; |
---|
71 | } |
---|
72 | |
---|
73 | Declaration* |
---|
74 | Mutator::mutate(ContextDecl *aggregateDecl) |
---|
75 | { |
---|
76 | handleAggregateDecl( aggregateDecl ); |
---|
77 | return aggregateDecl; |
---|
78 | } |
---|
79 | |
---|
80 | Declaration* |
---|
81 | Mutator::handleNamedTypeDecl(NamedTypeDecl *typeDecl) |
---|
82 | { |
---|
83 | mutateAll( typeDecl->get_parameters(), *this ); |
---|
84 | mutateAll( typeDecl->get_assertions(), *this ); |
---|
85 | typeDecl->set_base( maybeMutate( typeDecl->get_base(), *this ) ); |
---|
86 | return typeDecl; |
---|
87 | } |
---|
88 | |
---|
89 | TypeDecl* |
---|
90 | Mutator::mutate(TypeDecl *typeDecl) |
---|
91 | { |
---|
92 | handleNamedTypeDecl( typeDecl ); |
---|
93 | return typeDecl; |
---|
94 | } |
---|
95 | |
---|
96 | Declaration* |
---|
97 | Mutator::mutate(TypedefDecl *typeDecl) |
---|
98 | { |
---|
99 | handleNamedTypeDecl( typeDecl ); |
---|
100 | return typeDecl; |
---|
101 | } |
---|
102 | |
---|
103 | CompoundStmt* |
---|
104 | Mutator::mutate(CompoundStmt *compoundStmt) |
---|
105 | { |
---|
106 | mutateAll( compoundStmt->get_kids(), *this ); |
---|
107 | return compoundStmt; |
---|
108 | } |
---|
109 | |
---|
110 | Statement* |
---|
111 | Mutator::mutate(ExprStmt *exprStmt) |
---|
112 | { |
---|
113 | exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) ); |
---|
114 | return exprStmt; |
---|
115 | } |
---|
116 | |
---|
117 | Statement* |
---|
118 | Mutator::mutate(IfStmt *ifStmt) |
---|
119 | { |
---|
120 | ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) ); |
---|
121 | ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) ); |
---|
122 | ifStmt->set_elsePart( maybeMutate( ifStmt->get_elsePart(), *this ) ); |
---|
123 | return ifStmt; |
---|
124 | } |
---|
125 | |
---|
126 | Statement* |
---|
127 | Mutator::mutate(WhileStmt *whileStmt) |
---|
128 | { |
---|
129 | whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) ); |
---|
130 | whileStmt->set_body( maybeMutate( whileStmt->get_body(), *this ) ); |
---|
131 | return whileStmt; |
---|
132 | } |
---|
133 | |
---|
134 | Statement* |
---|
135 | Mutator::mutate(ForStmt *forStmt) |
---|
136 | { |
---|
137 | forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ) ); |
---|
138 | forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) ); |
---|
139 | forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) ); |
---|
140 | forStmt->set_body( maybeMutate( forStmt->get_body(), *this ) ); |
---|
141 | return forStmt; |
---|
142 | } |
---|
143 | |
---|
144 | Statement* |
---|
145 | Mutator::mutate(SwitchStmt *switchStmt) |
---|
146 | { |
---|
147 | switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) ); |
---|
148 | mutateAll( switchStmt->get_branches(), *this ); |
---|
149 | return switchStmt; |
---|
150 | } |
---|
151 | |
---|
152 | Statement* |
---|
153 | Mutator::mutate(ChooseStmt *switchStmt) |
---|
154 | { |
---|
155 | switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) ); |
---|
156 | mutateAll( switchStmt->get_branches(), *this ); |
---|
157 | return switchStmt; |
---|
158 | } |
---|
159 | |
---|
160 | Statement* |
---|
161 | Mutator::mutate(FallthruStmt *fallthruStmt) |
---|
162 | { |
---|
163 | return fallthruStmt; |
---|
164 | } |
---|
165 | |
---|
166 | Statement* |
---|
167 | Mutator::mutate(CaseStmt *caseStmt) |
---|
168 | { |
---|
169 | caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) ); |
---|
170 | mutateAll (caseStmt->get_statements(), *this ); |
---|
171 | |
---|
172 | return caseStmt; |
---|
173 | } |
---|
174 | |
---|
175 | Statement* |
---|
176 | Mutator::mutate(BranchStmt *branchStmt) |
---|
177 | { |
---|
178 | return branchStmt; |
---|
179 | } |
---|
180 | |
---|
181 | Statement* |
---|
182 | Mutator::mutate(ReturnStmt *returnStmt) |
---|
183 | { |
---|
184 | returnStmt->set_expr( maybeMutate( returnStmt->get_expr(), *this ) ); |
---|
185 | return returnStmt; |
---|
186 | } |
---|
187 | |
---|
188 | Statement* |
---|
189 | Mutator::mutate(TryStmt *tryStmt) |
---|
190 | { |
---|
191 | tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) ); |
---|
192 | mutateAll( tryStmt->get_catchers(), *this ); |
---|
193 | return tryStmt; |
---|
194 | } |
---|
195 | |
---|
196 | Statement* |
---|
197 | Mutator::mutate(CatchStmt *catchStmt) |
---|
198 | { |
---|
199 | catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) ); |
---|
200 | catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) ); |
---|
201 | return catchStmt; |
---|
202 | } |
---|
203 | |
---|
204 | Statement* |
---|
205 | Mutator::mutate(FinallyStmt *finalStmt) |
---|
206 | { |
---|
207 | finalStmt->set_block( maybeMutate( finalStmt->get_block(), *this ) ); |
---|
208 | return finalStmt; |
---|
209 | } |
---|
210 | |
---|
211 | NullStmt* |
---|
212 | Mutator::mutate(NullStmt *nullStmt) |
---|
213 | { |
---|
214 | return nullStmt; |
---|
215 | } |
---|
216 | |
---|
217 | Statement* |
---|
218 | Mutator::mutate(DeclStmt *declStmt) |
---|
219 | { |
---|
220 | declStmt->set_decl( maybeMutate( declStmt->get_decl(), *this ) ); |
---|
221 | return declStmt; |
---|
222 | } |
---|
223 | |
---|
224 | Expression* |
---|
225 | Mutator::mutate(ApplicationExpr *applicationExpr) |
---|
226 | { |
---|
227 | mutateAll( applicationExpr->get_results(), *this ); |
---|
228 | applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) ); |
---|
229 | mutateAll( applicationExpr->get_args(), *this ); |
---|
230 | return applicationExpr; |
---|
231 | } |
---|
232 | |
---|
233 | Expression* |
---|
234 | Mutator::mutate(UntypedExpr *untypedExpr) |
---|
235 | { |
---|
236 | mutateAll( untypedExpr->get_results(), *this ); |
---|
237 | mutateAll( untypedExpr->get_args(), *this ); |
---|
238 | return untypedExpr; |
---|
239 | } |
---|
240 | |
---|
241 | Expression* |
---|
242 | Mutator::mutate(NameExpr *nameExpr) |
---|
243 | { |
---|
244 | mutateAll( nameExpr->get_results(), *this ); |
---|
245 | return nameExpr; |
---|
246 | } |
---|
247 | |
---|
248 | Expression* |
---|
249 | Mutator::mutate(AddressExpr *addressExpr) |
---|
250 | { |
---|
251 | mutateAll( addressExpr->get_results(), *this ); |
---|
252 | addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) ); |
---|
253 | return addressExpr; |
---|
254 | } |
---|
255 | |
---|
256 | Expression* |
---|
257 | Mutator::mutate(LabelAddressExpr *labelAddressExpr) |
---|
258 | { |
---|
259 | mutateAll( labelAddressExpr->get_results(), *this ); |
---|
260 | labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) ); |
---|
261 | return labelAddressExpr; |
---|
262 | } |
---|
263 | |
---|
264 | Expression* |
---|
265 | Mutator::mutate(CastExpr *castExpr) |
---|
266 | { |
---|
267 | mutateAll( castExpr->get_results(), *this ); |
---|
268 | castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) ); |
---|
269 | return castExpr; |
---|
270 | } |
---|
271 | |
---|
272 | Expression* |
---|
273 | Mutator::mutate(UntypedMemberExpr *memberExpr) |
---|
274 | { |
---|
275 | mutateAll( memberExpr->get_results(), *this ); |
---|
276 | memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) ); |
---|
277 | return memberExpr; |
---|
278 | } |
---|
279 | |
---|
280 | Expression* |
---|
281 | Mutator::mutate(MemberExpr *memberExpr) |
---|
282 | { |
---|
283 | mutateAll( memberExpr->get_results(), *this ); |
---|
284 | memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) ); |
---|
285 | return memberExpr; |
---|
286 | } |
---|
287 | |
---|
288 | Expression* |
---|
289 | Mutator::mutate(VariableExpr *variableExpr) |
---|
290 | { |
---|
291 | mutateAll( variableExpr->get_results(), *this ); |
---|
292 | return variableExpr; |
---|
293 | } |
---|
294 | |
---|
295 | Expression* |
---|
296 | Mutator::mutate(ConstantExpr *constantExpr) |
---|
297 | { |
---|
298 | mutateAll( constantExpr->get_results(), *this ); |
---|
299 | // maybeMutate( constantExpr->get_constant(), *this ) |
---|
300 | return constantExpr; |
---|
301 | } |
---|
302 | |
---|
303 | Expression* |
---|
304 | Mutator::mutate(SizeofExpr *sizeofExpr) |
---|
305 | { |
---|
306 | mutateAll( sizeofExpr->get_results(), *this ); |
---|
307 | if( sizeofExpr->get_isType() ) { |
---|
308 | sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) ); |
---|
309 | } else { |
---|
310 | sizeofExpr->set_expr( maybeMutate( sizeofExpr->get_expr(), *this ) ); |
---|
311 | } |
---|
312 | return sizeofExpr; |
---|
313 | } |
---|
314 | |
---|
315 | Expression* |
---|
316 | Mutator::mutate(AttrExpr *attrExpr) |
---|
317 | { |
---|
318 | mutateAll( attrExpr->get_results(), *this ); |
---|
319 | if( attrExpr->get_isType() ) { |
---|
320 | attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) ); |
---|
321 | } else { |
---|
322 | attrExpr->set_expr( maybeMutate( attrExpr->get_expr(), *this ) ); |
---|
323 | } |
---|
324 | return attrExpr; |
---|
325 | } |
---|
326 | |
---|
327 | Expression* |
---|
328 | Mutator::mutate(LogicalExpr *logicalExpr) |
---|
329 | { |
---|
330 | mutateAll( logicalExpr->get_results(), *this ); |
---|
331 | logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) ); |
---|
332 | logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) ); |
---|
333 | return logicalExpr; |
---|
334 | } |
---|
335 | |
---|
336 | Expression* |
---|
337 | Mutator::mutate(ConditionalExpr *conditionalExpr) |
---|
338 | { |
---|
339 | mutateAll( conditionalExpr->get_results(), *this ); |
---|
340 | conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) ); |
---|
341 | conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) ); |
---|
342 | conditionalExpr->set_arg3( maybeMutate( conditionalExpr->get_arg3(), *this ) ); |
---|
343 | return conditionalExpr; |
---|
344 | } |
---|
345 | |
---|
346 | Expression* |
---|
347 | Mutator::mutate(CommaExpr *commaExpr) |
---|
348 | { |
---|
349 | mutateAll( commaExpr->get_results(), *this ); |
---|
350 | commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) ); |
---|
351 | commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) ); |
---|
352 | return commaExpr; |
---|
353 | } |
---|
354 | |
---|
355 | Expression* |
---|
356 | Mutator::mutate(TupleExpr *tupleExpr) |
---|
357 | { |
---|
358 | mutateAll( tupleExpr->get_results(), *this ); |
---|
359 | mutateAll( tupleExpr->get_exprs(), *this ); |
---|
360 | return tupleExpr; |
---|
361 | } |
---|
362 | |
---|
363 | Expression* |
---|
364 | Mutator::mutate(SolvedTupleExpr *tupleExpr) |
---|
365 | { |
---|
366 | mutateAll( tupleExpr->get_results(), *this ); |
---|
367 | mutateAll( tupleExpr->get_exprs(), *this ); |
---|
368 | return tupleExpr; |
---|
369 | } |
---|
370 | |
---|
371 | Expression* |
---|
372 | Mutator::mutate(TypeExpr *typeExpr) |
---|
373 | { |
---|
374 | mutateAll( typeExpr->get_results(), *this ); |
---|
375 | typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) ); |
---|
376 | return typeExpr; |
---|
377 | } |
---|
378 | |
---|
379 | Expression* |
---|
380 | Mutator::mutate(UntypedValofExpr *valofExpr) |
---|
381 | { |
---|
382 | mutateAll( valofExpr->get_results(), *this ); |
---|
383 | return valofExpr; |
---|
384 | } |
---|
385 | |
---|
386 | Type* |
---|
387 | Mutator::mutate(VoidType *voidType) |
---|
388 | { |
---|
389 | mutateAll( voidType->get_forall(), *this ); |
---|
390 | return voidType; |
---|
391 | } |
---|
392 | |
---|
393 | Type* |
---|
394 | Mutator::mutate(BasicType *basicType) |
---|
395 | { |
---|
396 | mutateAll( basicType->get_forall(), *this ); |
---|
397 | return basicType; |
---|
398 | } |
---|
399 | |
---|
400 | Type* |
---|
401 | Mutator::mutate(PointerType *pointerType) |
---|
402 | { |
---|
403 | mutateAll( pointerType->get_forall(), *this ); |
---|
404 | pointerType->set_base( maybeMutate( pointerType->get_base(), *this ) ); |
---|
405 | return pointerType; |
---|
406 | } |
---|
407 | |
---|
408 | Type* |
---|
409 | Mutator::mutate(ArrayType *arrayType) |
---|
410 | { |
---|
411 | mutateAll( arrayType->get_forall(), *this ); |
---|
412 | arrayType->set_dimension( maybeMutate( arrayType->get_dimension(), *this ) ); |
---|
413 | arrayType->set_base( maybeMutate( arrayType->get_base(), *this ) ); |
---|
414 | return arrayType; |
---|
415 | } |
---|
416 | |
---|
417 | Type* |
---|
418 | Mutator::mutate(FunctionType *functionType) |
---|
419 | { |
---|
420 | mutateAll( functionType->get_forall(), *this ); |
---|
421 | mutateAll( functionType->get_returnVals(), *this ); |
---|
422 | mutateAll( functionType->get_parameters(), *this ); |
---|
423 | return functionType; |
---|
424 | } |
---|
425 | |
---|
426 | Type* |
---|
427 | Mutator::handleReferenceToType(ReferenceToType *aggregateUseType) |
---|
428 | { |
---|
429 | mutateAll( aggregateUseType->get_forall(), *this ); |
---|
430 | mutateAll( aggregateUseType->get_parameters(), *this ); |
---|
431 | return aggregateUseType; |
---|
432 | } |
---|
433 | |
---|
434 | Type* |
---|
435 | Mutator::mutate(StructInstType *aggregateUseType) |
---|
436 | { |
---|
437 | handleReferenceToType( aggregateUseType ); |
---|
438 | return aggregateUseType; |
---|
439 | } |
---|
440 | |
---|
441 | Type* |
---|
442 | Mutator::mutate(UnionInstType *aggregateUseType) |
---|
443 | { |
---|
444 | handleReferenceToType( aggregateUseType ); |
---|
445 | return aggregateUseType; |
---|
446 | } |
---|
447 | |
---|
448 | Type* |
---|
449 | Mutator::mutate(EnumInstType *aggregateUseType) |
---|
450 | { |
---|
451 | handleReferenceToType( aggregateUseType ); |
---|
452 | return aggregateUseType; |
---|
453 | } |
---|
454 | |
---|
455 | Type* |
---|
456 | Mutator::mutate(ContextInstType *aggregateUseType) |
---|
457 | { |
---|
458 | handleReferenceToType( aggregateUseType ); |
---|
459 | mutateAll( aggregateUseType->get_members(), *this ); |
---|
460 | return aggregateUseType; |
---|
461 | } |
---|
462 | |
---|
463 | Type* |
---|
464 | Mutator::mutate(TypeInstType *aggregateUseType) |
---|
465 | { |
---|
466 | handleReferenceToType( aggregateUseType ); |
---|
467 | return aggregateUseType; |
---|
468 | } |
---|
469 | |
---|
470 | Type* |
---|
471 | Mutator::mutate(TupleType *tupleType) |
---|
472 | { |
---|
473 | mutateAll( tupleType->get_forall(), *this ); |
---|
474 | mutateAll( tupleType->get_types(), *this ); |
---|
475 | return tupleType; |
---|
476 | } |
---|
477 | |
---|
478 | Type* |
---|
479 | Mutator::mutate(TypeofType *typeofType) |
---|
480 | { |
---|
481 | assert( typeofType->get_expr() ); |
---|
482 | typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) ); |
---|
483 | return typeofType; |
---|
484 | } |
---|
485 | |
---|
486 | Type* |
---|
487 | Mutator::mutate(AttrType *attrType) |
---|
488 | { |
---|
489 | if( attrType->get_isType() ) { |
---|
490 | assert( attrType->get_type() ); |
---|
491 | attrType->set_type( attrType->get_type()->acceptMutator( *this ) ); |
---|
492 | } else { |
---|
493 | assert( attrType->get_expr() ); |
---|
494 | attrType->set_expr( attrType->get_expr()->acceptMutator( *this ) ); |
---|
495 | } |
---|
496 | return attrType; |
---|
497 | } |
---|
498 | |
---|
499 | Initializer* |
---|
500 | Mutator::mutate(MemberInit *memberInit) |
---|
501 | { |
---|
502 | memberInit->set_value( memberInit->get_value()->acceptMutator( *this ) ); |
---|
503 | return memberInit; |
---|
504 | } |
---|
505 | |
---|
506 | Initializer* |
---|
507 | Mutator::mutate(ElementInit *elementInit) |
---|
508 | { |
---|
509 | elementInit->set_value( elementInit->get_value()->acceptMutator( *this ) ); |
---|
510 | return elementInit; |
---|
511 | } |
---|
512 | |
---|
513 | Initializer* |
---|
514 | Mutator::mutate(SingleInit *singleInit) |
---|
515 | { |
---|
516 | singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) ); |
---|
517 | return singleInit; |
---|
518 | } |
---|
519 | |
---|
520 | Initializer* |
---|
521 | Mutator::mutate(ListInit *listInit) |
---|
522 | { |
---|
523 | mutateAll( listInit->get_designators(), *this ); |
---|
524 | mutateAll( listInit->get_initializers(), *this ); |
---|
525 | return listInit; |
---|
526 | } |
---|
527 | |
---|
528 | Subrange * |
---|
529 | Mutator::mutate(Subrange *subrange) |
---|
530 | { |
---|
531 | return subrange; |
---|
532 | } |
---|
533 | |
---|
534 | Constant * |
---|
535 | Mutator::mutate(Constant *constant) |
---|
536 | { |
---|
537 | return constant; |
---|
538 | } |
---|
539 | |
---|