Changeset 8a1289f for src/ResolvExpr


Ignore:
Timestamp:
May 30, 2018, 3:28:10 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
75308bcc
Parents:
80a7d48
Message:

Remove assorted expression clones from AlternativeFinder?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r80a7d48 r8a1289f  
    338338                        if ( ss >> val && ! (ss >> tmp) ) {
    339339                                if ( val >= 0 && (unsigned int)val < tupleType->size() ) {
    340                                         alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) );
     340                                        alternatives.push_back( Alternative( new TupleIndexExpr( expr, val ), env, newCost ) );
    341341                                } // if
    342342                        } // if
     
    347347                                int val;
    348348                                ss >> val;
    349                                 alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) );
     349                                alternatives.push_back( Alternative( new TupleIndexExpr( expr, val ), env, newCost ) );
    350350                        }
    351351                } // if
     
    353353
    354354        void AlternativeFinder::Finder::postvisit( ApplicationExpr *applicationExpr ) {
    355                 alternatives.push_back( Alternative( applicationExpr->clone(), env, Cost::zero ) );
     355                alternatives.push_back( Alternative( applicationExpr, env, Cost::zero ) );
    356356        }
    357357
     
    664664                        while ( pack->tupleStart == 0 ) {
    665665                                pack = &packs[pack->parent];
    666                                 exprs.push_front( pack->expr->clone() );
     666                                exprs.push_front( pack->expr );
    667667                                cost += pack->cost;
    668668                        }
     
    749749                                                        newResult.cost = results[i].cost;
    750750                                                        newResult.tupleStart = results[i].tupleStart;
    751                                                         newResult.expr = results[i].expr->clone();
     751                                                        newResult.expr = results[i].expr;
    752752                                                        argType = newResult.expr->get_result();
    753753
     
    12191219                        if ( isLvalue( alt.expr ) ) {
    12201220                                alternatives.push_back(
    1221                                         Alternative{ new AddressExpr( alt.expr->clone() ), alt.env, alt.cost } );
     1221                                        Alternative{ new AddressExpr( alt.expr ), alt.env, alt.cost } );
    12221222                        } // if
    12231223                } // for
     
    12251225
    12261226        void AlternativeFinder::Finder::postvisit( LabelAddressExpr * expr ) {
    1227                 alternatives.push_back( Alternative{ expr->clone(), env, Cost::zero } );
     1227                alternatives.push_back( Alternative{ expr, env, Cost::zero } );
    12281228        }
    12291229
     
    13201320                for ( Alternative & alt : finder.alternatives ) {
    13211321                        alternatives.push_back( Alternative(
    1322                                 new VirtualCastExpr( alt.expr->clone(), castExpr->get_result()->clone() ),
     1322                                new VirtualCastExpr( alt.expr, castExpr->get_result()->clone() ),
    13231323                                alt.env, alt.cost ) );
    13241324                }
     
    13551355
    13561356        void AlternativeFinder::Finder::postvisit( MemberExpr *memberExpr ) {
    1357                 alternatives.push_back( Alternative( memberExpr->clone(), env, Cost::zero ) );
     1357                alternatives.push_back( Alternative( memberExpr, env, Cost::zero ) );
    13581358        }
    13591359
     
    13861386
    13871387        void AlternativeFinder::Finder::postvisit( ConstantExpr *constantExpr ) {
    1388                 alternatives.push_back( Alternative( constantExpr->clone(), env, Cost::zero ) );
     1388                alternatives.push_back( Alternative( constantExpr, env, Cost::zero ) );
    13891389        }
    13901390
     
    14061406                        Alternative &choice = winners.front();
    14071407                        referenceToRvalueConversion( choice.expr, choice.cost );
    1408                         alternatives.push_back( Alternative( new SizeofExpr( choice.expr->clone() ), choice.env, Cost::zero ) );
     1408                        alternatives.push_back( Alternative( new SizeofExpr( choice.expr ), choice.env, Cost::zero ) );
    14091409                } // if
    14101410        }
     
    14271427                        Alternative &choice = winners.front();
    14281428                        referenceToRvalueConversion( choice.expr, choice.cost );
    1429                         alternatives.push_back( Alternative( new AlignofExpr( choice.expr->clone() ), choice.env, Cost::zero ) );
     1429                        alternatives.push_back( Alternative( new AlignofExpr( choice.expr ), choice.env, Cost::zero ) );
    14301430                } // if
    14311431        }
     
    14561456
    14571457        void AlternativeFinder::Finder::postvisit( OffsetofExpr *offsetofExpr ) {
    1458                 alternatives.push_back( Alternative( offsetofExpr->clone(), env, Cost::zero ) );
     1458                alternatives.push_back( Alternative( offsetofExpr, env, Cost::zero ) );
    14591459        }
    14601460
    14611461        void AlternativeFinder::Finder::postvisit( OffsetPackExpr *offsetPackExpr ) {
    1462                 alternatives.push_back( Alternative( offsetPackExpr->clone(), env, Cost::zero ) );
     1462                alternatives.push_back( Alternative( offsetPackExpr, env, Cost::zero ) );
    14631463        }
    14641464
     
    15381538                                compositeEnv.simpleCombine( second.env );
    15391539
    1540                                 LogicalExpr *newExpr = new LogicalExpr( first.expr->clone(), second.expr->clone(), logicalExpr->get_isAnd() );
     1540                                LogicalExpr *newExpr = new LogicalExpr( first.expr, second.expr, logicalExpr->get_isAnd() );
    15411541                                alternatives.push_back( Alternative( newExpr, compositeEnv, first.cost + second.cost ) );
    15421542                        }
     
    15711571                                        Type* commonType = nullptr;
    15721572                                        if ( unify( second.expr->result, third.expr->result, newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
    1573                                                 ConditionalExpr *newExpr = new ConditionalExpr( first.expr->clone(), second.expr->clone(), third.expr->clone() );
     1573                                                ConditionalExpr *newExpr = new ConditionalExpr( first.expr, second.expr, third.expr );
    15741574                                                newExpr->result = commonType ? commonType : second.expr->result->clone();
    15751575                                                // convert both options to the conditional result type
     
    15901590                secondFinder.findWithAdjustment( commaExpr->get_arg2() );
    15911591                for ( const Alternative & alt : secondFinder.alternatives ) {
    1592                         alternatives.push_back( Alternative( new CommaExpr( newFirstArg->clone(), alt.expr->clone() ), alt.env, alt.cost ) );
     1592                        alternatives.push_back( Alternative( new CommaExpr( newFirstArg, alt.expr ), alt.env, alt.cost ) );
    15931593                } // for
    15941594        }
     
    16121612                                Type* commonType = nullptr;
    16131613                                if ( unify( first.expr->result, second.expr->result, newAlt.env, needAssertions, haveAssertions, openVars, indexer, commonType ) ) {
    1614                                         RangeExpr * newExpr = new RangeExpr( first.expr->clone(), second.expr->clone() );
     1614                                        RangeExpr * newExpr = new RangeExpr( first.expr, second.expr );
    16151615                                        newExpr->result = commonType ? commonType : first.expr->result->clone();
    16161616                                        newAlt.expr = newExpr;
     
    16401640
    16411641        void AlternativeFinder::Finder::postvisit( TupleExpr *tupleExpr ) {
    1642                 alternatives.push_back( Alternative( tupleExpr->clone(), env, Cost::zero ) );
     1642                alternatives.push_back( Alternative( tupleExpr, env, Cost::zero ) );
    16431643        }
    16441644
    16451645        void AlternativeFinder::Finder::postvisit( ImplicitCopyCtorExpr * impCpCtorExpr ) {
    1646                 alternatives.push_back( Alternative( impCpCtorExpr->clone(), env, Cost::zero ) );
     1646                alternatives.push_back( Alternative( impCpCtorExpr, env, Cost::zero ) );
    16471647        }
    16481648
     
    16531653                finder.findWithoutPrune( ctorExpr->get_callExpr() );
    16541654                for ( Alternative & alt : finder.alternatives ) {
    1655                         alternatives.push_back( Alternative( new ConstructorExpr( alt.expr->clone() ), alt.env, alt.cost ) );
     1655                        alternatives.push_back( Alternative( new ConstructorExpr( alt.expr ), alt.env, alt.cost ) );
    16561656                }
    16571657        }
    16581658
    16591659        void AlternativeFinder::Finder::postvisit( TupleIndexExpr *tupleExpr ) {
    1660                 alternatives.push_back( Alternative( tupleExpr->clone(), env, Cost::zero ) );
     1660                alternatives.push_back( Alternative( tupleExpr, env, Cost::zero ) );
    16611661        }
    16621662
    16631663        void AlternativeFinder::Finder::postvisit( TupleAssignExpr *tupleAssignExpr ) {
    1664                 alternatives.push_back( Alternative( tupleAssignExpr->clone(), env, Cost::zero ) );
     1664                alternatives.push_back( Alternative( tupleAssignExpr, env, Cost::zero ) );
    16651665        }
    16661666
     
    16701670                for ( Alternative & alt : finder.alternatives ) {
    16711671                        // ensure that the id is passed on to the UniqueExpr alternative so that the expressions are "linked"
    1672                         UniqueExpr * newUnqExpr = new UniqueExpr( alt.expr->clone(), unqExpr->get_id() );
     1672                        UniqueExpr * newUnqExpr = new UniqueExpr( alt.expr, unqExpr->get_id() );
    16731673                        alternatives.push_back( Alternative( newUnqExpr, alt.env, alt.cost ) );
    16741674                }
     
    17211721                                        // count one safe conversion for each value that is thrown away
    17221722                                        thisCost.incSafe( discardedValues );
    1723                                         Alternative newAlt( new InitExpr( restructureCast( alt.expr->clone(), toType, true ), initAlt.designation->clone() ), newEnv, alt.cost, thisCost );
     1723                                        Alternative newAlt( new InitExpr( restructureCast( alt.expr, toType, true ), initAlt.designation ), newEnv, alt.cost, thisCost );
    17241724                                        inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( candidates ) );
    17251725                                }
Note: See TracChangeset for help on using the changeset viewer.