- File:
-
- 1 edited
-
src/ResolvExpr/CandidateFinder.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r396037d r99d4584 16 16 #include "CandidateFinder.hpp" 17 17 18 #include <sstream>19 20 #include "Candidate.hpp"21 #include "CompilationState.h"22 #include "SatisfyAssertions.hpp"23 18 #include "AST/Expr.hpp" 24 #include "AST/Node.hpp"25 #include "AST/Pass.hpp"26 27 #define PRINT( text ) if ( resolvep ) { text }28 19 29 20 namespace ResolvExpr { 30 21 31 namespace {32 33 /// Actually visits expressions to find their candidate interpretations34 struct Finder {35 CandidateFinder & candFinder;36 const ast::SymbolTable & symtab;37 CandidateList & candidates;38 const ast::TypeEnvironment & tenv;39 ast::ptr< ast::Type > & targetType;40 41 Finder( CandidateFinder & f )42 : candFinder( f ), symtab( f.symtab ), candidates( f.candidates ), tenv( f.env ),43 targetType( f.targetType ) {}44 45 #warning unimplemented46 };47 48 /// Prunes a list of candidates down to those that have the minimum conversion cost for a given49 /// return type. Skips ambiguous candidates.50 CandidateList pruneCandidates( CandidateList & candidates ) {51 #warning unimplemented52 (void)candidates;53 assert(false);54 return {};55 }56 57 } // anonymous namespace58 59 22 void CandidateFinder::find( const ast::Expr * expr, ResolvMode mode ) { 60 // Find alternatives for expression61 ast::Pass<Finder> finder{ *this };62 expr->accept( finder );63 64 if ( mode.failFast && candidates.empty() ) {65 SemanticError( expr, "No reasonable alternatives for expression " );66 }67 68 if ( mode.satisfyAssns || mode.prune ) {69 // trim candidates to just those where the assertions are satisfiable70 // - necessary pre-requisite to pruning71 CandidateList satisfied;72 std::vector< std::string > errors;73 for ( auto & candidate : candidates ) {74 satisfyAssertions( *candidate, symtab, satisfied, errors );75 }76 77 // fail early if none such78 if ( mode.failFast && satisfied.empty() ) {79 std::ostringstream stream;80 stream << "No alternatives with satisfiable assertions for " << expr << "\n";81 for ( const auto& err : errors ) {82 stream << err;83 }84 SemanticError( expr->location, stream.str() );85 }86 87 // reset candidates88 candidates = std::move( satisfied );89 }90 91 if ( mode.prune ) {92 // trim candidates to single best one93 auto oldsize = candidates.size();94 PRINT(95 std::cerr << "alternatives before prune:" << std::endl;96 print( std::cerr, candidates );97 )98 99 CandidateList pruned = pruneCandidates( candidates );100 if ( mode.failFast && pruned.empty() ) {101 std::ostringstream stream;102 CandidateList winners;103 104 #warning unimplemented105 assert(false);106 }107 }108 109 23 #warning unimplemented 24 (void)expr; (void)mode; 110 25 assert(false); 111 }112 113 std::vector< CandidateFinder > CandidateFinder::findSubExprs(114 const std::vector< ast::ptr< ast::Expr > > & xs115 ) {116 std::vector< CandidateFinder > out;117 118 for ( const auto & x : xs ) {119 out.emplace_back( symtab, env );120 out.back().find( x, ResolvMode::withAdjustment() );121 122 PRINT(123 std::cerr << "findSubExprs" << std::endl;124 print( std::cerr, out.back().candidates );125 )126 }127 128 return out;129 26 } 130 27
Note:
See TracChangeset
for help on using the changeset viewer.