Ignore:
Timestamp:
Feb 5, 2024, 2:17:33 AM (5 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
47bd204
Parents:
020fa10
Message:
  1. Add debug print option for replacePseudoFunc; 2. Change resolver handling enum types; 3. change QualifiedNameExpr? representation pre-resolver; 4. Disable able a test that currently doesn't work
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r020fa10 ra55ebcc  
    672672                void postvisit( const ast::StmtExpr * stmtExpr );
    673673                void postvisit( const ast::UntypedInitExpr * initExpr );
     674                void postvisit( const ast::QualifiedNameExpr * qualifiedExpr );
    674675
    675676                void postvisit( const ast::InitExpr * ) {
     
    890891                } else if ( auto unionInst = aggrExpr->result.as< ast::UnionInstType >() ) {
    891892                        addAggMembers( unionInst, aggrExpr, *cand, Cost::unsafe, "" );
    892                 } else if ( auto enumInst = aggrExpr->result.as< ast::EnumInstType >() ) {
     893                }
     894                else if ( auto enumInst = aggrExpr->result.as< ast::EnumInstType >() ) {
    893895                        // The Attribute Arrays are not yet generated, need to proxy them
    894896                        // as attribute function call
     
    14011403        void Finder::postvisit( const ast::VariableExpr * variableExpr ) {
    14021404                // not sufficient to just pass `variableExpr` here, type might have changed since
    1403                 // creation
    1404                 if ( auto obj = dynamic_cast<const ast::ObjectDecl *>( variableExpr->var.get() )) {
    1405                         if ( auto enumInstType = dynamic_cast<const ast::EnumInstType *>( obj->type.get() ) ) {
    1406                                 if ( enumInstType->base && enumInstType->base->base ) {
    1407                                         const CodeLocation & location = variableExpr->location;
    1408                                         auto ids = symtab.lookupId( "valueE" );
    1409                                                 for ( ast::SymbolTable::IdData & id : ids ) {
    1410                                                         if ( auto func = id.id.as<ast::FunctionDecl>() ) {
    1411                                                                 if ( func->params.size() == 1 ) {
    1412                                                                         ast::ptr<ast::DeclWithType> valueEParam = func->params.front();
    1413                                                                         auto valueEParamType = valueEParam->get_type();
    1414                                                                         ast::OpenVarSet funcOpen;
    1415                                                                         ast::AssertionSet funcNeed, funcHave;
    1416                                                                         ast::TypeEnvironment funcEnv{ tenv };
    1417                                                                         ast::ptr<ast::Type> common;
    1418                                                                         if ( unifyInexact( valueEParamType, enumInstType, funcEnv, funcNeed, funcHave, funcOpen, WidenMode{ true, true }, common ) ) {
    1419                                                                                 auto appl = new ast::ApplicationExpr( location,
    1420                                                                                         ast::VariableExpr::functionPointer( location,  func), { variableExpr } );
    1421                                                                                 // addCandidate( appl, copy( tenv ),  );
    1422                                                                                 Candidate cand {appl, copy( tenv )};
    1423                                                                                 addCandidate( cand, appl, Cost::safe );
    1424                                                                         }
    1425                                                                 }
    1426                                                         }
    1427                                                 }
    1428                                 }
    1429                        
    1430                         }
    1431                 }
    1432                 addCandidate( variableExpr, tenv );
    1433                
     1405                addCandidate( variableExpr, tenv );             
    14341406        }
    14351407
     
    18071779        }
    18081780
     1781        void Finder::postvisit( const ast::QualifiedNameExpr * expr ) {
     1782                std::vector< ast::SymbolTable::IdData > declList = symtab.lookupId( expr->name );
     1783                if ( declList.empty() ) return;
     1784
     1785                for ( ast::SymbolTable::IdData & data: declList ) {
     1786                        const ast::Type * t = data.id->get_type()->stripReferences();
     1787                        if ( const ast::EnumInstType * enumInstType =
     1788                                dynamic_cast<const ast::EnumInstType *>( t ) ) {
     1789                                if ( enumInstType->base->name == expr->type_decl->name ) {
     1790                                        Cost cost = Cost::zero;
     1791                                        ast::Expr * newExpr = data.combine( expr->location, cost );
     1792                                        CandidateRef newCand =
     1793                                                std::make_shared<Candidate>(
     1794                                                        newExpr, copy( tenv ), ast::OpenVarSet{},
     1795                                                        ast::AssertionSet{}, Cost::zero, cost
     1796                                                );
     1797                                       
     1798                                        if (newCand->expr->env) {
     1799                                                newCand->env.add(*newCand->expr->env);
     1800                                                auto mutExpr = newCand->expr.get_and_mutate();
     1801                                                mutExpr->env  = nullptr;
     1802                                                newCand->expr = mutExpr;
     1803                                        }
     1804
     1805                                        newCand->expr = ast::mutate_field(
     1806                                                newCand->expr.get(), &ast::Expr::result,
     1807                                                renameTyVars( newCand->expr->result ) );
     1808                                        addAnonConversions( newCand );
     1809                                        candidates.emplace_back( std::move( newCand ) );
     1810                                }
     1811                        }
     1812                }
     1813        }
    18091814        // size_t Finder::traceId = Stats::Heap::new_stacktrace_id("Finder");
    18101815        /// Prunes a list of candidates down to those that have the minimum conversion cost for a given
Note: See TracChangeset for help on using the changeset viewer.