Changes in src/ResolvExpr/Unify.cc [0873d22e:8d7bef2]
- File:
-
- 1 edited
-
src/ResolvExpr/Unify.cc (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
r0873d22e 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... … … 99 98 findOpenVars( newSecond, openVars, closedVars, needAssertions, haveAssertions, true ); 100 99 101 bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 102 delete newFirst; 103 delete newSecond; 104 return result; 100 return unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 105 101 } 106 102 … … 123 119 /// newSecond->print( std::cerr ); 124 120 /// std::cerr << std::endl; 125 bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 126 delete newFirst; 127 delete newSecond; 128 return result; 121 return unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 129 122 } 130 123 … … 171 164 Type *common = 0; 172 165 // attempt to unify equivalence class type (which has qualifiers stripped, so they must be restored) with the type to bind to 173 std::unique_ptr< Type > newType( curClass.type->clone());166 Type* newType = curClass.type->clone(); 174 167 newType->get_qualifiers() = typeInst->get_qualifiers(); 175 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 ) ) { 176 169 if ( common ) { 177 170 common->get_qualifiers() = Type::Qualifiers(); 178 delete curClass.type;179 171 curClass.type = common; 180 172 env.add( curClass ); … … 239 231 if ( common ) { 240 232 common->get_qualifiers() = Type::Qualifiers(); 241 delete class1.type;242 233 class1.type = common; 243 234 } // if … … 272 263 env.add( newClass ); 273 264 } // if 274 delete type1;275 delete type2;276 265 return result; 277 266 } … … 282 271 findOpenVars( type2, openVars, closedVars, needAssertions, haveAssertions, true ); 283 272 Type *commonType = 0; 284 if ( unifyInexact( type1, type2, env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType ) ) { 285 if ( commonType ) { 286 delete commonType; 287 } // if 288 return true; 289 } else { 290 return false; 291 } // if 273 return unifyInexact( type1, type2, env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType ); 292 274 } 293 275 … … 324 306 } else if ( isopen1 ) { 325 307 result = bindVar( var1, type2, entry1->second, env, needAssertions, haveAssertions, openVars, widenMode, indexer ); 326 } else if ( isopen2 ) { // TODO: swap widenMode values in call, since type positions are flipped?308 } else if ( isopen2 ) { 327 309 result = bindVar( var2, type1, entry2->second, env, needAssertions, haveAssertions, openVars, widenMode, indexer ); 328 310 } else { … … 483 465 484 466 template< typename Iterator, typename Func > 485 std::unique_ptr<Type>combineTypes( Iterator begin, Iterator end, Func & toType ) {467 Type* combineTypes( Iterator begin, Iterator end, Func & toType ) { 486 468 std::list< Type * > types; 487 469 for ( ; begin != end; ++begin ) { … … 489 471 flatten( toType( *begin ), back_inserter( types ) ); 490 472 } 491 return std::unique_ptr<Type>( new TupleType( Type::Qualifiers(), types ) );473 return new TupleType{ Type::Qualifiers(), types }; 492 474 } 493 475 … … 504 486 if ( isTtype1 && ! isTtype2 ) { 505 487 // combine all of the things in list2, then unify 506 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 ); 507 489 } else if ( isTtype2 && ! isTtype1 ) { 508 490 // combine all of the things in list1, then unify 509 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 ); 510 492 } else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) { 511 493 return false; … … 517 499 Type * t1 = (*list1Begin)->get_type(); 518 500 if ( Tuples::isTtype( t1 ) ) { 519 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 ); 520 502 } else return false; 521 503 } else if ( list2Begin != list2End ) { … … 523 505 Type * t2 = (*list2Begin)->get_type(); 524 506 if ( Tuples::isTtype( t2 ) ) { 525 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 ); 526 508 } else return false; 527 509 } else { … … 544 526 // expand ttype parameter into its actual type 545 527 if ( eqvClass.type ) { 546 delete typeInst;547 528 return eqvClass.type->clone(); 548 529 } … … 569 550 dst.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::C, nullptr, t, nullptr ) ); 570 551 } 571 delete dcl;572 552 } 573 553 } … … 578 558 // flatten the parameter lists for both functions so that tuple structure 579 559 // doesn't affect unification. Must be a clone so that the types don't change. 580 std::unique_ptr<FunctionType> flatFunc( functionType->clone());581 std::unique_ptr<FunctionType> flatOther( otherFunction->clone());560 FunctionType* flatFunc = functionType->clone(); 561 FunctionType* flatOther = otherFunction->clone(); 582 562 flattenList( flatFunc->get_parameters(), flatFunc->get_parameters(), env ); 583 563 flattenList( flatOther->get_parameters(), flatOther->get_parameters(), env ); … … 720 700 if ( isTtype1 && ! isTtype2 ) { 721 701 // combine all of the things in list2, then unify 722 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 ); 723 703 } else if ( isTtype2 && ! isTtype1 ) { 724 704 // combine all of the things in list1, then unify 725 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 ); 726 706 } else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) { 727 707 return false; … … 733 713 Type * t1 = *list1Begin; 734 714 if ( Tuples::isTtype( t1 ) ) { 735 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 ); 736 716 } else return false; 737 717 } else if ( list2Begin != list2End ) { … … 739 719 Type * t2 = *list2Begin; 740 720 if ( Tuples::isTtype( t2 ) ) { 741 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 ); 742 722 } else return false; 743 723 } else { … … 748 728 void Unify::postvisit(TupleType *tupleType) { 749 729 if ( TupleType *otherTuple = dynamic_cast< TupleType* >( type2 ) ) { 750 std::unique_ptr<TupleType> flat1( tupleType->clone());751 std::unique_ptr<TupleType> flat2( otherTuple->clone());730 TupleType* flat1 = tupleType->clone(); 731 TupleType* flat2 = otherTuple->clone(); 752 732 std::list<Type *> types1, types2; 753 733 … … 756 736 flat2->acceptMutator( expander ); 757 737 758 flatten( flat1 .get(), back_inserter( types1 ) );759 flatten( flat2 .get(), back_inserter( types2 ) );738 flatten( flat1, back_inserter( types1 ) ); 739 flatten( flat2, back_inserter( types2 ) ); 760 740 761 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.