[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 | // |
---|
[a436947] | 7 | // CommonType.cc -- |
---|
[a32b204] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Sun May 17 06:59:27 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[4040425] | 12 | // Last Modified On : Wed Mar 2 17:35:34 2016 |
---|
| 13 | // Update Count : 3 |
---|
[a32b204] | 14 | // |
---|
[51b7345] | 15 | |
---|
| 16 | #include "typeops.h" |
---|
| 17 | #include "SynTree/Type.h" |
---|
| 18 | #include "Unify.h" |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | /// #define DEBUG |
---|
| 22 | |
---|
| 23 | namespace ResolvExpr { |
---|
[a32b204] | 24 | class CommonType : public Visitor { |
---|
| 25 | public: |
---|
| 26 | CommonType( Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ); |
---|
| 27 | Type *get_result() const { return result; } |
---|
| 28 | private: |
---|
| 29 | virtual void visit( VoidType *voidType ); |
---|
| 30 | virtual void visit( BasicType *basicType ); |
---|
| 31 | virtual void visit( PointerType *pointerType ); |
---|
| 32 | virtual void visit( ArrayType *arrayType ); |
---|
| 33 | virtual void visit( FunctionType *functionType ); |
---|
| 34 | virtual void visit( StructInstType *aggregateUseType ); |
---|
| 35 | virtual void visit( UnionInstType *aggregateUseType ); |
---|
| 36 | virtual void visit( EnumInstType *aggregateUseType ); |
---|
[4040425] | 37 | virtual void visit( TraitInstType *aggregateUseType ); |
---|
[a32b204] | 38 | virtual void visit( TypeInstType *aggregateUseType ); |
---|
| 39 | virtual void visit( TupleType *tupleType ); |
---|
[44b7088] | 40 | virtual void visit( VarArgsType *varArgsType ); |
---|
[89e6ffc] | 41 | virtual void visit( ZeroType *zeroType ); |
---|
| 42 | virtual void visit( OneType *oneType ); |
---|
[a32b204] | 43 | |
---|
| 44 | template< typename RefType > void handleRefType( RefType *inst, Type *other ); |
---|
| 45 | |
---|
| 46 | Type *result; |
---|
| 47 | Type *type2; // inherited |
---|
| 48 | bool widenFirst, widenSecond; |
---|
| 49 | const SymTab::Indexer &indexer; |
---|
| 50 | TypeEnvironment &env; |
---|
| 51 | const OpenVarSet &openVars; |
---|
| 52 | }; |
---|
| 53 | |
---|
| 54 | Type *commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) { |
---|
| 55 | CommonType visitor( type2, widenFirst, widenSecond, indexer, env, openVars ); |
---|
| 56 | type1->accept( visitor ); |
---|
| 57 | Type *result = visitor.get_result(); |
---|
| 58 | if ( ! result ) { |
---|
| 59 | if ( widenSecond ) { |
---|
| 60 | TypeInstType *inst = dynamic_cast< TypeInstType* >( type2 ); |
---|
| 61 | if ( inst ) { |
---|
| 62 | NamedTypeDecl *nt = indexer.lookupType( inst->get_name() ); |
---|
| 63 | if ( nt ) { |
---|
| 64 | TypeDecl *type = dynamic_cast< TypeDecl* >( nt ); |
---|
| 65 | assert( type ); |
---|
| 66 | if ( type->get_base() ) { |
---|
| 67 | Type::Qualifiers tq1 = type1->get_qualifiers(), tq2 = type2->get_qualifiers(); |
---|
| 68 | AssertionSet have, need; |
---|
| 69 | OpenVarSet newOpen( openVars ); |
---|
| 70 | type1->get_qualifiers() = Type::Qualifiers(); |
---|
| 71 | type->get_base()->get_qualifiers() = tq1; |
---|
| 72 | if ( unifyExact( type1, type->get_base(), env, have, need, newOpen, indexer ) ) { |
---|
| 73 | result = type1->clone(); |
---|
| 74 | result->get_qualifiers() = tq1 + tq2; |
---|
| 75 | } // if |
---|
| 76 | type1->get_qualifiers() = tq1; |
---|
| 77 | type->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
| 78 | } // if |
---|
| 79 | } // if |
---|
| 80 | } // if |
---|
| 81 | } // if |
---|
| 82 | } // if |
---|
[51b7345] | 83 | #ifdef DEBUG |
---|
[a32b204] | 84 | std::cout << "============= commonType" << std::endl << "type1 is "; |
---|
| 85 | type1->print( std::cout ); |
---|
| 86 | std::cout << " type2 is "; |
---|
| 87 | type2->print( std::cout ); |
---|
| 88 | if ( result ) { |
---|
| 89 | std::cout << " common type is "; |
---|
| 90 | result->print( std::cout ); |
---|
| 91 | } else { |
---|
| 92 | std::cout << " no common type"; |
---|
| 93 | } // if |
---|
| 94 | std::cout << std::endl; |
---|
[51b7345] | 95 | #endif |
---|
[a32b204] | 96 | return result; |
---|
| 97 | } |
---|
[51b7345] | 98 | |
---|
[a32b204] | 99 | static const BasicType::Kind combinedType[ BasicType::NUMBER_OF_BASIC_TYPES ][ BasicType::NUMBER_OF_BASIC_TYPES ] = |
---|
| 100 | { |
---|
[51b7345] | 101 | /* Bool Char SignedChar UnsignedChar ShortSignedInt ShortUnsignedInt SignedInt UnsignedInt LongSignedInt LongUnsignedInt LongLongSignedInt LongLongUnsignedInt Float Double LongDouble FloatComplex DoubleComplex LongDoubleComplex FloatImaginary DoubleImaginary LongDoubleImaginary */ |
---|
[a32b204] | 102 | /* Bool */ { BasicType::Bool, BasicType::Char, BasicType::SignedChar, BasicType::UnsignedChar, BasicType::ShortSignedInt, BasicType::ShortUnsignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 103 | /* Char */ { BasicType::Char, BasicType::Char, BasicType::UnsignedChar, BasicType::UnsignedChar, BasicType::ShortSignedInt, BasicType::ShortUnsignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 104 | /* SignedChar */ { BasicType::SignedChar, BasicType::UnsignedChar, BasicType::SignedChar, BasicType::UnsignedChar, BasicType::ShortSignedInt, BasicType::ShortUnsignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 105 | /* UnsignedChar */ { BasicType::UnsignedChar, BasicType::UnsignedChar, BasicType::UnsignedChar, BasicType::UnsignedChar, BasicType::ShortSignedInt, BasicType::ShortUnsignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 106 | /* ShortSignedInt */ { BasicType::ShortSignedInt, BasicType::ShortSignedInt, BasicType::ShortSignedInt, BasicType::ShortSignedInt, BasicType::ShortSignedInt, BasicType::ShortUnsignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 107 | /* ShortUnsignedInt */ { BasicType::ShortUnsignedInt, BasicType::ShortUnsignedInt, BasicType::ShortUnsignedInt, BasicType::ShortUnsignedInt, BasicType::ShortUnsignedInt, BasicType::ShortUnsignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 108 | /* SignedInt */ { BasicType::SignedInt, BasicType::SignedInt, BasicType::SignedInt, BasicType::SignedInt, BasicType::SignedInt, BasicType::SignedInt, BasicType::SignedInt, BasicType::UnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 109 | /* UnsignedInt */ { BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::UnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 110 | /* LongSignedInt */ { BasicType::LongSignedInt, BasicType::LongSignedInt, BasicType::LongSignedInt, BasicType::LongSignedInt, BasicType::LongSignedInt, BasicType::LongSignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongSignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 111 | /* LongUnsignedInt */ { BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongUnsignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 112 | /* LongLongSignedInt */ { BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongSignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 113 | /* LongLongUnsignedInt */ { BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::LongLongUnsignedInt, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 114 | /* Float */ { BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 115 | /* Double */ { BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::Double, BasicType::LongDouble, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 116 | /* LongDouble */ { BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDouble, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 117 | /* FloatComplex */ { BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 118 | /* DoubleComplex */ { BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 119 | /* LongDoubleComplex */ { BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex }, |
---|
| 120 | /* FloatImaginary */ { BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatImaginary, BasicType::DoubleImaginary, BasicType::LongDoubleImaginary }, |
---|
| 121 | /* DoubleImaginary */ { BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::DoubleImaginary, BasicType::DoubleImaginary, BasicType::LongDoubleImaginary }, |
---|
| 122 | /* LongDoubleImaginary */ { BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleImaginary, BasicType::LongDoubleImaginary, BasicType::LongDoubleImaginary } |
---|
| 123 | }; |
---|
| 124 | |
---|
| 125 | CommonType::CommonType( Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) |
---|
| 126 | : result( 0 ), type2( type2 ), widenFirst( widenFirst ), widenSecond( widenSecond ), indexer( indexer ), env( env ), openVars( openVars ) { |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | void CommonType::visit( VoidType *voidType ) { |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | void CommonType::visit( BasicType *basicType ) { |
---|
| 133 | if ( BasicType *otherBasic = dynamic_cast< BasicType* >( type2 ) ) { |
---|
| 134 | BasicType::Kind newType = combinedType[ basicType->get_kind() ][ otherBasic->get_kind() ]; |
---|
| 135 | if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= otherBasic->get_qualifiers() ) || widenFirst ) && ( ( newType == otherBasic->get_kind() && basicType->get_qualifiers() <= otherBasic->get_qualifiers() ) || widenSecond ) ) { |
---|
| 136 | result = new BasicType( basicType->get_qualifiers() + otherBasic->get_qualifiers(), newType ); |
---|
| 137 | } // if |
---|
[89e6ffc] | 138 | } else if ( dynamic_cast< EnumInstType * > ( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) { |
---|
| 139 | // use signed int in lieu of the enum/zero/one type |
---|
[a436947] | 140 | BasicType::Kind newType = combinedType[ basicType->get_kind() ][ BasicType::SignedInt ]; |
---|
[89e6ffc] | 141 | if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= type2->get_qualifiers() ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->get_qualifiers() <= type2->get_qualifiers() ) || widenSecond ) ) { |
---|
| 142 | result = new BasicType( basicType->get_qualifiers() + type2->get_qualifiers(), newType ); |
---|
[a436947] | 143 | } // if |
---|
[a32b204] | 144 | } // if |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | void CommonType::visit( PointerType *pointerType ) { |
---|
| 148 | if ( PointerType *otherPointer = dynamic_cast< PointerType* >( type2 ) ) { |
---|
[db4977a] | 149 | if ( widenFirst && dynamic_cast< VoidType* >( otherPointer->get_base() ) && ! isFtype(pointerType->get_base(), indexer) ) { |
---|
[a32b204] | 150 | result = otherPointer->clone(); |
---|
| 151 | result->get_qualifiers() += pointerType->get_qualifiers(); |
---|
[db4977a] | 152 | } else if ( widenSecond && dynamic_cast< VoidType* >( pointerType->get_base() ) && ! isFtype(otherPointer->get_base(), indexer) ) { |
---|
[a32b204] | 153 | result = pointerType->clone(); |
---|
| 154 | result->get_qualifiers() += otherPointer->get_qualifiers(); |
---|
| 155 | } else if ( ( pointerType->get_base()->get_qualifiers() >= otherPointer->get_base()->get_qualifiers() || widenFirst ) |
---|
| 156 | && ( pointerType->get_base()->get_qualifiers() <= otherPointer->get_base()->get_qualifiers() || widenSecond ) ) { |
---|
| 157 | Type::Qualifiers tq1 = pointerType->get_base()->get_qualifiers(), tq2 = otherPointer->get_base()->get_qualifiers(); |
---|
| 158 | pointerType->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
| 159 | otherPointer->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
| 160 | AssertionSet have, need; |
---|
| 161 | OpenVarSet newOpen( openVars ); |
---|
| 162 | if ( unifyExact( pointerType->get_base(), otherPointer->get_base(), env, have, need, newOpen, indexer ) ) { |
---|
| 163 | if ( tq1 < tq2 ) { |
---|
| 164 | result = pointerType->clone(); |
---|
| 165 | } else { |
---|
| 166 | result = otherPointer->clone(); |
---|
| 167 | } // if |
---|
| 168 | result->get_qualifiers() = tq1 + tq2; |
---|
| 169 | } else { |
---|
| 170 | /// std::cout << "place for ptr-to-type" << std::endl; |
---|
| 171 | } // if |
---|
| 172 | pointerType->get_base()->get_qualifiers() = tq1; |
---|
| 173 | otherPointer->get_base()->get_qualifiers() = tq2; |
---|
| 174 | } // if |
---|
[89e6ffc] | 175 | } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) { |
---|
| 176 | result = pointerType->clone(); |
---|
| 177 | result->get_qualifiers() += type2->get_qualifiers(); |
---|
[a32b204] | 178 | } // if |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | void CommonType::visit( ArrayType *arrayType ) { |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | void CommonType::visit( FunctionType *functionType ) { |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | template< typename RefType > void CommonType::handleRefType( RefType *inst, Type *other ) { |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | void CommonType::visit( StructInstType *aggregateUseType ) { |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | void CommonType::visit( UnionInstType *aggregateUseType ) { |
---|
| 194 | } |
---|
| 195 | |
---|
[a436947] | 196 | void CommonType::visit( EnumInstType *enumInstType ) { |
---|
[89e6ffc] | 197 | if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) { |
---|
[a436947] | 198 | // reuse BasicType, EnumInstType code by swapping type2 with enumInstType |
---|
| 199 | Type * temp = type2; |
---|
| 200 | type2 = enumInstType; |
---|
| 201 | temp->accept( *this ); |
---|
| 202 | type2 = temp; |
---|
| 203 | } // if |
---|
[a32b204] | 204 | } |
---|
| 205 | |
---|
[4040425] | 206 | void CommonType::visit( TraitInstType *aggregateUseType ) { |
---|
[a32b204] | 207 | } |
---|
| 208 | |
---|
| 209 | void CommonType::visit( TypeInstType *inst ) { |
---|
| 210 | if ( widenFirst ) { |
---|
| 211 | NamedTypeDecl *nt = indexer.lookupType( inst->get_name() ); |
---|
| 212 | if ( nt ) { |
---|
| 213 | TypeDecl *type = dynamic_cast< TypeDecl* >( nt ); |
---|
| 214 | assert( type ); |
---|
| 215 | if ( type->get_base() ) { |
---|
| 216 | Type::Qualifiers tq1 = inst->get_qualifiers(), tq2 = type2->get_qualifiers(); |
---|
| 217 | AssertionSet have, need; |
---|
| 218 | OpenVarSet newOpen( openVars ); |
---|
| 219 | type2->get_qualifiers() = Type::Qualifiers(); |
---|
| 220 | type->get_base()->get_qualifiers() = tq1; |
---|
| 221 | if ( unifyExact( type->get_base(), type2, env, have, need, newOpen, indexer ) ) { |
---|
| 222 | result = type2->clone(); |
---|
| 223 | result->get_qualifiers() = tq1 + tq2; |
---|
| 224 | } // if |
---|
| 225 | type2->get_qualifiers() = tq2; |
---|
| 226 | type->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
| 227 | } // if |
---|
| 228 | } // if |
---|
| 229 | } // if |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | void CommonType::visit( TupleType *tupleType ) { |
---|
| 233 | } |
---|
[44b7088] | 234 | |
---|
| 235 | void CommonType::visit( VarArgsType *varArgsType ) { |
---|
| 236 | } |
---|
[89e6ffc] | 237 | |
---|
| 238 | void CommonType::visit( ZeroType *zeroType ) { |
---|
| 239 | if ( widenFirst ) { |
---|
| 240 | if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< PointerType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) { |
---|
| 241 | if ( widenSecond || zeroType->get_qualifiers() <= type2->get_qualifiers() ) { |
---|
| 242 | result = type2->clone(); |
---|
| 243 | result->get_qualifiers() += zeroType->get_qualifiers(); |
---|
| 244 | } |
---|
| 245 | } |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | void CommonType::visit( OneType *oneType ) { |
---|
| 250 | if ( widenFirst ) { |
---|
| 251 | if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) { |
---|
| 252 | if ( widenSecond || oneType->get_qualifiers() <= type2->get_qualifiers() ) { |
---|
| 253 | result = type2->clone(); |
---|
| 254 | result->get_qualifiers() += oneType->get_qualifiers(); |
---|
| 255 | } |
---|
| 256 | } |
---|
| 257 | } |
---|
| 258 | } |
---|
[51b7345] | 259 | } // namespace ResolvExpr |
---|
[a32b204] | 260 | |
---|
| 261 | // Local Variables: // |
---|
| 262 | // tab-width: 4 // |
---|
| 263 | // mode: c++ // |
---|
| 264 | // compile-command: "make install" // |
---|
| 265 | // End: // |
---|