- File:
-
- 1 edited
-
src/ResolvExpr/CandidateFinder.cpp (modified) (24 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r39d8950 r7f62b708 10 10 // Created On : Wed Jun 5 14:30:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Mar 16 11:58:00 202213 // Update Count : 312 // Last Modified On : Tue Oct 1 14:55:00 2019 13 // Update Count : 2 14 14 // 15 15 … … 595 595 /// Actually visits expressions to find their candidate interpretations 596 596 class Finder final : public ast::WithShortCircuiting { 597 const ResolveContext & context;598 597 const ast::SymbolTable & symtab; 599 598 public: … … 619 618 620 619 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 ) {} 623 622 624 623 void previsit( const ast::Node * ) { visit_children = false; } … … 873 872 Tuples::handleTupleAssignment( selfFinder, untypedExpr, argCandidates ); 874 873 875 CandidateFinder funcFinder ( context, tenv );874 CandidateFinder funcFinder{ symtab, tenv }; 876 875 if (auto nameExpr = untypedExpr->func.as<ast::NameExpr>()) { 877 876 auto kind = ast::SymbolTable::getSpecialFunctionKind(nameExpr->name); … … 919 918 // find function operators 920 919 ast::ptr< ast::Expr > opExpr = new ast::NameExpr{ untypedExpr->location, "?()" }; 921 CandidateFinder opFinder ( context, tenv );920 CandidateFinder opFinder{ symtab, tenv }; 922 921 // okay if there aren't any function operations 923 922 opFinder.find( opExpr, ResolvMode::withoutFailFast() ); … … 1060 1059 1061 1060 void postvisit( const ast::AddressExpr * addressExpr ) { 1062 CandidateFinder finder ( context, tenv );1061 CandidateFinder finder{ symtab, tenv }; 1063 1062 finder.find( addressExpr->arg ); 1064 1063 … … 1080 1079 ast::ptr< ast::Type > toType = castExpr->result; 1081 1080 assert( toType ); 1082 toType = resolveTypeof( toType, context);1081 toType = resolveTypeof( toType, symtab ); 1083 1082 // toType = SymTab::validateType( castExpr->location, toType, symtab ); 1084 1083 toType = adjustExprType( toType, tenv, symtab ); 1085 1084 1086 CandidateFinder finder ( context, tenv, toType );1085 CandidateFinder finder{ symtab, tenv, toType }; 1087 1086 finder.find( castExpr->arg, ResolvMode::withAdjustment() ); 1088 1087 … … 1137 1136 void postvisit( const ast::VirtualCastExpr * castExpr ) { 1138 1137 assertf( castExpr->result, "Implicit virtual cast targets not yet supported." ); 1139 CandidateFinder finder ( context, tenv );1138 CandidateFinder finder{ symtab, tenv }; 1140 1139 // don't prune here, all alternatives guaranteed to have same type 1141 1140 finder.find( castExpr->arg, ResolvMode::withoutPrune() ); … … 1154 1153 auto target = inst->base.get(); 1155 1154 1156 CandidateFinder finder ( context, tenv );1155 CandidateFinder finder{ symtab, tenv }; 1157 1156 1158 1157 auto pick_alternatives = [target, this](CandidateList & found, bool expect_ref) { … … 1203 1202 1204 1203 void postvisit( const ast::UntypedMemberExpr * memberExpr ) { 1205 CandidateFinder aggFinder ( context, tenv );1204 CandidateFinder aggFinder{ symtab, tenv }; 1206 1205 aggFinder.find( memberExpr->aggregate, ResolvMode::withAdjustment() ); 1207 1206 for ( CandidateRef & agg : aggFinder.candidates ) { … … 1288 1287 addCandidate( 1289 1288 new ast::SizeofExpr{ 1290 sizeofExpr->location, resolveTypeof( sizeofExpr->type, context) },1289 sizeofExpr->location, resolveTypeof( sizeofExpr->type, symtab ) }, 1291 1290 tenv ); 1292 1291 } else { 1293 1292 // find all candidates for the argument to sizeof 1294 CandidateFinder finder ( context, tenv );1293 CandidateFinder finder{ symtab, tenv }; 1295 1294 finder.find( sizeofExpr->expr ); 1296 1295 // find the lowest-cost candidate, otherwise ambiguous … … 1312 1311 addCandidate( 1313 1312 new ast::AlignofExpr{ 1314 alignofExpr->location, resolveTypeof( alignofExpr->type, context) },1313 alignofExpr->location, resolveTypeof( alignofExpr->type, symtab ) }, 1315 1314 tenv ); 1316 1315 } else { 1317 1316 // find all candidates for the argument to alignof 1318 CandidateFinder finder ( context, tenv );1317 CandidateFinder finder{ symtab, tenv }; 1319 1318 finder.find( alignofExpr->expr ); 1320 1319 // find the lowest-cost candidate, otherwise ambiguous … … 1355 1354 1356 1355 void postvisit( const ast::LogicalExpr * logicalExpr ) { 1357 CandidateFinder finder1 ( context, tenv );1356 CandidateFinder finder1{ symtab, tenv }; 1358 1357 finder1.find( logicalExpr->arg1, ResolvMode::withAdjustment() ); 1359 1358 if ( finder1.candidates.empty() ) return; 1360 1359 1361 CandidateFinder finder2 ( context, tenv );1360 CandidateFinder finder2{ symtab, tenv }; 1362 1361 finder2.find( logicalExpr->arg2, ResolvMode::withAdjustment() ); 1363 1362 if ( finder2.candidates.empty() ) return; … … 1385 1384 void postvisit( const ast::ConditionalExpr * conditionalExpr ) { 1386 1385 // candidates for condition 1387 CandidateFinder finder1 ( context, tenv );1386 CandidateFinder finder1{ symtab, tenv }; 1388 1387 finder1.find( conditionalExpr->arg1, ResolvMode::withAdjustment() ); 1389 1388 if ( finder1.candidates.empty() ) return; 1390 1389 1391 1390 // candidates for true result 1392 CandidateFinder finder2 ( context, tenv );1391 CandidateFinder finder2{ symtab, tenv }; 1393 1392 finder2.find( conditionalExpr->arg2, ResolvMode::withAdjustment() ); 1394 1393 if ( finder2.candidates.empty() ) return; 1395 1394 1396 1395 // candidates for false result 1397 CandidateFinder finder3 ( context, tenv );1396 CandidateFinder finder3{ symtab, tenv }; 1398 1397 finder3.find( conditionalExpr->arg3, ResolvMode::withAdjustment() ); 1399 1398 if ( finder3.candidates.empty() ) return; … … 1446 1445 void postvisit( const ast::CommaExpr * commaExpr ) { 1447 1446 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 }; 1451 1450 finder2.find( commaExpr->arg2, ResolvMode::withAdjustment() ); 1452 1451 … … 1461 1460 1462 1461 void postvisit( const ast::ConstructorExpr * ctorExpr ) { 1463 CandidateFinder finder ( context, tenv );1462 CandidateFinder finder{ symtab, tenv }; 1464 1463 finder.find( ctorExpr->callExpr, ResolvMode::withoutPrune() ); 1465 1464 for ( CandidateRef & r : finder.candidates ) { … … 1470 1469 void postvisit( const ast::RangeExpr * rangeExpr ) { 1471 1470 // resolve low and high, accept candidates where low and high types unify 1472 CandidateFinder finder1 ( context, tenv );1471 CandidateFinder finder1{ symtab, tenv }; 1473 1472 finder1.find( rangeExpr->low, ResolvMode::withAdjustment() ); 1474 1473 if ( finder1.candidates.empty() ) return; 1475 1474 1476 CandidateFinder finder2 ( context, tenv );1475 CandidateFinder finder2{ symtab, tenv }; 1477 1476 finder2.find( rangeExpr->high, ResolvMode::withAdjustment() ); 1478 1477 if ( finder2.candidates.empty() ) return; … … 1550 1549 1551 1550 void postvisit( const ast::UniqueExpr * unqExpr ) { 1552 CandidateFinder finder ( context, tenv );1551 CandidateFinder finder{ symtab, tenv }; 1553 1552 finder.find( unqExpr->expr, ResolvMode::withAdjustment() ); 1554 1553 for ( CandidateRef & r : finder.candidates ) { … … 1559 1558 1560 1559 void postvisit( const ast::StmtExpr * stmtExpr ) { 1561 addCandidate( resolveStmtExpr( stmtExpr, context), tenv );1560 addCandidate( resolveStmtExpr( stmtExpr, symtab ), tenv ); 1562 1561 } 1563 1562 … … 1571 1570 for ( const ast::InitAlternative & initAlt : initExpr->initAlts ) { 1572 1571 // calculate target type 1573 const ast::Type * toType = resolveTypeof( initAlt.type, context);1572 const ast::Type * toType = resolveTypeof( initAlt.type, symtab ); 1574 1573 // toType = SymTab::validateType( initExpr->location, toType, symtab ); 1575 1574 toType = adjustExprType( toType, tenv, symtab ); … … 1577 1576 // types are not bound to the initialization type, since return type variables are 1578 1577 // only open for the duration of resolving the UntypedExpr. 1579 CandidateFinder finder ( context, tenv, toType );1578 CandidateFinder finder{ symtab, tenv, toType }; 1580 1579 finder.find( initExpr->expr, ResolvMode::withAdjustment() ); 1581 1580 for ( CandidateRef & cand : finder.candidates ) { … … 1694 1693 } 1695 1694 else { 1696 satisfyAssertions(candidate, context.symtab, satisfied, errors);1695 satisfyAssertions(candidate, localSyms, satisfied, errors); 1697 1696 needRecomputeKey = true; 1698 1697 } … … 1856 1855 r->expr = ast::mutate_field( 1857 1856 r->expr.get(), &ast::Expr::result, 1858 adjustExprType( r->expr->result, r->env, context.symtab) );1857 adjustExprType( r->expr->result, r->env, localSyms ) ); 1859 1858 } 1860 1859 } … … 1874 1873 1875 1874 for ( const auto & x : xs ) { 1876 out.emplace_back( context, env );1875 out.emplace_back( localSyms, env ); 1877 1876 out.back().find( x, ResolvMode::withAdjustment() ); 1878 1877
Note:
See TracChangeset
for help on using the changeset viewer.