- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r09f34a84 r9e23b446 41 41 #include "Common/utility.h" // for move, copy 42 42 #include "SymTab/Mangler.h" 43 #include "SymTab/Validate.h" // for validateType 43 44 #include "Tuples/Tuples.h" // for handleTupleAssignment 44 45 #include "InitTweak/InitTweak.h" // for getPointerBase … … 269 270 unsigned nextArg, unsigned tupleStart = 0, Cost cost = Cost::zero, 270 271 unsigned nextExpl = 0, unsigned explAlt = 0 ) 271 : parent(parent), expr( expr ), cost( cost ), env( std::move( env ) ), need( std::move( need ) ),272 have( std::move( have ) ), open( std::move( open ) ), nextArg( nextArg ), tupleStart( tupleStart ),272 : parent(parent), expr( expr ), cost( cost ), env( move( env ) ), need( move( need ) ), 273 have( move( have ) ), open( move( open ) ), nextArg( nextArg ), tupleStart( tupleStart ), 273 274 nextExpl( nextExpl ), explAlt( explAlt ) {} 274 275 … … 276 277 const ArgPack & o, ast::TypeEnvironment && env, ast::AssertionSet && need, 277 278 ast::AssertionSet && have, ast::OpenVarSet && open, unsigned nextArg, Cost added ) 278 : parent( o.parent ), expr( o.expr ), cost( o.cost + added ), env( std::move( env ) ),279 need( std::move( need ) ), have( std::move( have ) ), open( std::move( open ) ), nextArg( nextArg ),279 : parent( o.parent ), expr( o.expr ), cost( o.cost + added ), env( move( env ) ), 280 need( move( need ) ), have( move( have ) ), open( move( open ) ), nextArg( nextArg ), 280 281 tupleStart( o.tupleStart ), nextExpl( 0 ), explAlt( 0 ) {} 281 282 … … 301 302 // reset pack to appropriate tuple 302 303 std::vector< ast::ptr< ast::Expr > > exprv( exprs.begin(), exprs.end() ); 303 expr = new ast::TupleExpr{ expr->location, std::move( exprv ) };304 expr = new ast::TupleExpr{ expr->location, move( exprv ) }; 304 305 tupleStart = pack->tupleStart - 1; 305 306 parent = pack->parent; … … 404 405 newResult.open, symtab ) 405 406 ) { 406 finalResults.emplace_back( std::move( newResult ) );407 finalResults.emplace_back( move( newResult ) ); 407 408 } 408 409 … … 423 424 if ( expl.exprs.empty() ) { 424 425 results.emplace_back( 425 results[i], std::move( env ), copy( results[i].need ),426 copy( results[i].have ), std::move( open ), nextArg + 1, expl.cost );426 results[i], move( env ), copy( results[i].need ), 427 copy( results[i].have ), move( open ), nextArg + 1, expl.cost ); 427 428 428 429 continue; … … 431 432 // add new result 432 433 results.emplace_back( 433 i, expl.exprs.front(), std::move( env ), copy( results[i].need ),434 copy( results[i].have ), std::move( open ), nextArg + 1, nTuples,434 i, expl.exprs.front(), move( env ), copy( results[i].need ), 435 copy( results[i].have ), move( open ), nextArg + 1, nTuples, 435 436 expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); 436 437 } … … 444 445 // splice final results onto results 445 446 for ( std::size_t i = 0; i < finalResults.size(); ++i ) { 446 results.emplace_back( std::move( finalResults[i] ) );447 results.emplace_back( move( finalResults[i] ) ); 447 448 } 448 449 return ! finalResults.empty(); … … 478 479 479 480 results.emplace_back( 480 i, expr, std::move( env ), std::move( need ), std::move( have ), std::move( open ), nextArg,481 i, expr, move( env ), move( need ), move( have ), move( open ), nextArg, 481 482 nTuples, Cost::zero, nextExpl, results[i].explAlt ); 482 483 } … … 494 495 if ( unify( paramType, cnst->result, env, need, have, open, symtab ) ) { 495 496 results.emplace_back( 496 i, new ast::DefaultArgExpr{ cnst->location, cnst }, std::move( env ),497 std::move( need ), std::move( have ), std::move( open ), nextArg, nTuples );497 i, new ast::DefaultArgExpr{ cnst->location, cnst }, move( env ), 498 move( need ), move( have ), move( open ), nextArg, nTuples ); 498 499 } 499 500 } … … 516 517 if ( expl.exprs.empty() ) { 517 518 results.emplace_back( 518 results[i], std::move( env ), std::move( need ), std::move( have ), std::move( open ),519 results[i], move( env ), move( need ), move( have ), move( open ), 519 520 nextArg + 1, expl.cost ); 520 521 … … 538 539 // add new result 539 540 results.emplace_back( 540 i, expr, std::move( env ), std::move( need ), std::move( have ), std::move( open ),541 i, expr, move( env ), move( need ), move( have ), move( open ), 541 542 nextArg + 1, nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); 542 543 } … … 576 577 restructureCast( idx, toType->getComponent( i ), isGenerated ) ); 577 578 } 578 return new ast::TupleExpr{ arg->location, std::move( components ) };579 return new ast::TupleExpr{ arg->location, move( components ) }; 579 580 } else { 580 581 // handle normally … … 672 673 } 673 674 std::vector< ast::ptr< ast::Expr > > vargs( args.begin(), args.end() ); 674 appExpr->args = std::move( vargs );675 appExpr->args = move( vargs ); 675 676 // build and validate new candidate 676 677 auto newCand = … … 783 784 if ( expl.exprs.empty() ) { 784 785 results.emplace_back( 785 results[i], std::move( env ), copy( results[i].need ),786 copy( results[i].have ), std::move( open ), nextArg + 1,786 results[i], move( env ), copy( results[i].need ), 787 copy( results[i].have ), move( open ), nextArg + 1, 787 788 expl.cost ); 788 789 … … 792 793 // add new result 793 794 results.emplace_back( 794 i, expl.exprs.front(), std::move( env ), copy( results[i].need ),795 copy( results[i].have ), std::move( open ), nextArg + 1, 0, expl.cost,795 i, expl.exprs.front(), move( env ), copy( results[i].need ), 796 copy( results[i].have ), move( open ), nextArg + 1, 0, expl.cost, 796 797 expl.exprs.size() == 1 ? 0 : 1, j ); 797 798 } … … 843 844 // as a member expression 844 845 addAnonConversions( newCand ); 845 candidates.emplace_back( std::move( newCand ) );846 candidates.emplace_back( move( newCand ) ); 846 847 } 847 848 } … … 901 902 const ast::EnumDecl * enumDecl = enumInst->base; 902 903 if ( const ast::Type* enumType = enumDecl->base ) { 903 // instance of enum (T) is a instance of type (T) 904 // instance of enum (T) is a instance of type (T) 904 905 funcFinder.otypeKeys.insert(Mangle::mangle(enumType, Mangle::NoGenericParams | Mangle::Type)); 905 906 } else { … … 907 908 funcFinder.otypeKeys.insert(Mangle::mangle(enumDecl, Mangle::NoGenericParams | Mangle::Type)); 908 909 } 909 } 910 } 910 911 else funcFinder.otypeKeys.insert(Mangle::mangle(argType, Mangle::NoGenericParams | Mangle::Type)); 911 912 } … … 986 987 funcE.emplace_back( *func, symtab ); 987 988 } 988 argExpansions.emplace_front( std::move( funcE ) );989 argExpansions.emplace_front( move( funcE ) ); 989 990 990 991 for ( const CandidateRef & op : opFinder ) { … … 1030 1031 if ( cvtCost != Cost::infinity ) { 1031 1032 withFunc->cvtCost = cvtCost; 1032 candidates.emplace_back( std::move( withFunc ) );1033 } 1034 } 1035 found = std::move( candidates );1033 candidates.emplace_back( move( withFunc ) ); 1034 } 1035 } 1036 found = move( candidates ); 1036 1037 1037 1038 // use a new list so that candidates are not examined by addAnonConversions twice … … 1090 1091 assert( toType ); 1091 1092 toType = resolveTypeof( toType, context ); 1093 // toType = SymTab::validateType( castExpr->location, toType, symtab ); 1092 1094 toType = adjustExprType( toType, tenv, symtab ); 1093 1095 … … 1131 1133 CandidateRef newCand = std::make_shared<Candidate>( 1132 1134 restructureCast( cand->expr, toType, castExpr->isGenerated ), 1133 copy( cand->env ), std::move( open ), std::move( need ), cand->cost,1135 copy( cand->env ), move( open ), move( need ), cand->cost, 1134 1136 cand->cost + thisCost ); 1135 1137 inferParameters( newCand, matches ); … … 1285 1287 // as a name expression 1286 1288 addAnonConversions( newCand ); 1287 candidates.emplace_back( std::move( newCand ) );1289 candidates.emplace_back( move( newCand ) ); 1288 1290 } 1289 1291 } … … 1394 1396 new ast::LogicalExpr{ 1395 1397 logicalExpr->location, r1->expr, r2->expr, logicalExpr->isAnd }, 1396 std::move( env ), std::move( open ), std::move( need ), r1->cost + r2->cost );1398 move( env ), move( open ), move( need ), r1->cost + r2->cost ); 1397 1399 } 1398 1400 } … … 1452 1454 // output candidate 1453 1455 CandidateRef newCand = std::make_shared<Candidate>( 1454 newExpr, std::move( env ), std::move( open ), std::move( need ), cost );1456 newExpr, move( env ), move( open ), move( need ), cost ); 1455 1457 inferParameters( newCand, candidates ); 1456 1458 } … … 1519 1521 // add candidate 1520 1522 CandidateRef newCand = std::make_shared<Candidate>( 1521 newExpr, std::move( env ), std::move( open ), std::move( need ),1523 newExpr, move( env ), move( open ), move( need ), 1522 1524 r1->cost + r2->cost ); 1523 1525 inferParameters( newCand, candidates ); … … 1548 1550 1549 1551 addCandidate( 1550 new ast::TupleExpr{ tupleExpr->location, std::move( exprs ) },1551 std::move( env ), std::move( open ), std::move( need ), sumCost( subs ) );1552 new ast::TupleExpr{ tupleExpr->location, move( exprs ) }, 1553 move( env ), move( open ), move( need ), sumCost( subs ) ); 1552 1554 } 1553 1555 } … … 1588 1590 // calculate target type 1589 1591 const ast::Type * toType = resolveTypeof( initAlt.type, context ); 1592 // toType = SymTab::validateType( initExpr->location, toType, symtab ); 1590 1593 toType = adjustExprType( toType, tenv, symtab ); 1591 1594 // The call to find must occur inside this loop, otherwise polymorphic return … … 1635 1638 initExpr->location, restructureCast( cand->expr, toType ), 1636 1639 initAlt.designation }, 1637 std::move(env), std::move( open ), std::move( need ), cand->cost, thisCost );1640 move(env), move( open ), move( need ), cand->cost, thisCost ); 1638 1641 inferParameters( newCand, matches ); 1639 1642 } … … 1768 1771 cand->env.applyFree( newResult ); 1769 1772 cand->expr = ast::mutate_field( 1770 cand->expr.get(), &ast::Expr::result, std::move( newResult ) );1773 cand->expr.get(), &ast::Expr::result, move( newResult ) ); 1771 1774 1772 1775 out.emplace_back( cand ); … … 1854 1857 1855 1858 auto oldsize = candidates.size(); 1856 candidates = std::move( pruned );1859 candidates = move( pruned ); 1857 1860 1858 1861 PRINT(
Note:
See TracChangeset
for help on using the changeset viewer.