source: translator/SynTree/Mutator.cc @ c11e31c

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since c11e31c was bdd516a, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

fixed sizeof type variable, find lowest cost alternative for sizeof expression, removed unused classes, added compiler flag, remove temporary file for -CFA, formatting

  • Property mode set to 100644
File size: 12.2 KB
Line 
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
11Mutator::Mutator() {}
12
13Mutator::~Mutator() {}
14
15ObjectDecl *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
22DeclarationWithType *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
29Declaration *Mutator::handleAggregateDecl( AggregateDecl *aggregateDecl ) {
30    mutateAll( aggregateDecl->get_parameters(), *this );
31    mutateAll( aggregateDecl->get_members(), *this );
32    return aggregateDecl;
33}
34
35Declaration *Mutator::mutate( StructDecl *aggregateDecl ) {
36    handleAggregateDecl( aggregateDecl );
37    return aggregateDecl;
38}
39
40Declaration *Mutator::mutate( UnionDecl *aggregateDecl ) {
41    handleAggregateDecl( aggregateDecl );
42    return aggregateDecl;
43}
44
45Declaration *Mutator::mutate( EnumDecl *aggregateDecl ) {
46    handleAggregateDecl( aggregateDecl );
47    return aggregateDecl;
48}
49
50Declaration *Mutator::mutate( ContextDecl *aggregateDecl ) {
51    handleAggregateDecl( aggregateDecl );
52    return aggregateDecl;
53}
54
55Declaration *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
62TypeDecl *Mutator::mutate( TypeDecl *typeDecl ) {
63    handleNamedTypeDecl( typeDecl );
64    return typeDecl;
65}
66
67Declaration *Mutator::mutate( TypedefDecl *typeDecl ) {
68    handleNamedTypeDecl( typeDecl );
69    return typeDecl;
70}
71
72CompoundStmt *Mutator::mutate( CompoundStmt *compoundStmt ) {
73    mutateAll( compoundStmt->get_kids(), *this );
74    return compoundStmt;
75}
76
77Statement *Mutator::mutate( ExprStmt *exprStmt ) {
78    exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) );
79    return exprStmt;
80}
81
82Statement *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
89Statement *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
95Statement *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
103Statement *Mutator::mutate( SwitchStmt *switchStmt ) {
104    switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
105    mutateAll( switchStmt->get_branches(), *this );
106    return switchStmt;
107}
108
109Statement *Mutator::mutate( ChooseStmt *switchStmt ) {
110    switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
111    mutateAll( switchStmt->get_branches(), *this );
112    return switchStmt;
113}
114
115Statement *Mutator::mutate( FallthruStmt *fallthruStmt ) {
116    return fallthruStmt;
117}
118
119Statement *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
126Statement *Mutator::mutate( BranchStmt *branchStmt ) {
127    return branchStmt;
128}
129
130Statement *Mutator::mutate( ReturnStmt *returnStmt ) {
131    returnStmt->set_expr( maybeMutate( returnStmt->get_expr(), *this ) );
132    return returnStmt;
133}
134
135Statement *Mutator::mutate( TryStmt *tryStmt ) {
136    tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );
137    mutateAll( tryStmt->get_catchers(), *this );
138    return tryStmt;
139}
140
141Statement *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
147Statement *Mutator::mutate( FinallyStmt *finalStmt ) {
148    finalStmt->set_block( maybeMutate( finalStmt->get_block(), *this ) );
149    return finalStmt;
150}
151
152NullStmt *Mutator::mutate( NullStmt *nullStmt ) {
153    return nullStmt;
154}
155
156Statement *Mutator::mutate( DeclStmt *declStmt ) {
157    declStmt->set_decl( maybeMutate( declStmt->get_decl(), *this ) );
158    return declStmt;
159}
160
161Expression *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
168Expression *Mutator::mutate( UntypedExpr *untypedExpr ) {
169    mutateAll( untypedExpr->get_results(), *this );
170    mutateAll( untypedExpr->get_args(), *this );
171    return untypedExpr;
172}
173
174Expression *Mutator::mutate( NameExpr *nameExpr ) {
175    mutateAll( nameExpr->get_results(), *this );
176    return nameExpr;
177}
178
179Expression *Mutator::mutate( AddressExpr *addressExpr ) {
180    mutateAll( addressExpr->get_results(), *this );
181    addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) );
182    return addressExpr;
183}
184
185Expression *Mutator::mutate( LabelAddressExpr *labelAddressExpr ) {
186    mutateAll( labelAddressExpr->get_results(), *this );
187    labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) );
188    return labelAddressExpr;
189}
190
191Expression *Mutator::mutate( CastExpr *castExpr ) {
192    mutateAll( castExpr->get_results(), *this );
193    castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) );
194    return castExpr;
195}
196
197Expression *Mutator::mutate( UntypedMemberExpr *memberExpr ) {
198    mutateAll( memberExpr->get_results(), *this );
199    memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
200    return memberExpr;
201}
202
203Expression *Mutator::mutate( MemberExpr *memberExpr ) {
204    mutateAll( memberExpr->get_results(), *this );
205    memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
206    return memberExpr;
207}
208
209Expression *Mutator::mutate( VariableExpr *variableExpr ) {
210    mutateAll( variableExpr->get_results(), *this );
211    return variableExpr;
212}
213
214Expression *Mutator::mutate( ConstantExpr *constantExpr ) {
215    mutateAll( constantExpr->get_results(), *this );
216//  maybeMutate( constantExpr->get_constant(), *this )
217    return constantExpr;
218}
219
220Expression *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
230Expression *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
240Expression *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
247Expression *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
255Expression *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
262Expression *Mutator::mutate( TupleExpr *tupleExpr ) {
263    mutateAll( tupleExpr->get_results(), *this );
264    mutateAll( tupleExpr->get_exprs(), *this );
265    return tupleExpr;
266}
267
268Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) {
269    mutateAll( tupleExpr->get_results(), *this );
270    mutateAll( tupleExpr->get_exprs(), *this );
271    return tupleExpr;
272}
273
274Expression *Mutator::mutate( TypeExpr *typeExpr ) {
275    mutateAll( typeExpr->get_results(), *this );
276    typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) );
277    return typeExpr;
278}
279
280Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {
281    mutateAll( valofExpr->get_results(), *this );
282    return valofExpr;
283}
284
285Type *Mutator::mutate( VoidType *voidType ) {
286    mutateAll( voidType->get_forall(), *this );
287    return voidType;
288}
289
290Type *Mutator::mutate( BasicType *basicType ) {
291    mutateAll( basicType->get_forall(), *this );
292    return basicType;
293}
294
295Type *Mutator::mutate( PointerType *pointerType ) {
296    mutateAll( pointerType->get_forall(), *this );
297    pointerType->set_base( maybeMutate( pointerType->get_base(), *this ) );
298    return pointerType;
299}
300
301Type *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
308Type *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
315Type *Mutator::handleReferenceToType( ReferenceToType *aggregateUseType ) {
316    mutateAll( aggregateUseType->get_forall(), *this );
317    mutateAll( aggregateUseType->get_parameters(), *this );
318    return aggregateUseType;
319}
320
321Type *Mutator::mutate( StructInstType *aggregateUseType ) {
322    handleReferenceToType( aggregateUseType );
323    return aggregateUseType;
324}
325
326Type *Mutator::mutate( UnionInstType *aggregateUseType ) {
327    handleReferenceToType( aggregateUseType );
328    return aggregateUseType;
329}
330
331Type *Mutator::mutate( EnumInstType *aggregateUseType ) {
332    handleReferenceToType( aggregateUseType );
333    return aggregateUseType;
334}
335
336Type *Mutator::mutate( ContextInstType *aggregateUseType ) {
337    handleReferenceToType( aggregateUseType );
338    mutateAll( aggregateUseType->get_members(), *this );
339    return aggregateUseType;
340}
341
342Type *Mutator::mutate( TypeInstType *aggregateUseType ) {
343    handleReferenceToType( aggregateUseType );
344    return aggregateUseType;
345}
346
347Type *Mutator::mutate( TupleType *tupleType ) {
348    mutateAll( tupleType->get_forall(), *this );
349    mutateAll( tupleType->get_types(), *this );
350    return tupleType;
351}
352
353Type *Mutator::mutate( TypeofType *typeofType ) {
354    assert( typeofType->get_expr() );
355    typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) );
356    return typeofType;
357}
358
359Type *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
370Initializer *Mutator::mutate( SingleInit *singleInit ) {
371    singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) );
372    return singleInit;
373}
374
375Initializer *Mutator::mutate( ListInit *listInit ) {
376    mutateAll( listInit->get_designators(), *this );
377    mutateAll( listInit->get_initializers(), *this );
378    return listInit;
379}
380
381Subrange *Mutator::mutate( Subrange *subrange ) {
382    return subrange;
383}
384
385Constant *Mutator::mutate( Constant *constant ) {
386    return constant;
387}
Note: See TracBrowser for help on using the repository browser.