Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleAssignment.cc

    rf831177 r1d2b64f  
    7373        };
    7474
    75         /// true if expr is an expression of tuple type
     75        /// true if expr is an expression of tuple type, i.e. a tuple expression, tuple variable, or MRV (multiple-return-value) function
    7676        bool isTuple( Expression *expr ) {
    7777                if ( ! expr ) return false;
    7878                assert( expr->has_result() );
    79                 return dynamic_cast< TupleType * >( expr->get_result() );
     79                return dynamic_cast<TupleExpr *>(expr) || expr->get_result()->size() > 1;
    8080        }
    8181
     
    142142                matcher->match( new_assigns );
    143143
    144                 if ( ! matcher->lhs.empty() || ! matcher->rhs.empty() ) {
    145                         // if both lhs and rhs are empty then this is the empty tuple case, wherein it's okay for new_assigns to be empty.
    146                         // if not the empty tuple case, return early so that no new alternatives are generated.
    147                         if ( new_assigns.empty() ) return;
    148                 }
     144                if ( new_assigns.empty() ) return;
    149145                ResolvExpr::AltList current;
    150146                // now resolve new assignments
     
    190186
    191187                // explode the lhs so that each field of the tuple-valued-expr is assigned.
    192                 explode( lhsAlt, spotter.currentFinder.get_indexer(), back_inserter(lhs), true );
     188                explode( lhsAlt, spotter.currentFinder.get_indexer(), back_inserter(lhs) );
    193189
    194190                // and finally, re-add the cast to each lhs expr, so that qualified tuple fields can be constructed
     
    215211        TupleAssignSpotter::MultipleAssignMatcher::MultipleAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList & alts ) : Matcher( spotter, alts ) {
    216212                // explode the rhs so that each field of the tuple-valued-expr is assigned.
    217                 explode( std::next(alts.begin(), 1), alts.end(), spotter.currentFinder.get_indexer(), back_inserter(rhs), true );
     213                explode( std::next(alts.begin(), 1), alts.end(), spotter.currentFinder.get_indexer(), back_inserter(rhs) );
    218214        }
    219215
     
    252248                static UniqueName lhsNamer( "__massassign_L" );
    253249                static UniqueName rhsNamer( "__massassign_R" );
    254                 // empty tuple case falls into this matcher, hence the second part of the assert
    255                 assert( (! lhs.empty() && rhs.size() <= 1) || (lhs.empty() && rhs.empty()) );
     250                assert ( ! lhs.empty() && rhs.size() <= 1);
    256251
    257252                ObjectDecl * rtmp = rhs.size() == 1 ? newObject( rhsNamer, rhs.front().expr ) : nullptr;
    258253                for ( ResolvExpr::Alternative & lhsAlt : lhs ) {
    259                         // create a temporary object for each value in the lhs and create a call involving the rhs
    260254                        ObjectDecl * ltmp = newObject( lhsNamer, lhsAlt.expr );
    261255                        out.push_back( createFunc( spotter.fname, ltmp, rtmp ) );
     
    269263                static UniqueName rhsNamer( "__multassign_R" );
    270264
     265                // xxx - need more complicated matching?
    271266                if ( lhs.size() == rhs.size() ) {
    272                         // produce a new temporary object for each value in the lhs and rhs and pairwise create the calls
    273267                        std::list< ObjectDecl * > ltmp;
    274268                        std::list< ObjectDecl * > rtmp;
Note: See TracChangeset for help on using the changeset viewer.