source: src/SynTree/Mutator.cc @ ea9b9d3

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 ea9b9d3 was 843054c2, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

licencing: seventh groups of files

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