Ignore:
Timestamp:
Aug 22, 2017, 7:09:33 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, resolv-new, with_gc
Children:
fc56cdbf
Parents:
0b5d871
Message:

Simplify tuple assignment code now that explode is reference-cast-aware

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleAssignment.cc

    r0b5d871 r5fb6830  
    182182
    183183                ResolvExpr::Alternative lhsAlt = alts.front();
    184                 // peel off the cast that exists on ctor/dtor expressions
    185                 bool isCast = false;
    186                 if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( lhsAlt.expr ) ) {
    187                         lhsAlt.expr = castExpr->get_arg();
    188                         castExpr->set_arg( nullptr );
    189                         delete castExpr;
    190                         isCast = true;
     184                // explode is aware of casts - ensure every LHS expression is sent into explode with a reference cast
     185                if ( ! dynamic_cast< CastExpr * >( lhsAlt.expr ) ) {
     186                        lhsAlt.expr = new CastExpr( lhsAlt.expr, new ReferenceType( Type::Qualifiers(), lhsAlt.expr->get_result()->clone() ) );
    191187                }
    192188
     
    194190                explode( lhsAlt, spotter.currentFinder.get_indexer(), back_inserter(lhs), true );
    195191
    196                 // and finally, re-add the cast to each lhs expr, so that qualified tuple fields can be constructed
    197                 if ( isCast ) {
    198                         for ( ResolvExpr::Alternative & alt : lhs ) {
    199                                 Expression *& expr = alt.expr;
    200                                 Type * type = expr->get_result()->clone();
    201                                 type->get_qualifiers() -= Type::Qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic );
    202                                 expr = new CastExpr( expr, new ReferenceType( Type::Qualifiers(), type ) );
    203                         }
    204                 }
    205 
    206192                for ( ResolvExpr::Alternative & alt : lhs ) {
    207193                        // every LHS value must be a reference - some come in with a cast expression, if it doesn't just cast to reference here.
    208                         // TODO: can this somehow be merge with the cast code directly above?
    209194                        if ( ! dynamic_cast< ReferenceType * >( alt.expr->get_result() ) ) {
    210195                                alt.expr = new CastExpr( alt.expr, new ReferenceType( Type::Qualifiers(), alt.expr->get_result()->clone() ) );
Note: See TracChangeset for help on using the changeset viewer.