Changeset fbecee5
- Timestamp:
- Oct 18, 2018, 4:26:11 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 2fd9f24
- Parents:
- 2c187378
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
r2c187378 rfbecee5 26 26 #include <string> 27 27 #include <type_traits> 28 #include <utility> 28 29 29 30 #include <cassert> … … 462 463 std::pair<long long int, bool> eval(Expression * expr); 463 464 465 // ----------------------------------------------------------------------------- 466 /// Reorders the input range in-place so that the minimal-value elements according to the 467 /// comparator are in front; 468 /// returns the iterator after the last minimal-value element. 469 template<typename Iter, typename Compare> 470 Iter sort_mins( Iter begin, Iter end, Compare& lt ) { 471 if ( begin == end ) return end; 472 473 Iter min_pos = begin; 474 for ( Iter i = begin + 1; i != end; ++i ) { 475 if ( lt( *i, *min_pos ) ) { 476 // new minimum cost; swap into first position 477 min_pos = begin; 478 std::iter_swap( min_pos, i ); 479 } else if ( ! lt( *min_pos, *i ) ) { 480 // duplicate minimum cost; swap into next minimum position 481 ++min_pos; 482 std::iter_swap( min_pos, i ); 483 } 484 } 485 return ++min_pos; 486 } 487 488 template<typename Iter, typename Compare> 489 inline Iter sort_mins( Iter begin, Iter end, Compare&& lt ) { 490 return sort_mins( begin, end, lt ); 491 } 492 493 /// sort_mins defaulted to use std::less 494 template<typename Iter> 495 inline Iter sort_mins( Iter begin, Iter end ) { 496 return sort_mins( begin, end, std::less<typename std::iterator_traits<Iter>::value_type>{} ); 497 } 498 464 499 // Local Variables: // 465 500 // tab-width: 4 // -
src/ResolvExpr/AlternativeFinder.cc
r2c187378 rfbecee5 254 254 SemanticError( expr, "No reasonable alternatives for expression " ); 255 255 } 256 if ( mode.resolveAssns ) {256 if ( mode.resolveAssns || mode.prune ) { 257 257 // trim candidates just to those where the assertions resolve 258 // - necessary pre-requisite to pruning 258 259 AltList candidates; 259 260 for ( unsigned i = 0; i < alternatives.size(); ++i ) { -
src/ResolvExpr/ResolveAssertions.cc
r2c187378 rfbecee5 18 18 #include <cassert> // for assertf 19 19 #include <list> // for list 20 #include <unordered_map> // for unordered_map 20 21 #include <utility> // for move 21 22 #include <vector> // for vector … … 23 24 #include "Alternative.h" // for Alternative, AssertionItem 24 25 #include "Common/FilterCombos.h" // for filterCombos 26 #include "Common/utility.h" // for sort_mins 25 27 #include "SymTab/Indexer.h" // for Indexer 26 28 #include "TypeEnvironment.h" // for TypeEnvironment, etc. … … 125 127 }; 126 128 129 /// Comparator for CandidateEnvMerger outputs that sums their costs and caches the stored 130 /// sums 131 struct CandidateCost { 132 using Element = CandidateEnvMerger::OutType; 133 private: 134 using Memo = std::unordered_map<const Element*, Cost>; 135 mutable Memo cache; ///< cache of element costs 136 const SymTab::Indexer& indexer; ///< Indexer for costing 137 138 public: 139 CandidateCost( const SymTab::Indexer& indexer ) : indexer(indexer) {} 140 141 /// reports the cost of an element 142 Cost get( const Element& x ) const { 143 Memo::const_iterator it = cache.find( &x ); 144 if ( it == cache.end() ) { 145 Cost k = Cost::zero; 146 for ( const auto& assn : x.assns ) { 147 k += computeConversionCost( 148 assn.match.adjType, assn.decl->get_type(), indexer, x.env ); 149 } 150 it = cache.emplace_hint( it, &x, k ); 151 } 152 return it->second; 153 } 154 155 /// compares elements by cost 156 bool operator() ( const Element& a, const Element& b ) const { 157 return get( a ) < get( b ); 158 } 159 }; 160 127 161 /// Flag for state iteration 128 162 enum IterateFlag { IterateState }; … … 275 309 } 276 310 } else { 277 // resolve deferred assertions by mutual compatibility 311 // resolve deferred assertions by mutual compatibility and sort by cost 278 312 std::vector<CandidateEnvMerger::OutType> compatible = filterCombos( 279 313 resn.deferred, 280 314 CandidateEnvMerger{ resn.alt.env, resn.alt.openVars, resn.indexer } ); 315 auto lmin = sort_mins( compatible.begin(), compatible.end(), 316 CandidateCost{resn.indexer} ); 281 317 282 for ( auto& compat : compatible ) { 318 // for ( auto& compat : compatible ) { 319 for ( auto it = compatible.begin(); it != lmin ; ++it ) { 320 auto& compat = *it; 283 321 ResnState new_resn = resn; 284 322 -
src/ResolvExpr/typeops.h
r2c187378 rfbecee5 72 72 Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env ); 73 73 74 // in AlternativeFinder.cc 75 Cost computeConversionCost( Type *actualType, Type *formalType, 76 const SymTab::Indexer &indexer, const TypeEnvironment &env ); 77 74 78 // in PtrsAssignable.cc 75 79 int ptrsAssignable( Type *src, Type *dest, const TypeEnvironment &env );
Note: See TracChangeset
for help on using the changeset viewer.