Changeset a181494


Ignore:
Timestamp:
Feb 21, 2018, 4:07:10 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
5a806be4
Parents:
599fbb6
git-author:
Rob Schluntz <rschlunt@…> (02/21/18 15:52:43)
git-committer:
Rob Schluntz <rschlunt@…> (02/21/18 16:07:10)
Message:

Adding cost for reference-to-rvalue conversions

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r599fbb6 ra181494  
    204204        } // namespace
    205205
    206         void referenceToRvalueConversion( Expression *& expr ) {
     206        void referenceToRvalueConversion( Expression *& expr, Cost & cost ) {
    207207                if ( dynamic_cast< ReferenceType * >( expr->get_result() ) ) {
    208208                        // cast away reference from expr
    209209                        expr = new CastExpr( expr, expr->get_result()->stripReferences()->clone() );
     210                        cost.incReference();
    210211                }
    211212        }
     
    435436                                        PRINT( std::cerr << "end of formals with varargs function: inc unsafe: " << convCost << std::endl; ; )
    436437                                        // convert reference-typed expressions to value-typed expressions
    437                                         referenceToRvalueConversion( *actualExpr );
     438                                        referenceToRvalueConversion( *actualExpr, convCost );
    438439                                        continue;
    439440                                } else {
     
    565566                                // DOESN'T WORK: grandchild nodes conflict with their cousins
    566567                                //if ( newNeedParents[ curDecl->get_uniqueId() ][ candDecl->get_uniqueId() ]++ > recursionParentLimit ) continue;
    567                                 Expression *varExpr = data.combine();
     568
     569                                Expression *varExpr = data.combine( newerAlt.cost );
    568570                                delete varExpr->get_result();
    569571                                varExpr->set_result( adjType->clone() );
     
    11211123                                        if ( FunctionType *function = dynamic_cast< FunctionType* >( pointer->get_base() ) ) {
    11221124                                                Alternative newFunc( *func );
    1123                                                 referenceToRvalueConversion( newFunc.expr );
     1125                                                referenceToRvalueConversion( newFunc.expr, newFunc.cost );
    11241126                                                makeFunctionAlternatives( newFunc, function, argExpansions,
    11251127                                                        std::back_inserter( candidates ) );
     
    11301132                                                if ( FunctionType *function = dynamic_cast< FunctionType* >( eqvClass.type ) ) {
    11311133                                                        Alternative newFunc( *func );
    1132                                                         referenceToRvalueConversion( newFunc.expr );
     1134                                                        referenceToRvalueConversion( newFunc.expr, newFunc.cost );
    11331135                                                        makeFunctionAlternatives( newFunc, function, argExpansions,
    11341136                                                                std::back_inserter( candidates ) );
     
    11601162                                                                dynamic_cast<FunctionType*>( pointer->get_base() ) ) {
    11611163                                                        Alternative newFunc( *funcOp );
    1162                                                         referenceToRvalueConversion( newFunc.expr );
     1164                                                        referenceToRvalueConversion( newFunc.expr, newFunc.cost );
    11631165                                                        makeFunctionAlternatives( newFunc, function, argExpansions,
    11641166                                                                std::back_inserter( candidates ) );
     
    13441346                for ( AltList::const_iterator agg = funcFinder.alternatives.begin(); agg != funcFinder.alternatives.end(); ++agg ) {
    13451347                        // 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
    1346                         std::unique_ptr<Expression> aggrExpr( agg->expr->clone() );
    1347                         Type * aggrType = aggrExpr->get_result();
    1348                         if ( dynamic_cast< ReferenceType * >( aggrType ) ) {
    1349                                 aggrType = aggrType->stripReferences();
    1350                                 aggrExpr.reset( new CastExpr( aggrExpr.release(), aggrType->clone() ) );
    1351                         }
     1348                        Cost cost = agg->cost;
     1349                        Expression * aggrExpr = agg->expr->clone();
     1350                        referenceToRvalueConversion( aggrExpr, cost );
     1351                        std::unique_ptr<Expression> guard( aggrExpr );
     1352
    13521353                        // find member of the given type
    13531354                        if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) {
    1354                                 addAggMembers( structInst, aggrExpr.get(), agg->cost, agg->env, memberExpr->get_member() );
     1355                                addAggMembers( structInst, aggrExpr, cost, agg->env, memberExpr->get_member() );
    13551356                        } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) {
    1356                                 addAggMembers( unionInst, aggrExpr.get(), agg->cost, agg->env, memberExpr->get_member() );
     1357                                addAggMembers( unionInst, aggrExpr, cost, agg->env, memberExpr->get_member() );
    13571358                        } else if ( TupleType * tupleType = dynamic_cast< TupleType * >( aggrExpr->get_result() ) ) {
    1358                                 addTupleMembers( tupleType, aggrExpr.get(), agg->cost, agg->env, memberExpr->get_member() );
     1359                                addTupleMembers( tupleType, aggrExpr, cost, agg->env, memberExpr->get_member() );
    13591360                        } // if
    13601361                } // for
     
    13701371                PRINT( std::cerr << "nameExpr is " << nameExpr->name << std::endl; )
    13711372                for ( auto & data : declList ) {
    1372                         Expression * newExpr = data.combine();
    1373                         // xxx - add in extra cost for with-statement exprs?
    1374                         alternatives.push_back( Alternative( newExpr, env, Cost::zero ) );
     1373                        Cost cost = Cost::zero;
     1374                        Expression * newExpr = data.combine( cost );
     1375                        alternatives.push_back( Alternative( newExpr, env, Cost::zero ) ); // xxx
    13751376                        PRINT(
    13761377                                std::cerr << "decl is ";
     
    14121413                        // return the lowest cost alternative for the argument
    14131414                        Alternative &choice = winners.front();
    1414                         referenceToRvalueConversion( choice.expr );
     1415                        referenceToRvalueConversion( choice.expr, choice.cost );
    14151416                        alternatives.push_back( Alternative( new SizeofExpr( choice.expr->clone() ), choice.env, Cost::zero ) );
    14161417                } // if
     
    14331434                        // return the lowest cost alternative for the argument
    14341435                        Alternative &choice = winners.front();
    1435                         referenceToRvalueConversion( choice.expr );
     1436                        referenceToRvalueConversion( choice.expr, choice.cost );
    14361437                        alternatives.push_back( Alternative( new AlignofExpr( choice.expr->clone() ), choice.env, Cost::zero ) );
    14371438                } // if
     
    14851486                        AltList & alternatives = finder.get_alternatives();
    14861487                        if ( typesCompatibleIgnoreQualifiers( argType, function->get_parameters().front()->get_type(), indexer, env ) ) {
    1487                                 alternatives.push_back( Alternative( new AttrExpr( data.combine(), argType->clone() ), env, Cost::zero ) );
     1488                                Cost cost = Cost::zero;
     1489                                Expression * newExpr = data.combine( cost );
     1490                                alternatives.push_back( Alternative( new AttrExpr( newExpr, argType->clone() ), env, cost ) );
    14881491                                for ( DeclarationWithType * retVal : function->returnVals ) {
    14891492                                        alternatives.back().expr->result = retVal->get_type()->clone();
     
    15221525                } else {
    15231526                        for ( auto & data : attrList ) {
    1524                                 alternatives.push_back( Alternative( data.combine(), env, Cost::zero ) );
     1527                                Cost cost = Cost::zero;
     1528                                Expression * newExpr = data.combine( cost );
     1529                                alternatives.push_back( Alternative( newExpr, env, cost ) );
    15251530                                renameTypes( alternatives.back().expr );
    15261531                        } // for
  • src/ResolvExpr/Resolver.cc

    r599fbb6 ra181494  
    526526                                        Alternative newFunc( func );
    527527                                        // Strip reference from function
    528                                         referenceToRvalueConversion( newFunc.expr );
     528                                        referenceToRvalueConversion( newFunc.expr, newFunc.cost );
    529529
    530530                                        // For all the set of arguments we have try to match it with the parameter of the current function alternative
  • src/ResolvExpr/typeops.h

    r599fbb6 ra181494  
    106106
    107107        // in AlternativeFinder.cc
    108         void referenceToRvalueConversion( Expression *& expr );
     108        void referenceToRvalueConversion( Expression *& expr, Cost & cost );
    109109
    110110        // flatten tuple type into list of types
  • src/SymTab/Indexer.cc

    r599fbb6 ra181494  
    603603                                        if ( dynamic_cast< StructInstType * >( t ) || dynamic_cast< UnionInstType * >( t ) ) {
    604604                                                Expression * base = expr->clone();
    605                                                 ResolvExpr::referenceToRvalueConversion( base );
     605                                                ResolvExpr::Cost cost = ResolvExpr::Cost::zero; // xxx - carry this cost into the indexer as a base cost?
     606                                                ResolvExpr::referenceToRvalueConversion( base, cost );
    606607                                                addMembers( t->getAggr(), new MemberExpr( dwt, base ), handleConflicts );
    607608                                        }
     
    705706        }
    706707
    707         Expression * Indexer::IdData::combine() const {
     708        Expression * Indexer::IdData::combine( ResolvExpr::Cost & cost ) const {
    708709                Expression * ret = nullptr;
    709710                if ( baseExpr ) {
    710711                        Expression * base = baseExpr->clone();
    711                         ResolvExpr::referenceToRvalueConversion( base );
     712                        ResolvExpr::referenceToRvalueConversion( base, cost );
    712713                        ret = new MemberExpr( id, base );
    713714                        // xxx - this introduces hidden environments, for now remove them.
  • src/SymTab/Indexer.h

    r599fbb6 ra181494  
    2323#include "SynTree/Visitor.h"  // for Visitor
    2424#include "SynTree/SynTree.h"  // for AST nodes
     25
     26namespace ResolvExpr {
     27class Cost;
     28}
    2529
    2630namespace SymTab {
     
    5155                        IdData( DeclarationWithType * id, Expression * baseExpr, BaseSyntaxNode * deleteStmt ) : id( id ), baseExpr( baseExpr ), deleteStmt( deleteStmt ) {}
    5256
    53                         Expression * combine() const;
     57                        Expression * combine( ResolvExpr::Cost & cost ) const;
    5458                };
    5559
Note: See TracChangeset for help on using the changeset viewer.