Changeset 43e0949 for src/ResolvExpr/AlternativeFinder.cc
- Timestamp:
- Feb 19, 2019, 1:19:47 PM (5 years ago)
- Branches:
- no_list
- Children:
- 2f42718
- Parents:
- 99614c2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r99614c2 r43e0949 367 367 std::string tmp; 368 368 if ( val >= 0 && (unsigned long long)val < tupleType->size() ) { 369 alternatives.push_back( Alternative{ 369 alternatives.push_back( Alternative{ 370 370 alt, new TupleIndexExpr( expr->clone(), val ), newCost } ); 371 371 } // if … … 474 474 } 475 475 476 // specialization cost of return types can't be accounted for directly, it disables 476 // specialization cost of return types can't be accounted for directly, it disables 477 477 // otherwise-identical calls, like this example based on auto-newline in the I/O lib: 478 478 // … … 1225 1225 // count one safe conversion for each value that is thrown away 1226 1226 thisCost.incSafe( discardedValues ); 1227 Alternative newAlt{ 1228 restructureCast( alt.expr->clone(), toType, castExpr->isGenerated ), 1227 Alternative newAlt{ 1228 restructureCast( alt.expr->clone(), toType, castExpr->isGenerated ), 1229 1229 alt.env, openVars, needAssertions, alt.cost, alt.cost + thisCost }; 1230 1230 inferParameters( newAlt, back_inserter( candidates ) ); … … 1290 1290 1291 1291 void AlternativeFinder::Finder::postvisit( NameExpr *nameExpr ) { 1292 std:: list< SymTab::Indexer::IdData > declList;1292 std::vector< SymTab::Indexer::IdData > declList; 1293 1293 indexer.lookupId( nameExpr->name, declList ); 1294 1294 PRINT( std::cerr << "nameExpr is " << nameExpr->name << std::endl; ) … … 1327 1327 if ( sizeofExpr->get_isType() ) { 1328 1328 Type * newType = sizeofExpr->get_type()->clone(); 1329 alternatives.push_back( Alternative{ 1329 alternatives.push_back( Alternative{ 1330 1330 new SizeofExpr{ resolveTypeof( newType, indexer ) }, env } ); 1331 1331 } else { … … 1342 1342 Alternative &choice = winners.front(); 1343 1343 referenceToRvalueConversion( choice.expr, choice.cost ); 1344 alternatives.push_back( Alternative{ 1344 alternatives.push_back( Alternative{ 1345 1345 choice, new SizeofExpr( choice.expr->clone() ), Cost::zero } ); 1346 1346 } // if … … 1350 1350 if ( alignofExpr->get_isType() ) { 1351 1351 Type * newType = alignofExpr->get_type()->clone(); 1352 alternatives.push_back( Alternative{ 1352 alternatives.push_back( Alternative{ 1353 1353 new AlignofExpr{ resolveTypeof( newType, indexer ) }, env } ); 1354 1354 } else { … … 1365 1365 Alternative &choice = winners.front(); 1366 1366 referenceToRvalueConversion( choice.expr, choice.cost ); 1367 alternatives.push_back( Alternative{ 1367 alternatives.push_back( Alternative{ 1368 1368 choice, new AlignofExpr{ choice.expr->clone() }, Cost::zero } ); 1369 1369 } // if … … 1376 1376 for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) { 1377 1377 if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) { 1378 alternatives.push_back( Alternative{ 1378 alternatives.push_back( Alternative{ 1379 1379 new OffsetofExpr{ aggInst->clone(), dwt }, env } ); 1380 1380 renameTypes( alternatives.back().expr ); … … 1420 1420 Cost cost = Cost::zero; 1421 1421 Expression * newExpr = data.combine( cost ); 1422 alternatives.push_back( Alternative{ 1423 new AttrExpr{ newExpr, argType->clone() }, env, OpenVarSet{}, 1422 alternatives.push_back( Alternative{ 1423 new AttrExpr{ newExpr, argType->clone() }, env, OpenVarSet{}, 1424 1424 AssertionList{}, Cost::zero, cost } ); 1425 1425 for ( DeclarationWithType * retVal : function->returnVals ) { … … 1434 1434 NameExpr *nameExpr = dynamic_cast< NameExpr* >( attrExpr->get_attr() ); 1435 1435 assert( nameExpr ); 1436 std:: list< SymTab::Indexer::IdData > attrList;1436 std::vector< SymTab::Indexer::IdData > attrList; 1437 1437 indexer.lookupId( nameExpr->get_name(), attrList ); 1438 1438 if ( attrExpr->get_isType() || attrExpr->get_expr() ) { … … 1461 1461 Cost cost = Cost::zero; 1462 1462 Expression * newExpr = data.combine( cost ); 1463 alternatives.push_back( Alternative{ 1463 alternatives.push_back( Alternative{ 1464 1464 newExpr, env, OpenVarSet{}, AssertionList{}, Cost::zero, cost } ); 1465 1465 renameTypes( alternatives.back().expr ); … … 1485 1485 cloneAll( second.need, need ); 1486 1486 1487 LogicalExpr *newExpr = new LogicalExpr{ 1487 LogicalExpr *newExpr = new LogicalExpr{ 1488 1488 first.expr->clone(), second.expr->clone(), logicalExpr->get_isAnd() }; 1489 alternatives.push_back( Alternative{ 1490 newExpr, std::move(compositeEnv), std::move(openVars), 1489 alternatives.push_back( Alternative{ 1490 newExpr, std::move(compositeEnv), std::move(openVars), 1491 1491 AssertionList( need.begin(), need.end() ), first.cost + second.cost } ); 1492 1492 } … … 1521 1521 cloneAll( third.need, need ); 1522 1522 AssertionSet have; 1523 1523 1524 1524 // unify true and false types, then infer parameters to produce new alternatives 1525 1525 Type* commonType = nullptr; 1526 if ( unify( second.expr->result, third.expr->result, compositeEnv, 1526 if ( unify( second.expr->result, third.expr->result, compositeEnv, 1527 1527 need, have, openVars, indexer, commonType ) ) { 1528 ConditionalExpr *newExpr = new ConditionalExpr{ 1528 ConditionalExpr *newExpr = new ConditionalExpr{ 1529 1529 first.expr->clone(), second.expr->clone(), third.expr->clone() }; 1530 1530 newExpr->result = commonType ? commonType : second.expr->result->clone(); 1531 1531 // convert both options to the conditional result type 1532 1532 Cost cost = first.cost + second.cost + third.cost; 1533 cost += computeExpressionConversionCost( 1533 cost += computeExpressionConversionCost( 1534 1534 newExpr->arg2, newExpr->result, indexer, compositeEnv ); 1535 cost += computeExpressionConversionCost( 1535 cost += computeExpressionConversionCost( 1536 1536 newExpr->arg3, newExpr->result, indexer, compositeEnv ); 1537 1537 // output alternative 1538 Alternative newAlt{ 1539 newExpr, std::move(compositeEnv), std::move(openVars), 1538 Alternative newAlt{ 1539 newExpr, std::move(compositeEnv), std::move(openVars), 1540 1540 AssertionList( need.begin(), need.end() ), cost }; 1541 1541 inferParameters( newAlt, back_inserter( alternatives ) ); … … 1552 1552 secondFinder.findWithAdjustment( commaExpr->get_arg2() ); 1553 1553 for ( const Alternative & alt : secondFinder.alternatives ) { 1554 alternatives.push_back( Alternative{ 1554 alternatives.push_back( Alternative{ 1555 1555 alt, new CommaExpr{ newFirstArg->clone(), alt.expr->clone() }, alt.cost } ); 1556 1556 } // for … … 1578 1578 1579 1579 Type* commonType = nullptr; 1580 if ( unify( first.expr->result, second.expr->result, compositeEnv, need, have, 1580 if ( unify( first.expr->result, second.expr->result, compositeEnv, need, have, 1581 1581 openVars, indexer, commonType ) ) { 1582 RangeExpr * newExpr = 1582 RangeExpr * newExpr = 1583 1583 new RangeExpr{ first.expr->clone(), second.expr->clone() }; 1584 1584 newExpr->result = commonType ? commonType : first.expr->result->clone(); 1585 Alternative newAlt{ 1586 newExpr, std::move(compositeEnv), std::move(openVars), 1585 Alternative newAlt{ 1586 newExpr, std::move(compositeEnv), std::move(openVars), 1587 1587 AssertionList( need.begin(), need.end() ), first.cost + second.cost }; 1588 1588 inferParameters( newAlt, back_inserter( alternatives ) ); … … 1611 1611 cloneAll( alt.need, need ); 1612 1612 } 1613 1614 alternatives.push_back( Alternative{ 1615 new TupleExpr{ exprs }, std::move(compositeEnv), std::move(openVars), 1613 1614 alternatives.push_back( Alternative{ 1615 new TupleExpr{ exprs }, std::move(compositeEnv), std::move(openVars), 1616 1616 AssertionList( need.begin(), need.end() ), sumCost( alts ) } ); 1617 1617 } // for … … 1632 1632 finder.findWithoutPrune( ctorExpr->get_callExpr() ); 1633 1633 for ( Alternative & alt : finder.alternatives ) { 1634 alternatives.push_back( Alternative{ 1634 alternatives.push_back( Alternative{ 1635 1635 alt, new ConstructorExpr( alt.expr->clone() ), alt.cost } ); 1636 1636 } … … 1684 1684 cloneAll( alt.need, need ); 1685 1685 AssertionSet have; 1686 OpenVarSet openVars( alt.openVars ); 1687 // xxx - find things in env that don't have a "representative type" and claim 1686 OpenVarSet openVars( alt.openVars ); 1687 // xxx - find things in env that don't have a "representative type" and claim 1688 1688 // those are open vars? 1689 1689 PRINT( 1690 1690 std::cerr << " @ " << toType << " " << initAlt.designation << std::endl; 1691 1691 ) 1692 // It's possible that a cast can throw away some values in a multiply-valued 1693 // expression. (An example is a cast-to-void, which casts from one value to 1694 // zero.) Figure out the prefix of the subexpression results that are cast 1695 // directly. The candidate is invalid if it has fewer results than there are 1692 // It's possible that a cast can throw away some values in a multiply-valued 1693 // expression. (An example is a cast-to-void, which casts from one value to 1694 // zero.) Figure out the prefix of the subexpression results that are cast 1695 // directly. The candidate is invalid if it has fewer results than there are 1696 1696 // types to cast to. 1697 1697 int discardedValues = alt.expr->result->size() - toType->size(); 1698 1698 if ( discardedValues < 0 ) continue; 1699 // xxx - may need to go into tuple types and extract relevant types and use 1700 // unifyList. Note that currently, this does not allow casting a tuple to an 1699 // xxx - may need to go into tuple types and extract relevant types and use 1700 // unifyList. Note that currently, this does not allow casting a tuple to an 1701 1701 // atomic type (e.g. (int)([1, 2, 3])) 1702 1702 1703 1703 // unification run for side-effects 1704 1704 unify( toType, alt.expr->result, newEnv, need, have, openVars, indexer ); … … 1709 1709 // count one safe conversion for each value that is thrown away 1710 1710 thisCost.incSafe( discardedValues ); 1711 Alternative newAlt{ 1712 new InitExpr{ 1713 restructureCast( alt.expr->clone(), toType, true ), initAlt.designation->clone() }, 1714 std::move(newEnv), std::move(openVars), 1711 Alternative newAlt{ 1712 new InitExpr{ 1713 restructureCast( alt.expr->clone(), toType, true ), initAlt.designation->clone() }, 1714 std::move(newEnv), std::move(openVars), 1715 1715 AssertionList( need.begin(), need.end() ), alt.cost, thisCost }; 1716 1716 inferParameters( newAlt, back_inserter( candidates ) );
Note: See TracChangeset
for help on using the changeset viewer.