Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    rab780e6 r0522ebe  
    4646#include "AST/Type.hpp"
    4747#include "Common/utility.h"       // for move, copy
     48#include "Parser/parserutility.h" // for notZeroExpr
    4849#include "SymTab/Mangler.h"
    4950#include "Tuples/Tuples.h"        // for handleTupleAssignment
     
    10171018                                        }
    10181019
    1019                                         if (argType.as<ast::PointerType>()) funcFinder.otypeKeys.insert(Mangle::Encoding::pointer);
     1020                                        if (argType.as<ast::PointerType>()) funcFinder.otypeKeys.insert(Mangle::Encoding::pointer);                                             
    10201021                                        else funcFinder.otypeKeys.insert(Mangle::mangle(argType, Mangle::NoGenericParams | Mangle::Type));
    10211022                                }
     
    12821283                                                restructureCast( cand->expr, toType, castExpr->isGenerated ),
    12831284                                                copy( cand->env ), std::move( open ), std::move( need ), cand->cost + thisCost);
    1284                                         // currently assertions are always resolved immediately so this should have no effect.
     1285                                        // currently assertions are always resolved immediately so this should have no effect. 
    12851286                                        // if this somehow changes in the future (e.g. delayed by indeterminate return type)
    12861287                                        // we may need to revisit the logic.
     
    15861587        void Finder::postvisit( const ast::LogicalExpr * logicalExpr ) {
    15871588                CandidateFinder finder1( context, tenv );
    1588                 ast::ptr<ast::Expr> arg1 = createCondExpr( logicalExpr->arg1 );
     1589                ast::ptr<ast::Expr> arg1 = notZeroExpr( logicalExpr->arg1 );
    15891590                finder1.find( arg1, ResolveMode::withAdjustment() );
    15901591                if ( finder1.candidates.empty() ) return;
    15911592
    15921593                CandidateFinder finder2( context, tenv );
    1593                 ast::ptr<ast::Expr> arg2 = createCondExpr( logicalExpr->arg2 );
     1594                ast::ptr<ast::Expr> arg2 = notZeroExpr( logicalExpr->arg2 );
    15941595                finder2.find( arg2, ResolveMode::withAdjustment() );
    15951596                if ( finder2.candidates.empty() ) return;
     
    16171618        void Finder::postvisit( const ast::ConditionalExpr * conditionalExpr ) {
    16181619                // candidates for condition
    1619                 ast::ptr<ast::Expr> arg1 = createCondExpr( conditionalExpr->arg1 );
    16201620                CandidateFinder finder1( context, tenv );
     1621                ast::ptr<ast::Expr> arg1 = notZeroExpr( conditionalExpr->arg1 );
    16211622                finder1.find( arg1, ResolveMode::withAdjustment() );
    16221623                if ( finder1.candidates.empty() ) return;
    16231624
    16241625                // 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();
    16281626                CandidateFinder finder2( context, tenv );
    16291627                finder2.allowVoid = true;
    1630                 finder2.find( arg2, ResolveMode::withAdjustment() );
     1628                finder2.find( conditionalExpr->arg2, ResolveMode::withAdjustment() );
    16311629                if ( finder2.candidates.empty() ) return;
    16321630
     
    18991897                                        CandidateRef newCand =
    19001898                                                std::make_shared<Candidate>(
    1901                                                         newExpr, copy( tenv ), ast::OpenVarSet{},
     1899                                                        newExpr, copy( tenv ), ast::OpenVarSet{}, 
    19021900                                                        ast::AssertionSet{}, Cost::zero, cost
    19031901                                                );
    1904 
     1902                                       
    19051903                                        if (newCand->expr->env) {
    19061904                                                newCand->env.add(*newCand->expr->env);
     
    22002198}
    22012199
    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 
    22182200} // namespace ResolvExpr
    22192201
Note: See TracChangeset for help on using the changeset viewer.