Ignore:
Timestamp:
Sep 10, 2016, 12:53:36 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, 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:
908cc83
Parents:
add7117
Message:

major refactoring of Rodolfo's tuple assignment code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.h

    radd7117 r5af62f1  
    6767                virtual void visit( ImplicitCopyCtorExpr * impCpCtorExpr );
    6868                virtual void visit( ConstructorExpr * ctorExpr );
    69           public:  // xxx - temporary hack - should make Tuples::TupleAssignment a friend
    70           /// Runs a new alternative finder on each element in [begin, end)
    71           /// and writes each alternative finder to out.
     69                /// Runs a new alternative finder on each element in [begin, end)
     70                /// and writes each alternative finder to out.
    7271                template< typename InputIterator, typename OutputIterator >
    7372                void findSubExprs( InputIterator begin, InputIterator end, OutputIterator out );
    7473
    75           private:
    7674                /// Adds alternatives for member expressions, given the aggregate, conversion cost for that aggregate, and name of the member
    7775                template< typename StructOrUnionType > void addAggMembers( StructOrUnionType *aggInst, Expression *expr, const Cost &newCost, const TypeEnvironment & env, Expression * member );
     
    9189
    9290        Expression *resolveInVoidContext( Expression *expr, const SymTab::Indexer &indexer, TypeEnvironment &env );
     91
     92        template< typename InputIterator, typename OutputIterator >
     93        void findMinCost( InputIterator begin, InputIterator end, OutputIterator out ) {
     94                AltList alternatives;
     95
     96                // select the alternatives that have the minimum parameter cost
     97                Cost minCost = Cost::infinity;
     98                for ( InputIterator i = begin; i != end; ++i ) {
     99                        if ( i->cost < minCost ) {
     100                                minCost = i->cost;
     101                                i->cost = i->cvtCost;
     102                                alternatives.clear();
     103                                alternatives.push_back( *i );
     104                        } else if ( i->cost == minCost ) {
     105                                i->cost = i->cvtCost;
     106                                alternatives.push_back( *i );
     107                        }
     108                }
     109                std::copy( alternatives.begin(), alternatives.end(), out );
     110        }
    93111} // namespace ResolvExpr
    94112
Note: See TracChangeset for help on using the changeset viewer.