- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
rd67cdb7 r4e66a18 174 174 } 175 175 176 void AlternativeFinder::find( Expression *expr, bool adjust, bool prune ) {176 void AlternativeFinder::find( Expression *expr, bool adjust, bool prune, bool failFast ) { 177 177 expr->accept( *this ); 178 if ( alternatives.empty() ) {178 if ( failFast && alternatives.empty() ) { 179 179 throw SemanticError( "No reasonable alternatives for expression ", expr ); 180 180 } … … 191 191 AltList::iterator oldBegin = alternatives.begin(); 192 192 pruneAlternatives( alternatives.begin(), alternatives.end(), front_inserter( alternatives ) ); 193 if ( alternatives.begin() == oldBegin ) {193 if ( failFast && alternatives.begin() == oldBegin ) { 194 194 std::ostringstream stream; 195 195 AltList winners; … … 214 214 } 215 215 216 void AlternativeFinder::findWithAdjustment( Expression *expr, bool prune ) { 217 find( expr, true, prune ); 216 void AlternativeFinder::findWithAdjustment( Expression *expr ) { 217 find( expr, true ); 218 } 219 220 void AlternativeFinder::findWithoutPrune( Expression * expr ) { 221 find( expr, true, false ); 222 } 223 224 void AlternativeFinder::maybeFind( Expression * expr ) { 225 find( expr, true, true, false ); 218 226 } 219 227 … … 714 722 715 723 // find function operators 724 static NameExpr *opExpr = new NameExpr( "?()" ); 716 725 AlternativeFinder funcOpFinder( indexer, env ); 717 NameExpr *opExpr = new NameExpr( "?()" ); 718 try { 719 funcOpFinder.findWithAdjustment( opExpr ); 720 } catch( SemanticError &e ) { 721 // it's ok if there aren't any defined function ops 722 } 726 // it's ok if there aren't any defined function ops 727 funcOpFinder.maybeFind( opExpr); 723 728 PRINT( 724 729 std::cerr << "known function ops:" << std::endl; … … 928 933 AlternativeFinder finder( indexer, env ); 929 934 // don't prune here, since it's guaranteed all alternatives will have the same type 930 // (giving the alternatives different types is half of the point of ConstructorExpr nodes) 931 finder.findWithAdjustment( castExpr->get_arg(), false ); 935 finder.findWithoutPrune( castExpr->get_arg() ); 932 936 for ( Alternative & alt : finder.alternatives ) { 933 937 alternatives.push_back( Alternative( … … 1226 1230 // don't prune here, since it's guaranteed all alternatives will have the same type 1227 1231 // (giving the alternatives different types is half of the point of ConstructorExpr nodes) 1228 finder.findWith Adjustment( ctorExpr->get_callExpr(), false);1232 finder.findWithoutPrune( ctorExpr->get_callExpr() ); 1229 1233 for ( Alternative & alt : finder.alternatives ) { 1230 1234 alternatives.push_back( Alternative( new ConstructorExpr( alt.expr->clone() ), alt.env, alt.cost ) );
Note: See TracChangeset
for help on using the changeset viewer.