[a32b204] | 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 | // |
---|
[834d4fc] | 7 | // AdjustExprType.cc -- |
---|
[a32b204] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Sat May 16 23:41:42 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[4040425] | 12 | // Last Modified On : Wed Mar 2 17:34:53 2016 |
---|
| 13 | // Update Count : 4 |
---|
[834d4fc] | 14 | // |
---|
[a32b204] | 15 | |
---|
[ea6332d] | 16 | #include "SymTab/Indexer.h" // for Indexer |
---|
| 17 | #include "SynTree/Declaration.h" // for TypeDecl, TypeDecl::Kind::Ftype |
---|
| 18 | #include "SynTree/Mutator.h" // for Mutator |
---|
| 19 | #include "SynTree/Type.h" // for PointerType, TypeInstType, Type |
---|
| 20 | #include "TypeEnvironment.h" // for EqvClass, TypeEnvironment |
---|
[51b7345] | 21 | |
---|
| 22 | namespace ResolvExpr { |
---|
[a32b204] | 23 | class AdjustExprType : public Mutator { |
---|
| 24 | typedef Mutator Parent; |
---|
[6c3a988f] | 25 | using Parent::mutate; |
---|
[a32b204] | 26 | public: |
---|
| 27 | AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer ); |
---|
| 28 | private: |
---|
| 29 | virtual Type* mutate( VoidType *voidType ); |
---|
| 30 | virtual Type* mutate( BasicType *basicType ); |
---|
| 31 | virtual Type* mutate( PointerType *pointerType ); |
---|
| 32 | virtual Type* mutate( ArrayType *arrayType ); |
---|
| 33 | virtual Type* mutate( FunctionType *functionType ); |
---|
| 34 | virtual Type* mutate( StructInstType *aggregateUseType ); |
---|
| 35 | virtual Type* mutate( UnionInstType *aggregateUseType ); |
---|
| 36 | virtual Type* mutate( EnumInstType *aggregateUseType ); |
---|
[4040425] | 37 | virtual Type* mutate( TraitInstType *aggregateUseType ); |
---|
[a32b204] | 38 | virtual Type* mutate( TypeInstType *aggregateUseType ); |
---|
| 39 | virtual Type* mutate( TupleType *tupleType ); |
---|
[44b7088] | 40 | virtual Type* mutate( VarArgsType *varArgsType ); |
---|
[89e6ffc] | 41 | virtual Type* mutate( ZeroType *zeroType ); |
---|
| 42 | virtual Type* mutate( OneType *oneType ); |
---|
[a32b204] | 43 | |
---|
| 44 | const TypeEnvironment &env; |
---|
| 45 | const SymTab::Indexer &indexer; |
---|
| 46 | }; |
---|
| 47 | |
---|
| 48 | void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { |
---|
| 49 | AdjustExprType adjuster( env, indexer ); |
---|
| 50 | Type *newType = type->acceptMutator( adjuster ); |
---|
| 51 | type = newType; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | AdjustExprType::AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer ) |
---|
| 55 | : env( env ), indexer( indexer ) { |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | Type *AdjustExprType::mutate( VoidType *voidType ) { |
---|
| 59 | return voidType; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | Type *AdjustExprType::mutate( BasicType *basicType ) { |
---|
| 63 | return basicType; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | Type *AdjustExprType::mutate( PointerType *pointerType ) { |
---|
[d9a0e76] | 67 | return pointerType; |
---|
| 68 | } |
---|
[51b7345] | 69 | |
---|
[a32b204] | 70 | Type *AdjustExprType::mutate( ArrayType *arrayType ) { |
---|
[834d4fc] | 71 | // need to recursively mutate the base type in order for multi-dimensional arrays to work. |
---|
| 72 | PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone()->acceptMutator( *this ) ); |
---|
[a32b204] | 73 | delete arrayType; |
---|
| 74 | return pointerType; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | Type *AdjustExprType::mutate( FunctionType *functionType ) { |
---|
| 78 | PointerType *pointerType = new PointerType( Type::Qualifiers(), functionType ); |
---|
| 79 | return pointerType; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | Type *AdjustExprType::mutate( StructInstType *aggregateUseType ) { |
---|
| 83 | return aggregateUseType; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | Type *AdjustExprType::mutate( UnionInstType *aggregateUseType ) { |
---|
| 87 | return aggregateUseType; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | Type *AdjustExprType::mutate( EnumInstType *aggregateUseType ) { |
---|
| 91 | return aggregateUseType; |
---|
| 92 | } |
---|
| 93 | |
---|
[4040425] | 94 | Type *AdjustExprType::mutate( TraitInstType *aggregateUseType ) { |
---|
[a32b204] | 95 | return aggregateUseType; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | Type *AdjustExprType::mutate( TypeInstType *typeInst ) { |
---|
| 99 | EqvClass eqvClass; |
---|
| 100 | if ( env.lookup( typeInst->get_name(), eqvClass ) ) { |
---|
[2c57025] | 101 | if ( eqvClass.data.kind == TypeDecl::Ftype ) { |
---|
[a32b204] | 102 | PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst ); |
---|
| 103 | return pointerType; |
---|
| 104 | } |
---|
| 105 | } else if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) { |
---|
| 106 | if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) { |
---|
| 107 | if ( tyDecl->get_kind() == TypeDecl::Ftype ) { |
---|
| 108 | PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst ); |
---|
| 109 | return pointerType; |
---|
| 110 | } // if |
---|
| 111 | } // if |
---|
| 112 | } // if |
---|
| 113 | return typeInst; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | Type *AdjustExprType::mutate( TupleType *tupleType ) { |
---|
| 117 | return tupleType; |
---|
| 118 | } |
---|
[44b7088] | 119 | |
---|
| 120 | Type *AdjustExprType::mutate( VarArgsType *varArgsType ) { |
---|
| 121 | return varArgsType; |
---|
| 122 | } |
---|
[89e6ffc] | 123 | |
---|
| 124 | Type *AdjustExprType::mutate( ZeroType *zeroType ) { |
---|
| 125 | return zeroType; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | Type *AdjustExprType::mutate( OneType *oneType ) { |
---|
| 129 | return oneType; |
---|
| 130 | } |
---|
[51b7345] | 131 | } // namespace ResolvExpr |
---|
[a32b204] | 132 | |
---|
| 133 | // Local Variables: // |
---|
| 134 | // tab-width: 4 // |
---|
| 135 | // mode: c++ // |
---|
| 136 | // compile-command: "make install" // |
---|
| 137 | // End: // |
---|