Changeset 1d7b0a8
- Timestamp:
- Jun 11, 2018, 2:50:06 PM (7 years ago)
- Branches:
- new-env
- Children:
- 6d53e779, 982f95d
- Parents:
- 8e18b8e
- Location:
- src/ResolvExpr
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r8e18b8e r1d7b0a8 233 233 } 234 234 235 void AlternativeFinder::find( Expression *expr, bool adjust, bool prune, bool failFast) {235 void AlternativeFinder::find( Expression *expr, ResolvMode mode ) { 236 236 PassVisitor<Finder> finder( *this ); 237 237 expr->accept( finder ); 238 if ( failFast && alternatives.empty() ) {238 if ( mode.failFast && alternatives.empty() ) { 239 239 PRINT( 240 240 std::cerr << "No reasonable alternatives for expression " << expr << std::endl; … … 242 242 SemanticError( expr, "No reasonable alternatives for expression " ); 243 243 } 244 if ( prune ) {244 if ( mode.prune ) { 245 245 auto oldsize = alternatives.size(); 246 246 PRINT( … … 250 250 AltList pruned; 251 251 pruneAlternatives( alternatives.begin(), alternatives.end(), back_inserter( pruned ) ); 252 if ( failFast && pruned.empty() ) {252 if ( mode.failFast && pruned.empty() ) { 253 253 std::ostringstream stream; 254 254 AltList winners; … … 269 269 } 270 270 // adjust types after pruning so that types substituted by pruneAlternatives are correctly adjusted 271 for ( AltList::iterator i = alternatives.begin(); i != alternatives.end(); ++i) {272 if ( adjust) {273 adjustExprType( i ->expr->get_result(), i->env, indexer );271 if ( mode.adjust ) { 272 for ( Alternative& i : alternatives ) { 273 adjustExprType( i.expr->result, i.env, indexer ); 274 274 } 275 275 } … … 283 283 284 284 void AlternativeFinder::findWithAdjustment( Expression *expr ) { 285 find( expr, true);285 find( expr, ResolvMode::withAdjustment() ); 286 286 } 287 287 288 288 void AlternativeFinder::findWithoutPrune( Expression * expr ) { 289 find( expr, true, false);289 find( expr, ResolvMode::withoutPrune() ); 290 290 } 291 291 292 292 void AlternativeFinder::maybeFind( Expression * expr ) { 293 find( expr, true, true, false);293 find( expr, ResolvMode::withoutFailFast() ); 294 294 } 295 295 -
src/ResolvExpr/AlternativeFinder.h
r8e18b8e r1d7b0a8 22 22 #include "Alternative.h" // for AltList, Alternative 23 23 #include "ExplodedActual.h" // for ExplodedActual 24 #include "ResolvMode.h" // for ResolvMode 24 25 #include "ResolvExpr/Cost.h" // for Cost, Cost::infinity 25 26 #include "ResolvExpr/TypeEnvironment.h" // for AssertionSet, OpenVarSet … … 68 69 } 69 70 70 void find( Expression *expr, bool adjust = false, bool prune = true, bool failFast = true);71 void find( Expression *expr, ResolvMode mode = ResolvMode{} ); 71 72 /// Calls find with the adjust flag set; adjustment turns array and function types into equivalent pointer types 72 73 void findWithAdjustment( Expression *expr ); -
src/ResolvExpr/Resolver.cc
r8e18b8e r1d7b0a8 33 33 #include "ResolveTypeof.h" // for resolveTypeof 34 34 #include "Resolver.h" 35 #include "ResolvMode.h" // for ResolvMode 35 36 #include "SymTab/Autogen.h" // for SizeType 36 37 #include "SymTab/Indexer.h" // for Indexer … … 165 166 166 167 namespace { 167 void findUnfinishedKindExpression( Expression * untyped, Alternative & alt, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, bool adjust = false, bool prune = true, bool failFast = true) {168 void findUnfinishedKindExpression( Expression * untyped, Alternative & alt, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, ResolvMode mode = ResolvMode{} ) { 168 169 assertf( untyped, "expected a non-null expression." ); 169 170 … … 172 173 TypeEnvironment env; 173 174 AlternativeFinder finder( indexer, env ); 174 finder.find( untyped, adjust, prune, failFast);175 finder.find( untyped, mode ); 175 176 176 177 #if 0 … … 218 219 219 220 /// resolve `untyped` to the expression whose alternative satisfies `pred` with the lowest cost; kindStr is used for providing better error messages 220 void findKindExpression(Expression *& untyped, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, bool adjust = false, bool prune = true, bool failFast = true) {221 void findKindExpression(Expression *& untyped, const SymTab::Indexer & indexer, const std::string & kindStr, std::function<bool(const Alternative &)> pred, ResolvMode mode = ResolvMode{}) { 221 222 if ( ! untyped ) return; 222 223 Alternative choice; 223 findUnfinishedKindExpression( untyped, choice, indexer, kindStr, pred, adjust, prune, failFast);224 findUnfinishedKindExpression( untyped, choice, indexer, kindStr, pred, mode ); 224 225 finishExpr( choice.expr, choice.env, untyped->env ); 225 226 untyped = choice.expr; … … 249 250 // set up and resolve expression cast to void 250 251 Alternative choice; 251 findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, true);252 findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, ResolvMode::withAdjustment() ); 252 253 CastExpr * castExpr = strict_dynamic_cast< CastExpr * >( choice.expr ); 253 254 env = std::move( choice.env );
Note: See TracChangeset
for help on using the changeset viewer.