source: translator/SynTree/Mutator.cc @ 0dd3a2f

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

licencing: third groups of files

  • Property mode set to 100644
File size: 12.3 KB
Line 
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
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
26Mutator::Mutator() {}
27
28Mutator::~Mutator() {}
29
30ObjectDecl *Mutator::mutate( ObjectDecl *objectDecl ) {
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;
35}
36
37DeclarationWithType *Mutator::mutate( FunctionDecl *functionDecl ) {
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
44Declaration *Mutator::handleAggregateDecl( AggregateDecl *aggregateDecl ) {
45        mutateAll( aggregateDecl->get_parameters(), *this );
46        mutateAll( aggregateDecl->get_members(), *this );
47        return aggregateDecl;
48}
49
50Declaration *Mutator::mutate( StructDecl *aggregateDecl ) {
51        handleAggregateDecl( aggregateDecl );
52        return aggregateDecl;
53}
54
55Declaration *Mutator::mutate( UnionDecl *aggregateDecl ) {
56        handleAggregateDecl( aggregateDecl );
57        return aggregateDecl;
58}
59
60Declaration *Mutator::mutate( EnumDecl *aggregateDecl ) {
61        handleAggregateDecl( aggregateDecl );
62        return aggregateDecl;
63}
64
65Declaration *Mutator::mutate( ContextDecl *aggregateDecl ) {
66        handleAggregateDecl( aggregateDecl );
67        return aggregateDecl;
68}
69
70Declaration *Mutator::handleNamedTypeDecl( NamedTypeDecl *typeDecl ) {
71        mutateAll( typeDecl->get_parameters(), *this );
72        mutateAll( typeDecl->get_assertions(), *this );
73        typeDecl->set_base( maybeMutate( typeDecl->get_base(), *this ) );
74        return typeDecl;
75}
76
77TypeDecl *Mutator::mutate( TypeDecl *typeDecl ) {
78        handleNamedTypeDecl( typeDecl );
79        return typeDecl;
80}
81
82Declaration *Mutator::mutate( TypedefDecl *typeDecl ) {
83        handleNamedTypeDecl( typeDecl );
84        return typeDecl;
85}
86
87CompoundStmt *Mutator::mutate( CompoundStmt *compoundStmt ) {
88        mutateAll( compoundStmt->get_kids(), *this );
89        return compoundStmt;
90}
91
92Statement *Mutator::mutate( ExprStmt *exprStmt ) {
93        exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) );
94        return exprStmt;
95}
96
97Statement *Mutator::mutate( IfStmt *ifStmt ) {
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;
102}
103
104Statement *Mutator::mutate( WhileStmt *whileStmt ) {
105        whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) );
106        whileStmt->set_body( maybeMutate( whileStmt->get_body(), *this ) );
107        return whileStmt;
108}
109
110Statement *Mutator::mutate( ForStmt *forStmt ) {
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;
116}
117
118Statement *Mutator::mutate( SwitchStmt *switchStmt ) {
119        switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
120        mutateAll( switchStmt->get_branches(), *this );
121        return switchStmt;
122}
123
124Statement *Mutator::mutate( ChooseStmt *switchStmt ) {
125        switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
126        mutateAll( switchStmt->get_branches(), *this );
127        return switchStmt;
128}
129
130Statement *Mutator::mutate( FallthruStmt *fallthruStmt ) {
131        return fallthruStmt;
132}
133
134Statement *Mutator::mutate( CaseStmt *caseStmt ) {
135        caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) );
136        mutateAll (caseStmt->get_statements(), *this );
137
138        return caseStmt;
139}
140
141Statement *Mutator::mutate( BranchStmt *branchStmt ) {
142        return branchStmt;
143}
144
145Statement *Mutator::mutate( ReturnStmt *returnStmt ) {
146        returnStmt->set_expr( maybeMutate( returnStmt->get_expr(), *this ) );
147        return returnStmt;
148}
149
150Statement *Mutator::mutate( TryStmt *tryStmt ) {
151        tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );
152        mutateAll( tryStmt->get_catchers(), *this );
153        return tryStmt;
154}
155
156Statement *Mutator::mutate( CatchStmt *catchStmt ) {
157        catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) );
158        catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) );
159        return catchStmt;
160}
161
162Statement *Mutator::mutate( FinallyStmt *finalStmt ) {
163        finalStmt->set_block( maybeMutate( finalStmt->get_block(), *this ) );
164        return finalStmt;
165}
166
167NullStmt *Mutator::mutate( NullStmt *nullStmt ) {
168        return nullStmt;
169}
170
171Statement *Mutator::mutate( DeclStmt *declStmt ) {
172        declStmt->set_decl( maybeMutate( declStmt->get_decl(), *this ) );
173        return declStmt;
174}
175
176Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) {
177        mutateAll( applicationExpr->get_results(), *this );
178        applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) );
179        mutateAll( applicationExpr->get_args(), *this );
180        return applicationExpr;
181}
182
183Expression *Mutator::mutate( UntypedExpr *untypedExpr ) {
184        mutateAll( untypedExpr->get_results(), *this );
185        mutateAll( untypedExpr->get_args(), *this );
186        return untypedExpr;
187}
188
189Expression *Mutator::mutate( NameExpr *nameExpr ) {
190        mutateAll( nameExpr->get_results(), *this );
191        return nameExpr;
192}
193
194Expression *Mutator::mutate( AddressExpr *addressExpr ) {
195        mutateAll( addressExpr->get_results(), *this );
196        addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) );
197        return addressExpr;
198}
199
200Expression *Mutator::mutate( LabelAddressExpr *labelAddressExpr ) {
201        mutateAll( labelAddressExpr->get_results(), *this );
202        labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) );
203        return labelAddressExpr;
204}
205
206Expression *Mutator::mutate( CastExpr *castExpr ) {
207        mutateAll( castExpr->get_results(), *this );
208        castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) );
209        return castExpr;
210}
211
212Expression *Mutator::mutate( UntypedMemberExpr *memberExpr ) {
213        mutateAll( memberExpr->get_results(), *this );
214        memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
215        return memberExpr;
216}
217
218Expression *Mutator::mutate( MemberExpr *memberExpr ) {
219        mutateAll( memberExpr->get_results(), *this );
220        memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
221        return memberExpr;
222}
223
224Expression *Mutator::mutate( VariableExpr *variableExpr ) {
225        mutateAll( variableExpr->get_results(), *this );
226        return variableExpr;
227}
228
229Expression *Mutator::mutate( ConstantExpr *constantExpr ) {
230        mutateAll( constantExpr->get_results(), *this );
231//  maybeMutate( constantExpr->get_constant(), *this )
232        return constantExpr;
233}
234
235Expression *Mutator::mutate( SizeofExpr *sizeofExpr ) {
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;
243}
244
245Expression *Mutator::mutate( AttrExpr *attrExpr ) {
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;
253}
254
255Expression *Mutator::mutate( LogicalExpr *logicalExpr ) {
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;
260}
261
262Expression *Mutator::mutate( ConditionalExpr *conditionalExpr ) {
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;
268}
269
270Expression *Mutator::mutate( CommaExpr *commaExpr ) {
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;
275}
276
277Expression *Mutator::mutate( TupleExpr *tupleExpr ) {
278        mutateAll( tupleExpr->get_results(), *this );
279        mutateAll( tupleExpr->get_exprs(), *this );
280        return tupleExpr;
281}
282
283Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) {
284        mutateAll( tupleExpr->get_results(), *this );
285        mutateAll( tupleExpr->get_exprs(), *this );
286        return tupleExpr;
287}
288
289Expression *Mutator::mutate( TypeExpr *typeExpr ) {
290        mutateAll( typeExpr->get_results(), *this );
291        typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) );
292        return typeExpr;
293}
294
295Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {
296        mutateAll( valofExpr->get_results(), *this );
297        return valofExpr;
298}
299
300Type *Mutator::mutate( VoidType *voidType ) {
301        mutateAll( voidType->get_forall(), *this );
302        return voidType;
303}
304
305Type *Mutator::mutate( BasicType *basicType ) {
306        mutateAll( basicType->get_forall(), *this );
307        return basicType;
308}
309
310Type *Mutator::mutate( PointerType *pointerType ) {
311        mutateAll( pointerType->get_forall(), *this );
312        pointerType->set_base( maybeMutate( pointerType->get_base(), *this ) );
313        return pointerType;
314}
315
316Type *Mutator::mutate( ArrayType *arrayType ) {
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;
321}
322
323Type *Mutator::mutate( FunctionType *functionType ) {
324        mutateAll( functionType->get_forall(), *this );
325        mutateAll( functionType->get_returnVals(), *this );
326        mutateAll( functionType->get_parameters(), *this );
327        return functionType;
328}
329
330Type *Mutator::handleReferenceToType( ReferenceToType *aggregateUseType ) {
331        mutateAll( aggregateUseType->get_forall(), *this );
332        mutateAll( aggregateUseType->get_parameters(), *this );
333        return aggregateUseType;
334}
335
336Type *Mutator::mutate( StructInstType *aggregateUseType ) {
337        handleReferenceToType( aggregateUseType );
338        return aggregateUseType;
339}
340
341Type *Mutator::mutate( UnionInstType *aggregateUseType ) {
342        handleReferenceToType( aggregateUseType );
343        return aggregateUseType;
344}
345
346Type *Mutator::mutate( EnumInstType *aggregateUseType ) {
347        handleReferenceToType( aggregateUseType );
348        return aggregateUseType;
349}
350
351Type *Mutator::mutate( ContextInstType *aggregateUseType ) {
352        handleReferenceToType( aggregateUseType );
353        mutateAll( aggregateUseType->get_members(), *this );
354        return aggregateUseType;
355}
356
357Type *Mutator::mutate( TypeInstType *aggregateUseType ) {
358        handleReferenceToType( aggregateUseType );
359        return aggregateUseType;
360}
361
362Type *Mutator::mutate( TupleType *tupleType ) {
363        mutateAll( tupleType->get_forall(), *this );
364        mutateAll( tupleType->get_types(), *this );
365        return tupleType;
366}
367
368Type *Mutator::mutate( TypeofType *typeofType ) {
369        assert( typeofType->get_expr() );
370        typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) );
371        return typeofType;
372}
373
374Type *Mutator::mutate( AttrType *attrType ) {
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;
383}
384
385Initializer *Mutator::mutate( SingleInit *singleInit ) {
386        singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) );
387        return singleInit;
388}
389
390Initializer *Mutator::mutate( ListInit *listInit ) {
391        mutateAll( listInit->get_designators(), *this );
392        mutateAll( listInit->get_initializers(), *this );
393        return listInit;
394}
395
396Subrange *Mutator::mutate( Subrange *subrange ) {
397        return subrange;
398}
399
400Constant *Mutator::mutate( Constant *constant ) {
401        return constant;
402}
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.