Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    r0873d22e r8d7bef2  
    1717#include <iterator>               // for back_insert_iterator, back_inserter
    1818#include <map>                    // for _Rb_tree_const_iterator, _Rb_tree_i...
    19 #include <memory>                 // for unique_ptr
    2019#include <set>                    // for set
    2120#include <string>                 // for string, operator==, operator!=, bas...
     
    9998                findOpenVars( newSecond, openVars, closedVars, needAssertions, haveAssertions, true );
    10099
    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 );
    105101        }
    106102
     
    123119///   newSecond->print( std::cerr );
    124120///   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 );
    129122        }
    130123
     
    171164                                Type *common = 0;
    172165                                // 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();
    174167                                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 ) ) {
    176169                                        if ( common ) {
    177170                                                common->get_qualifiers() = Type::Qualifiers();
    178                                                 delete curClass.type;
    179171                                                curClass.type = common;
    180172                                                env.add( curClass );
     
    239231                                if ( common ) {
    240232                                        common->get_qualifiers() = Type::Qualifiers();
    241                                         delete class1.type;
    242233                                        class1.type = common;
    243234                                } // if
     
    272263                        env.add( newClass );
    273264                } // if
    274                 delete type1;
    275                 delete type2;
    276265                return result;
    277266        }
     
    282271                findOpenVars( type2, openVars, closedVars, needAssertions, haveAssertions, true );
    283272                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 );
    292274        }
    293275
     
    324306                } else if ( isopen1 ) {
    325307                        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 ) {
    327309                        result = bindVar( var2, type1, entry2->second, env, needAssertions, haveAssertions, openVars, widenMode, indexer );
    328310                } else {
     
    483465
    484466        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 ) {
    486468                std::list< Type * > types;
    487469                for ( ; begin != end; ++begin ) {
     
    489471                        flatten( toType( *begin ), back_inserter( types ) );
    490472                }
    491                 return std::unique_ptr<Type>( new TupleType( Type::Qualifiers(), types ) );
     473                return new TupleType{ Type::Qualifiers(), types };
    492474        }
    493475
     
    504486                        if ( isTtype1 && ! isTtype2 ) {
    505487                                // 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 );
    507489                        } else if ( isTtype2 && ! isTtype1 ) {
    508490                                // 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 );
    510492                        } else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) {
    511493                                return false;
     
    517499                        Type * t1 = (*list1Begin)->get_type();
    518500                        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 );
    520502                        } else return false;
    521503                } else if ( list2Begin != list2End ) {
     
    523505                        Type * t2 = (*list2Begin)->get_type();
    524506                        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 );
    526508                        } else return false;
    527509                } else {
     
    544526                                        // expand ttype parameter into its actual type
    545527                                        if ( eqvClass.type ) {
    546                                                 delete typeInst;
    547528                                                return eqvClass.type->clone();
    548529                                        }
     
    569550                                dst.push_back( new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::C, nullptr, t, nullptr ) );
    570551                        }
    571                         delete dcl;
    572552                }
    573553        }
     
    578558                        // flatten the parameter lists for both functions so that tuple structure
    579559                        // 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();
    582562                        flattenList( flatFunc->get_parameters(), flatFunc->get_parameters(), env );
    583563                        flattenList( flatOther->get_parameters(), flatOther->get_parameters(), env );
     
    720700                        if ( isTtype1 && ! isTtype2 ) {
    721701                                // 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 );
    723703                        } else if ( isTtype2 && ! isTtype1 ) {
    724704                                // 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 );
    726706                        } else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) {
    727707                                return false;
     
    733713                        Type * t1 = *list1Begin;
    734714                        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 );
    736716                        } else return false;
    737717                } else if ( list2Begin != list2End ) {
     
    739719                        Type * t2 = *list2Begin;
    740720                        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 );
    742722                        } else return false;
    743723                } else {
     
    748728        void Unify::postvisit(TupleType *tupleType) {
    749729                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();
    752732                        std::list<Type *> types1, types2;
    753733
     
    756736                        flat2->acceptMutator( expander );
    757737
    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 ) );
    760740
    761741                        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.