Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r39d8950 r7f62b708  
    1010// Created On       : Wed Jun 5 14:30:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Mar 16 11:58:00 2022
    13 // Update Count     : 3
     12// Last Modified On : Tue Oct  1 14:55:00 2019
     13// Update Count     : 2
    1414//
    1515
     
    595595        /// Actually visits expressions to find their candidate interpretations
    596596        class Finder final : public ast::WithShortCircuiting {
    597                 const ResolveContext & context;
    598597                const ast::SymbolTable & symtab;
    599598        public:
     
    619618
    620619                Finder( CandidateFinder & f )
    621                 : context( f.context ), symtab( context.symtab ), selfFinder( f ),
    622                   candidates( f.candidates ), tenv( f.env ), targetType( f.targetType ) {}
     620                : symtab( f.localSyms ), selfFinder( f ), candidates( f.candidates ), tenv( f.env ),
     621                  targetType( f.targetType ) {}
    623622
    624623                void previsit( const ast::Node * ) { visit_children = false; }
     
    873872                        Tuples::handleTupleAssignment( selfFinder, untypedExpr, argCandidates );
    874873
    875                         CandidateFinder funcFinder( context, tenv );
     874                        CandidateFinder funcFinder{ symtab, tenv };
    876875                        if (auto nameExpr = untypedExpr->func.as<ast::NameExpr>()) {
    877876                                auto kind = ast::SymbolTable::getSpecialFunctionKind(nameExpr->name);
     
    919918                        // find function operators
    920919                        ast::ptr< ast::Expr > opExpr = new ast::NameExpr{ untypedExpr->location, "?()" };
    921                         CandidateFinder opFinder( context, tenv );
     920                        CandidateFinder opFinder{ symtab, tenv };
    922921                        // okay if there aren't any function operations
    923922                        opFinder.find( opExpr, ResolvMode::withoutFailFast() );
     
    10601059
    10611060                void postvisit( const ast::AddressExpr * addressExpr ) {
    1062                         CandidateFinder finder( context, tenv );
     1061                        CandidateFinder finder{ symtab, tenv };
    10631062                        finder.find( addressExpr->arg );
    10641063
     
    10801079                        ast::ptr< ast::Type > toType = castExpr->result;
    10811080                        assert( toType );
    1082                         toType = resolveTypeof( toType, context );
     1081                        toType = resolveTypeof( toType, symtab );
    10831082                        // toType = SymTab::validateType( castExpr->location, toType, symtab );
    10841083                        toType = adjustExprType( toType, tenv, symtab );
    10851084
    1086                         CandidateFinder finder( context, tenv, toType );
     1085                        CandidateFinder finder{ symtab, tenv, toType };
    10871086                        finder.find( castExpr->arg, ResolvMode::withAdjustment() );
    10881087
     
    11371136                void postvisit( const ast::VirtualCastExpr * castExpr ) {
    11381137                        assertf( castExpr->result, "Implicit virtual cast targets not yet supported." );
    1139                         CandidateFinder finder( context, tenv );
     1138                        CandidateFinder finder{ symtab, tenv };
    11401139                        // don't prune here, all alternatives guaranteed to have same type
    11411140                        finder.find( castExpr->arg, ResolvMode::withoutPrune() );
     
    11541153                        auto target = inst->base.get();
    11551154
    1156                         CandidateFinder finder( context, tenv );
     1155                        CandidateFinder finder{ symtab, tenv };
    11571156
    11581157                        auto pick_alternatives = [target, this](CandidateList & found, bool expect_ref) {
     
    12031202
    12041203                void postvisit( const ast::UntypedMemberExpr * memberExpr ) {
    1205                         CandidateFinder aggFinder( context, tenv );
     1204                        CandidateFinder aggFinder{ symtab, tenv };
    12061205                        aggFinder.find( memberExpr->aggregate, ResolvMode::withAdjustment() );
    12071206                        for ( CandidateRef & agg : aggFinder.candidates ) {
     
    12881287                                addCandidate(
    12891288                                        new ast::SizeofExpr{
    1290                                                 sizeofExpr->location, resolveTypeof( sizeofExpr->type, context ) },
     1289                                                sizeofExpr->location, resolveTypeof( sizeofExpr->type, symtab ) },
    12911290                                        tenv );
    12921291                        } else {
    12931292                                // find all candidates for the argument to sizeof
    1294                                 CandidateFinder finder( context, tenv );
     1293                                CandidateFinder finder{ symtab, tenv };
    12951294                                finder.find( sizeofExpr->expr );
    12961295                                // find the lowest-cost candidate, otherwise ambiguous
     
    13121311                                addCandidate(
    13131312                                        new ast::AlignofExpr{
    1314                                                 alignofExpr->location, resolveTypeof( alignofExpr->type, context ) },
     1313                                                alignofExpr->location, resolveTypeof( alignofExpr->type, symtab ) },
    13151314                                        tenv );
    13161315                        } else {
    13171316                                // find all candidates for the argument to alignof
    1318                                 CandidateFinder finder( context, tenv );
     1317                                CandidateFinder finder{ symtab, tenv };
    13191318                                finder.find( alignofExpr->expr );
    13201319                                // find the lowest-cost candidate, otherwise ambiguous
     
    13551354
    13561355                void postvisit( const ast::LogicalExpr * logicalExpr ) {
    1357                         CandidateFinder finder1( context, tenv );
     1356                        CandidateFinder finder1{ symtab, tenv };
    13581357                        finder1.find( logicalExpr->arg1, ResolvMode::withAdjustment() );
    13591358                        if ( finder1.candidates.empty() ) return;
    13601359
    1361                         CandidateFinder finder2( context, tenv );
     1360                        CandidateFinder finder2{ symtab, tenv };
    13621361                        finder2.find( logicalExpr->arg2, ResolvMode::withAdjustment() );
    13631362                        if ( finder2.candidates.empty() ) return;
     
    13851384                void postvisit( const ast::ConditionalExpr * conditionalExpr ) {
    13861385                        // candidates for condition
    1387                         CandidateFinder finder1( context, tenv );
     1386                        CandidateFinder finder1{ symtab, tenv };
    13881387                        finder1.find( conditionalExpr->arg1, ResolvMode::withAdjustment() );
    13891388                        if ( finder1.candidates.empty() ) return;
    13901389
    13911390                        // candidates for true result
    1392                         CandidateFinder finder2( context, tenv );
     1391                        CandidateFinder finder2{ symtab, tenv };
    13931392                        finder2.find( conditionalExpr->arg2, ResolvMode::withAdjustment() );
    13941393                        if ( finder2.candidates.empty() ) return;
    13951394
    13961395                        // candidates for false result
    1397                         CandidateFinder finder3( context, tenv );
     1396                        CandidateFinder finder3{ symtab, tenv };
    13981397                        finder3.find( conditionalExpr->arg3, ResolvMode::withAdjustment() );
    13991398                        if ( finder3.candidates.empty() ) return;
     
    14461445                void postvisit( const ast::CommaExpr * commaExpr ) {
    14471446                        ast::TypeEnvironment env{ tenv };
    1448                         ast::ptr< ast::Expr > arg1 = resolveInVoidContext( commaExpr->arg1, context, env );
    1449 
    1450                         CandidateFinder finder2( context, env );
     1447                        ast::ptr< ast::Expr > arg1 = resolveInVoidContext( commaExpr->arg1, symtab, env );
     1448
     1449                        CandidateFinder finder2{ symtab, env };
    14511450                        finder2.find( commaExpr->arg2, ResolvMode::withAdjustment() );
    14521451
     
    14611460
    14621461                void postvisit( const ast::ConstructorExpr * ctorExpr ) {
    1463                         CandidateFinder finder( context, tenv );
     1462                        CandidateFinder finder{ symtab, tenv };
    14641463                        finder.find( ctorExpr->callExpr, ResolvMode::withoutPrune() );
    14651464                        for ( CandidateRef & r : finder.candidates ) {
     
    14701469                void postvisit( const ast::RangeExpr * rangeExpr ) {
    14711470                        // resolve low and high, accept candidates where low and high types unify
    1472                         CandidateFinder finder1( context, tenv );
     1471                        CandidateFinder finder1{ symtab, tenv };
    14731472                        finder1.find( rangeExpr->low, ResolvMode::withAdjustment() );
    14741473                        if ( finder1.candidates.empty() ) return;
    14751474
    1476                         CandidateFinder finder2( context, tenv );
     1475                        CandidateFinder finder2{ symtab, tenv };
    14771476                        finder2.find( rangeExpr->high, ResolvMode::withAdjustment() );
    14781477                        if ( finder2.candidates.empty() ) return;
     
    15501549
    15511550                void postvisit( const ast::UniqueExpr * unqExpr ) {
    1552                         CandidateFinder finder( context, tenv );
     1551                        CandidateFinder finder{ symtab, tenv };
    15531552                        finder.find( unqExpr->expr, ResolvMode::withAdjustment() );
    15541553                        for ( CandidateRef & r : finder.candidates ) {
     
    15591558
    15601559                void postvisit( const ast::StmtExpr * stmtExpr ) {
    1561                         addCandidate( resolveStmtExpr( stmtExpr, context ), tenv );
     1560                        addCandidate( resolveStmtExpr( stmtExpr, symtab ), tenv );
    15621561                }
    15631562
     
    15711570                        for ( const ast::InitAlternative & initAlt : initExpr->initAlts ) {
    15721571                                // calculate target type
    1573                                 const ast::Type * toType = resolveTypeof( initAlt.type, context );
     1572                                const ast::Type * toType = resolveTypeof( initAlt.type, symtab );
    15741573                                // toType = SymTab::validateType( initExpr->location, toType, symtab );
    15751574                                toType = adjustExprType( toType, tenv, symtab );
     
    15771576                                // types are not bound to the initialization type, since return type variables are
    15781577                                // only open for the duration of resolving the UntypedExpr.
    1579                                 CandidateFinder finder( context, tenv, toType );
     1578                                CandidateFinder finder{ symtab, tenv, toType };
    15801579                                finder.find( initExpr->expr, ResolvMode::withAdjustment() );
    15811580                                for ( CandidateRef & cand : finder.candidates ) {
     
    16941693                }
    16951694                else {
    1696                         satisfyAssertions(candidate, context.symtab, satisfied, errors);
     1695                        satisfyAssertions(candidate, localSyms, satisfied, errors);
    16971696                        needRecomputeKey = true;
    16981697                }
     
    18561855                        r->expr = ast::mutate_field(
    18571856                                r->expr.get(), &ast::Expr::result,
    1858                                 adjustExprType( r->expr->result, r->env, context.symtab ) );
     1857                                adjustExprType( r->expr->result, r->env, localSyms ) );
    18591858                }
    18601859        }
     
    18741873
    18751874        for ( const auto & x : xs ) {
    1876                 out.emplace_back( context, env );
     1875                out.emplace_back( localSyms, env );
    18771876                out.back().find( x, ResolvMode::withAdjustment() );
    18781877
Note: See TracChangeset for help on using the changeset viewer.