Ignore:
Timestamp:
Apr 13, 2018, 5:00:24 PM (7 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
24de7b1
Parents:
04570c7
Message:

Improve memory usage of earlier AlternativeFinder? stack allocation fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r04570c7 r6f81db3  
    102102                void addAnonConversions( const Alternative & alt );
    103103                /// Adds alternatives for member expressions, given the aggregate, conversion cost for that aggregate, and name of the member
    104                 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 );
    105105                /// Adds alternatives for member expressions where the left side has tuple type
    106106                void addTupleMembers( TupleType * tupleType, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member );
     
    306306
    307307                if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) {
    308                         addAggMembers( structInst, aggrExpr, alt.cost+Cost::safe, alt.env, new NameExpr("") );
     308                        addAggMembers( structInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" );
    309309                } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) {
    310                         addAggMembers( unionInst, aggrExpr, alt.cost+Cost::safe, alt.env, new NameExpr("") );
     310                        addAggMembers( unionInst, aggrExpr, alt.cost+Cost::safe, alt.env, "" );
    311311                } // if
    312312        }
    313313
    314314        template< typename StructOrUnionType >
    315         void AlternativeFinder::Finder::addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member ) {
    316                 // by this point, member must be a name expr
    317                 NameExpr * nameExpr = dynamic_cast< NameExpr * >( member );
    318                 if ( ! nameExpr ) return;
    319                 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 ) {
    320316                std::list< Declaration* > members;
    321317                aggInst->lookup( name, members );
     
    13351331        }
    13361332
     1333        namespace {
     1334                /// Gets name from untyped member expression (member must be NameExpr)
     1335                const std::string& get_member_name( UntypedMemberExpr *memberExpr ) {
     1336                        NameExpr * nameExpr = dynamic_cast< NameExpr * >( memberExpr->get_member() );
     1337                        assert( nameExpr );
     1338                        return nameExpr->get_name();
     1339                }
     1340        }
     1341
    13371342        void AlternativeFinder::Finder::postvisit( UntypedMemberExpr *memberExpr ) {
    13381343                AlternativeFinder funcFinder( indexer, env );
     
    13461351                        // find member of the given type
    13471352                        if ( StructInstType *structInst = dynamic_cast< StructInstType* >( aggrExpr->get_result() ) ) {
    1348                                 addAggMembers( structInst, aggrExpr, cost, agg->env, memberExpr->get_member() );
     1353                                addAggMembers( structInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) );
    13491354                        } else if ( UnionInstType *unionInst = dynamic_cast< UnionInstType* >( aggrExpr->get_result() ) ) {
    1350                                 addAggMembers( unionInst, aggrExpr, cost, agg->env, memberExpr->get_member() );
     1355                                addAggMembers( unionInst, aggrExpr, cost, agg->env, get_member_name(memberExpr) );
    13511356                        } else if ( TupleType * tupleType = dynamic_cast< TupleType * >( aggrExpr->get_result() ) ) {
    13521357                                addTupleMembers( tupleType, aggrExpr, cost, agg->env, memberExpr->get_member() );
Note: See TracChangeset for help on using the changeset viewer.