Changeset b6d6e97
- Timestamp:
- Sep 27, 2017, 3:54:21 PM (7 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 7bcb8eb
- Parents:
- a4477db
- Location:
- src/ResolvExpr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
ra4477db rb6d6e97 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 ) ); -
src/ResolvExpr/AlternativeFinder.h
ra4477db rb6d6e97 34 34 public: 35 35 AlternativeFinder( const SymTab::Indexer &indexer, const TypeEnvironment &env ); 36 void find( Expression *expr, bool adjust = false, bool prune = true );36 void find( Expression *expr, bool adjust = false, bool prune = true, bool failFast = true ); 37 37 /// Calls find with the adjust flag set; adjustment turns array and function types into equivalent pointer types 38 void findWithAdjustment( Expression *expr, bool prune = true ); 38 void findWithAdjustment( Expression *expr ); 39 /// Calls find with the adjust flag set and prune flag unset; pruning ensures there is at most one alternative per result type 40 void findWithoutPrune( Expression *expr ); 41 /// Calls find with the adjust and prune flags set, failFast flags unset; fail fast ensures that there is at least one resulting alternative 42 void maybeFind( Expression *expr ); 39 43 AltList &get_alternatives() { return alternatives; } 40 44
Note: See TracChangeset
for help on using the changeset viewer.