Changeset 908cc83 for src/Tuples


Ignore:
Timestamp:
Sep 10, 2016, 1:31:37 PM (8 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:
8f7cea1
Parents:
5af62f1
Message:

make mass assignment resolve correctly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleAssignment.cc

    r5af62f1 r908cc83  
    5656                        virtual ~Matcher() {}
    5757                        virtual void match( std::list< Expression * > &out ) = 0;
    58                         virtual void solve( std::list< Expression * > &assigns ) = 0;
     58                        virtual void solve() = 0;
    5959                        static UntypedExpr *createAssgn( Expression *left, Expression *right );
    6060                  protected:
     
    6969                        }
    7070                        virtual void match( std::list< Expression * > &out );
    71                         virtual void solve( std::list< Expression * > &assigns );
     71                        virtual void solve();
    7272                };
    7373
     
    7676                        MultipleAssignMatcher( TupleAssignSpotter &spot, Expression *lhs, Expression *rhs );
    7777                        virtual void match( std::list< Expression * > &out );
    78                         virtual void solve( std::list< Expression * > &assigns );
     78                        virtual void solve();
    7979                };
    8080
     
    150150                if ( new_assigns.empty() ) return;
    151151                std::list< Expression * > solved_assigns;
    152                 ResolvExpr::AltList solved_alts;
    153152                ResolvExpr::AltList current;
    154153                // now resolve new assignments
     
    160159                        assert( alts.size() == 1 );
    161160                        assert( alts.front().expr != 0 );
    162                         current.push_back( finder.get_alternatives().front() );
    163                         solved_assigns.push_back( alts.front().expr->clone() );
     161                        current.push_back( alts.front() );
    164162                }
    165163                options.options.push_back( current );
    166164
    167                 matcher->solve( new_assigns );
     165                matcher->solve();
    168166        }
    169167
     
    197195        }
    198196
    199         void TupleAssignSpotter::MassAssignMatcher::solve( std::list< Expression * > &assigns ) {
     197        void TupleAssignSpotter::MassAssignMatcher::solve() {
    200198                assert( ! spotter.options.empty() );
    201                 ResolvExpr::AltList winners;
    202199                for ( std::list< ResolvExpr::AltList >::iterator i = spotter.options.begin(); i != spotter.options.end(); ++i ) {
    203                         findMinCost( i->begin(), i->end(), back_inserter(winners) );
    204                 }
    205 
    206                 std::list< Expression *> solved_assigns;
    207                 for ( ResolvExpr::AltList::iterator i = winners.begin(); i != winners.end(); ++i ) {
    208                         solved_assigns.push_back( i->expr );
    209                 }
    210                 spotter.currentFinder.get_alternatives().push_front( ResolvExpr::Alternative(new SolvedTupleExpr(solved_assigns), spotter.currentFinder.get_environ(), ResolvExpr::Cost() ) );
     200                        // extract expressions from the alternatives to produce a list of assignments that
     201                        // together form a single alternative
     202                        std::list< Expression *> solved_assigns;
     203                        for ( ResolvExpr::Alternative & alt : *i ) {
     204                                solved_assigns.push_back( alt.expr );
     205                        }
     206                        spotter.currentFinder.get_alternatives().push_front( ResolvExpr::Alternative(new SolvedTupleExpr(solved_assigns), spotter.currentFinder.get_environ(), ResolvExpr::sumCost( *i ) ) );
     207                }
    211208        }
    212209
     
    218215        }
    219216
    220         void TupleAssignSpotter::MultipleAssignMatcher::solve( std::list< Expression * > &assigns ) {
     217        void TupleAssignSpotter::MultipleAssignMatcher::solve() {
    221218                // options.print( std::cerr );
    222219                std::list< ResolvExpr::AltList > best = spotter.options.get_best();
Note: See TracChangeset for help on using the changeset viewer.