1 | #include <cassert>
|
---|
2 | #include "Mutator.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 | #include "utility.h"
|
---|
10 |
|
---|
11 | Mutator::Mutator() {}
|
---|
12 |
|
---|
13 | Mutator::~Mutator() {}
|
---|
14 |
|
---|
15 | ObjectDecl *Mutator::mutate( ObjectDecl *objectDecl ) {
|
---|
16 | objectDecl->set_type( maybeMutate( objectDecl->get_type(), *this ) );
|
---|
17 | objectDecl->set_init( maybeMutate( objectDecl->get_init(), *this ) );
|
---|
18 | objectDecl->set_bitfieldWidth( maybeMutate( objectDecl->get_bitfieldWidth(), *this ) );
|
---|
19 | return objectDecl;
|
---|
20 | }
|
---|
21 |
|
---|
22 | DeclarationWithType *Mutator::mutate( FunctionDecl *functionDecl ) {
|
---|
23 | functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) );
|
---|
24 | mutateAll( functionDecl->get_oldDecls(), *this );
|
---|
25 | functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
|
---|
26 | return functionDecl;
|
---|
27 | }
|
---|
28 |
|
---|
29 | Declaration *Mutator::handleAggregateDecl( AggregateDecl *aggregateDecl ) {
|
---|
30 | mutateAll( aggregateDecl->get_parameters(), *this );
|
---|
31 | mutateAll( aggregateDecl->get_members(), *this );
|
---|
32 | return aggregateDecl;
|
---|
33 | }
|
---|
34 |
|
---|
35 | Declaration *Mutator::mutate( StructDecl *aggregateDecl ) {
|
---|
36 | handleAggregateDecl( aggregateDecl );
|
---|
37 | return aggregateDecl;
|
---|
38 | }
|
---|
39 |
|
---|
40 | Declaration *Mutator::mutate( UnionDecl *aggregateDecl ) {
|
---|
41 | handleAggregateDecl( aggregateDecl );
|
---|
42 | return aggregateDecl;
|
---|
43 | }
|
---|
44 |
|
---|
45 | Declaration *Mutator::mutate( EnumDecl *aggregateDecl ) {
|
---|
46 | handleAggregateDecl( aggregateDecl );
|
---|
47 | return aggregateDecl;
|
---|
48 | }
|
---|
49 |
|
---|
50 | Declaration *Mutator::mutate( ContextDecl *aggregateDecl ) {
|
---|
51 | handleAggregateDecl( aggregateDecl );
|
---|
52 | return aggregateDecl;
|
---|
53 | }
|
---|
54 |
|
---|
55 | Declaration *Mutator::handleNamedTypeDecl( NamedTypeDecl *typeDecl ) {
|
---|
56 | mutateAll( typeDecl->get_parameters(), *this );
|
---|
57 | mutateAll( typeDecl->get_assertions(), *this );
|
---|
58 | typeDecl->set_base( maybeMutate( typeDecl->get_base(), *this ) );
|
---|
59 | return typeDecl;
|
---|
60 | }
|
---|
61 |
|
---|
62 | TypeDecl *Mutator::mutate( TypeDecl *typeDecl ) {
|
---|
63 | handleNamedTypeDecl( typeDecl );
|
---|
64 | return typeDecl;
|
---|
65 | }
|
---|
66 |
|
---|
67 | Declaration *Mutator::mutate( TypedefDecl *typeDecl ) {
|
---|
68 | handleNamedTypeDecl( typeDecl );
|
---|
69 | return typeDecl;
|
---|
70 | }
|
---|
71 |
|
---|
72 | CompoundStmt *Mutator::mutate( CompoundStmt *compoundStmt ) {
|
---|
73 | mutateAll( compoundStmt->get_kids(), *this );
|
---|
74 | return compoundStmt;
|
---|
75 | }
|
---|
76 |
|
---|
77 | Statement *Mutator::mutate( ExprStmt *exprStmt ) {
|
---|
78 | exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) );
|
---|
79 | return exprStmt;
|
---|
80 | }
|
---|
81 |
|
---|
82 | Statement *Mutator::mutate( IfStmt *ifStmt ) {
|
---|
83 | ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) );
|
---|
84 | ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) );
|
---|
85 | ifStmt->set_elsePart( maybeMutate( ifStmt->get_elsePart(), *this ) );
|
---|
86 | return ifStmt;
|
---|
87 | }
|
---|
88 |
|
---|
89 | Statement *Mutator::mutate( WhileStmt *whileStmt ) {
|
---|
90 | whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) );
|
---|
91 | whileStmt->set_body( maybeMutate( whileStmt->get_body(), *this ) );
|
---|
92 | return whileStmt;
|
---|
93 | }
|
---|
94 |
|
---|
95 | Statement *Mutator::mutate( ForStmt *forStmt ) {
|
---|
96 | forStmt->set_initialization( maybeMutate( forStmt->get_initialization(), *this ) );
|
---|
97 | forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) );
|
---|
98 | forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) );
|
---|
99 | forStmt->set_body( maybeMutate( forStmt->get_body(), *this ) );
|
---|
100 | return forStmt;
|
---|
101 | }
|
---|
102 |
|
---|
103 | Statement *Mutator::mutate( SwitchStmt *switchStmt ) {
|
---|
104 | switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
|
---|
105 | mutateAll( switchStmt->get_branches(), *this );
|
---|
106 | return switchStmt;
|
---|
107 | }
|
---|
108 |
|
---|
109 | Statement *Mutator::mutate( ChooseStmt *switchStmt ) {
|
---|
110 | switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
|
---|
111 | mutateAll( switchStmt->get_branches(), *this );
|
---|
112 | return switchStmt;
|
---|
113 | }
|
---|
114 |
|
---|
115 | Statement *Mutator::mutate( FallthruStmt *fallthruStmt ) {
|
---|
116 | return fallthruStmt;
|
---|
117 | }
|
---|
118 |
|
---|
119 | Statement *Mutator::mutate( CaseStmt *caseStmt ) {
|
---|
120 | caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) );
|
---|
121 | mutateAll (caseStmt->get_statements(), *this );
|
---|
122 |
|
---|
123 | return caseStmt;
|
---|
124 | }
|
---|
125 |
|
---|
126 | Statement *Mutator::mutate( BranchStmt *branchStmt ) {
|
---|
127 | return branchStmt;
|
---|
128 | }
|
---|
129 |
|
---|
130 | Statement *Mutator::mutate( ReturnStmt *returnStmt ) {
|
---|
131 | returnStmt->set_expr( maybeMutate( returnStmt->get_expr(), *this ) );
|
---|
132 | return returnStmt;
|
---|
133 | }
|
---|
134 |
|
---|
135 | Statement *Mutator::mutate( TryStmt *tryStmt ) {
|
---|
136 | tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );
|
---|
137 | mutateAll( tryStmt->get_catchers(), *this );
|
---|
138 | return tryStmt;
|
---|
139 | }
|
---|
140 |
|
---|
141 | Statement *Mutator::mutate( CatchStmt *catchStmt ) {
|
---|
142 | catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) );
|
---|
143 | catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) );
|
---|
144 | return catchStmt;
|
---|
145 | }
|
---|
146 |
|
---|
147 | Statement *Mutator::mutate( FinallyStmt *finalStmt ) {
|
---|
148 | finalStmt->set_block( maybeMutate( finalStmt->get_block(), *this ) );
|
---|
149 | return finalStmt;
|
---|
150 | }
|
---|
151 |
|
---|
152 | NullStmt *Mutator::mutate( NullStmt *nullStmt ) {
|
---|
153 | return nullStmt;
|
---|
154 | }
|
---|
155 |
|
---|
156 | Statement *Mutator::mutate( DeclStmt *declStmt ) {
|
---|
157 | declStmt->set_decl( maybeMutate( declStmt->get_decl(), *this ) );
|
---|
158 | return declStmt;
|
---|
159 | }
|
---|
160 |
|
---|
161 | Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) {
|
---|
162 | mutateAll( applicationExpr->get_results(), *this );
|
---|
163 | applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) );
|
---|
164 | mutateAll( applicationExpr->get_args(), *this );
|
---|
165 | return applicationExpr;
|
---|
166 | }
|
---|
167 |
|
---|
168 | Expression *Mutator::mutate( UntypedExpr *untypedExpr ) {
|
---|
169 | mutateAll( untypedExpr->get_results(), *this );
|
---|
170 | mutateAll( untypedExpr->get_args(), *this );
|
---|
171 | return untypedExpr;
|
---|
172 | }
|
---|
173 |
|
---|
174 | Expression *Mutator::mutate( NameExpr *nameExpr ) {
|
---|
175 | mutateAll( nameExpr->get_results(), *this );
|
---|
176 | return nameExpr;
|
---|
177 | }
|
---|
178 |
|
---|
179 | Expression *Mutator::mutate( AddressExpr *addressExpr ) {
|
---|
180 | mutateAll( addressExpr->get_results(), *this );
|
---|
181 | addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) );
|
---|
182 | return addressExpr;
|
---|
183 | }
|
---|
184 |
|
---|
185 | Expression *Mutator::mutate( LabelAddressExpr *labelAddressExpr ) {
|
---|
186 | mutateAll( labelAddressExpr->get_results(), *this );
|
---|
187 | labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) );
|
---|
188 | return labelAddressExpr;
|
---|
189 | }
|
---|
190 |
|
---|
191 | Expression *Mutator::mutate( CastExpr *castExpr ) {
|
---|
192 | mutateAll( castExpr->get_results(), *this );
|
---|
193 | castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) );
|
---|
194 | return castExpr;
|
---|
195 | }
|
---|
196 |
|
---|
197 | Expression *Mutator::mutate( UntypedMemberExpr *memberExpr ) {
|
---|
198 | mutateAll( memberExpr->get_results(), *this );
|
---|
199 | memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
|
---|
200 | return memberExpr;
|
---|
201 | }
|
---|
202 |
|
---|
203 | Expression *Mutator::mutate( MemberExpr *memberExpr ) {
|
---|
204 | mutateAll( memberExpr->get_results(), *this );
|
---|
205 | memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
|
---|
206 | return memberExpr;
|
---|
207 | }
|
---|
208 |
|
---|
209 | Expression *Mutator::mutate( VariableExpr *variableExpr ) {
|
---|
210 | mutateAll( variableExpr->get_results(), *this );
|
---|
211 | return variableExpr;
|
---|
212 | }
|
---|
213 |
|
---|
214 | Expression *Mutator::mutate( ConstantExpr *constantExpr ) {
|
---|
215 | mutateAll( constantExpr->get_results(), *this );
|
---|
216 | // maybeMutate( constantExpr->get_constant(), *this )
|
---|
217 | return constantExpr;
|
---|
218 | }
|
---|
219 |
|
---|
220 | Expression *Mutator::mutate( SizeofExpr *sizeofExpr ) {
|
---|
221 | mutateAll( sizeofExpr->get_results(), *this );
|
---|
222 | if ( sizeofExpr->get_isType() ) {
|
---|
223 | sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) );
|
---|
224 | } else {
|
---|
225 | sizeofExpr->set_expr( maybeMutate( sizeofExpr->get_expr(), *this ) );
|
---|
226 | }
|
---|
227 | return sizeofExpr;
|
---|
228 | }
|
---|
229 |
|
---|
230 | Expression *Mutator::mutate( AttrExpr *attrExpr ) {
|
---|
231 | mutateAll( attrExpr->get_results(), *this );
|
---|
232 | if ( attrExpr->get_isType() ) {
|
---|
233 | attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) );
|
---|
234 | } else {
|
---|
235 | attrExpr->set_expr( maybeMutate( attrExpr->get_expr(), *this ) );
|
---|
236 | }
|
---|
237 | return attrExpr;
|
---|
238 | }
|
---|
239 |
|
---|
240 | Expression *Mutator::mutate( LogicalExpr *logicalExpr ) {
|
---|
241 | mutateAll( logicalExpr->get_results(), *this );
|
---|
242 | logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) );
|
---|
243 | logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) );
|
---|
244 | return logicalExpr;
|
---|
245 | }
|
---|
246 |
|
---|
247 | Expression *Mutator::mutate( ConditionalExpr *conditionalExpr ) {
|
---|
248 | mutateAll( conditionalExpr->get_results(), *this );
|
---|
249 | conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) );
|
---|
250 | conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) );
|
---|
251 | conditionalExpr->set_arg3( maybeMutate( conditionalExpr->get_arg3(), *this ) );
|
---|
252 | return conditionalExpr;
|
---|
253 | }
|
---|
254 |
|
---|
255 | Expression *Mutator::mutate( CommaExpr *commaExpr ) {
|
---|
256 | mutateAll( commaExpr->get_results(), *this );
|
---|
257 | commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) );
|
---|
258 | commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) );
|
---|
259 | return commaExpr;
|
---|
260 | }
|
---|
261 |
|
---|
262 | Expression *Mutator::mutate( TupleExpr *tupleExpr ) {
|
---|
263 | mutateAll( tupleExpr->get_results(), *this );
|
---|
264 | mutateAll( tupleExpr->get_exprs(), *this );
|
---|
265 | return tupleExpr;
|
---|
266 | }
|
---|
267 |
|
---|
268 | Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) {
|
---|
269 | mutateAll( tupleExpr->get_results(), *this );
|
---|
270 | mutateAll( tupleExpr->get_exprs(), *this );
|
---|
271 | return tupleExpr;
|
---|
272 | }
|
---|
273 |
|
---|
274 | Expression *Mutator::mutate( TypeExpr *typeExpr ) {
|
---|
275 | mutateAll( typeExpr->get_results(), *this );
|
---|
276 | typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) );
|
---|
277 | return typeExpr;
|
---|
278 | }
|
---|
279 |
|
---|
280 | Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {
|
---|
281 | mutateAll( valofExpr->get_results(), *this );
|
---|
282 | return valofExpr;
|
---|
283 | }
|
---|
284 |
|
---|
285 | Type *Mutator::mutate( VoidType *voidType ) {
|
---|
286 | mutateAll( voidType->get_forall(), *this );
|
---|
287 | return voidType;
|
---|
288 | }
|
---|
289 |
|
---|
290 | Type *Mutator::mutate( BasicType *basicType ) {
|
---|
291 | mutateAll( basicType->get_forall(), *this );
|
---|
292 | return basicType;
|
---|
293 | }
|
---|
294 |
|
---|
295 | Type *Mutator::mutate( PointerType *pointerType ) {
|
---|
296 | mutateAll( pointerType->get_forall(), *this );
|
---|
297 | pointerType->set_base( maybeMutate( pointerType->get_base(), *this ) );
|
---|
298 | return pointerType;
|
---|
299 | }
|
---|
300 |
|
---|
301 | Type *Mutator::mutate( ArrayType *arrayType ) {
|
---|
302 | mutateAll( arrayType->get_forall(), *this );
|
---|
303 | arrayType->set_dimension( maybeMutate( arrayType->get_dimension(), *this ) );
|
---|
304 | arrayType->set_base( maybeMutate( arrayType->get_base(), *this ) );
|
---|
305 | return arrayType;
|
---|
306 | }
|
---|
307 |
|
---|
308 | Type *Mutator::mutate( FunctionType *functionType ) {
|
---|
309 | mutateAll( functionType->get_forall(), *this );
|
---|
310 | mutateAll( functionType->get_returnVals(), *this );
|
---|
311 | mutateAll( functionType->get_parameters(), *this );
|
---|
312 | return functionType;
|
---|
313 | }
|
---|
314 |
|
---|
315 | Type *Mutator::handleReferenceToType( ReferenceToType *aggregateUseType ) {
|
---|
316 | mutateAll( aggregateUseType->get_forall(), *this );
|
---|
317 | mutateAll( aggregateUseType->get_parameters(), *this );
|
---|
318 | return aggregateUseType;
|
---|
319 | }
|
---|
320 |
|
---|
321 | Type *Mutator::mutate( StructInstType *aggregateUseType ) {
|
---|
322 | handleReferenceToType( aggregateUseType );
|
---|
323 | return aggregateUseType;
|
---|
324 | }
|
---|
325 |
|
---|
326 | Type *Mutator::mutate( UnionInstType *aggregateUseType ) {
|
---|
327 | handleReferenceToType( aggregateUseType );
|
---|
328 | return aggregateUseType;
|
---|
329 | }
|
---|
330 |
|
---|
331 | Type *Mutator::mutate( EnumInstType *aggregateUseType ) {
|
---|
332 | handleReferenceToType( aggregateUseType );
|
---|
333 | return aggregateUseType;
|
---|
334 | }
|
---|
335 |
|
---|
336 | Type *Mutator::mutate( ContextInstType *aggregateUseType ) {
|
---|
337 | handleReferenceToType( aggregateUseType );
|
---|
338 | mutateAll( aggregateUseType->get_members(), *this );
|
---|
339 | return aggregateUseType;
|
---|
340 | }
|
---|
341 |
|
---|
342 | Type *Mutator::mutate( TypeInstType *aggregateUseType ) {
|
---|
343 | handleReferenceToType( aggregateUseType );
|
---|
344 | return aggregateUseType;
|
---|
345 | }
|
---|
346 |
|
---|
347 | Type *Mutator::mutate( TupleType *tupleType ) {
|
---|
348 | mutateAll( tupleType->get_forall(), *this );
|
---|
349 | mutateAll( tupleType->get_types(), *this );
|
---|
350 | return tupleType;
|
---|
351 | }
|
---|
352 |
|
---|
353 | Type *Mutator::mutate( TypeofType *typeofType ) {
|
---|
354 | assert( typeofType->get_expr() );
|
---|
355 | typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) );
|
---|
356 | return typeofType;
|
---|
357 | }
|
---|
358 |
|
---|
359 | Type *Mutator::mutate( AttrType *attrType ) {
|
---|
360 | if ( attrType->get_isType() ) {
|
---|
361 | assert( attrType->get_type() );
|
---|
362 | attrType->set_type( attrType->get_type()->acceptMutator( *this ) );
|
---|
363 | } else {
|
---|
364 | assert( attrType->get_expr() );
|
---|
365 | attrType->set_expr( attrType->get_expr()->acceptMutator( *this ) );
|
---|
366 | }
|
---|
367 | return attrType;
|
---|
368 | }
|
---|
369 |
|
---|
370 | Initializer *Mutator::mutate( MemberInit *memberInit ) {
|
---|
371 | memberInit->set_value( memberInit->get_value()->acceptMutator( *this ) );
|
---|
372 | return memberInit;
|
---|
373 | }
|
---|
374 |
|
---|
375 | Initializer *Mutator::mutate( ElementInit *elementInit ) {
|
---|
376 | elementInit->set_value( elementInit->get_value()->acceptMutator( *this ) );
|
---|
377 | return elementInit;
|
---|
378 | }
|
---|
379 |
|
---|
380 | Initializer *Mutator::mutate( SingleInit *singleInit ) {
|
---|
381 | singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) );
|
---|
382 | return singleInit;
|
---|
383 | }
|
---|
384 |
|
---|
385 | Initializer *Mutator::mutate( ListInit *listInit ) {
|
---|
386 | mutateAll( listInit->get_designators(), *this );
|
---|
387 | mutateAll( listInit->get_initializers(), *this );
|
---|
388 | return listInit;
|
---|
389 | }
|
---|
390 |
|
---|
391 | Subrange *Mutator::mutate( Subrange *subrange ) {
|
---|
392 | return subrange;
|
---|
393 | }
|
---|
394 |
|
---|
395 | Constant *Mutator::mutate( Constant *constant ) {
|
---|
396 | return constant;
|
---|
397 | }
|
---|