Changeset 624b722d for src/ResolvExpr
- Timestamp:
- Feb 1, 2018, 4:33:17 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 33c0ce8
- Parents:
- 0992849
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r0992849 r624b722d 1563 1563 // find alternatives for condition 1564 1564 AlternativeFinder firstFinder( indexer, env ); 1565 firstFinder.findWithAdjustment( conditionalExpr-> get_arg1());1565 firstFinder.findWithAdjustment( conditionalExpr->arg1 ); 1566 1566 if ( firstFinder.alternatives.empty() ) return; 1567 1567 // find alternatives for true expression 1568 1568 AlternativeFinder secondFinder( indexer, env ); 1569 secondFinder.findWithAdjustment( conditionalExpr-> get_arg2());1569 secondFinder.findWithAdjustment( conditionalExpr->arg2 ); 1570 1570 if ( secondFinder.alternatives.empty() ) return; 1571 1571 // find alterantives for false expression 1572 1572 AlternativeFinder thirdFinder( indexer, env ); 1573 thirdFinder.findWithAdjustment( conditionalExpr-> get_arg3());1573 thirdFinder.findWithAdjustment( conditionalExpr->arg3 ); 1574 1574 if ( thirdFinder.alternatives.empty() ) return; 1575 for ( AltList::const_iterator first = firstFinder.alternatives.begin(); first != firstFinder.alternatives.end(); ++first) {1576 for ( AltList::const_iterator second = secondFinder.alternatives.begin(); second != secondFinder.alternatives.end(); ++second) {1577 for ( AltList::const_iterator third = thirdFinder.alternatives.begin(); third != thirdFinder.alternatives.end(); ++third) {1575 for ( const Alternative & first : firstFinder.alternatives ) { 1576 for ( const Alternative & second : secondFinder.alternatives ) { 1577 for ( const Alternative & third : thirdFinder.alternatives ) { 1578 1578 TypeEnvironment compositeEnv; 1579 compositeEnv.simpleCombine( first ->env );1580 compositeEnv.simpleCombine( second ->env );1581 compositeEnv.simpleCombine( third ->env );1579 compositeEnv.simpleCombine( first.env ); 1580 compositeEnv.simpleCombine( second.env ); 1581 compositeEnv.simpleCombine( third.env ); 1582 1582 1583 1583 // unify true and false types, then infer parameters to produce new alternatives 1584 1584 OpenVarSet openVars; 1585 1585 AssertionSet needAssertions, haveAssertions; 1586 Alternative newAlt( 0, compositeEnv, first ->cost + second->cost + third->cost );1586 Alternative newAlt( 0, compositeEnv, first.cost + second.cost + third.cost ); 1587 1587 Type* commonType = nullptr; 1588 if ( unify( second ->expr->get_result(), third->expr->get_result(), newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {1589 ConditionalExpr *newExpr = new ConditionalExpr( first ->expr->clone(), second->expr->clone(), third->expr->clone() );1590 newExpr-> set_result( commonType ? commonType : second->expr->get_result()->clone());1588 if ( unify( second.expr->result, third.expr->result, newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) { 1589 ConditionalExpr *newExpr = new ConditionalExpr( first.expr->clone(), second.expr->clone(), third.expr->clone() ); 1590 newExpr->result = commonType ? commonType : second.expr->result->clone(); 1591 1591 // convert both options to the conditional result type 1592 1592 newAlt.cost += computeExpressionConversionCost( newExpr->arg2, newExpr->result, indexer, newAlt.env );
Note: See TracChangeset
for help on using the changeset viewer.