Changeset 396037d for src/ResolvExpr
- Timestamp:
- Jun 10, 2019, 6:02:36 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 6ad19fd, d57e349
- Parents:
- 5485e101
- Location:
- src/ResolvExpr
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r5485e101 r396037d 266 266 SemanticError( expr, "No reasonable alternatives for expression " ); 267 267 } 268 if ( mode. resolveAssns || mode.prune ) {268 if ( mode.satisfyAssns || mode.prune ) { 269 269 // trim candidates just to those where the assertions resolve 270 270 // - necessary pre-requisite to pruning -
src/ResolvExpr/CandidateFinder.cpp
r5485e101 r396037d 16 16 #include "CandidateFinder.hpp" 17 17 18 #include <sstream> 19 20 #include "Candidate.hpp" 21 #include "CompilationState.h" 22 #include "SatisfyAssertions.hpp" 18 23 #include "AST/Expr.hpp" 24 #include "AST/Node.hpp" 25 #include "AST/Pass.hpp" 26 27 #define PRINT( text ) if ( resolvep ) { text } 19 28 20 29 namespace ResolvExpr { 21 30 31 namespace { 32 33 /// Actually visits expressions to find their candidate interpretations 34 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 unimplemented 46 }; 47 48 /// Prunes a list of candidates down to those that have the minimum conversion cost for a given 49 /// return type. Skips ambiguous candidates. 50 CandidateList pruneCandidates( CandidateList & candidates ) { 51 #warning unimplemented 52 (void)candidates; 53 assert(false); 54 return {}; 55 } 56 57 } // anonymous namespace 58 22 59 void CandidateFinder::find( const ast::Expr * expr, ResolvMode mode ) { 60 // Find alternatives for expression 61 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 satisfiable 70 // - necessary pre-requisite to pruning 71 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 such 78 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 candidates 88 candidates = std::move( satisfied ); 89 } 90 91 if ( mode.prune ) { 92 // trim candidates to single best one 93 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 unimplemented 105 assert(false); 106 } 107 } 108 23 109 #warning unimplemented 24 (void)expr; (void)mode;25 110 assert(false); 26 111 } … … 31 116 std::vector< CandidateFinder > out; 32 117 33 #warning unimplemented 34 (void)xs; 35 assert(false); 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 } 36 127 37 128 return out; -
src/ResolvExpr/CandidateFinder.hpp
r5485e101 r396037d 19 19 #include "ResolvMode.h" 20 20 #include "AST/Fwd.hpp" 21 #include "AST/Node.hpp" 21 22 #include "AST/SymbolTable.hpp" 22 23 #include "AST/TypeEnvironment.hpp" … … 29 30 const ast::SymbolTable & symtab; ///< Symbol table to lookup candidates 30 31 const ast::TypeEnvironment & env; ///< Substitutions performed in this resolution 31 const ast::Type *targetType = nullptr; ///< Target type for resolution32 ast::ptr< ast::Type > targetType = nullptr; ///< Target type for resolution 32 33 33 34 CandidateFinder( const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ) -
src/ResolvExpr/ResolvMode.h
r5485e101 r396037d 22 22 const bool prune; ///< Prune alternatives to min-cost per return type? [true] 23 23 const bool failFast; ///< Fail on no resulting alternatives? [true] 24 const bool resolveAssns; ///< Resolveassertions? [false]24 const bool satisfyAssns; ///< Satisfy assertions? [false] 25 25 26 26 private: 27 constexpr ResolvMode(bool a, bool p, bool ff, bool ra)28 : adjust(a), prune(p), failFast(ff), resolveAssns(ra) {}27 constexpr ResolvMode(bool a, bool p, bool ff, bool sa) 28 : adjust(a), prune(p), failFast(ff), satisfyAssns(sa) {} 29 29 30 30 public: 31 31 /// Default settings 32 constexpr ResolvMode() : adjust(false), prune(true), failFast(true), resolveAssns(false) {}32 constexpr ResolvMode() : adjust(false), prune(true), failFast(true), satisfyAssns(false) {} 33 33 34 34 /// With adjust flag set; turns array and function types into equivalent pointers … … 43 43 static constexpr ResolvMode withoutFailFast() { return { true, true, false, false }; } 44 44 45 /// The same mode, but with resolveAssns turned on; for top-level calls45 /// The same mode, but with satisfyAssns turned on; for top-level calls 46 46 ResolvMode atTopLevel() const { return { adjust, prune, failFast, true }; } 47 47 }; -
src/ResolvExpr/module.mk
r5485e101 r396037d 35 35 ResolvExpr/Resolver.cc \ 36 36 ResolvExpr/ResolveTypeof.cc \ 37 ResolvExpr/SatisfyAssertions.cpp \ 37 38 ResolvExpr/SpecCost.cc \ 38 39 ResolvExpr/TypeEnvironment.cc \
Note: See TracChangeset
for help on using the changeset viewer.