Ignore:
Timestamp:
Mar 16, 2022, 4:41:01 PM (2 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
f7496c5
Parents:
9d8124f
Message:

Thread global information through resolution. Non-top-level calls to the resolver have a bit of a hack but improvements would require changes to the Pass helpers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r9d8124f r39d8950  
    1010// Created On       : Wed Jun 5 14:30:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Oct  1 14:55:00 2019
    13 // Update Count     : 2
     12// Last Modified On : Wed Mar 16 11:58:00 2022
     13// Update Count     : 3
    1414//
    1515
     
    595595        /// Actually visits expressions to find their candidate interpretations
    596596        class Finder final : public ast::WithShortCircuiting {
     597                const ResolveContext & context;
    597598                const ast::SymbolTable & symtab;
    598599        public:
     
    618619
    619620                Finder( CandidateFinder & f )
    620                 : symtab( f.localSyms ), selfFinder( f ), candidates( f.candidates ), tenv( f.env ),
    621                   targetType( f.targetType ) {}
     621                : context( f.context ), symtab( context.symtab ), selfFinder( f ),
     622                  candidates( f.candidates ), tenv( f.env ), targetType( f.targetType ) {}
    622623
    623624                void previsit( const ast::Node * ) { visit_children = false; }
     
    872873                        Tuples::handleTupleAssignment( selfFinder, untypedExpr, argCandidates );
    873874
    874                         CandidateFinder funcFinder{ symtab, tenv };
     875                        CandidateFinder funcFinder( context, tenv );
    875876                        if (auto nameExpr = untypedExpr->func.as<ast::NameExpr>()) {
    876877                                auto kind = ast::SymbolTable::getSpecialFunctionKind(nameExpr->name);
     
    918919                        // find function operators
    919920                        ast::ptr< ast::Expr > opExpr = new ast::NameExpr{ untypedExpr->location, "?()" };
    920                         CandidateFinder opFinder{ symtab, tenv };
     921                        CandidateFinder opFinder( context, tenv );
    921922                        // okay if there aren't any function operations
    922923                        opFinder.find( opExpr, ResolvMode::withoutFailFast() );
     
    10591060
    10601061                void postvisit( const ast::AddressExpr * addressExpr ) {
    1061                         CandidateFinder finder{ symtab, tenv };
     1062                        CandidateFinder finder( context, tenv );
    10621063                        finder.find( addressExpr->arg );
    10631064
     
    10791080                        ast::ptr< ast::Type > toType = castExpr->result;
    10801081                        assert( toType );
    1081                         toType = resolveTypeof( toType, symtab );
     1082                        toType = resolveTypeof( toType, context );
    10821083                        // toType = SymTab::validateType( castExpr->location, toType, symtab );
    10831084                        toType = adjustExprType( toType, tenv, symtab );
    10841085
    1085                         CandidateFinder finder{ symtab, tenv, toType };
     1086                        CandidateFinder finder( context, tenv, toType );
    10861087                        finder.find( castExpr->arg, ResolvMode::withAdjustment() );
    10871088
     
    11361137                void postvisit( const ast::VirtualCastExpr * castExpr ) {
    11371138                        assertf( castExpr->result, "Implicit virtual cast targets not yet supported." );
    1138                         CandidateFinder finder{ symtab, tenv };
     1139                        CandidateFinder finder( context, tenv );
    11391140                        // don't prune here, all alternatives guaranteed to have same type
    11401141                        finder.find( castExpr->arg, ResolvMode::withoutPrune() );
     
    11531154                        auto target = inst->base.get();
    11541155
    1155                         CandidateFinder finder{ symtab, tenv };
     1156                        CandidateFinder finder( context, tenv );
    11561157
    11571158                        auto pick_alternatives = [target, this](CandidateList & found, bool expect_ref) {
     
    12021203
    12031204                void postvisit( const ast::UntypedMemberExpr * memberExpr ) {
    1204                         CandidateFinder aggFinder{ symtab, tenv };
     1205                        CandidateFinder aggFinder( context, tenv );
    12051206                        aggFinder.find( memberExpr->aggregate, ResolvMode::withAdjustment() );
    12061207                        for ( CandidateRef & agg : aggFinder.candidates ) {
     
    12871288                                addCandidate(
    12881289                                        new ast::SizeofExpr{
    1289                                                 sizeofExpr->location, resolveTypeof( sizeofExpr->type, symtab ) },
     1290                                                sizeofExpr->location, resolveTypeof( sizeofExpr->type, context ) },
    12901291                                        tenv );
    12911292                        } else {
    12921293                                // find all candidates for the argument to sizeof
    1293                                 CandidateFinder finder{ symtab, tenv };
     1294                                CandidateFinder finder( context, tenv );
    12941295                                finder.find( sizeofExpr->expr );
    12951296                                // find the lowest-cost candidate, otherwise ambiguous
     
    13111312                                addCandidate(
    13121313                                        new ast::AlignofExpr{
    1313                                                 alignofExpr->location, resolveTypeof( alignofExpr->type, symtab ) },
     1314                                                alignofExpr->location, resolveTypeof( alignofExpr->type, context ) },
    13141315                                        tenv );
    13151316                        } else {
    13161317                                // find all candidates for the argument to alignof
    1317                                 CandidateFinder finder{ symtab, tenv };
     1318                                CandidateFinder finder( context, tenv );
    13181319                                finder.find( alignofExpr->expr );
    13191320                                // find the lowest-cost candidate, otherwise ambiguous
     
    13541355
    13551356                void postvisit( const ast::LogicalExpr * logicalExpr ) {
    1356                         CandidateFinder finder1{ symtab, tenv };
     1357                        CandidateFinder finder1( context, tenv );
    13571358                        finder1.find( logicalExpr->arg1, ResolvMode::withAdjustment() );
    13581359                        if ( finder1.candidates.empty() ) return;
    13591360
    1360                         CandidateFinder finder2{ symtab, tenv };
     1361                        CandidateFinder finder2( context, tenv );
    13611362                        finder2.find( logicalExpr->arg2, ResolvMode::withAdjustment() );
    13621363                        if ( finder2.candidates.empty() ) return;
     
    13841385                void postvisit( const ast::ConditionalExpr * conditionalExpr ) {
    13851386                        // candidates for condition
    1386                         CandidateFinder finder1{ symtab, tenv };
     1387                        CandidateFinder finder1( context, tenv );
    13871388                        finder1.find( conditionalExpr->arg1, ResolvMode::withAdjustment() );
    13881389                        if ( finder1.candidates.empty() ) return;
    13891390
    13901391                        // candidates for true result
    1391                         CandidateFinder finder2{ symtab, tenv };
     1392                        CandidateFinder finder2( context, tenv );
    13921393                        finder2.find( conditionalExpr->arg2, ResolvMode::withAdjustment() );
    13931394                        if ( finder2.candidates.empty() ) return;
    13941395
    13951396                        // candidates for false result
    1396                         CandidateFinder finder3{ symtab, tenv };
     1397                        CandidateFinder finder3( context, tenv );
    13971398                        finder3.find( conditionalExpr->arg3, ResolvMode::withAdjustment() );
    13981399                        if ( finder3.candidates.empty() ) return;
     
    14451446                void postvisit( const ast::CommaExpr * commaExpr ) {
    14461447                        ast::TypeEnvironment env{ tenv };
    1447                         ast::ptr< ast::Expr > arg1 = resolveInVoidContext( commaExpr->arg1, symtab, env );
    1448 
    1449                         CandidateFinder finder2{ symtab, env };
     1448                        ast::ptr< ast::Expr > arg1 = resolveInVoidContext( commaExpr->arg1, context, env );
     1449
     1450                        CandidateFinder finder2( context, env );
    14501451                        finder2.find( commaExpr->arg2, ResolvMode::withAdjustment() );
    14511452
     
    14601461
    14611462                void postvisit( const ast::ConstructorExpr * ctorExpr ) {
    1462                         CandidateFinder finder{ symtab, tenv };
     1463                        CandidateFinder finder( context, tenv );
    14631464                        finder.find( ctorExpr->callExpr, ResolvMode::withoutPrune() );
    14641465                        for ( CandidateRef & r : finder.candidates ) {
     
    14691470                void postvisit( const ast::RangeExpr * rangeExpr ) {
    14701471                        // resolve low and high, accept candidates where low and high types unify
    1471                         CandidateFinder finder1{ symtab, tenv };
     1472                        CandidateFinder finder1( context, tenv );
    14721473                        finder1.find( rangeExpr->low, ResolvMode::withAdjustment() );
    14731474                        if ( finder1.candidates.empty() ) return;
    14741475
    1475                         CandidateFinder finder2{ symtab, tenv };
     1476                        CandidateFinder finder2( context, tenv );
    14761477                        finder2.find( rangeExpr->high, ResolvMode::withAdjustment() );
    14771478                        if ( finder2.candidates.empty() ) return;
     
    15491550
    15501551                void postvisit( const ast::UniqueExpr * unqExpr ) {
    1551                         CandidateFinder finder{ symtab, tenv };
     1552                        CandidateFinder finder( context, tenv );
    15521553                        finder.find( unqExpr->expr, ResolvMode::withAdjustment() );
    15531554                        for ( CandidateRef & r : finder.candidates ) {
     
    15581559
    15591560                void postvisit( const ast::StmtExpr * stmtExpr ) {
    1560                         addCandidate( resolveStmtExpr( stmtExpr, symtab ), tenv );
     1561                        addCandidate( resolveStmtExpr( stmtExpr, context ), tenv );
    15611562                }
    15621563
     
    15701571                        for ( const ast::InitAlternative & initAlt : initExpr->initAlts ) {
    15711572                                // calculate target type
    1572                                 const ast::Type * toType = resolveTypeof( initAlt.type, symtab );
     1573                                const ast::Type * toType = resolveTypeof( initAlt.type, context );
    15731574                                // toType = SymTab::validateType( initExpr->location, toType, symtab );
    15741575                                toType = adjustExprType( toType, tenv, symtab );
     
    15761577                                // types are not bound to the initialization type, since return type variables are
    15771578                                // only open for the duration of resolving the UntypedExpr.
    1578                                 CandidateFinder finder{ symtab, tenv, toType };
     1579                                CandidateFinder finder( context, tenv, toType );
    15791580                                finder.find( initExpr->expr, ResolvMode::withAdjustment() );
    15801581                                for ( CandidateRef & cand : finder.candidates ) {
     
    16931694                }
    16941695                else {
    1695                         satisfyAssertions(candidate, localSyms, satisfied, errors);
     1696                        satisfyAssertions(candidate, context.symtab, satisfied, errors);
    16961697                        needRecomputeKey = true;
    16971698                }
     
    18551856                        r->expr = ast::mutate_field(
    18561857                                r->expr.get(), &ast::Expr::result,
    1857                                 adjustExprType( r->expr->result, r->env, localSyms ) );
     1858                                adjustExprType( r->expr->result, r->env, context.symtab ) );
    18581859                }
    18591860        }
     
    18731874
    18741875        for ( const auto & x : xs ) {
    1875                 out.emplace_back( localSyms, env );
     1876                out.emplace_back( context, env );
    18761877                out.back().find( x, ResolvMode::withAdjustment() );
    18771878
Note: See TracChangeset for help on using the changeset viewer.