Changeset 28f3a19 for src/ResolvExpr
- Timestamp:
- Jun 27, 2018, 3:28:41 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- b21c77a
- Parents:
- 0182bfa (diff), 63238a4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/ResolvExpr
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Alternative.cc
r0182bfa r28f3a19 30 30 31 31 namespace ResolvExpr { 32 Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( 0) {}32 Alternative::Alternative() : cost( Cost::zero ), cvtCost( Cost::zero ), expr( nullptr ) {} 33 33 34 34 Alternative::Alternative( Expression *expr, const TypeEnvironment &env, const Cost& cost ) -
src/ResolvExpr/AlternativeFinder.cc
r0182bfa r28f3a19 98 98 void postvisit( InitExpr * initExpr ); 99 99 void postvisit( DeletedExpr * delExpr ); 100 void postvisit( GenericExpr * genExpr ); 100 101 101 102 /// Adds alternatives for anonymous members … … 175 176 selected[ mangleName ] = current; 176 177 } else if ( candidate->cost == mapPlace->second.candidate->cost ) { 177 PRINT( 178 std::cerr << "marking ambiguous" << std::endl; 179 ) 180 mapPlace->second.isAmbiguous = true; 178 // if one of the candidates contains a deleted identifier, can pick the other, since 179 // deleted expressions should not be ambiguous if there is another option that is at least as good 180 if ( findDeletedExpr( candidate->expr ) ) { 181 // do nothing 182 PRINT( std::cerr << "candidate is deleted" << std::endl; ) 183 } else if ( findDeletedExpr( mapPlace->second.candidate->expr ) ) { 184 PRINT( std::cerr << "current is deleted" << std::endl; ) 185 selected[ mangleName ] = current; 186 } else { 187 PRINT( 188 std::cerr << "marking ambiguous" << std::endl; 189 ) 190 mapPlace->second.isAmbiguous = true; 191 } 181 192 } else { 182 193 PRINT( … … 298 309 // it's okay for the aggregate expression to have reference type -- cast it to the base type to treat the aggregate as the referenced value 299 310 Expression* aggrExpr = alt.expr->clone(); 300 alt.env.apply( aggrExpr-> get_result());301 Type * aggrType = aggrExpr-> get_result();311 alt.env.apply( aggrExpr->result ); 312 Type * aggrType = aggrExpr->result; 302 313 if ( dynamic_cast< ReferenceType * >( aggrType ) ) { 303 314 aggrType = aggrType->stripReferences(); … … 305 316 } 306 317 307 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr-> get_result()) ) {318 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->result ) ) { 308 319 addAggMembers( structInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" ); 309 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr-> get_result()) ) {320 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->result ) ) { 310 321 addAggMembers( unionInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" ); 311 322 } // if … … 317 328 aggInst->lookup( name, members ); 318 329 319 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { 320 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) { 321 alternatives.push_back( Alternative( new MemberExpr( dwt, expr->clone() ), env, newCost ) ); 322 renameTypes( alternatives.back().expr ); 323 addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression. 330 for ( Declaration * decl : members ) { 331 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( decl ) ) { 332 // addAnonAlternatives uses vector::push_back, which invalidates references to existing elements, so 333 // can't construct in place and use vector::back 334 Alternative newAlt( new MemberExpr( dwt, expr->clone() ), env, newCost ); 335 renameTypes( newAlt.expr ); 336 addAnonConversions( newAlt ); // add anonymous member interpretations whenever an aggregate value type is seen as a member expression. 337 alternatives.push_back( std::move(newAlt) ); 324 338 } else { 325 339 assert( false ); … … 331 345 if ( ConstantExpr * constantExpr = dynamic_cast< ConstantExpr * >( member ) ) { 332 346 // get the value of the constant expression as an int, must be between 0 and the length of the tuple type to have meaning 333 // xxx - this should be improved by memoizing the value of constant exprs 334 // during parsing and reusing that information here. 335 std::stringstream ss( constantExpr->get_constant()->get_value() ); 336 int val = 0; 347 auto val = constantExpr->intValue(); 337 348 std::string tmp; 338 if ( ss >> val && ! (ss >> tmp) ) { 339 if ( val >= 0 && (unsigned int)val < tupleType->size() ) { 340 alternatives.push_back( Alternative( new TupleIndexExpr( expr, val ), env, newCost ) ); 341 } // if 349 if ( val >= 0 && (unsigned long long)val < tupleType->size() ) { 350 alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) ); 342 351 } // if 343 } else if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( member ) ) {344 // xxx - temporary hack until 0/1 are int constants345 if ( nameExpr->get_name() == "0" || nameExpr->get_name() == "1" ) {346 std::stringstream ss( nameExpr->get_name() );347 int val;348 ss >> val;349 alternatives.push_back( Alternative( new TupleIndexExpr( expr, val ), env, newCost ) );350 }351 352 } // if 352 353 } … … 435 436 return Cost::infinity; 436 437 } 438 } 439 if ( DefaultArgExpr * def = dynamic_cast< DefaultArgExpr * >( *actualExpr ) ) { 440 // default arguments should be free - don't include conversion cost. 441 // Unwrap them here because they are not relevant to the rest of the system. 442 *actualExpr = def->expr; 443 ++formal; 444 continue; 437 445 } 438 446 Type * formalType = (*formal)->get_type(); … … 604 612 ConstantExpr* getDefaultValue( Initializer* init ) { 605 613 if ( SingleInit* si = dynamic_cast<SingleInit*>( init ) ) { 606 if ( CastExpr* ce = dynamic_cast<CastExpr*>( si->get_value() ) ) { 607 return dynamic_cast<ConstantExpr*>( ce->get_arg() ); 614 if ( CastExpr* ce = dynamic_cast<CastExpr*>( si->value ) ) { 615 return dynamic_cast<ConstantExpr*>( ce->arg ); 616 } else { 617 return dynamic_cast<ConstantExpr*>( si->value ); 608 618 } 609 619 } … … 866 876 indexer ) ) { 867 877 results.emplace_back( 868 i, cnstExpr, move(env), move(need), move(have),878 i, new DefaultArgExpr( cnstExpr ), move(env), move(need), move(have), 869 879 move(openVars), nextArg, nTuples ); 870 880 } … … 1058 1068 funcFinder.findWithAdjustment( untypedExpr->function ); 1059 1069 // if there are no function alternatives, then proceeding is a waste of time. 1070 // xxx - findWithAdjustment throws, so this check and others like it shouldn't be necessary. 1060 1071 if ( funcFinder.alternatives.empty() ) return; 1061 1072 … … 1085 1096 argExpansions.emplace_back(); 1086 1097 auto& argE = argExpansions.back(); 1087 argE.reserve( arg.alternatives.size() );1098 // argE.reserve( arg.alternatives.size() ); 1088 1099 1089 1100 for ( const Alternative& actual : arg ) { … … 1108 1119 std::back_inserter( candidates ) ); 1109 1120 } 1110 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr-> get_result()->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer)1111 if ( const EqvClass *eqvClass = func->env.lookup( typeInst-> get_name()) ) {1121 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->result->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer) 1122 if ( const EqvClass *eqvClass = func->env.lookup( typeInst->name ) ) { 1112 1123 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass->type ) ) { 1113 1124 Alternative newFunc( *func ); … … 1364 1375 Cost cost = Cost::zero; 1365 1376 Expression * newExpr = data.combine( cost ); 1366 alternatives.push_back( Alternative( newExpr, env, Cost::zero, cost ) ); 1377 1378 // addAnonAlternatives uses vector::push_back, which invalidates references to existing elements, so 1379 // can't construct in place and use vector::back 1380 Alternative newAlt( newExpr, env, Cost::zero, cost ); 1367 1381 PRINT( 1368 1382 std::cerr << "decl is "; … … 1373 1387 std::cerr << std::endl; 1374 1388 ) 1375 renameTypes( alternatives.back().expr ); 1376 addAnonConversions( alternatives.back() ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression. 1389 renameTypes( newAlt.expr ); 1390 addAnonConversions( newAlt ); // add anonymous member interpretations whenever an aggregate value type is seen as a name expression. 1391 alternatives.push_back( std::move(newAlt) ); 1377 1392 } // for 1378 1393 } … … 1741 1756 assertf( false, "AlternativeFinder should never see a DeletedExpr." ); 1742 1757 } 1758 1759 void AlternativeFinder::Finder::postvisit( GenericExpr * ) { 1760 assertf( false, "_Generic is not yet supported." ); 1761 } 1743 1762 } // namespace ResolvExpr 1744 1763 -
src/ResolvExpr/CommonType.cc
r0182bfa r28f3a19 24 24 #include "SynTree/Type.h" // for BasicType, BasicType::Kind::... 25 25 #include "SynTree/Visitor.h" // for Visitor 26 #include "Unify.h" // for unifyExact, bindVar,WidenMode26 #include "Unify.h" // for unifyExact, WidenMode 27 27 #include "typeops.h" // for isFtype 28 28 … … 176 176 } 177 177 178 static const BasicType::Kind combinedType[ BasicType::NUMBER_OF_BASIC_TYPES][ BasicType::NUMBER_OF_BASIC_TYPES ] =178 static const BasicType::Kind combinedType[][ BasicType::NUMBER_OF_BASIC_TYPES ] = 179 179 { 180 /* Bool Char SignedChar UnsignedChar ShortSignedInt ShortUnsignedInt SignedInt UnsignedInt LongSignedInt LongUnsignedInt LongLongSignedInt LongLongUnsignedInt Float Double LongDouble FloatComplex DoubleComplex LongDoubleComplex FloatImaginary DoubleImaginary LongDoubleImaginary SignedInt128 UnsignedInt128 */ 181 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, }, 182 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, }, 183 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, }, 184 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, }, 185 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, }, 186 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, }, 187 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, }, 188 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, }, 189 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, }, 190 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, }, 191 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, }, 192 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, }, 193 /* 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, BasicType::Float, BasicType::Float, }, 194 /* 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, BasicType::Double, BasicType::Double, }, 195 /* 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, BasicType::LongDouble, BasicType::LongDouble, }, 196 /* 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, BasicType::FloatComplex, BasicType::FloatComplex, }, 197 /* 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, BasicType::DoubleComplex, BasicType::DoubleComplex, }, 198 /* 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, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, }, 199 /* 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, BasicType::FloatImaginary, BasicType::FloatImaginary, }, 200 /* 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, BasicType::DoubleImaginary, BasicType::DoubleImaginary, }, 201 /* 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 }, 202 /* SignedInt128 */ { BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::SignedInt128, BasicType::UnsignedInt128, }, 203 /* UnsignedInt128 */ { BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::UnsignedInt128, BasicType::UnsignedInt128, }, 180 /* Bool Char SignedChar UnsignedChar ShortSignedInt ShortUnsignedInt SignedInt UnsignedInt LongSignedInt LongUnsignedInt LongLongSignedInt LongLongUnsignedInt Float Double LongDouble FloatComplex DoubleComplex LongDoubleComplex FloatImaginary DoubleImaginary LongDoubleImaginary SignedInt128 UnsignedInt128 Float80 Float128 */ 181 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128 }, 182 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128 }, 183 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128 }, 184 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128 }, 185 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128 }, 186 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128 }, 187 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128 }, 188 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128 }, 189 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128 }, 190 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128 }, 191 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128 }, 192 /* 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, BasicType::SignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128 }, 193 /* 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, BasicType::Float, BasicType::Float, BasicType::Float80, BasicType::Float128 }, 194 /* 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, BasicType::Double, BasicType::Double, BasicType::Float80, BasicType::Float128 }, 195 /* 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, BasicType::LongDouble, BasicType::LongDouble, BasicType::BasicType::LongDouble, BasicType::Float128 }, 196 /* 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, BasicType::FloatComplex, BasicType::FloatComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, }, 197 /* 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, BasicType::DoubleComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex }, 198 /* 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, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, }, 199 /* 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, BasicType::FloatImaginary, BasicType::FloatImaginary, BasicType::LongDoubleImaginary, BasicType::LongDoubleImaginary, }, 200 /* 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, BasicType::DoubleImaginary, BasicType::DoubleImaginary, BasicType::LongDoubleImaginary, BasicType::LongDoubleImaginary, }, 201 /* 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, BasicType::LongDoubleImaginary, BasicType::LongDoubleImaginary, }, 202 /* SignedInt128 */ { BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::SignedInt128, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::SignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128, }, 203 /* UnsignedInt128 */ { BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::UnsignedInt128, BasicType::UnsignedInt128, BasicType::Float80, BasicType::Float128, }, 204 /* Float80 */ { BasicType::Float80, BasicType::Float80, BasicType::Float80, BasicType::Float80, BasicType::Float80, BasicType::Float80, BasicType::Float80, BasicType::Float80, BasicType::Float80, BasicType::Float80, BasicType::Float80, BasicType::Float80, BasicType::Float80, BasicType::Float80, BasicType::LongDouble, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::Float80, BasicType::Float80, BasicType::Float80, BasicType::Float128 }, 205 /* Float128 */ { BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::LongDoubleComplex, BasicType::Float128, BasicType::Float128, BasicType::Float128, BasicType::Float128 }, 204 206 }; 207 static_assert( 208 sizeof(combinedType)/sizeof(combinedType[0][0]) == BasicType::NUMBER_OF_BASIC_TYPES*BasicType::NUMBER_OF_BASIC_TYPES, 209 "Each basic type kind should have a corresponding row in the combined type matrix" 210 ); 205 211 206 212 CommonType::CommonType( Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars ) … … 232 238 AssertionSet need, have; 233 239 WidenMode widen( widenFirst, widenSecond ); 234 if ( entry != openVars.end() && ! bindVar(var, voidPointer->get_base(), entry->second, env, need, have, openVars, widen, indexer ) ) return;240 if ( entry != openVars.end() && ! env.bindVar(var, voidPointer->get_base(), entry->second, need, have, openVars, widen, indexer ) ) return; 235 241 } 236 242 } -
src/ResolvExpr/ConversionCost.cc
r0182bfa r28f3a19 229 229 */ 230 230 231 static const int costMatrix[ BasicType::NUMBER_OF_BASIC_TYPES ][ BasicType::NUMBER_OF_BASIC_TYPES ] = { 232 /* Src \ Dest: Bool Char SChar UChar Short UShort Int UInt Long ULong LLong ULLong Float Double LDbl FCplex DCplex LDCplex FImag DImag LDImag I128, U128 */ 233 /* Bool */ { 0, 1, 1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 12, 13, 14, 12, 13, 14, -1, -1, -1, 10, 11, }, 234 /* Char */ { -1, 0, -1, 1, 2, 3, 4, 5, 5, 6, 7, 8, 11, 12, 13, 11, 12, 13, -1, -1, -1, 9, 10, }, 235 /* SChar */ { -1, -1, 0, 1, 2, 3, 4, 5, 5, 6, 7, 8, 11, 12, 13, 11, 12, 13, -1, -1, -1, 9, 10, }, 236 /* UChar */ { -1, -1, -1, 0, 1, 2, 3, 4, 4, 5, 6, 7, 10, 11, 12, 10, 11, 12, -1, -1, -1, 8, 9, }, 237 /* Short */ { -1, -1, -1, -1, 0, 1, 2, 3, 3, 4, 5, 6, 9, 10, 11, 9, 10, 11, -1, -1, -1, 7, 8, }, 238 /* UShort */{ -1, -1, -1, -1, -1, 0, 1, 2, 2, 3, 4, 5, 8, 9, 10, 8, 9, 10, -1, -1, -1, 6, 7, }, 239 /* Int */ { -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 3, 4, 7, 8, 9, 7, 8, 9, -1, -1, -1, 5, 6, }, 240 /* UInt */ { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, 6, 7, 8, 6, 7, 8, -1, -1, -1, 4, 5, }, 241 /* Long */ { -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 6, 7, 8, 6, 7, 8, -1, -1, -1, 4, 5, }, 242 /* ULong */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 5, 6, 7, 5, 6, 7, -1, -1, -1, 3, 4, }, 243 /* LLong */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 4, 5, 6, 4, 5, 6, -1, -1, -1, 2, 3, }, 244 /* ULLong */{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 4, 5, 3, 4, 5, -1, -1, -1, 1, 2, }, 245 246 /* Float */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 1, 2, 3, -1, -1, -1, -1, -1, }, 247 /* Double */{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, -1, 1, 2, -1, -1, -1, -1, -1, }, 248 /* LDbl */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, 1, -1, -1, -1, -1, -1, }, 249 /* FCplex */{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, -1, -1, -1, -1, -1, }, 250 /* DCplex */{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, }, 251 /* LDCplex */{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, }, 252 /* FImag */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 0, 1, 2, -1, -1, }, 253 /* DImag */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, -1, 0, 1, -1, -1, }, 254 /* LDImag */{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 0, -1, -1, }, 255 256 /* I128 */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 3, 4, 5, -1, -1, -1, 0, 1, }, 257 /* U128 */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 2, 3, 4, -1, -1, -1, -1, 0, }, 231 static const int costMatrix[][ BasicType::NUMBER_OF_BASIC_TYPES ] = { 232 /* Src \ Dest: Bool Char SChar UChar Short UShort Int UInt Long ULong LLong ULLong Float Double LDbl FCplex DCplex LDCplex FImag DImag LDImag I128, U128, F80, F128 */ 233 /* Bool */ { 0, 1, 1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 12, 13, 14, 12, 13, 14, -1, -1, -1, 10, 11, 14, 15}, 234 /* Char */ { -1, 0, -1, 1, 2, 3, 4, 5, 5, 6, 7, 8, 11, 12, 13, 11, 12, 13, -1, -1, -1, 9, 10, 13, 14}, 235 /* SChar */ { -1, -1, 0, 1, 2, 3, 4, 5, 5, 6, 7, 8, 11, 12, 13, 11, 12, 13, -1, -1, -1, 9, 10, 13, 14}, 236 /* UChar */ { -1, -1, -1, 0, 1, 2, 3, 4, 4, 5, 6, 7, 10, 11, 12, 10, 11, 12, -1, -1, -1, 8, 9, 12, 13}, 237 /* Short */ { -1, -1, -1, -1, 0, 1, 2, 3, 3, 4, 5, 6, 9, 10, 11, 9, 10, 11, -1, -1, -1, 7, 8, 11, 12}, 238 /* UShort */{ -1, -1, -1, -1, -1, 0, 1, 2, 2, 3, 4, 5, 8, 9, 10, 8, 9, 10, -1, -1, -1, 6, 7, 10, 11}, 239 /* Int */ { -1, -1, -1, -1, -1, -1, 0, 1, 1, 2, 3, 4, 7, 8, 9, 7, 8, 9, -1, -1, -1, 5, 6, 9, 10}, 240 /* UInt */ { -1, -1, -1, -1, -1, -1, -1, 0, -1, 1, 2, 3, 6, 7, 8, 6, 7, 8, -1, -1, -1, 4, 5, 8, 9}, 241 /* Long */ { -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 6, 7, 8, 6, 7, 8, -1, -1, -1, 4, 5, 8, 9}, 242 /* ULong */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 5, 6, 7, 5, 6, 7, -1, -1, -1, 3, 4, 7, 8}, 243 /* LLong */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 4, 5, 6, 4, 5, 6, -1, -1, -1, 2, 3, 6, 7}, 244 /* ULLong */{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 4, 5, 3, 4, 5, -1, -1, -1, 1, 2, 5, 6}, 245 246 /* Float */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 1, 2, 3, -1, -1, -1, -1, -1, 2, 3}, 247 /* Double */{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, -1, 1, 2, -1, -1, -1, -1, -1, 1, 2}, 248 /* LDbl */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, 1, -1, -1, -1, -1, -1, -1, 1}, 249 /* FCplex */{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, -1, -1, -1, -1, -1, -1, -1}, 250 /* DCplex */{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, -1, -1, -1, -1, -1, -1, -1}, 251 /* LDCplex */{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1}, 252 /* FImag */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 0, 1, 2, -1, -1, -1, -1}, 253 /* DImag */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, -1, 0, 1, -1, -1, -1, -1}, 254 /* LDImag */{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 0, -1, -1, -1, -1}, 255 256 /* I128 */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 3, 4, 3, 4, 5, -1, -1, -1, 0, 1, 4, 4}, 257 /* U128 */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 2, 3, 4, -1, -1, -1, -1, 0, 3, 3}, 258 259 /* F80 */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, -1, 0, 1}, 260 /* F128 */ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1, 0}, 258 261 }; 262 static_assert( 263 sizeof(costMatrix)/sizeof(costMatrix[0][0]) == BasicType::NUMBER_OF_BASIC_TYPES*BasicType::NUMBER_OF_BASIC_TYPES, 264 "Each basic type kind should have a corresponding row in the cost matrix" 265 ); 266 259 267 260 268 void ConversionCost::postvisit( VoidType * ) { -
src/ResolvExpr/ExplodedActual.h
r0182bfa r28f3a19 31 31 32 32 ExplodedActual() : env(), cost(Cost::zero), exprs() {} 33 34 33 ExplodedActual( const Alternative& actual, const SymTab::Indexer& indexer ); 34 ExplodedActual(ExplodedActual&&) = default; 35 ExplodedActual& operator= (ExplodedActual&&) = default; 35 36 }; 36 37 } -
src/ResolvExpr/Resolver.cc
r0182bfa r28f3a19 211 211 if ( findDeletedExpr( choice.expr ) ) { 212 212 trace( choice.expr ); 213 SemanticError( choice.expr, "Unique best alternative includes deleted identifier in " );213 SemanticError( untyped->location, choice.expr, "Unique best alternative includes deleted identifier in " ); 214 214 } 215 215 alt = std::move( choice ); … … 246 246 247 247 auto untyped = new CastExpr{ expr }; // cast to void 248 untyped->location = expr->location; 248 249 249 250 // set up and resolve expression cast to void … … 271 272 void findSingleExpression( Expression *& untyped, Type * type, const SymTab::Indexer & indexer ) { 272 273 assert( untyped && type ); 274 // transfer location to generated cast for error purposes 275 CodeLocation location = untyped->location; 273 276 untyped = new CastExpr( untyped, type ); 277 untyped->location = location; 274 278 findSingleExpression( untyped, indexer ); 275 279 removeExtraneousCast( untyped, indexer ); … … 574 578 575 579 // Make sure we don't widen any existing bindings 576 for ( auto & i : resultEnv ) { 577 i.allowWidening = false; 578 } 579 580 resultEnv.forbidWidening(); 581 580 582 // Find any unbound type variables 581 583 resultEnv.extractOpenVars( openVars ); -
src/ResolvExpr/Resolver.h
r0182bfa r28f3a19 36 36 void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer ); 37 37 void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer ); 38 /// Searches expr and returns the first DeletedExpr found, otherwise nullptr 39 DeletedExpr * findDeletedExpr( Expression * expr ); 38 40 } // namespace ResolvExpr 39 41 -
src/ResolvExpr/TypeEnvironment.cc
r0182bfa r28f3a19 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:19:47 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sun May 17 12:23:36 201513 // Update Count : 311 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Mon Jun 18 11:58:00 2018 13 // Update Count : 4 14 14 // 15 15 … … 24 24 #include "SynTree/Type.h" // for Type, FunctionType, Type::Fora... 25 25 #include "SynTree/TypeSubstitution.h" // for TypeSubstitution 26 #include "Tuples/Tuples.h" // for isTtype 26 27 #include "TypeEnvironment.h" 28 #include "typeops.h" // for occurs 29 #include "Unify.h" // for unifyInexact 27 30 28 31 namespace ResolvExpr { … … 46 49 47 50 void EqvClass::initialize( const EqvClass &src, EqvClass &dest ) { 51 initialize( src, dest, src.type ); 52 } 53 54 void EqvClass::initialize( const EqvClass &src, EqvClass &dest, const Type *ty ) { 48 55 dest.vars = src.vars; 49 dest.type = maybeClone( src.type);56 dest.type = maybeClone( ty ); 50 57 dest.allowWidening = src.allowWidening; 51 58 dest.data = src.data; 52 59 } 53 60 54 EqvClass::EqvClass() : type( 0), allowWidening( true ) {61 EqvClass::EqvClass() : type( nullptr ), allowWidening( true ) { 55 62 } 56 63 57 64 EqvClass::EqvClass( const EqvClass &other ) { 58 65 initialize( other, *this ); 66 } 67 68 EqvClass::EqvClass( const EqvClass &other, const Type *ty ) { 69 initialize( other, *this, ty ); 70 } 71 72 EqvClass::EqvClass( EqvClass &&other ) 73 : vars{std::move(other.vars)}, type{other.type}, 74 allowWidening{std::move(other.allowWidening)}, data{std::move(other.data)} { 75 other.type = nullptr; 59 76 } 60 77 … … 64 81 return *this; 65 82 } 83 84 EqvClass &EqvClass::operator=( EqvClass &&other ) { 85 if ( this == &other ) return *this; 86 87 vars = std::move(other.vars); 88 type = other.type; 89 allowWidening = std::move(other.allowWidening); 90 data = std::move(other.data); 91 92 return *this; 93 } 94 95 void EqvClass::set_type( Type* ty ) { type = ty; } 66 96 67 97 void EqvClass::print( std::ostream &os, Indenter indent ) const { … … 81 111 const EqvClass* TypeEnvironment::lookup( const std::string &var ) const { 82 112 for ( std::list< EqvClass >::const_iterator i = env.begin(); i != env.end(); ++i ) { 83 if ( i->vars.find( var ) != i->vars.end() ) { 84 /// std::cout << var << " is in class "; 85 /// i->print( std::cout ); 86 return &*i; 87 } 88 /// std::cout << var << " is not in class "; 89 /// i->print( std::cout ); 113 if ( i->vars.find( var ) != i->vars.end() ) return &*i; 90 114 } // for 91 115 return nullptr; … … 105 129 } 106 130 107 void TypeEnvironment::add( const EqvClass &eqvClass ) {108 filterOverlappingClasses( env, eqvClass );109 env.push_back( eqvClass );110 }111 112 131 void TypeEnvironment::add( EqvClass &&eqvClass ) { 113 132 filterOverlappingClasses( env, eqvClass ); … … 120 139 newClass.vars.insert( (*i)->get_name() ); 121 140 newClass.data = TypeDecl::Data{ (*i) }; 122 env.push_back( newClass);141 env.push_back( std::move(newClass) ); 123 142 } // for 124 143 } … … 134 153 // transition to TypeSubstitution 135 154 newClass.data = TypeDecl::Data{ TypeDecl::Dtype, false }; 136 add( newClass);155 add( std::move(newClass) ); 137 156 } 138 157 } … … 141 160 for ( std::list< EqvClass >::const_iterator theClass = env.begin(); theClass != env.end(); ++theClass ) { 142 161 for ( std::set< std::string >::const_iterator theVar = theClass->vars.begin(); theVar != theClass->vars.end(); ++theVar ) { 143 /// std::cerr << "adding " << *theVar;144 162 if ( theClass->type ) { 145 /// std::cerr << " bound to ";146 /// theClass->type->print( std::cerr );147 /// std::cerr << std::endl;148 163 sub.add( *theVar, theClass->type ); 149 164 } else if ( theVar != theClass->vars.begin() ) { 150 165 TypeInstType *newTypeInst = new TypeInstType( Type::Qualifiers(), *theClass->vars.begin(), theClass->data.kind == TypeDecl::Ftype ); 151 /// std::cerr << " bound to variable " << *theClass->vars.begin() << std::endl;152 166 sub.add( *theVar, newTypeInst ); 153 167 } // if 154 168 } // for 155 169 } // for 156 /// std::cerr << "input env is:" << std::endl;157 /// print( std::cerr, 8 );158 /// std::cerr << "sub is:" << std::endl;159 /// sub.print( std::cerr, 8 );160 170 sub.normalize(); 161 171 } 162 172 163 173 void TypeEnvironment::print( std::ostream &os, Indenter indent ) const { 164 for ( std::list< EqvClass >::const_iterator i = env.begin(); i != env.end(); ++i) {165 i->print( os, indent );174 for ( const EqvClass & theClass : env ) { 175 theClass.print( os, indent ); 166 176 } // for 167 177 } … … 169 179 std::list< EqvClass >::iterator TypeEnvironment::internal_lookup( const std::string &var ) { 170 180 for ( std::list< EqvClass >::iterator i = env.begin(); i != env.end(); ++i ) { 171 if ( i->vars.find( var ) == i->vars.end() ) { 172 return i; 173 } // if 181 if ( i->vars.count( var ) ) return i; 174 182 } // for 175 183 return env.end(); … … 178 186 void TypeEnvironment::simpleCombine( const TypeEnvironment &second ) { 179 187 env.insert( env.end(), second.env.begin(), second.env.end() ); 180 }181 182 void TypeEnvironment::combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) ) {183 TypeEnvironment secondCopy( second );184 for ( std::list< EqvClass >::iterator firstClass = env.begin(); firstClass != env.end(); ++firstClass ) {185 EqvClass &newClass = *firstClass;186 std::set< std::string > newVars;187 for ( std::set< std::string >::const_iterator var = firstClass->vars.begin(); var != firstClass->vars.end(); ++var ) {188 std::list< EqvClass >::iterator secondClass = secondCopy.internal_lookup( *var );189 if ( secondClass != secondCopy.env.end() ) {190 newVars.insert( secondClass->vars.begin(), secondClass->vars.end() );191 if ( secondClass->type ) {192 if ( newClass.type ) {193 newClass.type = combineFunc( newClass.type, secondClass->type );194 newClass.allowWidening = newClass.allowWidening && secondClass->allowWidening;195 } else {196 newClass.type = secondClass->type->clone();197 newClass.allowWidening = secondClass->allowWidening;198 } // if199 } // if200 secondCopy.env.erase( secondClass );201 } // if202 } // for203 newClass.vars.insert( newVars.begin(), newVars.end() );204 } // for205 for ( std::list< EqvClass >::iterator secondClass = secondCopy.env.begin(); secondClass != secondCopy.env.end(); ++secondClass ) {206 env.push_back( *secondClass );207 } // for208 188 } 209 189 … … 227 207 } 228 208 209 bool isFtype( Type *type ) { 210 if ( dynamic_cast< FunctionType* >( type ) ) { 211 return true; 212 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) { 213 return typeInst->get_isFtype(); 214 } // if 215 return false; 216 } 217 218 bool tyVarCompatible( const TypeDecl::Data & data, Type *type ) { 219 switch ( data.kind ) { 220 case TypeDecl::Dtype: 221 // to bind to an object type variable, the type must not be a function type. 222 // if the type variable is specified to be a complete type then the incoming 223 // type must also be complete 224 // xxx - should this also check that type is not a tuple type and that it's not a ttype? 225 return ! isFtype( type ) && (! data.isComplete || type->isComplete() ); 226 case TypeDecl::Ftype: 227 return isFtype( type ); 228 case TypeDecl::Ttype: 229 // ttype unifies with any tuple type 230 return dynamic_cast< TupleType * >( type ) || Tuples::isTtype( type ); 231 } // switch 232 return false; 233 } 234 235 bool TypeEnvironment::bindVar( TypeInstType *typeInst, Type *bindTo, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) { 236 237 // remove references from other, so that type variables can only bind to value types 238 bindTo = bindTo->stripReferences(); 239 OpenVarSet::const_iterator tyvar = openVars.find( typeInst->get_name() ); 240 assert( tyvar != openVars.end() ); 241 if ( ! tyVarCompatible( tyvar->second, bindTo ) ) { 242 return false; 243 } // if 244 if ( occurs( bindTo, typeInst->get_name(), *this ) ) { 245 return false; 246 } // if 247 auto curClass = internal_lookup( typeInst->get_name() ); 248 if ( curClass != env.end() ) { 249 if ( curClass->type ) { 250 Type *common = 0; 251 // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to 252 Type *newType = curClass->type->clone(); 253 newType->get_qualifiers() = typeInst->get_qualifiers(); 254 if ( unifyInexact( newType, bindTo, *this, need, have, openVars, widenMode & WidenMode( curClass->allowWidening, true ), indexer, common ) ) { 255 if ( common ) { 256 common->get_qualifiers() = Type::Qualifiers{}; 257 curClass->set_type( common ); 258 } // if 259 } else return false; 260 } else { 261 Type* newType = bindTo->clone(); 262 newType->get_qualifiers() = Type::Qualifiers{}; 263 curClass->set_type( newType ); 264 curClass->allowWidening = widenMode.widenFirst && widenMode.widenSecond; 265 } // if 266 } else { 267 EqvClass newClass; 268 newClass.vars.insert( typeInst->get_name() ); 269 newClass.type = bindTo->clone(); 270 newClass.type->get_qualifiers() = Type::Qualifiers(); 271 newClass.allowWidening = widenMode.widenFirst && widenMode.widenSecond; 272 newClass.data = data; 273 env.push_back( std::move(newClass) ); 274 } // if 275 return true; 276 } 277 278 bool TypeEnvironment::bindVarToVar( TypeInstType *var1, TypeInstType *var2, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) { 279 280 auto class1 = internal_lookup( var1->get_name() ); 281 auto class2 = internal_lookup( var2->get_name() ); 282 283 // exit early if variables already bound together 284 if ( class1 != env.end() && class1 == class2 ) { 285 class1->allowWidening &= widenMode; 286 return true; 287 } 288 289 bool widen1 = false, widen2 = false; 290 const Type *type1 = nullptr, *type2 = nullptr; 291 292 // check for existing bindings, perform occurs check 293 if ( class1 != env.end() ) { 294 if ( class1->type ) { 295 if ( occurs( class1->type, var2->get_name(), *this ) ) return false; 296 type1 = class1->type; 297 } // if 298 widen1 = widenMode.widenFirst && class1->allowWidening; 299 } // if 300 if ( class2 != env.end() ) { 301 if ( class2->type ) { 302 if ( occurs( class2->type, var1->get_name(), *this ) ) return false; 303 type2 = class2->type; 304 } // if 305 widen2 = widenMode.widenSecond && class2->allowWidening; 306 } // if 307 308 if ( type1 && type2 ) { 309 // both classes bound, merge if bound types can be unified 310 Type *newType1 = type1->clone(), *newType2 = type2->clone(); 311 WidenMode newWidenMode{ widen1, widen2 }; 312 Type *common = 0; 313 if ( unifyInexact( newType1, newType2, *this, need, have, openVars, newWidenMode, indexer, common ) ) { 314 class1->vars.insert( class2->vars.begin(), class2->vars.end() ); 315 class1->allowWidening = widen1 && widen2; 316 if ( common ) { 317 common->get_qualifiers() = Type::Qualifiers{}; 318 class1->set_type( common ); 319 } 320 env.erase( class2 ); 321 } else return false; 322 } else if ( class1 != env.end() && class2 != env.end() ) { 323 // both classes exist, at least one unbound, merge unconditionally 324 if ( type1 ) { 325 class1->vars.insert( class2->vars.begin(), class2->vars.end() ); 326 class1->allowWidening = widen1; 327 env.erase( class2 ); 328 } else { 329 class2->vars.insert( class1->vars.begin(), class1->vars.end() ); 330 class2->allowWidening = widen2; 331 env.erase( class1 ); 332 } // if 333 } else if ( class1 != env.end() ) { 334 // var2 unbound, add to class1 335 class1->vars.insert( var2->get_name() ); 336 class1->allowWidening = widen1; 337 } else if ( class2 != env.end() ) { 338 // var1 unbound, add to class2 339 class2->vars.insert( var1->get_name() ); 340 class2->allowWidening = widen2; 341 } else { 342 // neither var bound, create new class 343 EqvClass newClass; 344 newClass.vars.insert( var1->get_name() ); 345 newClass.vars.insert( var2->get_name() ); 346 newClass.allowWidening = widen1 && widen2; 347 newClass.data = data; 348 env.push_back( std::move(newClass) ); 349 } // if 350 return true; 351 } 352 353 void TypeEnvironment::forbidWidening() { 354 for ( EqvClass& c : env ) c.allowWidening = false; 355 } 356 229 357 std::ostream & operator<<( std::ostream & out, const TypeEnvironment & env ) { 230 358 env.print( out ); -
src/ResolvExpr/TypeEnvironment.h
r0182bfa r28f3a19 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:24:58 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jul 22 09:35:45 201713 // Update Count : 311 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Mon Jun 18 11:58:00 2018 13 // Update Count : 4 14 14 // 15 15 … … 21 21 #include <set> // for set 22 22 #include <string> // for string 23 #include <utility> // for move, swap 24 25 #include "WidenMode.h" // for WidenMode 23 26 24 27 #include "SynTree/Declaration.h" // for TypeDecl::Data, DeclarationWit... … … 77 80 78 81 void initialize( const EqvClass &src, EqvClass &dest ); 82 void initialize( const EqvClass &src, EqvClass &dest, const Type *ty ); 79 83 EqvClass(); 80 84 EqvClass( const EqvClass &other ); 85 EqvClass( const EqvClass &other, const Type *ty ); 86 EqvClass( EqvClass &&other ); 81 87 EqvClass &operator=( const EqvClass &other ); 88 EqvClass &operator=( EqvClass &&other ); 82 89 void print( std::ostream &os, Indenter indent = {} ) const; 90 91 /// Takes ownership of `ty`, freeing old `type` 92 void set_type(Type* ty); 83 93 }; 84 94 … … 86 96 public: 87 97 const EqvClass* lookup( const std::string &var ) const; 88 void add( const EqvClass &eqvClass );98 private: 89 99 void add( EqvClass &&eqvClass ); 100 public: 90 101 void add( const Type::ForallList &tyDecls ); 91 102 void add( const TypeSubstitution & sub ); … … 95 106 bool isEmpty() const { return env.empty(); } 96 107 void print( std::ostream &os, Indenter indent = {} ) const; 97 void combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) );108 // void combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) ); 98 109 void simpleCombine( const TypeEnvironment &second ); 99 110 void extractOpenVars( OpenVarSet &openVars ) const; … … 104 115 void addActual( const TypeEnvironment& actualEnv, OpenVarSet& openVars ); 105 116 106 typedef std::list< EqvClass >::iterator iterator; 107 iterator begin() { return env.begin(); } 108 iterator end() { return env.end(); } 109 typedef std::list< EqvClass >::const_iterator const_iterator; 110 const_iterator begin() const { return env.begin(); } 111 const_iterator end() const { return env.end(); } 117 /// Binds the type class represented by `typeInst` to the type `bindTo`; will add 118 /// the class if needed. Returns false on failure. 119 bool bindVar( TypeInstType *typeInst, Type *bindTo, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ); 120 121 /// Binds the type classes represented by `var1` and `var2` together; will add 122 /// one or both classes if needed. Returns false on failure. 123 bool bindVarToVar( TypeInstType *var1, TypeInstType *var2, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ); 124 125 /// Disallows widening for all bindings in the environment 126 void forbidWidening(); 127 128 using iterator = std::list< EqvClass >::const_iterator; 129 iterator begin() const { return env.begin(); } 130 iterator end() const { return env.end(); } 131 112 132 private: 113 133 std::list< EqvClass > env; 134 114 135 std::list< EqvClass >::iterator internal_lookup( const std::string &var ); 115 136 }; -
src/ResolvExpr/Unify.cc
r0182bfa r28f3a19 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:27:10 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Mar 16 16:22:54 201713 // Update Count : 4 211 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Mon Jun 18 11:58:00 2018 13 // Update Count : 43 14 14 // 15 15 … … 122 122 } 123 123 124 bool isFtype( Type *type ) {125 if ( dynamic_cast< FunctionType* >( type ) ) {126 return true;127 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( type ) ) {128 return typeInst->get_isFtype();129 } // if130 return false;131 }132 133 bool tyVarCompatible( const TypeDecl::Data & data, Type *type ) {134 switch ( data.kind ) {135 case TypeDecl::Dtype:136 // to bind to an object type variable, the type must not be a function type.137 // if the type variable is specified to be a complete type then the incoming138 // type must also be complete139 // xxx - should this also check that type is not a tuple type and that it's not a ttype?140 return ! isFtype( type ) && (! data.isComplete || type->isComplete() );141 case TypeDecl::Ftype:142 return isFtype( type );143 case TypeDecl::Ttype:144 // ttype unifies with any tuple type145 return dynamic_cast< TupleType * >( type ) || Tuples::isTtype( type );146 } // switch147 return false;148 }149 150 bool bindVar( TypeInstType *typeInst, Type *other, const TypeDecl::Data & data, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) {151 // remove references from other, so that type variables can only bind to value types152 other = other->stripReferences();153 OpenVarSet::const_iterator tyvar = openVars.find( typeInst->get_name() );154 assert( tyvar != openVars.end() );155 if ( ! tyVarCompatible( tyvar->second, other ) ) {156 return false;157 } // if158 if ( occurs( other, typeInst->get_name(), env ) ) {159 return false;160 } // if161 if ( const EqvClass *curClass = env.lookup( typeInst->get_name() ) ) {162 if ( curClass->type ) {163 Type *common = 0;164 // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to165 Type* newType = curClass->type->clone();166 newType->get_qualifiers() = typeInst->get_qualifiers();167 if ( unifyInexact( newType, other, env, needAssertions, haveAssertions, openVars, widenMode & WidenMode( curClass->allowWidening, true ), indexer, common ) ) {168 if ( common ) {169 common->get_qualifiers() = Type::Qualifiers();170 EqvClass newClass = *curClass;171 newClass.type = common;172 env.add( std::move(newClass) );173 } // if174 return true;175 } else {176 return false;177 } // if178 } else {179 EqvClass newClass = *curClass;180 newClass.type = other->clone();181 newClass.type->get_qualifiers() = Type::Qualifiers();182 newClass.allowWidening = widenMode.widenFirst && widenMode.widenSecond;183 env.add( std::move(newClass) );184 } // if185 } else {186 EqvClass newClass;187 newClass.vars.insert( typeInst->get_name() );188 newClass.type = other->clone();189 newClass.type->get_qualifiers() = Type::Qualifiers();190 newClass.allowWidening = widenMode.widenFirst && widenMode.widenSecond;191 newClass.data = data;192 env.add( newClass );193 } // if194 return true;195 }196 197 bool bindVarToVar( TypeInstType *var1, TypeInstType *var2, const TypeDecl::Data & data, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) {198 bool result = true;199 const EqvClass *class1 = env.lookup( var1->get_name() );200 const EqvClass *class2 = env.lookup( var2->get_name() );201 bool widen1 = false, widen2 = false;202 Type *type1 = nullptr, *type2 = nullptr;203 204 if ( class1 ) {205 if ( class1->type ) {206 if ( occurs( class1->type, var2->get_name(), env ) ) {207 return false;208 } // if209 type1 = class1->type->clone();210 } // if211 widen1 = widenMode.widenFirst && class1->allowWidening;212 } // if213 if ( class2 ) {214 if ( class2->type ) {215 if ( occurs( class2->type, var1->get_name(), env ) ) {216 return false;217 } // if218 type2 = class2->type->clone();219 } // if220 widen2 = widenMode.widenSecond && class2->allowWidening;221 } // if222 223 if ( type1 && type2 ) {224 // std::cerr << "has type1 && type2" << std::endl;225 WidenMode newWidenMode ( widen1, widen2 );226 Type *common = 0;227 if ( unifyInexact( type1, type2, env, needAssertions, haveAssertions, openVars, newWidenMode, indexer, common ) ) {228 EqvClass newClass1 = *class1;229 newClass1.vars.insert( class2->vars.begin(), class2->vars.end() );230 newClass1.allowWidening = widen1 && widen2;231 if ( common ) {232 common->get_qualifiers() = Type::Qualifiers();233 newClass1.type = common;234 } // if235 env.add( std::move(newClass1) );236 } else {237 result = false;238 } // if239 } else if ( class1 && class2 ) {240 if ( type1 ) {241 EqvClass newClass1 = *class1;242 newClass1.vars.insert( class2->vars.begin(), class2->vars.end() );243 newClass1.allowWidening = widen1;244 env.add( std::move(newClass1) );245 } else {246 EqvClass newClass2 = *class2;247 newClass2.vars.insert( class1->vars.begin(), class1->vars.end() );248 newClass2.allowWidening = widen2;249 env.add( std::move(newClass2) );250 } // if251 } else if ( class1 ) {252 EqvClass newClass1 = *class1;253 newClass1.vars.insert( var2->get_name() );254 newClass1.allowWidening = widen1;255 env.add( std::move(newClass1) );256 } else if ( class2 ) {257 EqvClass newClass2 = *class2;258 newClass2.vars.insert( var1->get_name() );259 newClass2.allowWidening = widen2;260 env.add( std::move(newClass2) );261 } else {262 EqvClass newClass;263 newClass.vars.insert( var1->get_name() );264 newClass.vars.insert( var2->get_name() );265 newClass.allowWidening = widen1 && widen2;266 newClass.data = data;267 env.add( newClass );268 } // if269 return result;270 }271 272 124 bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ) { 273 125 OpenVarSet closedVars; … … 307 159 308 160 if ( isopen1 && isopen2 && entry1->second == entry2->second ) { 309 result = bindVarToVar( var1, var2, entry1->second, env, needAssertions, haveAssertions, openVars, widenMode, indexer );161 result = env.bindVarToVar( var1, var2, entry1->second, needAssertions, haveAssertions, openVars, widenMode, indexer ); 310 162 } else if ( isopen1 ) { 311 result = bindVar( var1, type2, entry1->second, env, needAssertions, haveAssertions, openVars, widenMode, indexer );163 result = env.bindVar( var1, type2, entry1->second, needAssertions, haveAssertions, openVars, widenMode, indexer ); 312 164 } else if ( isopen2 ) { // TODO: swap widenMode values in call, since type positions are flipped? 313 result = bindVar( var2, type1, entry2->second, env, needAssertions, haveAssertions, openVars, widenMode, indexer );165 result = env.bindVar( var2, type1, entry2->second, needAssertions, haveAssertions, openVars, widenMode, indexer ); 314 166 } else { 315 167 PassVisitor<Unify> comparator( type2, env, needAssertions, haveAssertions, openVars, widenMode, indexer ); -
src/ResolvExpr/Unify.h
r0182bfa r28f3a19 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 13:09:04 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Jul 21 23:09:34 201713 // Update Count : 311 // Last Modified By : Aaron B. Moss 12 // Last Modified On : Mon Jun 18 11:58:00 2018 13 // Update Count : 4 14 14 // 15 15 … … 21 21 #include "SynTree/Declaration.h" // for TypeDecl, TypeDecl::Data 22 22 #include "TypeEnvironment.h" // for AssertionSet, OpenVarSet 23 #include "WidenMode.h" // for WidenMode 23 24 24 25 class Type; … … 29 30 30 31 namespace ResolvExpr { 31 struct WidenMode {32 WidenMode( bool widenFirst, bool widenSecond ): widenFirst( widenFirst ), widenSecond( widenSecond ) {}33 WidenMode &operator|=( const WidenMode &other ) { widenFirst |= other.widenFirst; widenSecond |= other.widenSecond; return *this; }34 WidenMode &operator&=( const WidenMode &other ) { widenFirst &= other.widenFirst; widenSecond &= other.widenSecond; return *this; }35 WidenMode operator|( const WidenMode &other ) { WidenMode newWM( *this ); newWM |= other; return newWM; }36 WidenMode operator&( const WidenMode &other ) { WidenMode newWM( *this ); newWM &= other; return newWM; }37 operator bool() { return widenFirst && widenSecond; }38 39 bool widenFirst : 1, widenSecond : 1;40 };41 42 bool bindVar( TypeInstType *typeInst, Type *other, const TypeDecl::Data & data, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer );43 32 bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ); 44 33 bool unify( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer, Type *&commonType ); 45 34 bool unifyExact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, OpenVarSet &openVars, const SymTab::Indexer &indexer ); 35 bool unifyInexact( Type *type1, Type *type2, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer, Type *&common ); 46 36 47 37 template< typename Iterator1, typename Iterator2 >
Note: See TracChangeset
for help on using the changeset viewer.