Changeset 85521c7 for src/ResolvExpr
- Timestamp:
- Feb 1, 2018, 5:40:01 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, stuck-waitfor-destruct, with_gc
- Children:
- 0188a0bc
- Parents:
- d0a045c7 (diff), 33c0ce8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/ResolvExpr
- Files:
-
- 2 edited
-
AlternativeFinder.cc (modified) (1 diff)
-
Resolver.cc (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
rd0a045c7 r85521c7 1563 1563 // find alternatives for condition 1564 1564 AlternativeFinder firstFinder( indexer, env ); 1565 firstFinder.findWithAdjustment( conditionalExpr-> get_arg1());1565 firstFinder.findWithAdjustment( conditionalExpr->arg1 ); 1566 1566 if ( firstFinder.alternatives.empty() ) return; 1567 1567 // find alternatives for true expression 1568 1568 AlternativeFinder secondFinder( indexer, env ); 1569 secondFinder.findWithAdjustment( conditionalExpr-> get_arg2());1569 secondFinder.findWithAdjustment( conditionalExpr->arg2 ); 1570 1570 if ( secondFinder.alternatives.empty() ) return; 1571 1571 // find alterantives for false expression 1572 1572 AlternativeFinder thirdFinder( indexer, env ); 1573 thirdFinder.findWithAdjustment( conditionalExpr-> get_arg3());1573 thirdFinder.findWithAdjustment( conditionalExpr->arg3 ); 1574 1574 if ( thirdFinder.alternatives.empty() ) return; 1575 for ( AltList::const_iterator first = firstFinder.alternatives.begin(); first != firstFinder.alternatives.end(); ++first) {1576 for ( AltList::const_iterator second = secondFinder.alternatives.begin(); second != secondFinder.alternatives.end(); ++second) {1577 for ( AltList::const_iterator third = thirdFinder.alternatives.begin(); third != thirdFinder.alternatives.end(); ++third) {1575 for ( const Alternative & first : firstFinder.alternatives ) { 1576 for ( const Alternative & second : secondFinder.alternatives ) { 1577 for ( const Alternative & third : thirdFinder.alternatives ) { 1578 1578 TypeEnvironment compositeEnv; 1579 compositeEnv.simpleCombine( first ->env );1580 compositeEnv.simpleCombine( second ->env );1581 compositeEnv.simpleCombine( third ->env );1579 compositeEnv.simpleCombine( first.env ); 1580 compositeEnv.simpleCombine( second.env ); 1581 compositeEnv.simpleCombine( third.env ); 1582 1582 1583 1583 // unify true and false types, then infer parameters to produce new alternatives 1584 1584 OpenVarSet openVars; 1585 1585 AssertionSet needAssertions, haveAssertions; 1586 Alternative newAlt( 0, compositeEnv, first ->cost + second->cost + third->cost );1586 Alternative newAlt( 0, compositeEnv, first.cost + second.cost + third.cost ); 1587 1587 Type* commonType = nullptr; 1588 if ( unify( second ->expr->get_result(), third->expr->get_result(), newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {1589 ConditionalExpr *newExpr = new ConditionalExpr( first ->expr->clone(), second->expr->clone(), third->expr->clone() );1590 newExpr-> set_result( commonType ? commonType : second->expr->get_result()->clone());1588 if ( unify( second.expr->result, third.expr->result, newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) { 1589 ConditionalExpr *newExpr = new ConditionalExpr( first.expr->clone(), second.expr->clone(), third.expr->clone() ); 1590 newExpr->result = commonType ? commonType : second.expr->result->clone(); 1591 1591 // convert both options to the conditional result type 1592 1592 newAlt.cost += computeExpressionConversionCost( newExpr->arg2, newExpr->result, indexer, newAlt.env ); -
src/ResolvExpr/Resolver.cc
rd0a045c7 r85521c7 82 82 void previsit( ConstructorInit *ctorInit ); 83 83 private: 84 typedef std::list< Initializer * >::iterator InitIterator;84 typedef std::list< Initializer * >::iterator InitIterator; 85 85 86 86 template< typename PtrType > 87 87 void handlePtrType( PtrType * type ); 88 88 89 void resolveAggrInit( ReferenceToType *, InitIterator &, InitIterator & ); 90 void resolveSingleAggrInit( Declaration *, InitIterator &, InitIterator &, TypeSubstitution sub ); 91 void fallbackInit( ConstructorInit * ctorInit ); 89 void resolveWithExprs( std::list< Expression * > & withExprs, std::list< Statement * > & newStmts ); 90 void fallbackInit( ConstructorInit * ctorInit ); 92 91 93 92 Type * functionReturn = nullptr; … … 269 268 std::cerr << std::endl; 270 269 #endif 271 Type *new_type = resolveTypeof( functionDecl-> get_type(), indexer );270 Type *new_type = resolveTypeof( functionDecl->type, indexer ); 272 271 functionDecl->set_type( new_type ); 273 272 GuardValue( functionReturn ); 274 functionReturn = ResolvExpr::extractResultType( functionDecl->get_functionType() ); 273 functionReturn = ResolvExpr::extractResultType( functionDecl->type ); 274 275 { 276 // resolve with-exprs with parameters in scope and add any newly generated declarations to the 277 // front of the function body. 278 auto guard = makeFuncGuard( [this]() { indexer.enterScope(); }, [this](){ indexer.leaveScope(); } ); 279 indexer.addFunctionType( functionDecl->type ); 280 std::list< Statement * > newStmts; 281 resolveWithExprs( functionDecl->withExprs, newStmts ); 282 functionDecl->statements->kids.splice( functionDecl->statements->kids.begin(), newStmts ); 283 } 275 284 } 276 285 … … 279 288 // xxx - it might be necessary to somehow keep the information from this environment, but I can't currently 280 289 // see how it's useful. 281 for ( Declaration * d : functionDecl-> get_functionType()->get_parameters()) {290 for ( Declaration * d : functionDecl->type->parameters ) { 282 291 if ( ObjectDecl * obj = dynamic_cast< ObjectDecl * >( d ) ) { 283 if ( SingleInit * init = dynamic_cast< SingleInit * >( obj-> get_init()) ) {284 delete init-> get_value()->get_env();285 init-> get_value()->set_env( nullptr );292 if ( SingleInit * init = dynamic_cast< SingleInit * >( obj->init ) ) { 293 delete init->value->env; 294 init->value->env = nullptr; 286 295 } 287 296 } … … 584 593 } 585 594 586 587 void Resolver::previsit( WithStmt * withStmt ) { 588 for ( Expression *& expr : withStmt->exprs ) { 595 void Resolver::resolveWithExprs( std::list< Expression * > & withExprs, std::list< Statement * > & newStmts ) { 596 for ( Expression *& expr : withExprs ) { 589 597 // only struct- and union-typed expressions are viable candidates 590 598 findKindExpression( expr, indexer, "with statement", isStructOrUnion ); … … 595 603 ObjectDecl * tmp = ObjectDecl::newObject( tmpNamer.newName(), expr->result->clone(), new SingleInit( expr ) ); 596 604 expr = new VariableExpr( tmp ); 597 stmtsToAddBefore.push_back( new DeclStmt( tmp ) );605 newStmts.push_back( new DeclStmt( tmp ) ); 598 606 if ( InitTweak::isConstructable( tmp->type ) ) { 599 607 // generate ctor/dtor and resolve them … … 603 611 } 604 612 } 613 } 614 615 void Resolver::previsit( WithStmt * withStmt ) { 616 resolveWithExprs( withStmt->exprs, stmtsToAddBefore ); 605 617 } 606 618 … … 716 728 PassVisitor<Resolver> resolver( indexer ); 717 729 stmtExpr->accept( resolver ); 730 stmtExpr->computeResult(); 718 731 } 719 732
Note:
See TracChangeset
for help on using the changeset viewer.