[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 |
---|
[6f95000] | 12 | // Last Modified On : Thu Mar 16 16:24:31 2017 |
---|
| 13 | // Update Count : 7 |
---|
[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 | |
---|
[a2a77af] | 44 | void getCommonWithVoidPointer( PointerType* voidPointer, PointerType* otherPointer ); |
---|
[a32b204] | 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 ) { |
---|
[2c57025] | 59 | // this appears to be handling for opaque type declarations |
---|
[a32b204] | 60 | if ( widenSecond ) { |
---|
[2c57025] | 61 | if ( TypeInstType *inst = dynamic_cast< TypeInstType* >( type2 ) ) { |
---|
| 62 | if ( NamedTypeDecl *nt = indexer.lookupType( inst->get_name() ) ) { |
---|
| 63 | TypeDecl *type = safe_dynamic_cast< TypeDecl* >( nt ); |
---|
[a32b204] | 64 | if ( type->get_base() ) { |
---|
| 65 | Type::Qualifiers tq1 = type1->get_qualifiers(), tq2 = type2->get_qualifiers(); |
---|
| 66 | AssertionSet have, need; |
---|
| 67 | OpenVarSet newOpen( openVars ); |
---|
| 68 | type1->get_qualifiers() = Type::Qualifiers(); |
---|
| 69 | type->get_base()->get_qualifiers() = tq1; |
---|
| 70 | if ( unifyExact( type1, type->get_base(), env, have, need, newOpen, indexer ) ) { |
---|
| 71 | result = type1->clone(); |
---|
[6f95000] | 72 | result->get_qualifiers() = tq1 | tq2; |
---|
[a32b204] | 73 | } // if |
---|
| 74 | type1->get_qualifiers() = tq1; |
---|
| 75 | type->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
| 76 | } // if |
---|
| 77 | } // if |
---|
| 78 | } // if |
---|
| 79 | } // if |
---|
| 80 | } // if |
---|
[51b7345] | 81 | #ifdef DEBUG |
---|
[a32b204] | 82 | std::cout << "============= commonType" << std::endl << "type1 is "; |
---|
| 83 | type1->print( std::cout ); |
---|
| 84 | std::cout << " type2 is "; |
---|
| 85 | type2->print( std::cout ); |
---|
| 86 | if ( result ) { |
---|
| 87 | std::cout << " common type is "; |
---|
| 88 | result->print( std::cout ); |
---|
| 89 | } else { |
---|
| 90 | std::cout << " no common type"; |
---|
| 91 | } // if |
---|
| 92 | std::cout << std::endl; |
---|
[51b7345] | 93 | #endif |
---|
[a32b204] | 94 | return result; |
---|
| 95 | } |
---|
[51b7345] | 96 | |
---|
[a32b204] | 97 | static const BasicType::Kind combinedType[ BasicType::NUMBER_OF_BASIC_TYPES ][ BasicType::NUMBER_OF_BASIC_TYPES ] = |
---|
| 98 | { |
---|
[51b7345] | 99 | /* Bool Char SignedChar UnsignedChar ShortSignedInt ShortUnsignedInt SignedInt UnsignedInt LongSignedInt LongUnsignedInt LongLongSignedInt LongLongUnsignedInt Float Double LongDouble FloatComplex DoubleComplex LongDoubleComplex FloatImaginary DoubleImaginary LongDoubleImaginary */ |
---|
[a32b204] | 100 | /* 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 }, |
---|
| 101 | /* 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 }, |
---|
| 102 | /* 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 }, |
---|
| 103 | /* 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 }, |
---|
| 104 | /* 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 }, |
---|
| 105 | /* 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 }, |
---|
| 106 | /* 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 }, |
---|
| 107 | /* 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 }, |
---|
| 108 | /* 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 }, |
---|
| 109 | /* 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 }, |
---|
| 110 | /* 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 }, |
---|
| 111 | /* 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 }, |
---|
| 112 | /* 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 }, |
---|
| 113 | /* 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 }, |
---|
| 114 | /* 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 }, |
---|
| 115 | /* 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 }, |
---|
| 116 | /* 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 }, |
---|
| 117 | /* 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 }, |
---|
| 118 | /* 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 }, |
---|
| 119 | /* 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 }, |
---|
| 120 | /* 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 } |
---|
| 121 | }; |
---|
| 122 | |
---|
| 123 | CommonType::CommonType( Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) |
---|
| 124 | : result( 0 ), type2( type2 ), widenFirst( widenFirst ), widenSecond( widenSecond ), indexer( indexer ), env( env ), openVars( openVars ) { |
---|
| 125 | } |
---|
| 126 | |
---|
[7e003011] | 127 | void CommonType::visit( __attribute((unused)) VoidType *voidType ) {} |
---|
[a32b204] | 128 | |
---|
| 129 | void CommonType::visit( BasicType *basicType ) { |
---|
| 130 | if ( BasicType *otherBasic = dynamic_cast< BasicType* >( type2 ) ) { |
---|
| 131 | BasicType::Kind newType = combinedType[ basicType->get_kind() ][ otherBasic->get_kind() ]; |
---|
| 132 | if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= otherBasic->get_qualifiers() ) || widenFirst ) && ( ( newType == otherBasic->get_kind() && basicType->get_qualifiers() <= otherBasic->get_qualifiers() ) || widenSecond ) ) { |
---|
[6f95000] | 133 | result = new BasicType( basicType->get_qualifiers() | otherBasic->get_qualifiers(), newType ); |
---|
[a32b204] | 134 | } // if |
---|
[89e6ffc] | 135 | } else if ( dynamic_cast< EnumInstType * > ( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) { |
---|
| 136 | // use signed int in lieu of the enum/zero/one type |
---|
[a436947] | 137 | BasicType::Kind newType = combinedType[ basicType->get_kind() ][ BasicType::SignedInt ]; |
---|
[89e6ffc] | 138 | if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= type2->get_qualifiers() ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->get_qualifiers() <= type2->get_qualifiers() ) || widenSecond ) ) { |
---|
[6f95000] | 139 | result = new BasicType( basicType->get_qualifiers() | type2->get_qualifiers(), newType ); |
---|
[a436947] | 140 | } // if |
---|
[a32b204] | 141 | } // if |
---|
| 142 | } |
---|
| 143 | |
---|
[a2a77af] | 144 | void CommonType::getCommonWithVoidPointer( PointerType* voidPointer, PointerType* otherPointer ) { |
---|
| 145 | if ( TypeInstType* var = dynamic_cast< TypeInstType* >( otherPointer->get_base() ) ) { |
---|
| 146 | OpenVarSet::const_iterator entry = openVars.find( var->get_name() ); |
---|
| 147 | if ( entry != openVars.end() ) { |
---|
| 148 | AssertionSet need, have; |
---|
| 149 | WidenMode widen( widenFirst, widenSecond ); |
---|
| 150 | if ( entry != openVars.end() && ! bindVar(var, voidPointer->get_base(), entry->second, env, need, have, openVars, widen, indexer ) ) return; |
---|
| 151 | } |
---|
[2c57025] | 152 | } |
---|
[a2a77af] | 153 | result = voidPointer->clone(); |
---|
[6f95000] | 154 | result->get_qualifiers() |= otherPointer->get_qualifiers(); |
---|
[2c57025] | 155 | } |
---|
| 156 | |
---|
[a32b204] | 157 | void CommonType::visit( PointerType *pointerType ) { |
---|
| 158 | if ( PointerType *otherPointer = dynamic_cast< PointerType* >( type2 ) ) { |
---|
[d7dc824] | 159 | if ( widenFirst && dynamic_cast< VoidType* >( otherPointer->get_base() ) && ! isFtype(pointerType->get_base()) ) { |
---|
[a2a77af] | 160 | getCommonWithVoidPointer( otherPointer, pointerType ); |
---|
[d7dc824] | 161 | } else if ( widenSecond && dynamic_cast< VoidType* >( pointerType->get_base() ) && ! isFtype(otherPointer->get_base()) ) { |
---|
[a2a77af] | 162 | getCommonWithVoidPointer( pointerType, otherPointer ); |
---|
[a32b204] | 163 | } else if ( ( pointerType->get_base()->get_qualifiers() >= otherPointer->get_base()->get_qualifiers() || widenFirst ) |
---|
| 164 | && ( pointerType->get_base()->get_qualifiers() <= otherPointer->get_base()->get_qualifiers() || widenSecond ) ) { |
---|
| 165 | Type::Qualifiers tq1 = pointerType->get_base()->get_qualifiers(), tq2 = otherPointer->get_base()->get_qualifiers(); |
---|
| 166 | pointerType->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
| 167 | otherPointer->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
| 168 | AssertionSet have, need; |
---|
| 169 | OpenVarSet newOpen( openVars ); |
---|
| 170 | if ( unifyExact( pointerType->get_base(), otherPointer->get_base(), env, have, need, newOpen, indexer ) ) { |
---|
| 171 | if ( tq1 < tq2 ) { |
---|
| 172 | result = pointerType->clone(); |
---|
| 173 | } else { |
---|
| 174 | result = otherPointer->clone(); |
---|
| 175 | } // if |
---|
[6f95000] | 176 | result->get_qualifiers() = tq1 | tq2; |
---|
[a32b204] | 177 | } else { |
---|
| 178 | /// std::cout << "place for ptr-to-type" << std::endl; |
---|
| 179 | } // if |
---|
| 180 | pointerType->get_base()->get_qualifiers() = tq1; |
---|
| 181 | otherPointer->get_base()->get_qualifiers() = tq2; |
---|
| 182 | } // if |
---|
[89e6ffc] | 183 | } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) { |
---|
| 184 | result = pointerType->clone(); |
---|
[6f95000] | 185 | result->get_qualifiers() |= type2->get_qualifiers(); |
---|
[a32b204] | 186 | } // if |
---|
| 187 | } |
---|
| 188 | |
---|
[7e003011] | 189 | void CommonType::visit( __attribute((unused)) ArrayType *arrayType ) {} |
---|
| 190 | void CommonType::visit( __attribute((unused)) FunctionType *functionType ) {} |
---|
| 191 | void CommonType::visit( __attribute((unused)) StructInstType *aggregateUseType ) {} |
---|
| 192 | void CommonType::visit( __attribute((unused)) UnionInstType *aggregateUseType ) {} |
---|
[a32b204] | 193 | |
---|
[a436947] | 194 | void CommonType::visit( EnumInstType *enumInstType ) { |
---|
[89e6ffc] | 195 | if ( dynamic_cast< BasicType * >( type2 ) || dynamic_cast< ZeroType* >( type2 ) || dynamic_cast< OneType* >( type2 ) ) { |
---|
[a436947] | 196 | // reuse BasicType, EnumInstType code by swapping type2 with enumInstType |
---|
| 197 | Type * temp = type2; |
---|
| 198 | type2 = enumInstType; |
---|
| 199 | temp->accept( *this ); |
---|
| 200 | type2 = temp; |
---|
| 201 | } // if |
---|
[a32b204] | 202 | } |
---|
| 203 | |
---|
[7e003011] | 204 | void CommonType::visit( __attribute((unused)) TraitInstType *aggregateUseType ) { |
---|
[a32b204] | 205 | } |
---|
| 206 | |
---|
| 207 | void CommonType::visit( TypeInstType *inst ) { |
---|
| 208 | if ( widenFirst ) { |
---|
| 209 | NamedTypeDecl *nt = indexer.lookupType( inst->get_name() ); |
---|
| 210 | if ( nt ) { |
---|
[2c57025] | 211 | TypeDecl *type = safe_dynamic_cast< TypeDecl* >( nt ); |
---|
[a32b204] | 212 | if ( type->get_base() ) { |
---|
| 213 | Type::Qualifiers tq1 = inst->get_qualifiers(), tq2 = type2->get_qualifiers(); |
---|
| 214 | AssertionSet have, need; |
---|
| 215 | OpenVarSet newOpen( openVars ); |
---|
| 216 | type2->get_qualifiers() = Type::Qualifiers(); |
---|
| 217 | type->get_base()->get_qualifiers() = tq1; |
---|
| 218 | if ( unifyExact( type->get_base(), type2, env, have, need, newOpen, indexer ) ) { |
---|
| 219 | result = type2->clone(); |
---|
[6f95000] | 220 | result->get_qualifiers() = tq1 | tq2; |
---|
[a32b204] | 221 | } // if |
---|
| 222 | type2->get_qualifiers() = tq2; |
---|
| 223 | type->get_base()->get_qualifiers() = Type::Qualifiers(); |
---|
| 224 | } // if |
---|
| 225 | } // if |
---|
| 226 | } // if |
---|
| 227 | } |
---|
| 228 | |
---|
[7e003011] | 229 | void CommonType::visit( __attribute((unused)) TupleType *tupleType ) {} |
---|
| 230 | void CommonType::visit( __attribute((unused)) VarArgsType *varArgsType ) {} |
---|
[89e6ffc] | 231 | |
---|
| 232 | void CommonType::visit( ZeroType *zeroType ) { |
---|
| 233 | if ( widenFirst ) { |
---|
| 234 | if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< PointerType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) { |
---|
| 235 | if ( widenSecond || zeroType->get_qualifiers() <= type2->get_qualifiers() ) { |
---|
| 236 | result = type2->clone(); |
---|
[6f95000] | 237 | result->get_qualifiers() |= zeroType->get_qualifiers(); |
---|
[89e6ffc] | 238 | } |
---|
[4cb935e] | 239 | } else if ( widenSecond && dynamic_cast< OneType* >( type2 ) ) { |
---|
| 240 | result = new BasicType( zeroType->get_qualifiers(), BasicType::SignedInt ); |
---|
[6f95000] | 241 | result->get_qualifiers() |= type2->get_qualifiers(); |
---|
[89e6ffc] | 242 | } |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | void CommonType::visit( OneType *oneType ) { |
---|
| 247 | if ( widenFirst ) { |
---|
| 248 | if ( dynamic_cast< BasicType* >( type2 ) || dynamic_cast< EnumInstType* >( type2 ) ) { |
---|
| 249 | if ( widenSecond || oneType->get_qualifiers() <= type2->get_qualifiers() ) { |
---|
| 250 | result = type2->clone(); |
---|
[6f95000] | 251 | result->get_qualifiers() |= oneType->get_qualifiers(); |
---|
[89e6ffc] | 252 | } |
---|
[4cb935e] | 253 | } else if ( widenSecond && dynamic_cast< ZeroType* >( type2 ) ) { |
---|
| 254 | result = new BasicType( oneType->get_qualifiers(), BasicType::SignedInt ); |
---|
[6f95000] | 255 | result->get_qualifiers() |= type2->get_qualifiers(); |
---|
[89e6ffc] | 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: // |
---|