[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 | //
|
---|
[71f4e4f] | 7 | // Mutator.cc --
|
---|
[0dd3a2f] | 8 | //
|
---|
| 9 | // Author : Richard C. Bilson
|
---|
| 10 | // Created On : Mon May 18 07:44:20 2015
|
---|
[6d49ea3] | 11 | // Last Modified By : Peter A. Buhr
|
---|
| 12 | // Last Modified On : Thu Aug 17 15:39:37 2017
|
---|
| 13 | // Update Count : 27
|
---|
[0dd3a2f] | 14 | //
|
---|
| 15 |
|
---|
[ea6332d] | 16 | #include <cassert> // for assert
|
---|
| 17 | #include <list> // for list
|
---|
| 18 |
|
---|
[5ea7a22] | 19 | #include "Attribute.h" // for Attribute
|
---|
[ea6332d] | 20 | #include "Declaration.h" // for ObjectDecl, Declaration, DeclarationWi...
|
---|
| 21 | #include "Expression.h" // for Expression, ConstantExpr, ConditionalExpr
|
---|
| 22 | #include "Initializer.h" // for ConstructorInit, Initializer, Designation
|
---|
[51b73452] | 23 | #include "Mutator.h"
|
---|
[ea6332d] | 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;
|
---|
[51b73452] | 30 |
|
---|
[d9a0e76] | 31 | Mutator::Mutator() {}
|
---|
[51b73452] | 32 |
|
---|
[d9a0e76] | 33 | Mutator::~Mutator() {}
|
---|
[51b73452] | 34 |
|
---|
[135b431] | 35 | Type * Mutator::mutate( TupleType *tupleType ) {
|
---|
[0dd3a2f] | 36 | mutateAll( tupleType->get_forall(), *this );
|
---|
| 37 | mutateAll( tupleType->get_types(), *this );
|
---|
[62423350] | 38 | mutateAll( tupleType->get_members(), *this );
|
---|
[0dd3a2f] | 39 | return tupleType;
|
---|
[51b73452] | 40 | }
|
---|
| 41 |
|
---|
[135b431] | 42 | Type * Mutator::mutate( TypeofType *typeofType ) {
|
---|
[0dd3a2f] | 43 | assert( typeofType->get_expr() );
|
---|
| 44 | typeofType->set_expr( typeofType->get_expr()->acceptMutator( *this ) );
|
---|
| 45 | return typeofType;
|
---|
[51b73452] | 46 | }
|
---|
| 47 |
|
---|
[135b431] | 48 | Type * Mutator::mutate( AttrType *attrType ) {
|
---|
[0dd3a2f] | 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;
|
---|
[51b73452] | 57 | }
|
---|
| 58 |
|
---|
[135b431] | 59 | Type * Mutator::mutate( VarArgsType *varArgsType ) {
|
---|
[44b7088] | 60 | mutateAll( varArgsType->get_forall(), *this );
|
---|
| 61 | return varArgsType;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[135b431] | 64 | Type * Mutator::mutate( ZeroType *zeroType ) {
|
---|
[89e6ffc] | 65 | mutateAll( zeroType->get_forall(), *this );
|
---|
| 66 | return zeroType;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[135b431] | 69 | Type * Mutator::mutate( OneType *oneType ) {
|
---|
[89e6ffc] | 70 | mutateAll( oneType->get_forall(), *this );
|
---|
| 71 | return oneType;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[e994912] | 74 |
|
---|
[135b431] | 75 | Designation * Mutator::mutate( Designation * designation ) {
|
---|
[e4d829b] | 76 | mutateAll( designation->get_designators(), *this );
|
---|
| 77 | return designation;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[135b431] | 80 | Initializer * Mutator::mutate( SingleInit *singleInit ) {
|
---|
[0dd3a2f] | 81 | singleInit->set_value( singleInit->get_value()->acceptMutator( *this ) );
|
---|
| 82 | return singleInit;
|
---|
[51b73452] | 83 | }
|
---|
| 84 |
|
---|
[135b431] | 85 | Initializer * Mutator::mutate( ListInit *listInit ) {
|
---|
[e4d829b] | 86 | mutateAll( listInit->get_designations(), *this );
|
---|
[0dd3a2f] | 87 | mutateAll( listInit->get_initializers(), *this );
|
---|
| 88 | return listInit;
|
---|
[51b73452] | 89 | }
|
---|
| 90 |
|
---|
[135b431] | 91 | Initializer * Mutator::mutate( ConstructorInit *ctorInit ) {
|
---|
[71f4e4f] | 92 | ctorInit->set_ctor( maybeMutate( ctorInit->get_ctor(), *this ) );
|
---|
[d5556a3] | 93 | ctorInit->set_dtor( maybeMutate( ctorInit->get_dtor(), *this ) );
|
---|
[71f4e4f] | 94 | ctorInit->set_init( maybeMutate( ctorInit->get_init(), *this ) );
|
---|
| 95 | return ctorInit;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[e994912] | 98 |
|
---|
[135b431] | 99 | Subrange * Mutator::mutate( Subrange *subrange ) {
|
---|
[0dd3a2f] | 100 | return subrange;
|
---|
[51b73452] | 101 | }
|
---|
| 102 |
|
---|
[e994912] | 103 |
|
---|
[135b431] | 104 | Constant * Mutator::mutate( Constant *constant ) {
|
---|
[0dd3a2f] | 105 | return constant;
|
---|
[51b73452] | 106 | }
|
---|
[0dd3a2f] | 107 |
|
---|
[5ea7a22] | 108 | Attribute * Mutator::mutate( Attribute * attribute ) {
|
---|
| 109 | mutateAll( attribute->parameters, *this );
|
---|
| 110 | return attribute;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[447c356] | 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 |
|
---|
[0dd3a2f] | 123 | // Local Variables: //
|
---|
| 124 | // tab-width: 4 //
|
---|
| 125 | // mode: c++ //
|
---|
| 126 | // compile-command: "make install" //
|
---|
| 127 | // End: //
|
---|