source: src/SynTree/Mutator.cc @ b6fe7e6

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since b6fe7e6 was b6fe7e6, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

make constructor expressions work, fix bug with using the wrong TypeEnvironment? on member exprs, remove many unnecessary ctor/dtors from the prelude

  • Property mode set to 100644
File size: 15.0 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 : Thu Aug  4 11:23:21 2016
13// Update Count     : 19
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 "Common/utility.h"
25
26Mutator::Mutator() {}
27
28Mutator::~Mutator() {}
29
30DeclarationWithType *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( TraitDecl *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( AsmStmt *asmStmt ) {
98        asmStmt->set_instruction( maybeMutate( asmStmt->get_instruction(), *this ) );
99        mutateAll( asmStmt->get_output(), *this );
100        mutateAll( asmStmt->get_input(), *this );
101        mutateAll( asmStmt->get_clobber(), *this );
102        return asmStmt;
103}
104
105Statement *Mutator::mutate( IfStmt *ifStmt ) {
106        ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) );
107        ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) );
108        ifStmt->set_elsePart( maybeMutate( ifStmt->get_elsePart(), *this ) );
109        return ifStmt;
110}
111
112Statement *Mutator::mutate( WhileStmt *whileStmt ) {
113        whileStmt->set_condition( maybeMutate( whileStmt->get_condition(), *this ) );
114        whileStmt->set_body( maybeMutate( whileStmt->get_body(), *this ) );
115        return whileStmt;
116}
117
118Statement *Mutator::mutate( ForStmt *forStmt ) {
119        mutateAll( forStmt->get_initialization(), *this );
120        forStmt->set_condition( maybeMutate( forStmt->get_condition(), *this ) );
121        forStmt->set_increment( maybeMutate( forStmt->get_increment(), *this ) );
122        forStmt->set_body( maybeMutate( forStmt->get_body(), *this ) );
123        return forStmt;
124}
125
126Statement *Mutator::mutate( SwitchStmt *switchStmt ) {
127        switchStmt->set_condition( maybeMutate( switchStmt->get_condition(), *this ) );
128        mutateAll( switchStmt->get_statements(), *this );
129        return switchStmt;
130}
131
132Statement *Mutator::mutate( CaseStmt *caseStmt ) {
133        caseStmt->set_condition( maybeMutate( caseStmt->get_condition(), *this ) );
134        mutateAll (caseStmt->get_statements(), *this );
135
136        return caseStmt;
137}
138
139Statement *Mutator::mutate( BranchStmt *branchStmt ) {
140        return branchStmt;
141}
142
143Statement *Mutator::mutate( ReturnStmt *returnStmt ) {
144        returnStmt->set_expr( maybeMutate( returnStmt->get_expr(), *this ) );
145        return returnStmt;
146}
147
148Statement *Mutator::mutate( TryStmt *tryStmt ) {
149        tryStmt->set_block( maybeMutate( tryStmt->get_block(), *this ) );
150        mutateAll( tryStmt->get_catchers(), *this );
151        return tryStmt;
152}
153
154Statement *Mutator::mutate( CatchStmt *catchStmt ) {
155        catchStmt->set_decl( maybeMutate( catchStmt->get_decl(), *this ) );
156        catchStmt->set_body( maybeMutate( catchStmt->get_body(), *this ) );
157        return catchStmt;
158}
159
160Statement *Mutator::mutate( FinallyStmt *finalStmt ) {
161        finalStmt->set_block( maybeMutate( finalStmt->get_block(), *this ) );
162        return finalStmt;
163}
164
165NullStmt *Mutator::mutate( NullStmt *nullStmt ) {
166        return nullStmt;
167}
168
169Statement *Mutator::mutate( DeclStmt *declStmt ) {
170        declStmt->set_decl( maybeMutate( declStmt->get_decl(), *this ) );
171        return declStmt;
172}
173
174Statement *Mutator::mutate( ImplicitCtorDtorStmt *impCtorDtorStmt ) {
175        impCtorDtorStmt->set_callStmt( maybeMutate( impCtorDtorStmt->get_callStmt(), *this ) );
176        return impCtorDtorStmt;
177}
178
179Expression *Mutator::mutate( ApplicationExpr *applicationExpr ) {
180        mutateAll( applicationExpr->get_results(), *this );
181        applicationExpr->set_function( maybeMutate( applicationExpr->get_function(), *this ) );
182        mutateAll( applicationExpr->get_args(), *this );
183        return applicationExpr;
184}
185
186Expression *Mutator::mutate( UntypedExpr *untypedExpr ) {
187        mutateAll( untypedExpr->get_results(), *this );
188        mutateAll( untypedExpr->get_args(), *this );
189        return untypedExpr;
190}
191
192Expression *Mutator::mutate( NameExpr *nameExpr ) {
193        mutateAll( nameExpr->get_results(), *this );
194        return nameExpr;
195}
196
197Expression *Mutator::mutate( AddressExpr *addressExpr ) {
198        mutateAll( addressExpr->get_results(), *this );
199        addressExpr->set_arg( maybeMutate( addressExpr->get_arg(), *this ) );
200        return addressExpr;
201}
202
203Expression *Mutator::mutate( LabelAddressExpr *labelAddressExpr ) {
204        mutateAll( labelAddressExpr->get_results(), *this );
205        labelAddressExpr->set_arg( maybeMutate( labelAddressExpr->get_arg(), *this ) );
206        return labelAddressExpr;
207}
208
209Expression *Mutator::mutate( CastExpr *castExpr ) {
210        mutateAll( castExpr->get_results(), *this );
211        castExpr->set_arg( maybeMutate( castExpr->get_arg(), *this ) );
212        return castExpr;
213}
214
215Expression *Mutator::mutate( UntypedMemberExpr *memberExpr ) {
216        mutateAll( memberExpr->get_results(), *this );
217        memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
218        return memberExpr;
219}
220
221Expression *Mutator::mutate( MemberExpr *memberExpr ) {
222        mutateAll( memberExpr->get_results(), *this );
223        memberExpr->set_aggregate( maybeMutate( memberExpr->get_aggregate(), *this ) );
224        return memberExpr;
225}
226
227Expression *Mutator::mutate( VariableExpr *variableExpr ) {
228        mutateAll( variableExpr->get_results(), *this );
229        return variableExpr;
230}
231
232Expression *Mutator::mutate( ConstantExpr *constantExpr ) {
233        mutateAll( constantExpr->get_results(), *this );
234//  maybeMutate( constantExpr->get_constant(), *this )
235        return constantExpr;
236}
237
238Expression *Mutator::mutate( SizeofExpr *sizeofExpr ) {
239        mutateAll( sizeofExpr->get_results(), *this );
240        if ( sizeofExpr->get_isType() ) {
241                sizeofExpr->set_type( maybeMutate( sizeofExpr->get_type(), *this ) );
242        } else {
243                sizeofExpr->set_expr( maybeMutate( sizeofExpr->get_expr(), *this ) );
244        }
245        return sizeofExpr;
246}
247
248Expression *Mutator::mutate( AlignofExpr *alignofExpr ) {
249        mutateAll( alignofExpr->get_results(), *this );
250        if ( alignofExpr->get_isType() ) {
251                alignofExpr->set_type( maybeMutate( alignofExpr->get_type(), *this ) );
252        } else {
253                alignofExpr->set_expr( maybeMutate( alignofExpr->get_expr(), *this ) );
254        }
255        return alignofExpr;
256}
257
258Expression *Mutator::mutate( UntypedOffsetofExpr *offsetofExpr ) {
259        mutateAll( offsetofExpr->get_results(), *this );
260        offsetofExpr->set_type( maybeMutate( offsetofExpr->get_type(), *this ) );
261        return offsetofExpr;
262}
263
264Expression *Mutator::mutate( OffsetofExpr *offsetofExpr ) {
265        mutateAll( offsetofExpr->get_results(), *this );
266        offsetofExpr->set_type( maybeMutate( offsetofExpr->get_type(), *this ) );
267        offsetofExpr->set_member( maybeMutate( offsetofExpr->get_member(), *this ) );
268        return offsetofExpr;
269}
270
271Expression *Mutator::mutate( OffsetPackExpr *offsetPackExpr ) {
272        mutateAll( offsetPackExpr->get_results(), *this );
273        offsetPackExpr->set_type( maybeMutate( offsetPackExpr->get_type(), *this ) );
274        return offsetPackExpr;
275}
276
277Expression *Mutator::mutate( AttrExpr *attrExpr ) {
278        mutateAll( attrExpr->get_results(), *this );
279        if ( attrExpr->get_isType() ) {
280                attrExpr->set_type( maybeMutate( attrExpr->get_type(), *this ) );
281        } else {
282                attrExpr->set_expr( maybeMutate( attrExpr->get_expr(), *this ) );
283        }
284        return attrExpr;
285}
286
287Expression *Mutator::mutate( LogicalExpr *logicalExpr ) {
288        mutateAll( logicalExpr->get_results(), *this );
289        logicalExpr->set_arg1( maybeMutate( logicalExpr->get_arg1(), *this ) );
290        logicalExpr->set_arg2( maybeMutate( logicalExpr->get_arg2(), *this ) );
291        return logicalExpr;
292}
293
294Expression *Mutator::mutate( ConditionalExpr *conditionalExpr ) {
295        mutateAll( conditionalExpr->get_results(), *this );
296        conditionalExpr->set_arg1( maybeMutate( conditionalExpr->get_arg1(), *this ) );
297        conditionalExpr->set_arg2( maybeMutate( conditionalExpr->get_arg2(), *this ) );
298        conditionalExpr->set_arg3( maybeMutate( conditionalExpr->get_arg3(), *this ) );
299        return conditionalExpr;
300}
301
302Expression *Mutator::mutate( CommaExpr *commaExpr ) {
303        mutateAll( commaExpr->get_results(), *this );
304        commaExpr->set_arg1( maybeMutate( commaExpr->get_arg1(), *this ) );
305        commaExpr->set_arg2( maybeMutate( commaExpr->get_arg2(), *this ) );
306        return commaExpr;
307}
308
309Expression *Mutator::mutate( TupleExpr *tupleExpr ) {
310        mutateAll( tupleExpr->get_results(), *this );
311        mutateAll( tupleExpr->get_exprs(), *this );
312        return tupleExpr;
313}
314
315Expression *Mutator::mutate( SolvedTupleExpr *tupleExpr ) {
316        mutateAll( tupleExpr->get_results(), *this );
317        mutateAll( tupleExpr->get_exprs(), *this );
318        return tupleExpr;
319}
320
321Expression *Mutator::mutate( TypeExpr *typeExpr ) {
322        mutateAll( typeExpr->get_results(), *this );
323        typeExpr->set_type( maybeMutate( typeExpr->get_type(), *this ) );
324        return typeExpr;
325}
326
327Expression *Mutator::mutate( AsmExpr *asmExpr ) {
328        asmExpr->set_inout( maybeMutate( asmExpr->get_inout(), *this ) );
329        asmExpr->set_constraint( maybeMutate( asmExpr->get_constraint(), *this ) );
330        asmExpr->set_operand( maybeMutate( asmExpr->get_operand(), *this ) );
331        return asmExpr;
332}
333
334Expression* Mutator::mutate( ImplicitCopyCtorExpr *impCpCtorExpr ) {
335        impCpCtorExpr->set_callExpr( maybeMutate( impCpCtorExpr->get_callExpr(), *this ) );
336        mutateAll( impCpCtorExpr->get_tempDecls(), *this );
337        mutateAll( impCpCtorExpr->get_returnDecls(), *this );
338        return impCpCtorExpr;
339}
340
341Expression* Mutator::mutate( ConstructorExpr *ctorExpr ) {
342        mutateAll( ctorExpr->get_results(), *this );
343        ctorExpr->set_callExpr( maybeMutate( ctorExpr->get_callExpr(), *this ) );
344        return ctorExpr;
345}
346
347Expression *Mutator::mutate( CompoundLiteralExpr *compLitExpr ) {
348        mutateAll( compLitExpr->get_results(), *this );
349        compLitExpr->set_type( maybeMutate( compLitExpr->get_type(), *this ) );
350        compLitExpr->set_initializer( maybeMutate( compLitExpr->get_initializer(), *this ) );
351        return compLitExpr;
352}
353
354Expression *Mutator::mutate( UntypedValofExpr *valofExpr ) {
355        mutateAll( valofExpr->get_results(), *this );
356        return valofExpr;
357}
358
359Expression *Mutator::mutate( RangeExpr *rangeExpr ) {
360        rangeExpr->set_low( maybeMutate( rangeExpr->get_low(), *this ) );
361        rangeExpr->set_high( maybeMutate( rangeExpr->get_high(), *this ) );
362        return rangeExpr;
363}
364
365Type *Mutator::mutate( VoidType *voidType ) {
366        mutateAll( voidType->get_forall(), *this );
367        return voidType;
368}
369
370Type *Mutator::mutate( BasicType *basicType ) {
371        mutateAll( basicType->get_forall(), *this );
372        return basicType;
373}
374
375Type *Mutator::mutate( PointerType *pointerType ) {
376        mutateAll( pointerType->get_forall(), *this );
377        pointerType->set_base( maybeMutate( pointerType->get_base(), *this ) );
378        return pointerType;
379}
380
381Type *Mutator::mutate( ArrayType *arrayType ) {
382        mutateAll( arrayType->get_forall(), *this );
383        arrayType->set_dimension( maybeMutate( arrayType->get_dimension(), *this ) );
384        arrayType->set_base( maybeMutate( arrayType->get_base(), *this ) );
385        return arrayType;
386}
387
388Type *Mutator::mutate( FunctionType *functionType ) {
389        mutateAll( functionType->get_forall(), *this );
390        mutateAll( functionType->get_returnVals(), *this );
391        mutateAll( functionType->get_parameters(), *this );
392        return functionType;
393}
394
395Type *Mutator::handleReferenceToType( ReferenceToType *aggregateUseType ) {
396        mutateAll( aggregateUseType->get_forall(), *this );
397        mutateAll( aggregateUseType->get_parameters(), *this );
398        return aggregateUseType;
399}
400
401Type *Mutator::mutate( StructInstType *aggregateUseType ) {
402        handleReferenceToType( aggregateUseType );
403        return aggregateUseType;
404}
405
406Type *Mutator::mutate( UnionInstType *aggregateUseType ) {
407        handleReferenceToType( aggregateUseType );
408        return aggregateUseType;
409}
410
411Type *Mutator::mutate( EnumInstType *aggregateUseType ) {
412        handleReferenceToType( aggregateUseType );
413        return aggregateUseType;
414}
415
416Type *Mutator::mutate( TraitInstType *aggregateUseType ) {
417        handleReferenceToType( aggregateUseType );
418        mutateAll( aggregateUseType->get_members(), *this );
419        return aggregateUseType;
420}
421
422Type *Mutator::mutate( TypeInstType *aggregateUseType ) {
423        handleReferenceToType( aggregateUseType );
424        return aggregateUseType;
425}
426
427Type *Mutator::mutate( TupleType *tupleType ) {
428        mutateAll( tupleType->get_forall(), *this );
429        mutateAll( tupleType->get_types(), *this );
430        return tupleType;
431}
432
433Type *Mutator::mutate( TypeofType *typeofType ) {
434        assert( typeofType->get_expr() );
435        typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) );
436        return typeofType;
437}
438
439Type *Mutator::mutate( AttrType *attrType ) {
440        if ( attrType->get_isType() ) {
441                assert( attrType->get_type() );
442                attrType->set_type( attrType->get_type()->acceptMutator( *this ) );
443        } else {
444                assert( attrType->get_expr() );
445                attrType->set_expr( attrType->get_expr()->acceptMutator( *this ) );
446        }
447        return attrType;
448}
449
450Type *Mutator::mutate( VarArgsType *varArgsType ) {
451        mutateAll( varArgsType->get_forall(), *this );
452        return varArgsType;
453}
454
455Initializer *Mutator::mutate( SingleInit *singleInit ) {
456        singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) );
457        return singleInit;
458}
459
460Initializer *Mutator::mutate( ListInit *listInit ) {
461        mutateAll( listInit->get_designators(), *this );
462        mutateAll( listInit->get_initializers(), *this );
463        return listInit;
464}
465
466Initializer *Mutator::mutate( ConstructorInit *ctorInit ) {
467        ctorInit->set_ctor( maybeMutate( ctorInit->get_ctor(), *this ) );
468        ctorInit->set_init( maybeMutate( ctorInit->get_init(), *this ) );
469        return ctorInit;
470}
471
472Subrange *Mutator::mutate( Subrange *subrange ) {
473        return subrange;
474}
475
476Constant *Mutator::mutate( Constant *constant ) {
477        return constant;
478}
479
480// Local Variables: //
481// tab-width: 4 //
482// mode: c++ //
483// compile-command: "make install" //
484// End: //
Note: See TracBrowser for help on using the repository browser.