Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.h

    rb6fe7e6 r8f7cea1  
    6767                virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr );
    6868                virtual void visit( ConstructorExpr * ctorExpr );
    69           public:  // xxx - temporary hack - should make Tuples::TupleAssignment a friend
     69                virtual void visit( TupleIndexExpr *tupleExpr );
     70                /// Runs a new alternative finder on each element in [begin, end)
     71                /// and writes each alternative finder to out.
    7072                template< typename InputIterator, typename OutputIterator >
    7173                void findSubExprs( InputIterator begin, InputIterator end, OutputIterator out );
    7274
    73           private:
    7475                /// Adds alternatives for member expressions, given the aggregate, conversion cost for that aggregate, and name of the member
    75                 template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, const std::string &name );
     76                template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member );
    7677                /// Adds alternatives for offsetof expressions, given the base type and name of the member
    7778                template< typename StructOrUnionType > void addOffsetof( StructOrUnionType *aggInst, const std::string &name );
     
    8990
    9091        Expression *resolveInVoidContext( Expression *expr, const SymTab::Indexer &indexer, TypeEnvironment &env );
     92
     93        template< typename InputIterator, typename OutputIterator >
     94        void findMinCost( InputIterator begin, InputIterator end, OutputIterator out ) {
     95                AltList alternatives;
     96
     97                // select the alternatives that have the minimum parameter cost
     98                Cost minCost = Cost::infinity;
     99                for ( InputIterator i = begin; i != end; ++i ) {
     100                        if ( i->cost < minCost ) {
     101                                minCost = i->cost;
     102                                i->cost = i->cvtCost;
     103                                alternatives.clear();
     104                                alternatives.push_back( *i );
     105                        } else if ( i->cost == minCost ) {
     106                                i->cost = i->cvtCost;
     107                                alternatives.push_back( *i );
     108                        }
     109                }
     110                std::copy( alternatives.begin(), alternatives.end(), out );
     111        }
     112
     113        Cost sumCost( const AltList &in );
    91114} // namespace ResolvExpr
    92115
Note: See TracChangeset for help on using the changeset viewer.