Changeset d20a343


Ignore:
Timestamp:
May 17, 2018, 4:25:54 PM (7 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, with_gc
Children:
aee472e
Parents:
4f68f6d
git-author:
Rob Schluntz <rschlunt@…> (05/17/18 16:25:24)
git-committer:
Rob Schluntz <rschlunt@…> (05/17/18 16:25:54)
Message:

Add cast to LHS type in tuple multiple assignment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleAssignment.cc

    r4f68f6d rd20a343  
    318318                assert( (! lhs.empty() && rhs.size() <= 1) || (lhs.empty() && rhs.empty()) );
    319319
     320                // xxx - may need to split this up into multiple declarations, because potential conversion to references
     321                //  probably should not reference local variable - see MultipleAssignMatcher::match
    320322                ObjectDecl * rtmp = rhs.size() == 1 ? newObject( rhsNamer, rhs.front().expr ) : nullptr;
    321323                for ( ResolvExpr::Alternative & lhsAlt : lhs ) {
     
    336338                        std::list< ObjectDecl * > ltmp;
    337339                        std::list< ObjectDecl * > rtmp;
    338                         std::transform( lhs.begin(), lhs.end(), back_inserter( ltmp ), [&]( ResolvExpr::Alternative & alt ){
    339                                 return newObject( lhsNamer, alt.expr );
    340                         });
    341                         std::transform( rhs.begin(), rhs.end(), back_inserter( rtmp ), [&]( ResolvExpr::Alternative & alt ){
    342                                 return newObject( rhsNamer, alt.expr );
    343                         });
    344                         zipWith( ltmp.begin(), ltmp.end(), rtmp.begin(), rtmp.end(), back_inserter(out), [&](ObjectDecl * obj1, ObjectDecl * obj2 ) { return createFunc(spotter.fname, obj1, obj2); } );
     340                        for ( auto p : group_iterate( lhs, rhs ) ) {
     341                                ResolvExpr::Alternative & lhsAlt = std::get<0>(p);
     342                                ResolvExpr::Alternative & rhsAlt = std::get<1>(p);
     343                                // convert RHS to LHS type minus one reference -- important for the case where LHS is && and RHS is lvalue, etc.
     344                                ReferenceType * lhsType = strict_dynamic_cast<ReferenceType *>( lhsAlt.expr->result );
     345                                rhsAlt.expr = new CastExpr( rhsAlt.expr, lhsType->base->clone() );
     346                                ObjectDecl * lobj = newObject( lhsNamer, lhsAlt.expr );
     347                                ObjectDecl * robj = newObject( rhsNamer, rhsAlt.expr );
     348                                out.push_back( createFunc(spotter.fname, lobj, robj) );
     349                                ltmp.push_back( lobj );
     350                                rtmp.push_back( robj );
     351                        }
    345352                        tmpDecls.splice( tmpDecls.end(), ltmp );
    346353                        tmpDecls.splice( tmpDecls.end(), rtmp );
Note: See TracChangeset for help on using the changeset viewer.