[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 | // |
---|
| 7 | // AdjustExprType.cc -- |
---|
| 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 |
---|
[a32b204] | 14 | // |
---|
| 15 | |
---|
[51b7345] | 16 | #include "typeops.h" |
---|
| 17 | #include "SynTree/Type.h" |
---|
| 18 | #include "TypeEnvironment.h" |
---|
| 19 | #include "SymTab/Indexer.h" |
---|
| 20 | |
---|
| 21 | namespace ResolvExpr { |
---|
[a32b204] | 22 | class AdjustExprType : public Mutator { |
---|
| 23 | typedef Mutator Parent; |
---|
| 24 | public: |
---|
| 25 | AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer ); |
---|
| 26 | private: |
---|
| 27 | virtual Type* mutate( VoidType *voidType ); |
---|
| 28 | virtual Type* mutate( BasicType *basicType ); |
---|
| 29 | virtual Type* mutate( PointerType *pointerType ); |
---|
| 30 | virtual Type* mutate( ArrayType *arrayType ); |
---|
| 31 | virtual Type* mutate( FunctionType *functionType ); |
---|
| 32 | virtual Type* mutate( StructInstType *aggregateUseType ); |
---|
| 33 | virtual Type* mutate( UnionInstType *aggregateUseType ); |
---|
| 34 | virtual Type* mutate( EnumInstType *aggregateUseType ); |
---|
[4040425] | 35 | virtual Type* mutate( TraitInstType *aggregateUseType ); |
---|
[a32b204] | 36 | virtual Type* mutate( TypeInstType *aggregateUseType ); |
---|
| 37 | virtual Type* mutate( TupleType *tupleType ); |
---|
[44b7088] | 38 | virtual Type* mutate( VarArgsType *varArgsType ); |
---|
[a32b204] | 39 | |
---|
| 40 | const TypeEnvironment &env; |
---|
| 41 | const SymTab::Indexer &indexer; |
---|
| 42 | }; |
---|
| 43 | |
---|
| 44 | void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { |
---|
| 45 | AdjustExprType adjuster( env, indexer ); |
---|
| 46 | Type *newType = type->acceptMutator( adjuster ); |
---|
| 47 | type = newType; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | AdjustExprType::AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer ) |
---|
| 51 | : env( env ), indexer( indexer ) { |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | Type *AdjustExprType::mutate( VoidType *voidType ) { |
---|
| 55 | return voidType; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | Type *AdjustExprType::mutate( BasicType *basicType ) { |
---|
| 59 | return basicType; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | Type *AdjustExprType::mutate( PointerType *pointerType ) { |
---|
[d9a0e76] | 63 | return pointerType; |
---|
| 64 | } |
---|
[51b7345] | 65 | |
---|
[a32b204] | 66 | Type *AdjustExprType::mutate( ArrayType *arrayType ) { |
---|
| 67 | PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone() ); |
---|
| 68 | delete arrayType; |
---|
| 69 | return pointerType; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | Type *AdjustExprType::mutate( FunctionType *functionType ) { |
---|
| 73 | PointerType *pointerType = new PointerType( Type::Qualifiers(), functionType ); |
---|
| 74 | return pointerType; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | Type *AdjustExprType::mutate( StructInstType *aggregateUseType ) { |
---|
| 78 | return aggregateUseType; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | Type *AdjustExprType::mutate( UnionInstType *aggregateUseType ) { |
---|
| 82 | return aggregateUseType; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | Type *AdjustExprType::mutate( EnumInstType *aggregateUseType ) { |
---|
| 86 | return aggregateUseType; |
---|
| 87 | } |
---|
| 88 | |
---|
[4040425] | 89 | Type *AdjustExprType::mutate( TraitInstType *aggregateUseType ) { |
---|
[a32b204] | 90 | return aggregateUseType; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | Type *AdjustExprType::mutate( TypeInstType *typeInst ) { |
---|
| 94 | EqvClass eqvClass; |
---|
| 95 | if ( env.lookup( typeInst->get_name(), eqvClass ) ) { |
---|
| 96 | if ( eqvClass.kind == TypeDecl::Ftype ) { |
---|
| 97 | PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst ); |
---|
| 98 | return pointerType; |
---|
| 99 | } |
---|
| 100 | } else if ( NamedTypeDecl *ntDecl = indexer.lookupType( typeInst->get_name() ) ) { |
---|
| 101 | if ( TypeDecl *tyDecl = dynamic_cast< TypeDecl* >( ntDecl ) ) { |
---|
| 102 | if ( tyDecl->get_kind() == TypeDecl::Ftype ) { |
---|
| 103 | PointerType *pointerType = new PointerType( Type::Qualifiers(), typeInst ); |
---|
| 104 | return pointerType; |
---|
| 105 | } // if |
---|
| 106 | } // if |
---|
| 107 | } // if |
---|
| 108 | return typeInst; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | Type *AdjustExprType::mutate( TupleType *tupleType ) { |
---|
| 112 | return tupleType; |
---|
| 113 | } |
---|
[44b7088] | 114 | |
---|
| 115 | Type *AdjustExprType::mutate( VarArgsType *varArgsType ) { |
---|
| 116 | return varArgsType; |
---|
| 117 | } |
---|
[51b7345] | 118 | } // namespace ResolvExpr |
---|
[a32b204] | 119 | |
---|
| 120 | // Local Variables: // |
---|
| 121 | // tab-width: 4 // |
---|
| 122 | // mode: c++ // |
---|
| 123 | // compile-command: "make install" // |
---|
| 124 | // End: // |
---|