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 17 15:39:37 2017 |
---|
13 | // Update Count : 27 |
---|
14 | // |
---|
15 | |
---|
16 | #include <cassert> // for assert |
---|
17 | #include <list> // for list |
---|
18 | |
---|
19 | #include "Attribute.h" // for Attribute |
---|
20 | #include "Declaration.h" // for ObjectDecl, Declaration, DeclarationWi... |
---|
21 | #include "Expression.h" // for Expression, ConstantExpr, ConditionalExpr |
---|
22 | #include "Initializer.h" // for ConstructorInit, Initializer, Designation |
---|
23 | #include "Mutator.h" |
---|
24 | #include "Statement.h" // for Statement, CatchStmt, AsmStmt, ForStmt |
---|
25 | #include "Type.h" // for Type, Type::ForallList, AttrType, Arra... |
---|
26 | #include "TypeSubstitution.h" // for TypeSubstitution |
---|
27 | |
---|
28 | class Constant; |
---|
29 | class Subrange; |
---|
30 | |
---|
31 | Mutator::Mutator() {} |
---|
32 | |
---|
33 | Mutator::~Mutator() {} |
---|
34 | |
---|
35 | Type * Mutator::mutate( TupleType *tupleType ) { |
---|
36 | mutateAll( tupleType->get_forall(), *this ); |
---|
37 | mutateAll( tupleType->get_types(), *this ); |
---|
38 | mutateAll( tupleType->get_members(), *this ); |
---|
39 | return tupleType; |
---|
40 | } |
---|
41 | |
---|
42 | Type * Mutator::mutate( TypeofType *typeofType ) { |
---|
43 | assert( typeofType->get_expr() ); |
---|
44 | typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) ); |
---|
45 | return typeofType; |
---|
46 | } |
---|
47 | |
---|
48 | Type * Mutator::mutate( AttrType *attrType ) { |
---|
49 | if ( attrType->get_isType() ) { |
---|
50 | assert( attrType->get_type() ); |
---|
51 | attrType->set_type( attrType->get_type()->acceptMutator( *this ) ); |
---|
52 | } else { |
---|
53 | assert( attrType->get_expr() ); |
---|
54 | attrType->set_expr( attrType->get_expr()->acceptMutator( *this ) ); |
---|
55 | } |
---|
56 | return attrType; |
---|
57 | } |
---|
58 | |
---|
59 | Type * Mutator::mutate( VarArgsType *varArgsType ) { |
---|
60 | mutateAll( varArgsType->get_forall(), *this ); |
---|
61 | return varArgsType; |
---|
62 | } |
---|
63 | |
---|
64 | Type * Mutator::mutate( ZeroType *zeroType ) { |
---|
65 | mutateAll( zeroType->get_forall(), *this ); |
---|
66 | return zeroType; |
---|
67 | } |
---|
68 | |
---|
69 | Type * Mutator::mutate( OneType *oneType ) { |
---|
70 | mutateAll( oneType->get_forall(), *this ); |
---|
71 | return oneType; |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | Designation * Mutator::mutate( Designation * designation ) { |
---|
76 | mutateAll( designation->get_designators(), *this ); |
---|
77 | return designation; |
---|
78 | } |
---|
79 | |
---|
80 | Initializer * Mutator::mutate( SingleInit *singleInit ) { |
---|
81 | singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) ); |
---|
82 | return singleInit; |
---|
83 | } |
---|
84 | |
---|
85 | Initializer * Mutator::mutate( ListInit *listInit ) { |
---|
86 | mutateAll( listInit->get_designations(), *this ); |
---|
87 | mutateAll( listInit->get_initializers(), *this ); |
---|
88 | return listInit; |
---|
89 | } |
---|
90 | |
---|
91 | Initializer * Mutator::mutate( ConstructorInit *ctorInit ) { |
---|
92 | ctorInit->set_ctor( maybeMutate( ctorInit->get_ctor(), *this ) ); |
---|
93 | ctorInit->set_dtor( maybeMutate( ctorInit->get_dtor(), *this ) ); |
---|
94 | ctorInit->set_init( maybeMutate( ctorInit->get_init(), *this ) ); |
---|
95 | return ctorInit; |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | Subrange * Mutator::mutate( Subrange *subrange ) { |
---|
100 | return subrange; |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | Constant * Mutator::mutate( Constant *constant ) { |
---|
105 | return constant; |
---|
106 | } |
---|
107 | |
---|
108 | Attribute * Mutator::mutate( Attribute * attribute ) { |
---|
109 | mutateAll( attribute->parameters, *this ); |
---|
110 | return attribute; |
---|
111 | } |
---|
112 | |
---|
113 | TypeSubstitution * Mutator::mutate( TypeSubstitution * sub ) { |
---|
114 | for ( auto & p : sub->typeEnv ) { |
---|
115 | p.second = maybeMutate( p.second, *this ); |
---|
116 | } |
---|
117 | for ( auto & p : sub->varEnv ) { |
---|
118 | p.second = maybeMutate( p.second, *this ); |
---|
119 | } |
---|
120 | return sub; |
---|
121 | } |
---|
122 | |
---|
123 | // Local Variables: // |
---|
124 | // tab-width: 4 // |
---|
125 | // mode: c++ // |
---|
126 | // compile-command: "make install" // |
---|
127 | // End: // |
---|