source: translator/SynTree/Mutator.cc @ f7f6785

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 f7f6785 was d9a0e76, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

remove Parser.old, add -XCFA to driver, copy ptrdiff_t from stddef.h in preclude, remove casts from initialization constants, adjust formatting

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