| 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 | // CommonType.cc --
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // Author           : Richard C. Bilson
 | 
|---|
| 10 | // Created On       : Sun May 17 06:59:27 2015
 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Wed Mar  2 17:35:34 2016
 | 
|---|
| 13 | // Update Count     : 3
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include "typeops.h"
 | 
|---|
| 17 | #include "SynTree/Type.h"
 | 
|---|
| 18 | #include "Unify.h"
 | 
|---|
| 19 | 
 | 
|---|
| 20 | 
 | 
|---|
| 21 | /// #define DEBUG
 | 
|---|
| 22 | 
 | 
|---|
| 23 | namespace ResolvExpr {
 | 
|---|
| 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 );
 | 
|---|
| 37 |                 virtual void visit( TraitInstType *aggregateUseType );
 | 
|---|
| 38 |                 virtual void visit( TypeInstType *aggregateUseType );
 | 
|---|
| 39 |                 virtual void visit( TupleType *tupleType );
 | 
|---|
| 40 |                 virtual void visit( VarArgsType *varArgsType );
 | 
|---|
| 41 | 
 | 
|---|
| 42 |                 template< typename RefType > void handleRefType( RefType *inst, Type *other );
 | 
|---|
| 43 | 
 | 
|---|
| 44 |                 Type *result;
 | 
|---|
| 45 |                 Type *type2;                            // inherited
 | 
|---|
| 46 |                 bool widenFirst, widenSecond;
 | 
|---|
| 47 |                 const SymTab::Indexer &indexer;
 | 
|---|
| 48 |                 TypeEnvironment &env;
 | 
|---|
| 49 |                 const OpenVarSet &openVars;
 | 
|---|
| 50 |         };
 | 
|---|
| 51 | 
 | 
