- File:
-
- 1 edited
-
src/ResolvExpr/AlternativeFinder.cc (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
re04ef3a r22cad76 19 19 #include <functional> 20 20 #include <cassert> 21 #include <unordered_map> 22 #include <utility> 23 #include <vector> 21 24 22 25 #include "AlternativeFinder.h" … … 39 42 #include "Tuples/NameMatcher.h" 40 43 #include "Common/utility.h" 44 #include "InitTweak/InitTweak.h" 41 45 42 46 extern bool resolvep; … … 407 411 } 408 412 409 static const int recursionLimit = 10; 413 /// Map of declaration uniqueIds (intended to be the assertions in an AssertionSet) to their parents and the number of times they've been included 414 typedef std::unordered_map< UniqueId, std::unordered_map< UniqueId, unsigned > > AssertionParentSet; 415 416 static const int recursionLimit = 10; ///< Limit to depth of recursion satisfaction 417 static const unsigned recursionParentLimit = 1; ///< Limit to the number of times an assertion can recursively use itself 410 418 411 419 void addToIndexer( AssertionSet &assertSet, SymTab::Indexer &indexer ) { … … 416 424 } 417 425 } 418 426 419 427 template< typename ForwardIterator, typename OutputIterator > 420 void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, int level, const SymTab::Indexer &indexer, OutputIterator out ) { 428 void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, const AssertionParentSet &needParents, 429 int level, const SymTab::Indexer &indexer, OutputIterator out ) { 421 430 if ( begin == end ) { 422 431 if ( newNeed.empty() ) { … … 431 440 printAssertionSet( newNeed, std::cerr, 8 ); 432 441 ) 433 inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, level+1, indexer, out );442 inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, needParents, level+1, indexer, out ); 434 443 return; 435 444 } … … 438 447 ForwardIterator cur = begin++; 439 448 if ( ! cur->second ) { 440 inferRecursive( begin, end, newAlt, openVars, decls, newNeed, level, indexer, out );449 inferRecursive( begin, end, newAlt, openVars, decls, newNeed, needParents, level, indexer, out ); 441 450 } 442 451 DeclarationWithType *curDecl = cur->first; … … 455 464 std::cerr << std::endl; 456 465 ) 466 457 467 AssertionSet newHave, newerNeed( newNeed ); 458 468 TypeEnvironment newEnv( newAlt.env ); … … 477 487 newerAlt.env = newEnv; 478 488 assert( (*candidate)->get_uniqueId() ); 479 Expression *varExpr = new VariableExpr( static_cast< DeclarationWithType* >( Declaration::declFromId( (*candidate)->get_uniqueId() ) ) ); 489 DeclarationWithType *candDecl = static_cast< DeclarationWithType* >( Declaration::declFromId( (*candidate)->get_uniqueId() ) ); 490 AssertionParentSet newNeedParents( needParents ); 491 // skip repeatingly-self-recursive assertion satisfaction 492 if ( newNeedParents[ curDecl->get_uniqueId() ][ candDecl->get_uniqueId() ]++ > recursionParentLimit ) continue; 493 Expression *varExpr = new VariableExpr( candDecl ); 480 494 deleteAll( varExpr->get_results() ); 481 495 varExpr->get_results().clear(); … … 491 505 // XXX: this is a memory leak, but adjType can't be deleted because it might contain assertions 492 506 appExpr->get_inferParams()[ curDecl->get_uniqueId() ] = ParamEntry( (*candidate)->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr ); 493 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, level, indexer, out );507 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, newNeedParents, level, indexer, out ); 494 508 } else { 495 509 delete adjType; … … 513 527 addToIndexer( have, decls ); 514 528 AssertionSet newNeed; 515 inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, 0, indexer, out ); 529 AssertionParentSet needParents; 530 inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, needParents, 0, indexer, out ); 516 531 // PRINT( 517 532 // std::cerr << "declaration 14 is "; … … 546 561 547 562 { 548 NameExpr *fname = 0;; 549 if ( ( fname = dynamic_cast<NameExpr *>( untypedExpr->get_function())) 550 && ( fname->get_name() == std::string("&&")) ) { 563 std::string fname = InitTweak::getFunctionName( untypedExpr ); 564 if ( fname == "&&" ) { 551 565 VoidType v = Type::Qualifiers(); // resolve to type void * 552 566 PointerType pt( Type::Qualifiers(), v.clone() );
Note:
See TracChangeset
for help on using the changeset viewer.