Ignore:
Timestamp:
Feb 19, 2019, 1:19:47 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
no_list
Children:
2f42718
Parents:
99614c2
Message:

more lists converted to vectors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r99614c2 r43e0949  
    367367                        std::string tmp;
    368368                        if ( val >= 0 && (unsigned long long)val < tupleType->size() ) {
    369                                 alternatives.push_back( Alternative{ 
     369                                alternatives.push_back( Alternative{
    370370                                        alt, new TupleIndexExpr( expr->clone(), val ), newCost } );
    371371                        } // if
     
    474474                }
    475475
    476                 // specialization cost of return types can't be accounted for directly, it disables 
     476                // specialization cost of return types can't be accounted for directly, it disables
    477477                // otherwise-identical calls, like this example based on auto-newline in the I/O lib:
    478478                //
     
    12251225                                // count one safe conversion for each value that is thrown away
    12261226                                thisCost.incSafe( discardedValues );
    1227                                 Alternative newAlt{ 
    1228                                         restructureCast( alt.expr->clone(), toType, castExpr->isGenerated ), 
     1227                                Alternative newAlt{
     1228                                        restructureCast( alt.expr->clone(), toType, castExpr->isGenerated ),
    12291229                                        alt.env, openVars, needAssertions, alt.cost, alt.cost + thisCost };
    12301230                                inferParameters( newAlt, back_inserter( candidates ) );
     
    12901290
    12911291        void AlternativeFinder::Finder::postvisit( NameExpr *nameExpr ) {
    1292                 std::list< SymTab::Indexer::IdData > declList;
     1292                std::vector< SymTab::Indexer::IdData > declList;
    12931293                indexer.lookupId( nameExpr->name, declList );
    12941294                PRINT( std::cerr << "nameExpr is " << nameExpr->name << std::endl; )
     
    13271327                if ( sizeofExpr->get_isType() ) {
    13281328                        Type * newType = sizeofExpr->get_type()->clone();
    1329                         alternatives.push_back( Alternative{ 
     1329                        alternatives.push_back( Alternative{
    13301330                                new SizeofExpr{ resolveTypeof( newType, indexer ) }, env } );
    13311331                } else {
     
    13421342                        Alternative &choice = winners.front();
    13431343                        referenceToRvalueConversion( choice.expr, choice.cost );
    1344                         alternatives.push_back( Alternative{ 
     1344                        alternatives.push_back( Alternative{
    13451345                                choice, new SizeofExpr( choice.expr->clone() ), Cost::zero } );
    13461346                } // if
     
    13501350                if ( alignofExpr->get_isType() ) {
    13511351                        Type * newType = alignofExpr->get_type()->clone();
    1352                         alternatives.push_back( Alternative{ 
     1352                        alternatives.push_back( Alternative{
    13531353                                new AlignofExpr{ resolveTypeof( newType, indexer ) }, env } );
    13541354                } else {
     
    13651365                        Alternative &choice = winners.front();
    13661366                        referenceToRvalueConversion( choice.expr, choice.cost );
    1367                         alternatives.push_back( Alternative{ 
     1367                        alternatives.push_back( Alternative{
    13681368                                choice, new AlignofExpr{ choice.expr->clone() }, Cost::zero } );
    13691369                } // if
     
    13761376                for ( std::list< Declaration* >::const_iterator i = members.begin(); i != members.end(); ++i ) {
    13771377                        if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType* >( *i ) ) {
    1378                                 alternatives.push_back( Alternative{ 
     1378                                alternatives.push_back( Alternative{
    13791379                                        new OffsetofExpr{ aggInst->clone(), dwt }, env } );
    13801380                                renameTypes( alternatives.back().expr );
     
    14201420                                Cost cost = Cost::zero;
    14211421                                Expression * newExpr = data.combine( cost );
    1422                                 alternatives.push_back( Alternative{ 
    1423                                         new AttrExpr{ newExpr, argType->clone() }, env, OpenVarSet{}, 
     1422                                alternatives.push_back( Alternative{
     1423                                        new AttrExpr{ newExpr, argType->clone() }, env, OpenVarSet{},
    14241424                                        AssertionList{}, Cost::zero, cost } );
    14251425                                for ( DeclarationWithType * retVal : function->returnVals ) {
     
    14341434                NameExpr *nameExpr = dynamic_cast< NameExpr* >( attrExpr->get_attr() );
    14351435                assert( nameExpr );
    1436                 std::list< SymTab::Indexer::IdData > attrList;
     1436                std::vector< SymTab::Indexer::IdData > attrList;
    14371437                indexer.lookupId( nameExpr->get_name(), attrList );
    14381438                if ( attrExpr->get_isType() || attrExpr->get_expr() ) {
     
    14611461                                Cost cost = Cost::zero;
    14621462                                Expression * newExpr = data.combine( cost );
    1463                                 alternatives.push_back( Alternative{ 
     1463                                alternatives.push_back( Alternative{
    14641464                                        newExpr, env, OpenVarSet{}, AssertionList{}, Cost::zero, cost } );
    14651465                                renameTypes( alternatives.back().expr );
     
    14851485                                cloneAll( second.need, need );
    14861486
    1487                                 LogicalExpr *newExpr = new LogicalExpr{ 
     1487                                LogicalExpr *newExpr = new LogicalExpr{
    14881488                                        first.expr->clone(), second.expr->clone(), logicalExpr->get_isAnd() };
    1489                                 alternatives.push_back( Alternative{ 
    1490                                         newExpr, std::move(compositeEnv), std::move(openVars), 
     1489                                alternatives.push_back( Alternative{
     1490                                        newExpr, std::move(compositeEnv), std::move(openVars),
    14911491                                        AssertionList( need.begin(), need.end() ), first.cost + second.cost } );
    14921492                        }
     
    15211521                                        cloneAll( third.need, need );
    15221522                                        AssertionSet have;
    1523                                        
     1523
    15241524                                        // unify true and false types, then infer parameters to produce new alternatives
    15251525                                        Type* commonType = nullptr;
    1526                                         if ( unify( second.expr->result, third.expr->result, compositeEnv, 
     1526                                        if ( unify( second.expr->result, third.expr->result, compositeEnv,
    15271527                                                        need, have, openVars, indexer, commonType ) ) {
    1528                                                 ConditionalExpr *newExpr = new ConditionalExpr{ 
     1528                                                ConditionalExpr *newExpr = new ConditionalExpr{
    15291529                                                        first.expr->clone(), second.expr->clone(), third.expr->clone() };
    15301530                                                newExpr->result = commonType ? commonType : second.expr->result->clone();
    15311531                                                // convert both options to the conditional result type
    15321532                                                Cost cost = first.cost + second.cost + third.cost;
    1533                                                 cost += computeExpressionConversionCost( 
     1533                                                cost += computeExpressionConversionCost(
    15341534                                                        newExpr->arg2, newExpr->result, indexer, compositeEnv );
    1535                                                 cost += computeExpressionConversionCost( 
     1535                                                cost += computeExpressionConversionCost(
    15361536                                                        newExpr->arg3, newExpr->result, indexer, compositeEnv );
    15371537                                                // output alternative
    1538                                                 Alternative newAlt{ 
    1539                                                         newExpr, std::move(compositeEnv), std::move(openVars), 
     1538                                                Alternative newAlt{
     1539                                                        newExpr, std::move(compositeEnv), std::move(openVars),
    15401540                                                        AssertionList( need.begin(), need.end() ), cost };
    15411541                                                inferParameters( newAlt, back_inserter( alternatives ) );
     
    15521552                secondFinder.findWithAdjustment( commaExpr->get_arg2() );
    15531553                for ( const Alternative & alt : secondFinder.alternatives ) {
    1554                         alternatives.push_back( Alternative{ 
     1554                        alternatives.push_back( Alternative{
    15551555                                alt, new CommaExpr{ newFirstArg->clone(), alt.expr->clone() }, alt.cost } );
    15561556                } // for
     
    15781578
    15791579                                Type* commonType = nullptr;
    1580                                 if ( unify( first.expr->result, second.expr->result, compositeEnv, need, have, 
     1580                                if ( unify( first.expr->result, second.expr->result, compositeEnv, need, have,
    15811581                                                openVars, indexer, commonType ) ) {
    1582                                         RangeExpr * newExpr = 
     1582                                        RangeExpr * newExpr =
    15831583                                                new RangeExpr{ first.expr->clone(), second.expr->clone() };
    15841584                                        newExpr->result = commonType ? commonType : first.expr->result->clone();
    1585                                         Alternative newAlt{ 
    1586                                                 newExpr, std::move(compositeEnv), std::move(openVars), 
     1585                                        Alternative newAlt{
     1586                                                newExpr, std::move(compositeEnv), std::move(openVars),
    15871587                                                AssertionList( need.begin(), need.end() ), first.cost + second.cost };
    15881588                                        inferParameters( newAlt, back_inserter( alternatives ) );
     
    16111611                                cloneAll( alt.need, need );
    16121612                        }
    1613                        
    1614                         alternatives.push_back( Alternative{ 
    1615                                 new TupleExpr{ exprs }, std::move(compositeEnv), std::move(openVars), 
     1613
     1614                        alternatives.push_back( Alternative{
     1615                                new TupleExpr{ exprs }, std::move(compositeEnv), std::move(openVars),
    16161616                                AssertionList( need.begin(), need.end() ), sumCost( alts ) } );
    16171617                } // for
     
    16321632                finder.findWithoutPrune( ctorExpr->get_callExpr() );
    16331633                for ( Alternative & alt : finder.alternatives ) {
    1634                         alternatives.push_back( Alternative{ 
     1634                        alternatives.push_back( Alternative{
    16351635                                alt, new ConstructorExpr( alt.expr->clone() ), alt.cost } );
    16361636                }
     
    16841684                                cloneAll( alt.need, need );
    16851685                                AssertionSet have;
    1686                                 OpenVarSet openVars( alt.openVars ); 
    1687                                 // xxx - find things in env that don't have a "representative type" and claim 
     1686                                OpenVarSet openVars( alt.openVars );
     1687                                // xxx - find things in env that don't have a "representative type" and claim
    16881688                                // those are open vars?
    16891689                                PRINT(
    16901690                                        std::cerr << "  @ " << toType << " " << initAlt.designation << std::endl;
    16911691                                )
    1692                                 // It's possible that a cast can throw away some values in a multiply-valued 
    1693                                 // expression. (An example is a cast-to-void, which casts from one value to 
    1694                                 // zero.)  Figure out the prefix of the subexpression results that are cast 
    1695                                 // directly.  The candidate is invalid if it has fewer results than there are 
     1692                                // It's possible that a cast can throw away some values in a multiply-valued
     1693                                // expression. (An example is a cast-to-void, which casts from one value to
     1694                                // zero.)  Figure out the prefix of the subexpression results that are cast
     1695                                // directly.  The candidate is invalid if it has fewer results than there are
    16961696                                // types to cast to.
    16971697                                int discardedValues = alt.expr->result->size() - toType->size();
    16981698                                if ( discardedValues < 0 ) continue;
    1699                                 // xxx - may need to go into tuple types and extract relevant types and use 
    1700                                 // unifyList. Note that currently, this does not allow casting a tuple to an 
     1699                                // xxx - may need to go into tuple types and extract relevant types and use
     1700                                // unifyList. Note that currently, this does not allow casting a tuple to an
    17011701                                // atomic type (e.g. (int)([1, 2, 3]))
    1702                                
     1702
    17031703                                // unification run for side-effects
    17041704                                unify( toType, alt.expr->result, newEnv, need, have, openVars, indexer );
     
    17091709                                        // count one safe conversion for each value that is thrown away
    17101710                                        thisCost.incSafe( discardedValues );
    1711                                         Alternative newAlt{ 
    1712                                                 new InitExpr{ 
    1713                                                         restructureCast( alt.expr->clone(), toType, true ), initAlt.designation->clone() }, 
    1714                                                 std::move(newEnv), std::move(openVars), 
     1711                                        Alternative newAlt{
     1712                                                new InitExpr{
     1713                                                        restructureCast( alt.expr->clone(), toType, true ), initAlt.designation->clone() },
     1714                                                std::move(newEnv), std::move(openVars),
    17151715                                                AssertionList( need.begin(), need.end() ), alt.cost, thisCost };
    17161716                                        inferParameters( newAlt, back_inserter( candidates ) );
Note: See TracChangeset for help on using the changeset viewer.