Changeset eba74ba for src/ResolvExpr/AlternativeFinder.cc
- Timestamp:
- May 25, 2018, 2:51:06 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- cdc4d43
- Parents:
- 3ef35bd (diff), 58e822a (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r3ef35bd reba74ba 689 689 const ExplodedArgs& args, std::vector<ArgPack>& results, std::size_t& genStart, 690 690 const SymTab::Indexer& indexer, unsigned nTuples = 0 ) { 691 if ( TupleType * tupleType = dynamic_cast<TupleType*>( formalType ) ) {691 if ( TupleType * tupleType = dynamic_cast<TupleType*>( formalType ) ) { 692 692 // formalType is a TupleType - group actuals into a TupleExpr 693 693 ++nTuples; 694 694 for ( Type* type : *tupleType ) { 695 695 // xxx - dropping initializer changes behaviour from previous, but seems correct 696 // ^^^ need to handle the case where a tuple has a default argument 696 697 if ( ! instantiateArgument( 697 698 type, nullptr, args, results, genStart, indexer, nTuples ) ) … … 704 705 } 705 706 return true; 706 } else if ( TypeInstType * ttype = Tuples::isTtype( formalType ) ) {707 } else if ( TypeInstType * ttype = Tuples::isTtype( formalType ) ) { 707 708 // formalType is a ttype, consumes all remaining arguments 708 709 // xxx - mixing default arguments with variadic?? … … 907 908 // consider only first exploded actual 908 909 Expression* expr = expl.exprs.front(); 909 Type* actualType = expr-> get_result()->clone();910 Type* actualType = expr->result->clone(); 910 911 911 912 PRINT( … … 938 939 ApplicationExpr *appExpr = new ApplicationExpr( func.expr->clone() ); 939 940 // sum cost and accumulate actuals 940 std::list<Expression*>& args = appExpr-> get_args();941 std::list<Expression*>& args = appExpr->args; 941 942 Cost cost = func.cost; 942 943 const ArgPack* pack = &result; … … 965 966 // add all type variables as open variables now so that those not used in the parameter 966 967 // list are still considered open. 967 funcEnv.add( funcType-> get_forall());968 969 if ( targetType && ! targetType->isVoid() && ! funcType-> get_returnVals().empty() ) {968 funcEnv.add( funcType->forall ); 969 970 if ( targetType && ! targetType->isVoid() && ! funcType->returnVals.empty() ) { 970 971 // attempt to narrow based on expected target type 971 Type * returnType = funcType-> get_returnVals().front()->get_type();972 Type * returnType = funcType->returnVals.front()->get_type(); 972 973 if ( ! unify( returnType, targetType, funcEnv, funcNeed, funcHave, funcOpenVars, 973 974 indexer ) ) { … … 982 983 std::size_t genStart = 0; 983 984 984 for ( DeclarationWithType* formal : funcType-> get_parameters()) {985 for ( DeclarationWithType* formal : funcType->parameters ) { 985 986 ObjectDecl* obj = strict_dynamic_cast< ObjectDecl* >( formal ); 986 987 if ( ! instantiateArgument( 987 obj-> get_type(), obj->get_init(), args, results, genStart, indexer ) )988 obj->type, obj->init, args, results, genStart, indexer ) ) 988 989 return; 989 990 } … … 1066 1067 void AlternativeFinder::Finder::postvisit( UntypedExpr *untypedExpr ) { 1067 1068 AlternativeFinder funcFinder( indexer, env ); 1068 funcFinder.findWithAdjustment( untypedExpr-> get_function());1069 funcFinder.findWithAdjustment( untypedExpr->function ); 1069 1070 // if there are no function alternatives, then proceeding is a waste of time. 1070 1071 if ( funcFinder.alternatives.empty() ) return; … … 1275 1276 AlternativeFinder finder( indexer, env ); 1276 1277 finder.targetType = toType; 1277 finder.findWithAdjustment( castExpr-> get_arg());1278 finder.findWithAdjustment( castExpr->arg ); 1278 1279 1279 1280 AltList candidates; … … 1282 1283 OpenVarSet openVars; 1283 1284 1285 alt.env.extractOpenVars( openVars ); 1286 1284 1287 // It's possible that a cast can throw away some values in a multiply-valued expression. (An example is a 1285 1288 // cast-to-void, which casts from one value to zero.) Figure out the prefix of the subexpression results 1286 1289 // that are cast directly. The candidate is invalid if it has fewer results than there are types to cast 1287 1290 // to. 1288 int discardedValues = alt.expr-> get_result()->size() - castExpr->get_result()->size();1291 int discardedValues = alt.expr->result->size() - castExpr->result->size(); 1289 1292 if ( discardedValues < 0 ) continue; 1290 1293 // xxx - may need to go into tuple types and extract relevant types and use unifyList. Note that currently, this does not 1291 1294 // allow casting a tuple to an atomic type (e.g. (int)([1, 2, 3])) 1292 1295 // unification run for side-effects 1293 unify( castExpr-> get_result(), alt.expr->get_result(), alt.env, needAssertions,1296 unify( castExpr->result, alt.expr->result, alt.env, needAssertions, 1294 1297 haveAssertions, openVars, indexer ); 1295 Cost thisCost = castCost( alt.expr-> get_result(), castExpr->get_result(), indexer,1298 Cost thisCost = castCost( alt.expr->result, castExpr->result, indexer, 1296 1299 alt.env ); 1297 1300 PRINT( … … 1706 1709 AlternativeFinder finder( indexer, env ); 1707 1710 finder.targetType = toType; 1708 finder.findWithAdjustment( initExpr-> get_expr());1711 finder.findWithAdjustment( initExpr->expr ); 1709 1712 for ( Alternative & alt : finder.get_alternatives() ) { 1710 1713 TypeEnvironment newEnv( alt.env ); … … 1713 1716 PRINT( 1714 1717 std::cerr << " @ " << toType << " " << initAlt.designation << std::endl; 1715 1718 ) 1716 1719 // It's possible that a cast can throw away some values in a multiply-valued expression. (An example is a 1717 1720 // cast-to-void, which casts from one value to zero.) Figure out the prefix of the subexpression results 1718 1721 // that are cast directly. The candidate is invalid if it has fewer results than there are types to cast 1719 1722 // to. 1720 int discardedValues = alt.expr-> get_result()->size() - toType->size();1723 int discardedValues = alt.expr->result->size() - toType->size(); 1721 1724 if ( discardedValues < 0 ) continue; 1722 1725 // xxx - may need to go into tuple types and extract relevant types and use unifyList. Note that currently, this does not 1723 1726 // allow casting a tuple to an atomic type (e.g. (int)([1, 2, 3])) 1724 1727 // unification run for side-effects 1725 unify( toType, alt.expr-> get_result(), newEnv, needAssertions, haveAssertions, openVars, indexer ); // xxx - do some inspecting on this line... why isn't result bound to initAlt.type??1726 1727 Cost thisCost = castCost( alt.expr-> get_result(), toType, indexer, newEnv );1728 unify( toType, alt.expr->result, newEnv, needAssertions, haveAssertions, openVars, indexer ); // xxx - do some inspecting on this line... why isn't result bound to initAlt.type?? 1729 1730 Cost thisCost = castCost( alt.expr->result, toType, indexer, newEnv ); 1728 1731 if ( thisCost != Cost::infinity ) { 1729 1732 // count one safe conversion for each value that is thrown away
Note: See TracChangeset
for help on using the changeset viewer.