|---|
| 52 |         Type *commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) {
 | 
|---|
| 53 |                 CommonType visitor( type2, widenFirst, widenSecond, indexer, env, openVars );
 | 
|---|
| 54 |                 type1->accept( visitor );
 | 
|---|
| 55 |                 Type *result = visitor.get_result();
 | 
|---|
| 56 |                 if ( ! result ) {
 | 
|---|
| 57 |                         if ( widenSecond ) {
 | 
|---|
| 58 |                                 TypeInstType *inst = dynamic_cast< TypeInstType* >( type2 );
 | 
|---|
| 59 |                                 if ( inst ) {
 | 
|---|
| 60 |                                         NamedTypeDecl *nt = indexer.lookupType( inst->get_name() );
 | 
|---|
| 61 |                                         if ( nt ) {
 | 
|---|
| 62 |                                                 TypeDecl *type = dynamic_cast< TypeDecl* >( nt );
 | 
|---|
| 63 |                                                 assert( type );
 | 
|---|
| 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();
 | 
|---|
| 72 |                                                                 result->get_qualifiers() = tq1 + tq2;
 | 
|---|
| 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
 | 
|---|
| 81 | #ifdef DEBUG
 | 
|---|
| 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;
 | 
|---|
| 93 | #endif
 | 
|---|
| 94 |                 return result;
 | 
|---|
| 95 |         }
 | 
|---|
| 96 | 
 | 
|---|
| 97 |         static const BasicType::Kind combinedType[ BasicType::NUMBER_OF_BASIC_TYPES ][ BasicType::NUMBER_OF_BASIC_TYPES ] =
 | 
|---|
| 98 |         {
 | 
|---|
| 99 | /*              Bool            Char    SignedChar      UnsignedChar    ShortSignedInt  ShortUnsignedInt        SignedInt       UnsignedInt     LongSignedInt   LongUnsignedInt LongLongSignedInt       LongLongUnsignedInt     Float   Double  LongDouble      FloatComplex    DoubleComplex   LongDoubleComplex       FloatImaginary  DoubleImaginary LongDoubleImaginary */
 | 
|---|
| 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 | 
 | 
|---|
| 127 |         void CommonType::visit( VoidType *voidType ) {
 | 
|---|
| 128 |         }
 | 
|---|
| 129 | 
 | 
|---|
| 130 |         void CommonType::visit( BasicType *basicType ) {
 | 
|---|
| 131 |                 if ( BasicType *otherBasic = dynamic_cast< BasicType* >( type2 ) ) {
 | 
|---|
| 132 |                         BasicType::Kind newType = combinedType[ basicType->get_kind() ][ otherBasic->get_kind() ];
 | 
|---|
| 133 |                         if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= otherBasic->get_qualifiers() ) || widenFirst ) && ( ( newType == otherBasic->get_kind() && basicType->get_qualifiers() <= otherBasic->get_qualifiers() ) || widenSecond ) ) {
 | 
|---|
| 134 |                                 result = new BasicType( basicType->get_qualifiers() + otherBasic->get_qualifiers(), newType );
 | 
|---|
| 135 |                         } // if
 | 
|---|
| 136 |                 } else if ( EnumInstType *enumInstType = dynamic_cast< EnumInstType * > ( type2 ) ) {
 | 
|---|
| 137 |                         // use signed int in lieu of the enum type
 | 
|---|
| 138 |                         BasicType::Kind newType = combinedType[ basicType->get_kind() ][ BasicType::SignedInt ];
 | 
|---|
| 139 |                         if ( ( ( newType == basicType->get_kind() && basicType->get_qualifiers() >= enumInstType->get_qualifiers() ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->get_qualifiers() <= enumInstType->get_qualifiers() ) || widenSecond ) ) {
 | 
|---|
| 140 |                                 result = new BasicType( basicType->get_qualifiers() + enumInstType->get_qualifiers(), newType );
 | 
|---|
| 141 |                         } // if
 | 
|---|
| 142 |                 } // if
 | 
|---|
| 143 |         }
 | 
|---|
| 144 | 
 | 
|---|
| 145 |         void CommonType::visit( PointerType *pointerType ) {
 | 
|---|
| 146 |                 if ( PointerType *otherPointer = dynamic_cast< PointerType* >( type2 ) ) {
 | 
|---|
| 147 |                         if ( widenFirst && dynamic_cast< VoidType* >( otherPointer->get_base() ) && ! isFtype(pointerType->get_base(), indexer) ) {
 | 
|---|
| 148 |                                 result = otherPointer->clone();
 | 
|---|
| 149 |                                 result->get_qualifiers() += pointerType->get_qualifiers();
 | 
|---|
| 150 |                         } else if ( widenSecond && dynamic_cast< VoidType* >( pointerType->get_base() ) && ! isFtype(otherPointer->get_base(), indexer) ) {
 | 
|---|
| 151 |                                 result = pointerType->clone();
 | 
|---|
| 152 |                                 result->get_qualifiers() += otherPointer->get_qualifiers();
 | 
|---|
| 153 |                         } else if ( ( pointerType->get_base()->get_qualifiers() >= otherPointer->get_base()->get_qualifiers() || widenFirst )
 | 
|---|
| 154 |                                            && ( pointerType->get_base()->get_qualifiers() <= otherPointer->get_base()->get_qualifiers() || widenSecond ) ) {
 | 
|---|
| 155 |                                 Type::Qualifiers tq1 = pointerType->get_base()->get_qualifiers(), tq2 = otherPointer->get_base()->get_qualifiers();
 | 
|---|
| 156 |                                 pointerType->get_base()->get_qualifiers() = Type::Qualifiers();
 | 
|---|
| 157 |                                 otherPointer->get_base()->get_qualifiers() = Type::Qualifiers();
 | 
|---|
| 158 |                                 AssertionSet have, need;
 | 
|---|
| 159 |                                 OpenVarSet newOpen( openVars );
 | 
|---|
| 160 |                                 if ( unifyExact( pointerType->get_base(), otherPointer->get_base(), env, have, need, newOpen, indexer ) ) {
 | 
|---|
| 161 |                                         if ( tq1 < tq2 ) {
 | 
|---|
| 162 |                                                 result = pointerType->clone();
 | 
|---|
| 163 |                                         } else {
 | 
|---|
| 164 |                                                 result = otherPointer->clone();
 | 
|---|
| 165 |                                         } // if
 | 
|---|
| 166 |                                         result->get_qualifiers() = tq1 + tq2;
 | 
|---|
| 167 |                                 } else {
 | 
|---|
| 168 |                                         /// std::cout << "place for ptr-to-type" << std::endl;
 | 
|---|
| 169 |                                 } // if
 | 
|---|
| 170 |                                 pointerType->get_base()->get_qualifiers() = tq1;
 | 
|---|
| 171 |                                 otherPointer->get_base()->get_qualifiers() = tq2;
 | 
|---|
| 172 |                         } // if
 | 
|---|
| 173 |                 } // if
 | 
|---|
| 174 |         }
 | 
|---|
| 175 | 
 | 
|---|
| 176 |         void CommonType::visit( ArrayType *arrayType ) {
 | 
|---|
| 177 |         }
 | 
|---|
| 178 | 
 | 
|---|
| 179 |         void CommonType::visit( FunctionType *functionType ) {
 | 
|---|
| 180 |         }
 | 
|---|
| 181 | 
 | 
|---|
| 182 |         template< typename RefType > void CommonType::handleRefType( RefType *inst, Type *other ) {
 | 
|---|
| 183 |         }
 | 
|---|
| 184 | 
 | 
|---|
| 185 |         void CommonType::visit( StructInstType *aggregateUseType ) {
 | 
|---|
| 186 |         }
 | 
|---|
| 187 | 
 | 
|---|
| 188 |         void CommonType::visit( UnionInstType *aggregateUseType ) {
 | 
|---|
| 189 |         }
 | 
|---|
| 190 | 
 | 
|---|
| 191 |         void CommonType::visit( EnumInstType *enumInstType ) {
 | 
|---|
| 192 |                 if ( dynamic_cast< BasicType * >( type2 ) ) {
 | 
|---|
| 193 |                         // reuse BasicType, EnumInstType code by swapping type2 with enumInstType
 | 
|---|
| 194 |                         Type * temp = type2;
 | 
|---|
| 195 |                         type2 = enumInstType;
 | 
|---|
| 196 |                         temp->accept( *this );
 | 
|---|
| 197 |                         type2 = temp;
 | 
|---|
| 198 |                 } // if
 | 
|---|
| 199 |         }
 | 
|---|
| 200 | 
 | 
|---|
| 201 |         void CommonType::visit( TraitInstType *aggregateUseType ) {
 | 
|---|
| 202 |         }
 | 
|---|
| 203 | 
 | 
|---|
| 204 |         void CommonType::visit( TypeInstType *inst ) {
 | 
|---|
| 205 |                 if ( widenFirst ) {
 | 
|---|
| 206 |                         NamedTypeDecl *nt = indexer.lookupType( inst->get_name() );
 | 
|---|
| 207 |                         if ( nt ) {
 | 
|---|
| 208 |                                 TypeDecl *type = dynamic_cast< TypeDecl* >( nt );
 | 
|---|
| 209 |                                 assert( type );
 | 
|---|
| 210 |                                 if ( type->get_base() ) {
 | 
|---|
| 211 |                                         Type::Qualifiers tq1 = inst->get_qualifiers(), tq2 = type2->get_qualifiers();
 | 
|---|
| 212 |                                         AssertionSet have, need;
 | 
|---|
| 213 |                                         OpenVarSet newOpen( openVars );
 | 
|---|
| 214 |                                         type2->get_qualifiers() = Type::Qualifiers();
 | 
|---|
| 215 |                                         type->get_base()->get_qualifiers() = tq1;
 | 
|---|
| 216 |                                         if ( unifyExact( type->get_base(), type2, env, have, need, newOpen, indexer ) ) {
 | 
|---|
| 217 |                                                 result = type2->clone();
 | 
|---|
| 218 |                                                 result->get_qualifiers() = tq1 + tq2;
 | 
|---|
| 219 |                                         } // if
 | 
|---|
| 220 |                                         type2->get_qualifiers() = tq2;
 | 
|---|
| 221 |                                         type->get_base()->get_qualifiers() = Type::Qualifiers();
 | 
|---|
| 222 |                                 } // if
 | 
|---|
| 223 |                         } // if
 | 
|---|
| 224 |                 } // if
 | 
|---|
| 225 |         }
 | 
|---|
| 226 | 
 | 
|---|
| 227 |         void CommonType::visit( TupleType *tupleType ) {
 | 
|---|
| 228 |         }
 | 
|---|
| 229 | 
 | 
|---|
| 230 |         void CommonType::visit( VarArgsType *varArgsType ) {
 | 
|---|
| 231 |         }
 | 
|---|
| 232 | } // namespace ResolvExpr
 | 
|---|
| 233 | 
 | 
|---|
| 234 | // Local Variables: //
 | 
|---|
| 235 | // tab-width: 4 //
 | 
|---|
| 236 | // mode: c++ //
 | 
|---|
| 237 | // compile-command: "make install" //
 | 
|---|
| 238 | // End: //
 | 
|---|