- Timestamp:
- Nov 30, 2023, 2:41:11 PM (6 months ago)
- Branches:
- master
- Children:
- d787828d
- Parents:
- 83fd57d
- Location:
- src
- Files:
-
- 6 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r83fd57d r4a89b52 105 105 106 106 // CandidateFinder finder{ symtab, env }; 107 // finder.find( arg, Resolv Mode::withAdjustment() );107 // finder.find( arg, ResolveMode::withAdjustment() ); 108 108 // assertf( finder.candidates.size() > 0, 109 109 // "Somehow castable expression failed to find alternatives." ); … … 974 974 // xxx - is it possible that handleTupleAssignment and main finder both produce candidates? 975 975 // this means there exists ctor/assign functions with a tuple as first parameter. 976 Resolv Mode mode = {976 ResolveMode mode = { 977 977 true, // adjust 978 978 !untypedExpr->func.as<ast::NameExpr>(), // prune if not calling by name … … 989 989 CandidateFinder opFinder( context, tenv ); 990 990 // okay if there aren't any function operations 991 opFinder.find( opExpr, Resolv Mode::withoutFailFast() );991 opFinder.find( opExpr, ResolveMode::withoutFailFast() ); 992 992 PRINT( 993 993 std::cerr << "known function ops:" << std::endl; … … 1175 1175 if ( castExpr->kind == ast::CastExpr::Return ) { 1176 1176 finder.strictMode = true; 1177 finder.find( castExpr->arg, Resolv Mode::withAdjustment() );1177 finder.find( castExpr->arg, ResolveMode::withAdjustment() ); 1178 1178 1179 1179 // return casts are eliminated (merely selecting an overload, no actual operation) 1180 1180 candidates = std::move(finder.candidates); 1181 1181 } 1182 finder.find( castExpr->arg, Resolv Mode::withAdjustment() );1182 finder.find( castExpr->arg, ResolveMode::withAdjustment() ); 1183 1183 1184 1184 if ( !finder.candidates.empty() ) reason.code = NoMatch; … … 1251 1251 CandidateFinder finder( context, tenv ); 1252 1252 // don't prune here, all alternatives guaranteed to have same type 1253 finder.find( castExpr->arg, Resolv Mode::withoutPrune() );1253 finder.find( castExpr->arg, ResolveMode::withoutPrune() ); 1254 1254 for ( CandidateRef & r : finder.candidates ) { 1255 1255 addCandidate( … … 1298 1298 1299 1299 // don't prune here, since it's guaranteed all alternatives will have the same type 1300 finder.find( tech1.get(), Resolv Mode::withoutPrune() );1300 finder.find( tech1.get(), ResolveMode::withoutPrune() ); 1301 1301 pick_alternatives(finder.candidates, false); 1302 1302 … … 1307 1307 std::unique_ptr<const ast::Expr> fallback { ast::UntypedExpr::createDeref(loc, new ast::UntypedExpr(loc, new ast::NameExpr(loc, castExpr->concrete_target.getter), { castExpr->arg })) }; 1308 1308 // don't prune here, since it's guaranteed all alternatives will have the same type 1309 finder.find( fallback.get(), Resolv Mode::withoutPrune() );1309 finder.find( fallback.get(), ResolveMode::withoutPrune() ); 1310 1310 1311 1311 pick_alternatives(finder.candidates, true); … … 1316 1316 void Finder::postvisit( const ast::UntypedMemberExpr * memberExpr ) { 1317 1317 CandidateFinder aggFinder( context, tenv ); 1318 aggFinder.find( memberExpr->aggregate, Resolv Mode::withAdjustment() );1318 aggFinder.find( memberExpr->aggregate, ResolveMode::withAdjustment() ); 1319 1319 for ( CandidateRef & agg : aggFinder.candidates ) { 1320 1320 // it's okay for the aggregate expression to have reference type -- cast it to the … … 1475 1475 void Finder::postvisit( const ast::LogicalExpr * logicalExpr ) { 1476 1476 CandidateFinder finder1( context, tenv ); 1477 finder1.find( logicalExpr->arg1, Resolv Mode::withAdjustment() );1477 finder1.find( logicalExpr->arg1, ResolveMode::withAdjustment() ); 1478 1478 if ( finder1.candidates.empty() ) return; 1479 1479 1480 1480 CandidateFinder finder2( context, tenv ); 1481 finder2.find( logicalExpr->arg2, Resolv Mode::withAdjustment() );1481 finder2.find( logicalExpr->arg2, ResolveMode::withAdjustment() ); 1482 1482 if ( finder2.candidates.empty() ) return; 1483 1483 … … 1505 1505 // candidates for condition 1506 1506 CandidateFinder finder1( context, tenv ); 1507 finder1.find( conditionalExpr->arg1, Resolv Mode::withAdjustment() );1507 finder1.find( conditionalExpr->arg1, ResolveMode::withAdjustment() ); 1508 1508 if ( finder1.candidates.empty() ) return; 1509 1509 … … 1511 1511 CandidateFinder finder2( context, tenv ); 1512 1512 finder2.allowVoid = true; 1513 finder2.find( conditionalExpr->arg2, Resolv Mode::withAdjustment() );1513 finder2.find( conditionalExpr->arg2, ResolveMode::withAdjustment() ); 1514 1514 if ( finder2.candidates.empty() ) return; 1515 1515 … … 1517 1517 CandidateFinder finder3( context, tenv ); 1518 1518 finder3.allowVoid = true; 1519 finder3.find( conditionalExpr->arg3, Resolv Mode::withAdjustment() );1519 finder3.find( conditionalExpr->arg3, ResolveMode::withAdjustment() ); 1520 1520 if ( finder3.candidates.empty() ) return; 1521 1521 … … 1570 1570 1571 1571 CandidateFinder finder2( context, env ); 1572 finder2.find( commaExpr->arg2, Resolv Mode::withAdjustment() );1572 finder2.find( commaExpr->arg2, ResolveMode::withAdjustment() ); 1573 1573 1574 1574 for ( const CandidateRef & r2 : finder2.candidates ) { … … 1584 1584 CandidateFinder finder( context, tenv ); 1585 1585 finder.allowVoid = true; 1586 finder.find( ctorExpr->callExpr, Resolv Mode::withoutPrune() );1586 finder.find( ctorExpr->callExpr, ResolveMode::withoutPrune() ); 1587 1587 for ( CandidateRef & r : finder.candidates ) { 1588 1588 addCandidate( *r, new ast::ConstructorExpr{ ctorExpr->location, r->expr } ); … … 1593 1593 // resolve low and high, accept candidates where low and high types unify 1594 1594 CandidateFinder finder1( context, tenv ); 1595 finder1.find( rangeExpr->low, Resolv Mode::withAdjustment() );1595 finder1.find( rangeExpr->low, ResolveMode::withAdjustment() ); 1596 1596 if ( finder1.candidates.empty() ) return; 1597 1597 1598 1598 CandidateFinder finder2( context, tenv ); 1599 finder2.find( rangeExpr->high, Resolv Mode::withAdjustment() );1599 finder2.find( rangeExpr->high, ResolveMode::withAdjustment() ); 1600 1600 if ( finder2.candidates.empty() ) return; 1601 1601 … … 1673 1673 void Finder::postvisit( const ast::UniqueExpr * unqExpr ) { 1674 1674 CandidateFinder finder( context, tenv ); 1675 finder.find( unqExpr->expr, Resolv Mode::withAdjustment() );1675 finder.find( unqExpr->expr, ResolveMode::withAdjustment() ); 1676 1676 for ( CandidateRef & r : finder.candidates ) { 1677 1677 // ensure that the the id is passed on so that the expressions are "linked" … … 1699 1699 // only open for the duration of resolving the UntypedExpr. 1700 1700 CandidateFinder finder( context, tenv, toType ); 1701 finder.find( initExpr->expr, Resolv Mode::withAdjustment() );1701 finder.find( initExpr->expr, ResolveMode::withAdjustment() ); 1702 1702 1703 1703 Cost minExprCost = Cost::infinity; … … 1889 1889 } 1890 1890 1891 void CandidateFinder::find( const ast::Expr * expr, Resolv Mode mode ) {1891 void CandidateFinder::find( const ast::Expr * expr, ResolveMode mode ) { 1892 1892 // Find alternatives for expression 1893 1893 ast::Pass<Finder> finder{ *this }; … … 2004 2004 for ( const auto & x : xs ) { 2005 2005 out.emplace_back( context, env ); 2006 out.back().find( x, Resolv Mode::withAdjustment() );2006 out.back().find( x, ResolveMode::withAdjustment() ); 2007 2007 2008 2008 PRINT( -
src/ResolvExpr/CandidateFinder.hpp
r83fd57d r4a89b52 17 17 18 18 #include "Candidate.hpp" 19 #include "Resolv Mode.h"19 #include "ResolveMode.hpp" 20 20 #include "AST/Fwd.hpp" 21 21 #include "AST/Node.hpp" … … 43 43 44 44 /// Fill candidates with feasible resolutions for `expr` 45 void find( const ast::Expr * expr, Resolv Mode mode = {} );45 void find( const ast::Expr * expr, ResolveMode mode = {} ); 46 46 bool pruneCandidates( CandidateList & candidates, CandidateList & out, std::vector<std::string> & errors ); 47 47 -
src/ResolvExpr/CandidatePrinter.cpp
r83fd57d r4a89b52 16 16 #include "CandidatePrinter.hpp" 17 17 18 #include <iostream> 19 18 20 #include "AST/Expr.hpp" 19 21 #include "AST/Pass.hpp" … … 23 25 #include "ResolvExpr/CandidateFinder.hpp" 24 26 #include "ResolvExpr/Resolver.h" 25 26 #include <iostream>27 27 28 28 namespace ResolvExpr { … … 39 39 ast::TypeEnvironment env; 40 40 CandidateFinder finder( { symtab, transUnit().global }, env ); 41 finder.find( stmt->expr, Resolv Mode::withAdjustment() );41 finder.find( stmt->expr, ResolveMode::withAdjustment() ); 42 42 int count = 1; 43 43 os << "There are " << finder.candidates.size() << " candidates\n"; -
src/ResolvExpr/ResolveMode.hpp
r83fd57d r4a89b52 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Resolv Mode.h--7 // ResolveMode.hpp -- 8 8 // 9 9 // Author : Aaron B. Moss … … 19 19 20 20 /// Flag set for resolution 21 struct Resolv Mode {21 struct ResolveMode { 22 22 const bool adjust; ///< Adjust array and function types to pointer types? [false] 23 23 const bool prune; ///< Prune alternatives to min-cost per return type? [true] 24 24 const bool failFast; ///< Fail on no resulting alternatives? [true] 25 25 26 constexpr Resolv Mode(bool a, bool p, bool ff)26 constexpr ResolveMode(bool a, bool p, bool ff) 27 27 : adjust(a), prune(p), failFast(ff) {} 28 28 29 29 /// Default settings 30 constexpr Resolv Mode() : adjust(false), prune(true), failFast(true) {}30 constexpr ResolveMode() : adjust(false), prune(true), failFast(true) {} 31 31 32 32 /// With adjust flag set; turns array and function types into equivalent pointers 33 static constexpr Resolv Mode withAdjustment() { return { true, true, true }; }33 static constexpr ResolveMode withAdjustment() { return { true, true, true }; } 34 34 35 35 /// With adjust flag set but prune unset; pruning ensures there is at least one alternative 36 36 /// per result type 37 static constexpr Resolv Mode withoutPrune() { return { true, false, true }; }37 static constexpr ResolveMode withoutPrune() { return { true, false, true }; } 38 38 39 39 /// With adjust and prune flags set but failFast unset; failFast ensures there is at least 40 40 /// one resulting alternative 41 static constexpr Resolv Mode withoutFailFast() { return { true, true, false }; }41 static constexpr ResolveMode withoutFailFast() { return { true, true, false }; } 42 42 43 43 /// The same mode, but with satisfyAssns turned on; for top-level calls 44 Resolv Mode atTopLevel() const { return { adjust, true, failFast }; }44 ResolveMode atTopLevel() const { return { adjust, true, failFast }; } 45 45 }; 46 46 -
src/ResolvExpr/Resolver.cc
r83fd57d r4a89b52 25 25 #include "Resolver.h" 26 26 #include "ResolveTypeof.h" 27 #include "Resolv Mode.h" // for ResolvMode27 #include "ResolveMode.hpp" // for ResolveMode 28 28 #include "typeops.h" // for extractResultType 29 29 #include "Unify.h" // for unify … … 123 123 CandidateRef findUnfinishedKindExpression( 124 124 const ast::Expr * untyped, const ResolveContext & context, const std::string & kind, 125 std::function<bool(const Candidate &)> pred = anyCandidate, Resolv Mode mode = {}125 std::function<bool(const Candidate &)> pred = anyCandidate, ResolveMode mode = {} 126 126 ) { 127 127 if ( ! untyped ) return nullptr; … … 263 263 ast::ptr< ast::CastExpr > untyped = new ast::CastExpr{ expr }; 264 264 CandidateRef choice = findUnfinishedKindExpression( 265 untyped, context, "", anyCandidate, Resolv Mode::withAdjustment() );265 untyped, context, "", anyCandidate, ResolveMode::withAdjustment() ); 266 266 267 267 // a cast expression has either 0 or 1 interpretations (by language rules); … … 292 292 const ast::Expr * untyped, const ResolveContext & context, 293 293 std::function<bool(const Candidate &)> pred = anyCandidate, 294 const std::string & kind = "", Resolv Mode mode = {}294 const std::string & kind = "", ResolveMode mode = {} 295 295 ) { 296 296 if ( ! untyped ) return {}; … … 860 860 861 861 // Find all candidates for a function in canonical form 862 funcFinder.find( clause.target, Resolv Mode::withAdjustment() );862 funcFinder.find( clause.target, ResolveMode::withAdjustment() ); 863 863 864 864 if ( funcFinder.candidates.empty() ) { -
src/ResolvExpr/module.mk
r83fd57d r4a89b52 47 47 ResolvExpr/ResolveTypeof.cc \ 48 48 ResolvExpr/ResolveTypeof.h \ 49 ResolvExpr/Resolv Mode.h\49 ResolvExpr/ResolveMode.hpp \ 50 50 ResolvExpr/SatisfyAssertions.cpp \ 51 51 ResolvExpr/SatisfyAssertions.hpp \ -
src/Tuples/TupleAssignment.cc
r83fd57d r4a89b52 13 13 // Update Count : 10 14 14 // 15 16 #include "Tuples.h" 15 17 16 18 #include <algorithm> // for transform … … 224 226 // by the cast type as needed, and transfer the resulting environment. 225 227 ResolvExpr::CandidateFinder finder( spotter.crntFinder.context, env ); 226 finder.find( rhsCand->expr, ResolvExpr::Resolv Mode::withAdjustment() );228 finder.find( rhsCand->expr, ResolvExpr::ResolveMode::withAdjustment() ); 227 229 assert( 1 == finder.candidates.size() ); 228 230 env = std::move( finder.candidates.front()->env ); … … 345 347 346 348 try { 347 finder.find( expr, ResolvExpr::Resolv Mode::withAdjustment() );349 finder.find( expr, ResolvExpr::ResolveMode::withAdjustment() ); 348 350 } catch (...) { 349 351 // No match is not failure, just that this tuple assignment is invalid.
Note: See TracChangeset
for help on using the changeset viewer.