- File:
-
- 1 edited
-
src/ResolvExpr/CandidateFinder.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r0522ebe rab780e6 46 46 #include "AST/Type.hpp" 47 47 #include "Common/utility.h" // for move, copy 48 #include "Parser/parserutility.h" // for notZeroExpr49 48 #include "SymTab/Mangler.h" 50 49 #include "Tuples/Tuples.h" // for handleTupleAssignment … … 1018 1017 } 1019 1018 1020 if (argType.as<ast::PointerType>()) funcFinder.otypeKeys.insert(Mangle::Encoding::pointer); 1019 if (argType.as<ast::PointerType>()) funcFinder.otypeKeys.insert(Mangle::Encoding::pointer); 1021 1020 else funcFinder.otypeKeys.insert(Mangle::mangle(argType, Mangle::NoGenericParams | Mangle::Type)); 1022 1021 } … … 1283 1282 restructureCast( cand->expr, toType, castExpr->isGenerated ), 1284 1283 copy( cand->env ), std::move( open ), std::move( need ), cand->cost + thisCost); 1285 // currently assertions are always resolved immediately so this should have no effect. 1284 // currently assertions are always resolved immediately so this should have no effect. 1286 1285 // if this somehow changes in the future (e.g. delayed by indeterminate return type) 1287 1286 // we may need to revisit the logic. … … 1587 1586 void Finder::postvisit( const ast::LogicalExpr * logicalExpr ) { 1588 1587 CandidateFinder finder1( context, tenv ); 1589 ast::ptr<ast::Expr> arg1 = notZeroExpr( logicalExpr->arg1 );1588 ast::ptr<ast::Expr> arg1 = createCondExpr( logicalExpr->arg1 ); 1590 1589 finder1.find( arg1, ResolveMode::withAdjustment() ); 1591 1590 if ( finder1.candidates.empty() ) return; 1592 1591 1593 1592 CandidateFinder finder2( context, tenv ); 1594 ast::ptr<ast::Expr> arg2 = notZeroExpr( logicalExpr->arg2 );1593 ast::ptr<ast::Expr> arg2 = createCondExpr( logicalExpr->arg2 ); 1595 1594 finder2.find( arg2, ResolveMode::withAdjustment() ); 1596 1595 if ( finder2.candidates.empty() ) return; … … 1618 1617 void Finder::postvisit( const ast::ConditionalExpr * conditionalExpr ) { 1619 1618 // candidates for condition 1619 ast::ptr<ast::Expr> arg1 = createCondExpr( conditionalExpr->arg1 ); 1620 1620 CandidateFinder finder1( context, tenv ); 1621 ast::ptr<ast::Expr> arg1 = notZeroExpr( conditionalExpr->arg1 );1622 1621 finder1.find( arg1, ResolveMode::withAdjustment() ); 1623 1622 if ( finder1.candidates.empty() ) return; 1624 1623 1625 1624 // candidates for true result 1625 // FIX ME: resolves and runs arg1 twice when arg2 is missing. 1626 ast::Expr const * arg2 = conditionalExpr->arg2; 1627 arg2 = arg2 ? arg2 : conditionalExpr->arg1.get(); 1626 1628 CandidateFinder finder2( context, tenv ); 1627 1629 finder2.allowVoid = true; 1628 finder2.find( conditionalExpr->arg2, ResolveMode::withAdjustment() );1630 finder2.find( arg2, ResolveMode::withAdjustment() ); 1629 1631 if ( finder2.candidates.empty() ) return; 1630 1632 … … 1897 1899 CandidateRef newCand = 1898 1900 std::make_shared<Candidate>( 1899 newExpr, copy( tenv ), ast::OpenVarSet{}, 1901 newExpr, copy( tenv ), ast::OpenVarSet{}, 1900 1902 ast::AssertionSet{}, Cost::zero, cost 1901 1903 ); 1902 1904 1903 1905 if (newCand->expr->env) { 1904 1906 newCand->env.add(*newCand->expr->env); … … 2198 2200 } 2199 2201 2202 const ast::Expr * createCondExpr( const ast::Expr * expr ) { 2203 assert( expr ); 2204 return new ast::CastExpr( expr->location, 2205 ast::UntypedExpr::createCall( expr->location, 2206 "?!=?", 2207 { 2208 expr, 2209 new ast::ConstantExpr( expr->location, 2210 new ast::ZeroType(), "0", std::make_optional( 0ull ) 2211 ), 2212 } 2213 ), 2214 new ast::BasicType( ast::BasicType::SignedInt ) 2215 ); 2216 } 2217 2200 2218 } // namespace ResolvExpr 2201 2219
Note:
See TracChangeset
for help on using the changeset viewer.