Changeset 7aa209e7 for src/ResolvExpr
- Timestamp:
- Apr 17, 2024, 10:50:36 AM (4 months ago)
- Branches:
- master
- Children:
- 8fd53b6e
- Parents:
- 710d0c8c
- Location:
- src/ResolvExpr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r710d0c8c r7aa209e7 1400 1400 } 1401 1401 } 1402 1402 1403 1403 CandidateRef newCand = std::make_shared<Candidate>( 1404 1404 newExpr, copy( tenv ), ast::OpenVarSet{}, ast::AssertionSet{}, bentConversion? Cost::safe: Cost::zero, … … 1794 1794 auto commonAsEnumAttr = common.as<ast::EnumAttrType>(); 1795 1795 if ( commonAsEnumAttr && commonAsEnumAttr->attr == ast::EnumAttribute::Value ) { 1796 1797 1796 auto callExpr = new ast::UntypedExpr( 1798 1797 cand->expr->location, new ast::NameExpr( cand->expr->location, "valueE"), {cand->expr} ); … … 1823 1822 // if this somehow changes in the future (e.g. delayed by indeterminate return type) 1824 1823 // we may need to revisit the logic. 1825 inferParameters( newCand, matches ); 1824 inferParameters( newCand, matches ); 1826 1825 } 1827 } 1828 } 1826 } 1827 } 1829 1828 } 1830 1829 } … … 2151 2150 } 2152 2151 2153 // get the valueE(...) ApplicationExpr that returns the enum value 2154 const ast::Expr * getValueEnumCall( 2155 const ast::Expr * expr, 2156 const ResolvExpr::ResolveContext & context, const ast::TypeEnvironment & env ) { 2157 auto callExpr = new ast::UntypedExpr( 2158 expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} ); 2159 CandidateFinder finder( context, env ); 2160 finder.find( callExpr ); 2161 CandidateList winners = findMinCost( finder.candidates ); 2162 if (winners.size() != 1) { 2163 SemanticError( callExpr, "Ambiguous expression in valueE" ); 2164 } 2165 CandidateRef & choice = winners.front(); 2166 return choice->expr; 2152 const ast::Expr * getValueEnumCall( const ast::Expr * expr, 2153 const ResolveContext & context, const ast::TypeEnvironment & env ) { 2154 auto callExpr = new ast::UntypedExpr( 2155 expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} ); 2156 CandidateFinder finder( context, env ); 2157 finder.find( callExpr ); 2158 CandidateList winners = findMinCost( finder.candidates ); 2159 if (winners.size() != 1) { 2160 SemanticError( callExpr, "Ambiguous expression in valueE" ); 2161 } 2162 CandidateRef & choice = winners.front(); 2163 return choice->expr; 2167 2164 } 2168 2165 -
src/ResolvExpr/CandidateFinder.hpp
r710d0c8c r7aa209e7 30 30 struct CandidateFinder { 31 31 CandidateList candidates; ///< List of candidate resolutions 32 const ResolveContext & context; ///< Information about where the canditates are being found.32 const ResolveContext & context; ///< Information about where the canditates are being found. 33 33 const ast::TypeEnvironment & env; ///< Substitutions performed in this resolution 34 34 ast::ptr< ast::Type > targetType; ///< Target type for resolution 35 35 bool strictMode = false; ///< If set to true, requires targetType to be exact match (inside return cast) 36 36 bool allowVoid = false; ///< If set to true, allow void-returning function calls (only top level, cast to void and first in comma) 37 std::set< std::string > otypeKeys; ///different type may map to same key37 std::set< std::string > otypeKeys; ///< different type may map to same key 38 38 39 39 CandidateFinder( … … 70 70 const ast::Expr * expr, Cost & cost ); 71 71 72 const ast::Expr * getValueEnumCall(const ast::Expr * expr, 73 const ResolvExpr::ResolveContext & context, const ast::TypeEnvironment & env ); 72 /// Get the valueE application that returns the enum's value. 73 const ast::Expr * getValueEnumCall( const ast::Expr * expr, 74 const ResolveContext & context, const ast::TypeEnvironment & env ); 75 74 76 /// Wrap an expression to convert the result to a conditional result. 75 77 const ast::Expr * createCondExpr( const ast::Expr * expr );
Note: See TracChangeset
for help on using the changeset viewer.