Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    ra8706fc r8e18b8e  
    2121#include <list>                    // for _List_iterator, list, _List_const_...
    2222#include <map>                     // for _Rb_tree_iterator, map, _Rb_tree_c...
    23 #include <memory>                  // for allocator_traits<>::value_type, unique_ptr
     23#include <memory>                  // for allocator_traits<>::value_type
    2424#include <utility>                 // for pair
    2525#include <vector>                  // for vector
     
    3535#include "ResolveTypeof.h"         // for resolveTypeof
    3636#include "Resolver.h"              // for resolveStmtExpr
     37#include "Common/GC.h"             // for new_static_root
    3738#include "SymTab/Indexer.h"        // for Indexer
    3839#include "SymTab/Mangler.h"        // for Mangler
     
    101102                void addAnonConversions( const Alternative & alt );
    102103                /// Adds alternatives for member expressions, given the aggregate, conversion cost for that aggregate, and name of the member
    103                 template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member );
     104                template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string & name );
    104105                /// Adds alternatives for member expressions where the left side has tuple type
    105106                void addTupleMembers( TupleType * tupleType, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member );
     
    165166                                        candidate->env.apply( newType );
    166167                                        mangleName = SymTab::Mangler::mangle( newType );
    167                                         delete newType;
    168168                                }
    169169                                std::map< std::string, PruneStruct >::iterator mapPlace = selected.find( mangleName );
     
    297297                // adds anonymous member interpretations whenever an aggregate value type is seen.
    298298                // 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
    299                 std::unique_ptr<Expression> aggrExpr( alt.expr->clone() );
     299                Expression* aggrExpr = alt.expr->clone();
    300300                alt.env.apply( aggrExpr->get_result() );
    301301                Type * aggrType = aggrExpr->get_result();
    302302                if ( dynamic_cast< ReferenceType * >( aggrType ) ) {
    303303                        aggrType = aggrType->stripReferences();
    304                         aggrExpr.reset( new CastExpr( aggrExpr.release(), aggrType->clone() ) );
     304                        aggrExpr = new CastExpr{ aggrExpr, aggrType->clone() };
    305305                }
    306306
    307307                if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) {
    308                         NameExpr nameExpr( "" );
    309                         addAggMembers( structInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr );
     308                        addAggMembers( structInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" );
    310309                } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) {
    311                         NameExpr nameExpr( "" );
    312                         addAggMembers( unionInst, aggrExpr.get(), alt.cost+Cost::safe, alt.env, &nameExpr );
     310                        addAggMembers( unionInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" );
    313311                } // if
    314312        }
    315313
    316314        template< typename StructOrUnionType >
    317         void AlternativeFinder::Finder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ) {
    318                 // by this point, member must be a name expr
    319                 NameExpr * nameExpr = dynamic_cast< NameExpr * >( member );
    320                 if ( ! nameExpr ) return;
    321                 const std::string & name = nameExpr->get_name();
     315        void AlternativeFinder::Finder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string & name ) {
    322316                std::list< Declaration* > members;
    323317                aggInst->lookup( name, members );
     
    344338                        if ( ss >> val && ! (ss >> tmp) ) {
    345339                                if ( val >= 0 && (unsigned int)val < tupleType->size() ) {
    346                                         alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) );
     340                                        alternatives.push_back( Alternative( new TupleIndexExpr( expr, val ), env, newCost ) );
    347341                                } // if
    348342                        } // if
     
    353347                                int val;
    354348                                ss >> val;
    355                                 alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) );
     349                                alternatives.push_back( Alternative( new TupleIndexExpr( expr, val ), env, newCost ) );
    356350                        }
    357351                } // if
     
    359353
    360354        void AlternativeFinder::Finder::postvisit( ApplicationExpr *applicationExpr ) {
    361                 alternatives.push_back( Alternative( applicationExpr->clone(), env, Cost::zero ) );
     355                alternatives.push_back( Alternative( applicationExpr, env, Cost::zero ) );
    362356        }
    363357
     
    468462        }
    469463
    470         // /// Map of declaration uniqueIds (intended to be the assertions in an AssertionSet) to their parents and the number of times they've been included
    471         //typedef std::unordered_map< UniqueId, std::unordered_map< UniqueId, unsigned > > AssertionParentSet;
    472 
    473464        static const int recursionLimit = /*10*/ 4;  ///< Limit to depth of recursion satisfaction
    474         //static const unsigned recursionParentLimit = 1;  ///< Limit to the number of times an assertion can recursively use itself
    475465
    476466        void addToIndexer( AssertionSet &assertSet, SymTab::Indexer &indexer ) {
     
    483473
    484474        template< typename ForwardIterator, typename OutputIterator >
    485         void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, /*const AssertionParentSet &needParents,*/
    486                                                  int level, const SymTab::Indexer &indexer, OutputIterator out ) {
     475        void inferRecursive( ForwardIterator begin, ForwardIterator end, const Alternative &newAlt, OpenVarSet &openVars, const SymTab::Indexer &decls, const AssertionSet &newNeed, int level, const SymTab::Indexer &indexer, OutputIterator out ) {
    487476                if ( begin == end ) {
    488477                        if ( newNeed.empty() ) {
     
    502491                                        printAssertionSet( newNeed, std::cerr, 8 );
    503492                                )
    504                                 inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, /*needParents,*/ level+1, indexer, out );
     493                                inferRecursive( newNeed.begin(), newNeed.end(), newAlt, openVars, decls, newerNeed, level+1, indexer, out );
    505494                                return;
    506495                        }
     
    509498                ForwardIterator cur = begin++;
    510499                if ( ! cur->second.isUsed ) {
    511                         inferRecursive( begin, end, newAlt, openVars, decls, newNeed, /*needParents,*/ level, indexer, out );
     500                        inferRecursive( begin, end, newAlt, openVars, decls, newNeed, level, indexer, out );
    512501                        return; // xxx - should this continue? previously this wasn't here, and it looks like it should be
    513502                }
     
    562551                                }
    563552
    564                                 //AssertionParentSet newNeedParents( needParents );
    565                                 // skip repeatingly-self-recursive assertion satisfaction
    566                                 // DOESN'T WORK: grandchild nodes conflict with their cousins
    567                                 //if ( newNeedParents[ curDecl->get_uniqueId() ][ candDecl->get_uniqueId() ]++ > recursionParentLimit ) continue;
    568 
    569553                                Expression *varExpr = data.combine( newerAlt.cvtCost );
    570                                 delete varExpr->get_result();
    571554                                varExpr->set_result( adjType->clone() );
    572555                                PRINT(
     
    582565                                        inferParameters = (*inferParameters)[ id ].inferParams.get();
    583566                                }
    584                                 // XXX: this is a memory leak, but adjType can't be deleted because it might contain assertions
    585                                 (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( candidate->get_uniqueId(), adjType->clone(), curDecl->get_type()->clone(), varExpr );
    586                                 inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, /*newNeedParents,*/ level, indexer, out );
    587                         } else {
    588                                 delete adjType;
     567                               
     568                                (*inferParameters)[ curDecl->get_uniqueId() ] = ParamEntry( candidate->get_uniqueId(), adjType, curDecl->get_type(), varExpr );
     569                                inferRecursive( begin, end, newerAlt, newOpenVars, newDecls, newerNeed, level, indexer, out );
    589570                        }
    590571                }
     
    606587                addToIndexer( have, decls );
    607588                AssertionSet newNeed;
    608                 //AssertionParentSet needParents;
    609589                PRINT(
    610590                        std::cerr << "env is: " << std::endl;
     
    613593                )
    614594
    615                 inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, /*needParents,*/ 0, indexer, out );
     595                inferRecursive( need.begin(), need.end(), newAlt, openVars, decls, newNeed, 0, indexer, out );
    616596//      PRINT(
    617597//          std::cerr << "declaration 14 is ";
     
    634614        struct ArgPack {
    635615                std::size_t parent;                ///< Index of parent pack
    636                 std::unique_ptr<Expression> expr;  ///< The argument stored here
     616                Expression* expr;                  ///< The argument stored here
    637617                Cost cost;                         ///< The cost of this argument
    638618                TypeEnvironment env;               ///< Environment for this pack
     
    646626
    647627                ArgPack()
    648                         : parent(0), expr(), cost(Cost::zero), env(), need(), have(), openVars(), nextArg(0),
    649                           tupleStart(0), nextExpl(0), explAlt(0) {}
     628                        : parent(0), expr(nullptr), cost(Cost::zero), env(), need(), have(), openVars(),
     629                          nextArg(0), tupleStart(0), nextExpl(0), explAlt(0) {}
    650630
    651631                ArgPack(const TypeEnvironment& env, const AssertionSet& need, const AssertionSet& have,
    652632                                const OpenVarSet& openVars)
    653                         : parent(0), expr(), cost(Cost::zero), env(env), need(need), have(have),
     633                        : parent(0), expr(nullptr), cost(Cost::zero), env(env), need(need), have(have),
    654634                          openVars(openVars), nextArg(0), tupleStart(0), nextExpl(0), explAlt(0) {}
    655635
     
    658638                                unsigned tupleStart = 0, Cost cost = Cost::zero, unsigned nextExpl = 0,
    659639                                unsigned explAlt = 0 )
    660                         : parent(parent), expr(expr->clone()), cost(cost), env(move(env)), need(move(need)),
     640                        : parent(parent), expr(expr), cost(cost), env(move(env)), need(move(need)),
    661641                          have(move(have)), openVars(move(openVars)), nextArg(nextArg), tupleStart(tupleStart),
    662642                          nextExpl(nextExpl), explAlt(explAlt) {}
     
    664644                ArgPack(const ArgPack& o, TypeEnvironment&& env, AssertionSet&& need, AssertionSet&& have,
    665645                                OpenVarSet&& openVars, unsigned nextArg, Cost added )
    666                         : parent(o.parent), expr(o.expr ? o.expr->clone() : nullptr), cost(o.cost + added),
    667                           env(move(env)), need(move(need)), have(move(have)), openVars(move(openVars)),
    668                           nextArg(nextArg), tupleStart(o.tupleStart), nextExpl(0), explAlt(0) {}
     646                        : parent(o.parent), expr(o.expr), cost(o.cost + added), env(move(env)),
     647                          need(move(need)), have(move(have)), openVars(move(openVars)), nextArg(nextArg),
     648                          tupleStart(o.tupleStart), nextExpl(0), explAlt(0) {}
    669649
    670650                /// true iff this pack is in the middle of an exploded argument
     
    681661                        std::list<Expression*> exprs;
    682662                        const ArgPack* pack = this;
    683                         if ( expr ) { exprs.push_front( expr.release() ); }
     663                        if ( expr ) { exprs.push_front( expr ); }
    684664                        while ( pack->tupleStart == 0 ) {
    685665                                pack = &packs[pack->parent];
    686                                 exprs.push_front( pack->expr->clone() );
     666                                exprs.push_front( pack->expr );
    687667                                cost += pack->cost;
    688668                        }
    689669                        // reset pack to appropriate tuple
    690                         expr.reset( new TupleExpr( exprs ) );
     670                        expr = new TupleExpr{ exprs };
    691671                        tupleStart = pack->tupleStart - 1;
    692672                        parent = pack->parent;
     
    741721
    742722                                                results.emplace_back(
    743                                                         i, expl.exprs[results[i].nextExpl].get(), copy(results[i].env),
     723                                                        i, expl.exprs[results[i].nextExpl], copy(results[i].env),
    744724                                                        copy(results[i].need), copy(results[i].have),
    745725                                                        copy(results[i].openVars), nextArg, nTuples, Cost::zero, nextExpl,
     
    762742                                                        newResult.parent = i;
    763743                                                        std::list<Expression*> emptyList;
    764                                                         newResult.expr.reset( new TupleExpr( emptyList ) );
     744                                                        newResult.expr = new TupleExpr{ emptyList };
    765745                                                        argType = newResult.expr->get_result();
    766746                                                } else {
     
    769749                                                        newResult.cost = results[i].cost;
    770750                                                        newResult.tupleStart = results[i].tupleStart;
    771                                                         newResult.expr.reset( results[i].expr->clone() );
     751                                                        newResult.expr = results[i].expr;
    772752                                                        argType = newResult.expr->get_result();
    773753
     
    819799                                                // add new result
    820800                                                results.emplace_back(
    821                                                         i, expl.exprs.front().get(), move(env), copy(results[i].need),
     801                                                        i, expl.exprs.front(), move(env), copy(results[i].need),
    822802                                                        copy(results[i].have), move(openVars), nextArg + 1,
    823803                                                        nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );
     
    845825                        if ( results[i].hasExpl() ) {
    846826                                const ExplodedActual& expl = results[i].getExpl( args );
    847                                 Expression* expr = expl.exprs[results[i].nextExpl].get();
     827                                Expression* expr = expl.exprs[results[i].nextExpl];
    848828
    849829                                TypeEnvironment env = results[i].env;
     
    916896
    917897                                // consider only first exploded actual
    918                                 Expression* expr = expl.exprs.front().get();
     898                                Expression* expr = expl.exprs.front();
    919899                                Type* actualType = expr->result->clone();
    920900
     
    944924
    945925        template<typename OutputIterator>
    946         void AlternativeFinder::Finder::validateFunctionAlternative( const Alternative &func, ArgPack& result,
    947                         const std::vector<ArgPack>& results, OutputIterator out ) {
    948                 ApplicationExpr *appExpr = new ApplicationExpr( func.expr->clone() );
     926        void AlternativeFinder::Finder::validateFunctionAlternative( const Alternative &func,
     927                        ArgPack& result, const std::vector<ArgPack>& results, OutputIterator out ) {
     928                ApplicationExpr *appExpr = new ApplicationExpr( func.expr );
    949929                // sum cost and accumulate actuals
    950930                std::list<Expression*>& args = appExpr->args;
     
    952932                const ArgPack* pack = &result;
    953933                while ( pack->expr ) {
    954                         args.push_front( pack->expr->clone() );
     934                        args.push_front( pack->expr );
    955935                        cost += pack->cost;
    956936                        pack = &results[pack->parent];
     
    1019999
    10201000                                                results.emplace_back(
    1021                                                         i, expl.exprs[results[i].nextExpl].get(), copy(results[i].env),
     1001                                                        i, expl.exprs[results[i].nextExpl], copy(results[i].env),
    10221002                                                        copy(results[i].need), copy(results[i].have),
    10231003                                                        copy(results[i].openVars), nextArg, 0, Cost::zero, nextExpl,
     
    10551035                                                // add new result
    10561036                                                results.emplace_back(
    1057                                                         i, expl.exprs.front().get(), move(env), copy(results[i].need),
     1037                                                        i, expl.exprs.front(), move(env), copy(results[i].need),
    10581038                                                        copy(results[i].have), move(openVars), nextArg + 1, 0,
    10591039                                                        expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );
     
    10891069
    10901070                // find function operators
    1091                 static NameExpr *opExpr = new NameExpr( "?()" );
     1071                static auto *opExpr = new_static_root<NameExpr>( "?()" );
    10921072                AlternativeFinder funcOpFinder( indexer, env );
    10931073                // it's ok if there aren't any defined function ops
    1094                 funcOpFinder.maybeFind( opExpr);
     1074                funcOpFinder.maybeFind( opExpr );
    10951075                PRINT(
    10961076                        std::cerr << "known function ops:" << std::endl;
     
    11211101                                )
    11221102                                // check if the type is pointer to function
    1123                                 if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr->result->stripReferences() ) ) {
    1124                                         if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->base ) ) {
     1103                                if ( PointerType *pointer = dynamic_cast< PointerType* >( func->expr->get_result()->stripReferences() ) ) {
     1104                                        if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
    11251105                                                Alternative newFunc( *func );
    11261106                                                referenceToRvalueConversion( newFunc.expr, newFunc.cost );
     
    11281108                                                        std::back_inserter( candidates ) );
    11291109                                        }
    1130                                 } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->result->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer)
    1131                                         EqvClass eqvClass;
    1132                                         if ( func->env.lookup( typeInst->name, eqvClass ) && eqvClass.type ) {
    1133                                                 if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) {
     1110                                } else if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( func->expr->get_result()->stripReferences() ) ) { // handle ftype (e.g. *? on function pointer)
     1111                                        if ( const EqvClass *eqvClass = func->env.lookup( typeInst->get_name() ) ) {
     1112                                                if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass->type ) ) {
    11341113                                                        Alternative newFunc( *func );
    11351114                                                        referenceToRvalueConversion( newFunc.expr, newFunc.cost );
     
    11591138                                        // check if type is a pointer to function
    11601139                                        if ( PointerType* pointer = dynamic_cast<PointerType*>(
    1161                                                         funcOp->expr->result->stripReferences() ) ) {
     1140                                                        funcOp->expr->get_result()->stripReferences() ) ) {
    11621141                                                if ( FunctionType* function =
    1163                                                                 dynamic_cast<FunctionType*>( pointer->base ) ) {
     1142                                                                dynamic_cast<FunctionType*>( pointer->get_base() ) ) {
    11641143                                                        Alternative newFunc( *funcOp );
    11651144                                                        referenceToRvalueConversion( newFunc.expr, newFunc.cost );
     
    11831162                        PRINT(
    11841163                                ApplicationExpr *appExpr = strict_dynamic_cast< ApplicationExpr* >( withFunc.expr );
    1185                                 PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr->function->result );
    1186                                 FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->base );
    1187                                 std::cerr << "Case +++++++++++++ " << appExpr->function << std::endl;
     1164                                PointerType *pointer = strict_dynamic_cast< PointerType* >( appExpr->get_function()->get_result() );
     1165                                FunctionType *function = strict_dynamic_cast< FunctionType* >( pointer->get_base() );
     1166                                std::cerr << "Case +++++++++++++ " << appExpr->get_function() << std::endl;
    11881167                                std::cerr << "formals are:" << std::endl;
    1189                                 printAll( function->parameters, std::cerr, 8 );
     1168                                printAll( function->get_parameters(), std::cerr, 8 );
    11901169                                std::cerr << "actuals are:" << std::endl;
    1191                                 printAll( appExpr->args, std::cerr, 8 );
     1170                                printAll( appExpr->get_args(), std::cerr, 8 );
    11921171                                std::cerr << "bindings are:" << std::endl;
    11931172                                withFunc.env.print( std::cerr, 8 );
     
    12301209        bool isLvalue( Expression *expr ) {
    12311210                // xxx - recurse into tuples?
    1232                 return expr->result && ( expr->result->get_lvalue() || dynamic_cast< ReferenceType * >( expr->result ) );
     1211                return expr->result && ( expr->get_result()->get_lvalue() || dynamic_cast< ReferenceType * >( expr->get_result() ) );
    12331212        }
    12341213
     
    12391218                        if ( isLvalue( alt.expr ) ) {
    12401219                                alternatives.push_back(
    1241                                         Alternative{ new AddressExpr( alt.expr->clone() ), alt.env, alt.cost } );
     1220                                        Alternative{ new AddressExpr( alt.expr ), alt.env, alt.cost } );
    12421221                        } // if
    12431222                } // for
     
    12451224
    12461225        void AlternativeFinder::Finder::postvisit( LabelAddressExpr * expr ) {
    1247                 alternatives.push_back( Alternative{ expr->clone(), env, Cost::zero } );
     1226                alternatives.push_back( Alternative{ expr, env, Cost::zero } );
    12481227        }
    12491228
     
    12651244                                componentExprs.push_back( restructureCast( idx, toType->getComponent( i ), isGenerated ) );
    12661245                        }
    1267                         delete argExpr;
    12681246                        assert( componentExprs.size() > 0 );
    12691247                        // produce the tuple of casts
     
    13411319                for ( Alternative & alt : finder.alternatives ) {
    13421320                        alternatives.push_back( Alternative(
    1343                                 new VirtualCastExpr( alt.expr->clone(), castExpr->get_result()->clone() ),
     1321                                new VirtualCastExpr( alt.expr, castExpr->get_result()->clone() ),
    13441322                                alt.env, alt.cost ) );
     1323                }
     1324        }
     1325
     1326        namespace {
     1327                /// Gets name from untyped member expression (member must be NameExpr)
     1328                const std::string& get_member_name( UntypedMemberExpr *memberExpr ) {
     1329                        NameExpr * nameExpr = dynamic_cast< NameExpr * >( memberExpr->get_member() );
     1330                        assert( nameExpr );
     1331                        return nameExpr->get_name();
    13451332                }
    13461333        }
     
    13541341                        Expression * aggrExpr = agg->expr->clone();
    13551342                        referenceToRvalueConversion( aggrExpr, cost );
    1356                         std::unique_ptr<Expression> guard( aggrExpr );
    13571343
    13581344                        // find member of the given type
    13591345                        if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) {
    1360                                 addAggMembers( structInst, aggrExpr, cost, agg->env, memberExpr->get_member() );
     1346                                addAggMembers( structInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) );
    13611347                        } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) {
    1362                                 addAggMembers( unionInst, aggrExpr, cost, agg->env, memberExpr->get_member() );
     1348                                addAggMembers( unionInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) );
    13631349                        } else if ( TupleType * tupleType = dynamic_cast< TupleType * >( aggrExpr->get_result() ) ) {
    13641350                                addTupleMembers( tupleType, aggrExpr, cost, agg->env, memberExpr->get_member() );
     
    13681354
    13691355        void AlternativeFinder::Finder::postvisit( MemberExpr *memberExpr ) {
    1370                 alternatives.push_back( Alternative( memberExpr->clone(), env, Cost::zero ) );
     1356                alternatives.push_back( Alternative( memberExpr, env, Cost::zero ) );
    13711357        }
    13721358
     
    13991385
    14001386        void AlternativeFinder::Finder::postvisit( ConstantExpr *constantExpr ) {
    1401                 alternatives.push_back( Alternative( constantExpr->clone(), env, Cost::zero ) );
     1387                alternatives.push_back( Alternative( constantExpr, env, Cost::zero ) );
    14021388        }
    14031389
     
    14191405                        Alternative &choice = winners.front();
    14201406                        referenceToRvalueConversion( choice.expr, choice.cost );
    1421                         alternatives.push_back( Alternative( new SizeofExpr( choice.expr->clone() ), choice.env, Cost::zero ) );
     1407                        alternatives.push_back( Alternative( new SizeofExpr( choice.expr ), choice.env, Cost::zero ) );
    14221408                } // if
    14231409        }
     
    14401426                        Alternative &choice = winners.front();
    14411427                        referenceToRvalueConversion( choice.expr, choice.cost );
    1442                         alternatives.push_back( Alternative( new AlignofExpr( choice.expr->clone() ), choice.env, Cost::zero ) );
     1428                        alternatives.push_back( Alternative( new AlignofExpr( choice.expr ), choice.env, Cost::zero ) );
    14431429                } // if
    14441430        }
     
    14691455
    14701456        void AlternativeFinder::Finder::postvisit( OffsetofExpr *offsetofExpr ) {
    1471                 alternatives.push_back( Alternative( offsetofExpr->clone(), env, Cost::zero ) );
     1457                alternatives.push_back( Alternative( offsetofExpr, env, Cost::zero ) );
    14721458        }
    14731459
    14741460        void AlternativeFinder::Finder::postvisit( OffsetPackExpr *offsetPackExpr ) {
    1475                 alternatives.push_back( Alternative( offsetPackExpr->clone(), env, Cost::zero ) );
     1461                alternatives.push_back( Alternative( offsetPackExpr, env, Cost::zero ) );
    14761462        }
    14771463
     
    15511537                                compositeEnv.simpleCombine( second.env );
    15521538
    1553                                 LogicalExpr *newExpr = new LogicalExpr( first.expr->clone(), second.expr->clone(), logicalExpr->get_isAnd() );
     1539                                LogicalExpr *newExpr = new LogicalExpr( first.expr, second.expr, logicalExpr->get_isAnd() );
    15541540                                alternatives.push_back( Alternative( newExpr, compositeEnv, first.cost + second.cost ) );
    15551541                        }
     
    15841570                                        Type* commonType = nullptr;
    15851571                                        if ( unify( second.expr->result, third.expr->result, newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
    1586                                                 ConditionalExpr *newExpr = new ConditionalExpr( first.expr->clone(), second.expr->clone(), third.expr->clone() );
     1572                                                ConditionalExpr *newExpr = new ConditionalExpr( first.expr, second.expr, third.expr );
    15871573                                                newExpr->result = commonType ? commonType : second.expr->result->clone();
    15881574                                                // convert both options to the conditional result type
     
    16031589                secondFinder.findWithAdjustment( commaExpr->get_arg2() );
    16041590                for ( const Alternative & alt : secondFinder.alternatives ) {
    1605                         alternatives.push_back( Alternative( new CommaExpr( newFirstArg->clone(), alt.expr->clone() ), alt.env, alt.cost ) );
     1591                        alternatives.push_back( Alternative( new CommaExpr( newFirstArg, alt.expr ), alt.env, alt.cost ) );
    16061592                } // for
    1607                 delete newFirstArg;
    16081593        }
    16091594
     
    16261611                                Type* commonType = nullptr;
    16271612                                if ( unify( first.expr->result, second.expr->result, newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
    1628                                         RangeExpr * newExpr = new RangeExpr( first.expr->clone(), second.expr->clone() );
     1613                                        RangeExpr * newExpr = new RangeExpr( first.expr, second.expr );
    16291614                                        newExpr->result = commonType ? commonType : first.expr->result->clone();
    16301615                                        newAlt.expr = newExpr;
     
    16541639
    16551640        void AlternativeFinder::Finder::postvisit( TupleExpr *tupleExpr ) {
    1656                 alternatives.push_back( Alternative( tupleExpr->clone(), env, Cost::zero ) );
     1641                alternatives.push_back( Alternative( tupleExpr, env, Cost::zero ) );
    16571642        }
    16581643
    16591644        void AlternativeFinder::Finder::postvisit( ImplicitCopyCtorExpr * impCpCtorExpr ) {
    1660                 alternatives.push_back( Alternative( impCpCtorExpr->clone(), env, Cost::zero ) );
     1645                alternatives.push_back( Alternative( impCpCtorExpr, env, Cost::zero ) );
    16611646        }
    16621647
     
    16671652                finder.findWithoutPrune( ctorExpr->get_callExpr() );
    16681653                for ( Alternative & alt : finder.alternatives ) {
    1669                         alternatives.push_back( Alternative( new ConstructorExpr( alt.expr->clone() ), alt.env, alt.cost ) );
     1654                        alternatives.push_back( Alternative( new ConstructorExpr( alt.expr ), alt.env, alt.cost ) );
    16701655                }
    16711656        }
    16721657
    16731658        void AlternativeFinder::Finder::postvisit( TupleIndexExpr *tupleExpr ) {
    1674                 alternatives.push_back( Alternative( tupleExpr->clone(), env, Cost::zero ) );
     1659                alternatives.push_back( Alternative( tupleExpr, env, Cost::zero ) );
    16751660        }
    16761661
    16771662        void AlternativeFinder::Finder::postvisit( TupleAssignExpr *tupleAssignExpr ) {
    1678                 alternatives.push_back( Alternative( tupleAssignExpr->clone(), env, Cost::zero ) );
     1663                alternatives.push_back( Alternative( tupleAssignExpr, env, Cost::zero ) );
    16791664        }
    16801665
     
    16841669                for ( Alternative & alt : finder.alternatives ) {
    16851670                        // ensure that the id is passed on to the UniqueExpr alternative so that the expressions are "linked"
    1686                         UniqueExpr * newUnqExpr = new UniqueExpr( alt.expr->clone(), unqExpr->get_id() );
     1671                        UniqueExpr * newUnqExpr = new UniqueExpr( alt.expr, unqExpr->get_id() );
    16871672                        alternatives.push_back( Alternative( newUnqExpr, alt.env, alt.cost ) );
    16881673                }
     
    17351720                                        // count one safe conversion for each value that is thrown away
    17361721                                        thisCost.incSafe( discardedValues );
    1737                                         Alternative newAlt( new InitExpr( restructureCast( alt.expr->clone(), toType, true ), initAlt.designation->clone() ), newEnv, alt.cost, thisCost );
     1722                                        Alternative newAlt( new InitExpr( restructureCast( alt.expr, toType, true ), initAlt.designation ), newEnv, alt.cost, thisCost );
    17381723                                        inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( candidates ) );
    17391724                                }
Note: See TracChangeset for help on using the changeset viewer.