source: translator/SynTree/Mutator.cc @ 91b216b4

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 91b216b4 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 12.6 KB
RevLine 
[51b7345]1/*
2 * This file is part of the Cforall project
3 *
4 * $Id: Mutator.cc,v 1.30 2005/08/29 20:59:25 rcbilson Exp $
5 *
6 */
7
8#include <cassert>
9#include "Mutator.h"
10#include "Initializer.h"
11#include "Statement.h"
12#include "Type.h"
13#include "Declaration.h"
14#include "Expression.h"
15#include "Constant.h"
16#include "utility.h"
17
18Mutator::Mutator()
19{
20}
21
22Mutator::~Mutator()
23{
24}
25
26ObjectDecl*
27Mutator::mutate(ObjectDecl *objectDecl)
28{
29    objectDecl->set_type( maybeMutate( objectDecl->get_type(), *this ) );
30    objectDecl->set_init( maybeMutate( objectDecl->get_init(), *this ) );
31    objectDecl->set_bitfieldWidth( maybeMutate( objectDecl->get_bitfieldWidth(), *this ) );
32    return objectDecl;
33}
34
35DeclarationWithType*
36Mutator::mutate(FunctionDecl *functionDecl)
37{
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*
45Mutator::handleAggregateDecl(AggregateDecl *aggregateDecl)
46{
47    mutateAll( aggregateDecl->get_parameters(), *this );
48    mutateAll( aggregateDecl->get_members(), *this );
49    return aggregateDecl;
50}
51
52Declaration* 
53Mutator::mutate(StructDecl *aggregateDecl)
54{
55    handleAggregateDecl( aggregateDecl );
56    return aggregateDecl;
57}
58
59Declaration* 
60Mutator::mutate(UnionDecl *aggregateDecl)
61{
62    handleAggregateDecl( aggregateDecl );
63    return aggregateDecl;
64}
65
66Declaration* 
67Mutator::mutate(EnumDecl *aggregateDecl)
68{
69    handleAggregateDecl( aggregateDecl );
70    return aggregateDecl;
71}
72
73Declaration* 
74Mutator::mutate(ContextDecl *aggregateDecl)
75{
76    handleAggregateDecl( aggregateDecl );
77    return aggregateDecl;
78}
79
80Declaration*
81Mutator::handleNamedTypeDecl(NamedTypeDecl *typeDecl)
82{
83    mutateAll( typeDecl->get_parameters(), *this );
84    mutateAll( typeDecl->get_assertions(), *this );
85    typeDecl->set_base( maybeMutate( typeDecl->get_base(), *this ) );
86    return typeDecl;
87}
88
89TypeDecl* 
90Mutator::mutate(TypeDecl *typeDecl)
91{
92    handleNamedTypeDecl( typeDecl );
93    return typeDecl;
94}
95
96Declaration* 
97Mutator::mutate(TypedefDecl *typeDecl)
98{
99    handleNamedTypeDecl( typeDecl );
100    return typeDecl;
101}
102
103CompoundStmt*
104Mutator::mutate(CompoundStmt *compoundStmt)
105{
106    mutateAll( compoundStmt->get_kids(), *this );
107    return compoundStmt;
108}
109
110Statement*
111Mutator::mutate(ExprStmt *exprStmt)
112{
113    exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) );
114    return exprStmt;
115}
116
117Statement*
118Mutator::mutate(IfStmt *ifStmt)
119{
120    ifStmt->set_condition(  maybeMutate( ifStmt->get_condition(), *this ) );
121    ifStmt->set_thenPart(  maybeMutate( ifStmt->get_thenPart(), *this ) );
122    ifStmt->set_elsePart(  maybeMutate( ifStmt->get_elsePart(), *this ) );
123    return ifStmt;
124}
125
126Statement*
127Mutator::mutate(WhileStmt *whileStmt)
128{
129    whileStmt->set_condition(  maybeMutate( whileStmt->get_condition(), *this ) );
130    whileStmt->set_body(    maybeMutate( whileStmt->get_body(), *this ) );
131    return whileStmt;
132}
133
134Statement*
135Mutator::mutate(ForStmt *forStmt)
136{
137    forStmt->set_initialization(    maybeMutate( forStmt->get_initialization(), *this ) );
138    forStmt->set_condition(  maybeMutate( forStmt->get_condition(), *this ) );
139    forStmt->set_increment(  maybeMutate( forStmt->get_increment(), *this ) );
140    forStmt->set_body(  maybeMutate( forStmt->get_body(), *this ) );
141    return forStmt;
142}
143
144Statement*
145Mutator::mutate(SwitchStmt *switchStmt)
146{
147    switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
148    mutateAll( switchStmt->get_branches(), *this );
149    return switchStmt;
150}
151
152Statement*
153Mutator::mutate(ChooseStmt *switchStmt)
154{
155    switchStmt->set_condition(  maybeMutate( switchStmt->get_condition(), *this ) );
156    mutateAll( switchStmt->get_branches(), *this );
157    return switchStmt;
158}
159
160Statement*
161Mutator::mutate(FallthruStmt *fallthruStmt)
162{
163    return fallthruStmt;
164}
165
166Statement*
167Mutator::mutate(CaseStmt *caseStmt)
168{
169    caseStmt->set_condition(    maybeMutate( caseStmt->get_condition(), *this ) );
170    mutateAll (caseStmt->get_statements(), *this );
171
172    return caseStmt;
173}
174
175Statement*
176Mutator::mutate(BranchStmt *branchStmt)
177{
178    return branchStmt;
179}
180
181Statement*
182Mutator::mutate(ReturnStmt *returnStmt)
183{
184    returnStmt->set_expr(  maybeMutate( returnStmt->get_expr(), *this ) );
185    return returnStmt;
186}
187
188Statement*
189Mutator::mutate(TryStmt *tryStmt)
190{
191    tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );
192    mutateAll( tryStmt->get_catchers(), *this );
193    return tryStmt;
194}
195
196Statement*
197Mutator::mutate(CatchStmt *catchStmt)
198{
199    catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) );
200    catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) );
201    return catchStmt;
202}
203
204Statement*
205Mutator::mutate(FinallyStmt *finalStmt)
206{
207    finalStmt->set_block( maybeMutate( finalStmt->get_block(), *this ) );
208    return finalStmt;
209}
210
211NullStmt*
212Mutator::mutate(NullStmt *nullStmt)
213{
214    return nullStmt;
215}
216
217Statement*
218Mutator::mutate(DeclStmt *declStmt)
219{
220    declStmt->set_decl( maybeMutate( declStmt->get_decl(), *this ) );
221    return declStmt;
222}
223
224Expression*
225Mutator::mutate(ApplicationExpr *applicationExpr)
226{
227    mutateAll( applicationExpr->get_results(), *this );
228    applicationExpr->set_function(  maybeMutate( applicationExpr->get_function(), *this ) );
229    mutateAll( applicationExpr->get_args(), *this );
230    return applicationExpr;
231}
232
233Expression*
234Mutator::mutate(UntypedExpr *untypedExpr)
235{
236    mutateAll( untypedExpr->get_results(), *this );
237    mutateAll( untypedExpr->get_args(), *this );
238    return untypedExpr;
239}
240
241Expression*
242Mutator::mutate(NameExpr *nameExpr)
243{
244    mutateAll( nameExpr->get_results(), *this );
245    return nameExpr;
246}
247
248Expression*
249Mutator::mutate(AddressExpr *addressExpr)
250{
251    mutateAll( addressExpr->get_results(), *this );
252    addressExpr->set_arg(  maybeMutate( addressExpr->get_arg(), *this ) );
253    return addressExpr;
254}
255
256Expression*
257Mutator::mutate(LabelAddressExpr *labelAddressExpr)
258{
259    mutateAll( labelAddressExpr->get_results(), *this );
260    labelAddressExpr->set_arg(  maybeMutate( labelAddressExpr->get_arg(), *this ) );
261    return labelAddressExpr;
262}
263
264Expression*
265Mutator::mutate(CastExpr *castExpr)
266{
267    mutateAll( castExpr->get_results(), *this );
268    castExpr->set_arg(  maybeMutate( castExpr->get_arg(), *this ) );
269    return castExpr;
270}
271
272Expression*
273Mutator::mutate(UntypedMemberExpr *memberExpr)
274{
275    mutateAll( memberExpr->get_results(), *this );
276    memberExpr->set_aggregate(  maybeMutate( memberExpr->get_aggregate(), *this ) );
277    return memberExpr;
278}
279
280Expression*
281Mutator::mutate(MemberExpr *memberExpr)
282{
283    mutateAll( memberExpr->get_results(), *this );
284    memberExpr->set_aggregate(  maybeMutate( memberExpr->get_aggregate(), *this ) );
285    return memberExpr;
286}
287
288Expression*
289Mutator::mutate(VariableExpr *variableExpr)
290{
291    mutateAll( variableExpr->get_results(), *this );
292    return variableExpr;
293}
294
295Expression*
296Mutator::mutate(ConstantExpr *constantExpr)
297{
298    mutateAll( constantExpr->get_results(), *this );
299//  maybeMutate( constantExpr->get_constant(), *this )
300    return constantExpr;
301}
302
303Expression*
304Mutator::mutate(SizeofExpr *sizeofExpr)
305{
306    mutateAll( sizeofExpr->get_results(), *this );
307    if( sizeofExpr->get_isType() ) {
308        sizeofExpr->set_type(    maybeMutate( sizeofExpr->get_type(), *this ) );
309    } else {
310        sizeofExpr->set_expr(    maybeMutate( sizeofExpr->get_expr(), *this ) );
311    }
312    return sizeofExpr;
313}
314
315Expression*
316Mutator::mutate(AttrExpr *attrExpr)
317{
318    mutateAll( attrExpr->get_results(), *this );
319    if( attrExpr->get_isType() ) {
320        attrExpr->set_type(      maybeMutate( attrExpr->get_type(), *this ) );
321    } else {
322        attrExpr->set_expr(      maybeMutate( attrExpr->get_expr(), *this ) );
323    }
324    return attrExpr;
325}
326
327Expression*
328Mutator::mutate(LogicalExpr *logicalExpr)
329{
330    mutateAll( logicalExpr->get_results(), *this );
331    logicalExpr->set_arg1(  maybeMutate( logicalExpr->get_arg1(), *this ) );
332    logicalExpr->set_arg2(  maybeMutate( logicalExpr->get_arg2(), *this ) );
333    return logicalExpr;
334}
335
336Expression*
337Mutator::mutate(ConditionalExpr *conditionalExpr)
338{
339    mutateAll( conditionalExpr->get_results(), *this );
340    conditionalExpr->set_arg1(  maybeMutate( conditionalExpr->get_arg1(), *this ) );
341    conditionalExpr->set_arg2(  maybeMutate( conditionalExpr->get_arg2(), *this ) );
342    conditionalExpr->set_arg3(  maybeMutate( conditionalExpr->get_arg3(), *this ) );
343    return conditionalExpr;
344}
345
346Expression*
347Mutator::mutate(CommaExpr *commaExpr)
348{
349    mutateAll( commaExpr->get_results(), *this );
350    commaExpr->set_arg1(    maybeMutate( commaExpr->get_arg1(), *this ) );
351    commaExpr->set_arg2(    maybeMutate( commaExpr->get_arg2(), *this ) );
352    return commaExpr;
353}
354
355Expression*
356Mutator::mutate(TupleExpr *tupleExpr)
357{
358    mutateAll( tupleExpr->get_results(), *this );
359    mutateAll( tupleExpr->get_exprs(), *this );
360    return tupleExpr;
361}
362
363Expression*
364Mutator::mutate(SolvedTupleExpr *tupleExpr)
365{
366    mutateAll( tupleExpr->get_results(), *this );
367    mutateAll( tupleExpr->get_exprs(), *this );
368    return tupleExpr;
369}
370
371Expression*
372Mutator::mutate(TypeExpr *typeExpr)
373{
374    mutateAll( typeExpr->get_results(), *this );
375    typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) );
376    return typeExpr;
377}
378
379Expression*
380Mutator::mutate(UntypedValofExpr *valofExpr)
381{
382    mutateAll( valofExpr->get_results(), *this );
383    return valofExpr;
384}
385
386Type*
387Mutator::mutate(VoidType *voidType)
388{
389    mutateAll( voidType->get_forall(), *this );
390    return voidType;
391}
392
393Type*
394Mutator::mutate(BasicType *basicType)
395{
396    mutateAll( basicType->get_forall(), *this );
397    return basicType;
398}
399
400Type*
401Mutator::mutate(PointerType *pointerType)
402{
403    mutateAll( pointerType->get_forall(), *this );
404    pointerType->set_base( maybeMutate( pointerType->get_base(), *this ) );
405    return pointerType;
406}
407
408Type*
409Mutator::mutate(ArrayType *arrayType)
410{
411    mutateAll( arrayType->get_forall(), *this );
412    arrayType->set_dimension( maybeMutate( arrayType->get_dimension(), *this ) );
413    arrayType->set_base( maybeMutate( arrayType->get_base(), *this ) );
414    return arrayType;
415}
416
417Type*
418Mutator::mutate(FunctionType *functionType)
419{
420    mutateAll( functionType->get_forall(), *this );
421    mutateAll( functionType->get_returnVals(), *this );
422    mutateAll( functionType->get_parameters(), *this );
423    return functionType;
424}
425
426Type*
427Mutator::handleReferenceToType(ReferenceToType *aggregateUseType)
428{
429    mutateAll( aggregateUseType->get_forall(), *this );
430    mutateAll( aggregateUseType->get_parameters(), *this );
431    return aggregateUseType;
432}
433
434Type* 
435Mutator::mutate(StructInstType *aggregateUseType)
436{
437    handleReferenceToType( aggregateUseType );
438    return aggregateUseType;
439}
440
441Type* 
442Mutator::mutate(UnionInstType *aggregateUseType)
443{
444    handleReferenceToType( aggregateUseType );
445    return aggregateUseType;
446}
447
448Type* 
449Mutator::mutate(EnumInstType *aggregateUseType)
450{
451    handleReferenceToType( aggregateUseType );
452    return aggregateUseType;
453}
454
455Type* 
456Mutator::mutate(ContextInstType *aggregateUseType)
457{
458    handleReferenceToType( aggregateUseType );
459    mutateAll( aggregateUseType->get_members(), *this );
460    return aggregateUseType;
461}
462
463Type* 
464Mutator::mutate(TypeInstType *aggregateUseType)
465{
466    handleReferenceToType( aggregateUseType );
467    return aggregateUseType;
468}
469
470Type*
471Mutator::mutate(TupleType *tupleType)
472{
473    mutateAll( tupleType->get_forall(), *this );
474    mutateAll( tupleType->get_types(), *this );
475    return tupleType;
476}
477
478Type*
479Mutator::mutate(TypeofType *typeofType)
480{
481    assert( typeofType->get_expr() );
482    typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) );
483    return typeofType;
484}
485
486Type*
487Mutator::mutate(AttrType *attrType)
488{
489    if( attrType->get_isType() ) {
490        assert( attrType->get_type() );
491        attrType->set_type( attrType->get_type()->acceptMutator( *this ) );
492    } else {
493        assert( attrType->get_expr() );
494        attrType->set_expr( attrType->get_expr()->acceptMutator( *this ) );
495    }
496    return attrType;
497}
498
499Initializer*
500Mutator::mutate(MemberInit *memberInit)
501{
502    memberInit->set_value( memberInit->get_value()->acceptMutator( *this ) );
503    return memberInit;
504}
505
506Initializer*
507Mutator::mutate(ElementInit *elementInit)
508{
509    elementInit->set_value( elementInit->get_value()->acceptMutator( *this ) );
510    return elementInit;
511}
512
513Initializer*
514Mutator::mutate(SingleInit *singleInit)
515{
516    singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) );
517    return singleInit;
518}
519
520Initializer*
521Mutator::mutate(ListInit *listInit)
522{
523    mutateAll( listInit->get_designators(), *this );
524    mutateAll( listInit->get_initializers(), *this );
525    return listInit;
526}
527
528Subrange *
529Mutator::mutate(Subrange *subrange)
530{
531    return subrange;
532}
533
534Constant *
535Mutator::mutate(Constant *constant)
536{
537    return constant;
538}
539
Note: See TracBrowser for help on using the repository browser.