Changeset 8d7bef2 for src/ResolvExpr/Unify.cc
- Timestamp:
- Mar 20, 2018, 5:12:25 PM (7 years ago)
- Branches:
- new-env, with_gc
- Children:
- 7e4b44db
- Parents:
- 68f9c43
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.