Changeset 8d7bef2 for src/ResolvExpr
- Timestamp:
- Mar 20, 2018, 5:12:25 PM (6 years ago)
- Branches:
- new-env, with_gc
- Children:
- 7e4b44db
- Parents:
- 68f9c43
- Location:
- src/ResolvExpr
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AlternativeFinder.cc
r68f9c43 r8d7bef2 21 21 #include <list> // for _List_iterator, list, _List_const_... 22 22 #include <map> // for _Rb_tree_iterator, map, _Rb_tree_c... 23 #include <memory> // for allocator_traits<>::value_type , unique_ptr23 #include <memory> // for allocator_traits<>::value_type 24 24 #include <utility> // for pair 25 25 #include <vector> // for vector … … 296 296 // adds anonymous member interpretations whenever an aggregate value type is seen. 297 297 // it's okay for the aggregate expression to have reference type -- cast it to the base type to treat the aggregate as the referenced value 298 std::unique_ptr<Expression> aggrExpr( alt.expr->clone());298 Expression* aggrExpr = alt.expr->clone(); 299 299 alt.env.apply( aggrExpr->get_result() ); 300 300 Type * aggrType = aggrExpr->get_result(); 301 301 if ( dynamic_cast< ReferenceType * >( aggrType ) ) { 302 302 aggrType = aggrType->stripReferences(); 303 aggrExpr .reset( new CastExpr( aggrExpr.release(), aggrType->clone() ) );303 aggrExpr = new CastExpr{ aggrExpr, aggrType->clone() }; 304 304 } 305 305 306 306 if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) { 307 307 NameExpr nameExpr( "" ); 308 addAggMembers( structInst, aggrExpr .get(), alt.cost+Cost::safe, alt.env, &nameExpr );308 addAggMembers( structInst, aggrExpr, alt.cost+Cost::safe, alt.env, &nameExpr ); 309 309 } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) { 310 310 NameExpr nameExpr( "" ); 311 addAggMembers( unionInst, aggrExpr .get(), alt.cost+Cost::safe, alt.env, &nameExpr );311 addAggMembers( unionInst, aggrExpr, alt.cost+Cost::safe, alt.env, &nameExpr ); 312 312 } // if 313 313 } … … 630 630 struct ArgPack { 631 631 std::size_t parent; ///< Index of parent pack 632 std::unique_ptr<Expression> expr;///< The argument stored here632 Expression* expr; ///< The argument stored here 633 633 Cost cost; ///< The cost of this argument 634 634 TypeEnvironment env; ///< Environment for this pack … … 677 677 std::list<Expression*> exprs; 678 678 const ArgPack* pack = this; 679 if ( expr ) { exprs.push_front( expr .release()); }679 if ( expr ) { exprs.push_front( expr ); } 680 680 while ( pack->tupleStart == 0 ) { 681 681 pack = &packs[pack->parent]; … … 684 684 } 685 685 // reset pack to appropriate tuple 686 expr .reset( new TupleExpr( exprs ) );686 expr = new TupleExpr{ exprs }; 687 687 tupleStart = pack->tupleStart - 1; 688 688 parent = pack->parent; … … 736 736 737 737 results.emplace_back( 738 i, expl.exprs[results[i].nextExpl] .get(), copy(results[i].env),738 i, expl.exprs[results[i].nextExpl], copy(results[i].env), 739 739 copy(results[i].need), copy(results[i].have), 740 740 copy(results[i].openVars), nextArg, nTuples, Cost::zero, nextExpl, … … 757 757 newResult.parent = i; 758 758 std::list<Expression*> emptyList; 759 newResult.expr .reset( new TupleExpr( emptyList ) );759 newResult.expr = new TupleExpr{ emptyList }; 760 760 argType = newResult.expr->get_result(); 761 761 } else { … … 764 764 newResult.cost = results[i].cost; 765 765 newResult.tupleStart = results[i].tupleStart; 766 newResult.expr .reset( results[i].expr->clone());766 newResult.expr = results[i].expr->clone(); 767 767 argType = newResult.expr->get_result(); 768 768 … … 814 814 // add new result 815 815 results.emplace_back( 816 i, expl.exprs.front() .get(), move(env), copy(results[i].need),816 i, expl.exprs.front(), move(env), copy(results[i].need), 817 817 copy(results[i].have), move(openVars), nextArg + 1, 818 818 nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); … … 840 840 if ( results[i].hasExpl() ) { 841 841 const ExplodedActual& expl = results[i].getExpl( args ); 842 Expression* expr = expl.exprs[results[i].nextExpl] .get();842 Expression* expr = expl.exprs[results[i].nextExpl]; 843 843 844 844 TypeEnvironment env = results[i].env; … … 911 911 912 912 // consider only first exploded actual 913 Expression* expr = expl.exprs.front() .get();913 Expression* expr = expl.exprs.front(); 914 914 Type* actualType = expr->get_result()->clone(); 915 915 … … 1014 1014 1015 1015 results.emplace_back( 1016 i, expl.exprs[results[i].nextExpl] .get(), copy(results[i].env),1016 i, expl.exprs[results[i].nextExpl], copy(results[i].env), 1017 1017 copy(results[i].need), copy(results[i].have), 1018 1018 copy(results[i].openVars), nextArg, 0, Cost::zero, nextExpl, … … 1050 1050 // add new result 1051 1051 results.emplace_back( 1052 i, expl.exprs.front() .get(), move(env), copy(results[i].need),1052 i, expl.exprs.front(), move(env), copy(results[i].need), 1053 1053 copy(results[i].have), move(openVars), nextArg + 1, 0, 1054 1054 expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); … … 1344 1344 Expression * aggrExpr = agg->expr->clone(); 1345 1345 referenceToRvalueConversion( aggrExpr, cost ); 1346 std::unique_ptr<Expression> guard( aggrExpr );1347 1346 1348 1347 // find member of the given type -
src/ResolvExpr/ExplodedActual.h
r68f9c43 r8d7bef2 16 16 #pragma once 17 17 18 #include <memory>19 18 #include <vector> 20 19 … … 29 28 TypeEnvironment env; 30 29 Cost cost; 31 std::vector< std::unique_ptr<Expression>> exprs;30 std::vector< Expression* > exprs; 32 31 33 32 ExplodedActual() : env(), cost(Cost::zero), exprs() {} -
src/ResolvExpr/Unify.cc
r68f9c43 r8d7bef2 17 17 #include <iterator> // for back_insert_iterator, back_inserter 18 18 #include <map> // for _Rb_tree_const_iterator, _Rb_tree_i... 19 #include <memory> // for unique_ptr20 19 #include <set> // for set 21 20 #include <string> // for string, operator==, operator!=, bas... … … 165 164 Type *common = 0; 166 165 // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to 167 std::unique_ptr< Type > newType( curClass.type->clone());166 Type* newType = curClass.type->clone(); 168 167 newType->get_qualifiers() = typeInst->get_qualifiers(); 169 if ( unifyInexact( newType .get(), other, env, needAssertions, haveAssertions, openVars, widenMode & WidenMode( curClass.allowWidening, true ), indexer, common ) ) {168 if ( unifyInexact( newType, other, env, needAssertions, haveAssertions, openVars, widenMode & WidenMode( curClass.allowWidening, true ), indexer, common ) ) { 170 169 if ( common ) { 171 170 common->get_qualifiers() = Type::Qualifiers(); … … 466 465 467 466 template< typename Iterator, typename Func > 468 std::unique_ptr<Type>combineTypes( Iterator begin, Iterator end, Func & toType ) {467 Type* combineTypes( Iterator begin, Iterator end, Func & toType ) { 469 468 std::list< Type * > types; 470 469 for ( ; begin != end; ++begin ) { … … 472 471 flatten( toType( *begin ), back_inserter( types ) ); 473 472 } 474 return std::unique_ptr<Type>( new TupleType( Type::Qualifiers(), types ) );473 return new TupleType{ Type::Qualifiers(), types }; 475 474 } 476 475 … … 487 486 if ( isTtype1 && ! isTtype2 ) { 488 487 // combine all of the things in list2, then unify 489 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ) .get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );488 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 490 489 } else if ( isTtype2 && ! isTtype1 ) { 491 490 // combine all of the things in list1, then unify 492 return unifyExact( combineTypes( list1Begin, list1End, get_type ) .get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );491 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 493 492 } else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) { 494 493 return false; … … 500 499 Type * t1 = (*list1Begin)->get_type(); 501 500 if ( Tuples::isTtype( t1 ) ) { 502 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ) .get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );501 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 503 502 } else return false; 504 503 } else if ( list2Begin != list2End ) { … … 506 505 Type * t2 = (*list2Begin)->get_type(); 507 506 if ( Tuples::isTtype( t2 ) ) { 508 return unifyExact( combineTypes( list1Begin, list1End, get_type ) .get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );507 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 509 508 } else return false; 510 509 } else { … … 559 558 // flatten the parameter lists for both functions so that tuple structure 560 559 // doesn't affect unification. Must be a clone so that the types don't change. 561 std::unique_ptr<FunctionType> flatFunc( functionType->clone());562 std::unique_ptr<FunctionType> flatOther( otherFunction->clone());560 FunctionType* flatFunc = functionType->clone(); 561 FunctionType* flatOther = otherFunction->clone(); 563 562 flattenList( flatFunc->get_parameters(), flatFunc->get_parameters(), env ); 564 563 flattenList( flatOther->get_parameters(), flatOther->get_parameters(), env ); … … 701 700 if ( isTtype1 && ! isTtype2 ) { 702 701 // combine all of the things in list2, then unify 703 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ) .get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );702 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 704 703 } else if ( isTtype2 && ! isTtype1 ) { 705 704 // combine all of the things in list1, then unify 706 return unifyExact( combineTypes( list1Begin, list1End, get_type ) .get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );705 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 707 706 } else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) { 708 707 return false; … … 714 713 Type * t1 = *list1Begin; 715 714 if ( Tuples::isTtype( t1 ) ) { 716 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ) .get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );715 return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 717 716 } else return false; 718 717 } else if ( list2Begin != list2End ) { … … 720 719 Type * t2 = *list2Begin; 721 720 if ( Tuples::isTtype( t2 ) ) { 722 return unifyExact( combineTypes( list1Begin, list1End, get_type ) .get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );721 return unifyExact( combineTypes( list1Begin, list1End, get_type ), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 723 722 } else return false; 724 723 } else { … … 729 728 void Unify::postvisit(TupleType *tupleType) { 730 729 if ( TupleType *otherTuple = dynamic_cast< TupleType* >( type2 ) ) { 731 std::unique_ptr<TupleType> flat1( tupleType->clone());732 std::unique_ptr<TupleType> flat2( otherTuple->clone());730 TupleType* flat1 = tupleType->clone(); 731 TupleType* flat2 = otherTuple->clone(); 733 732 std::list<Type *> types1, types2; 734 733 … … 737 736 flat2->acceptMutator( expander ); 738 737 739 flatten( flat1 .get(), back_inserter( types1 ) );740 flatten( flat2 .get(), back_inserter( types2 ) );738 flatten( flat1, back_inserter( types1 ) ); 739 flatten( flat2, back_inserter( types2 ) ); 741 740 742 741 result = unifyList( types1.begin(), types1.end(), types2.begin(), types2.end(), env, needAssertions, haveAssertions, openVars, indexer );
Note: See TracChangeset
for help on using the changeset viewer.