- Timestamp:
- Jun 19, 2019, 2:15:08 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 1ae47de, b69233ac
- Parents:
- 3fc0f2a
- Location:
- src/ResolvExpr
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r3fc0f2a r17a0ede2 559 559 /// Generate a cast expression from `arg` to `toType` 560 560 const ast::Expr * restructureCast( 561 ast::ptr< ast::Expr > & arg, const ast::Type * toType, ast::GeneratedFlag isGenerated 561 ast::ptr< ast::Expr > & arg, const ast::Type * toType, ast::GeneratedFlag isGenerated = ast::GeneratedCast 562 562 ) { 563 563 if ( … … 1404 1404 1405 1405 void postvisit( const ast::StmtExpr * stmtExpr ) { 1406 #warning unimplemented 1407 (void)stmtExpr; 1408 assert(false); 1406 addCandidate( resolveStmtExpr( stmtExpr, symtab ), tenv ); 1409 1407 } 1410 1408 1411 1409 void postvisit( const ast::UntypedInitExpr * initExpr ) { 1412 #warning unimplemented 1413 (void)initExpr; 1414 assert(false); 1410 // handle each option like a cast 1411 CandidateList matches; 1412 PRINT( 1413 std::cerr << "untyped init expr: " << initExpr << std::endl; 1414 ) 1415 // O(n^2) checks of d-types with e-types 1416 for ( const ast::InitAlternative & initAlt : initExpr->initAlts ) { 1417 // calculate target type 1418 const ast::Type * toType = resolveTypeof( initAlt.type, symtab ); 1419 toType = SymTab::validateType( toType, symtab ); 1420 toType = adjustExprType( toType, tenv, symtab ); 1421 // The call to find must occur inside this loop, otherwise polymorphic return 1422 // types are not bound to the initialization type, since return type variables are 1423 // only open for the duration of resolving the UntypedExpr. 1424 CandidateFinder finder{ symtab, tenv, toType }; 1425 finder.find( initExpr->expr, ResolvMode::withAdjustment() ); 1426 for ( CandidateRef & cand : finder.candidates ) { 1427 ast::TypeEnvironment env{ cand->env }; 1428 ast::AssertionSet need( cand->need.begin(), cand->need.end() ), have; 1429 ast::OpenVarSet open{ cand->open }; 1430 1431 PRINT( 1432 std::cerr << " @ " << toType << " " << initAlt.designation << std::endl; 1433 ) 1434 1435 // It is possible that a cast can throw away some values in a multiply-valued 1436 // expression, e.g. cast-to-void, one value to zero. Figure out the prefix of 1437 // the subexpression results that are cast directly. The candidate is invalid 1438 // if it has fewer results than there are types to cast to. 1439 int discardedValues = cand->expr->result->size() - toType->size(); 1440 if ( discardedValues < 0 ) continue; 1441 1442 // unification run for side-effects 1443 unify( toType, cand->expr->result, env, need, have, open, symtab ); 1444 Cost thisCost = castCost( cand->expr->result, toType, symtab, env ); 1445 1446 if ( thisCost != Cost::infinity ) { 1447 // count one safe conversion for each value that is thrown away 1448 thisCost.incSafe( discardedValues ); 1449 CandidateRef newCand = std::make_shared<Candidate>( 1450 new ast::InitExpr{ 1451 initExpr->location, restructureCast( cand->expr, toType ), 1452 initAlt.designation }, 1453 copy( cand->env ), move( open ), move( need ), cand->cost, thisCost ); 1454 inferParameters( newCand, matches ); 1455 } 1456 } 1457 } 1458 1459 // select first on argument cost, then conversion cost 1460 CandidateList minArgCost = findMinCost( matches ); 1461 promoteCvtCost( minArgCost ); 1462 candidates = findMinCost( minArgCost ); 1415 1463 } 1416 1464 -
src/ResolvExpr/Resolver.cc
r3fc0f2a r17a0ede2 1249 1249 1250 1250 void resolve( std::list< ast::ptr<ast::Decl> >& translationUnit ) { 1251 ast::Pass< Resolver_new> resolver;1251 ast::Pass< Resolver_new > resolver; 1252 1252 accept_all( translationUnit, resolver ); 1253 } 1254 1255 ast::ptr< ast::Expr > resolveStmtExpr( 1256 const ast::StmtExpr * stmtExpr, const ast::SymbolTable & symtab 1257 ) { 1258 assert( stmtExpr ); 1259 ast::Pass< Resolver_new > resolver{ symtab }; 1260 ast::ptr< ast::Expr > ret = stmtExpr; 1261 ret = ret->accept( resolver ); 1262 strict_dynamic_cast< ast::StmtExpr * >( ret.get_and_mutate() )->computeResult(); 1263 return ret; 1253 1264 } 1254 1265 -
src/ResolvExpr/Resolver.h
r3fc0f2a r17a0ede2 31 31 class Decl; 32 32 class DeletedExpr; 33 class StmtExpr; 33 34 class SymbolTable; 34 35 class TypeEnvironment; … … 58 59 ast::ptr< ast::Expr > resolveInVoidContext( 59 60 const ast::Expr * expr, const ast::SymbolTable & symtab, ast::TypeEnvironment & env ); 61 /// Resolves a statement expression 62 ast::ptr< ast::Expr > resolveStmtExpr( 63 const ast::StmtExpr * stmtExpr, const ast::SymbolTable & symtab ); 60 64 } // namespace ResolvExpr 61 65
Note: See TracChangeset
for help on using the changeset viewer.