Ignore:
Timestamp:
Jan 9, 2017, 3:37:36 PM (5 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
627f585
Parents:
6c3a988f
Message:

address exprs are now only exploded for tuple assignments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/Explode.h

    r6c3a988f rf831177  
    3333        /// helper function used by explode
    3434        template< typename OutputIterator >
    35         void explodeUnique( Expression * expr, const ResolvExpr::Alternative & alt, const SymTab::Indexer & indexer, OutputIterator out ) {
     35        void explodeUnique( Expression * expr, const ResolvExpr::Alternative & alt, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign ) {
     36                if ( isTupleAssign ) {
     37                        // tuple assignment needs AddressExprs to be recursively exploded to easily get at all of the components
     38                        if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( expr ) ) {
     39                                ResolvExpr::AltList alts;
     40                                explodeUnique( addrExpr->get_arg(), alt, indexer, back_inserter( alts ), isTupleAssign );
     41                                for ( ResolvExpr::Alternative & alt : alts ) {
     42                                        // distribute '&' over all components
     43                                        alt.expr = distributeAddr( alt.expr );
     44                                        *out++ = alt;
     45                                }
     46                                // in tuple assignment, still need to handle the other cases, but only if not already handled here (don't want to output too many alternatives)
     47                                return;
     48                        }
     49                }
    3650                Type * res = expr->get_result();
    37                 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( expr ) ) {
    38                         ResolvExpr::AltList alts;
    39                         explodeUnique( addrExpr->get_arg(), alt, indexer, back_inserter( alts ) );
    40                         for ( ResolvExpr::Alternative & alt : alts ) {
    41                                 // distribute '&' over all components
    42                                 alt.expr = distributeAddr( alt.expr );
    43                                 *out++ = alt;
    44                         }
    45                 } else if ( TupleType * tupleType = dynamic_cast< TupleType * > ( res ) ) {
     51                if ( TupleType * tupleType = dynamic_cast< TupleType * > ( res ) ) {
    4652                        if ( TupleExpr * tupleExpr = dynamic_cast< TupleExpr * >( expr ) ) {
    4753                                // can open tuple expr and dump its exploded components
    4854                                for ( Expression * expr : tupleExpr->get_exprs() ) {
    49                                         explodeUnique( expr, alt, indexer, out );
     55                                        explodeUnique( expr, alt, indexer, out, isTupleAssign );
    5056                                }
    5157                        } else {
     
    5864                                for ( unsigned int i = 0; i < tupleType->size(); i++ ) {
    5965                                        TupleIndexExpr * idx = new TupleIndexExpr( arg->clone(), i );
    60                                         explodeUnique( idx, alt, indexer, out );
     66                                        explodeUnique( idx, alt, indexer, out, isTupleAssign );
    6167                                        delete idx;
    6268                                }
     
    7177        /// expands a tuple-valued alternative into multiple alternatives, each with a non-tuple-type
    7278        template< typename OutputIterator >
    73         void explode( const ResolvExpr::Alternative &alt, const SymTab::Indexer & indexer, OutputIterator out ) {
    74                 explodeUnique( alt.expr, alt, indexer, out );
     79        void explode( const ResolvExpr::Alternative &alt, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign = false ) {
     80                explodeUnique( alt.expr, alt, indexer, out, isTupleAssign );
    7581        }
    7682
    7783        // explode list of alternatives
    7884        template< typename AltIterator, typename OutputIterator >
    79         void explode( AltIterator altBegin, AltIterator altEnd, const SymTab::Indexer & indexer, OutputIterator out ) {
     85        void explode( AltIterator altBegin, AltIterator altEnd, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign = false ) {
    8086                for ( ; altBegin != altEnd; ++altBegin ) {
    81                         explode( *altBegin, indexer, out );
     87                        explode( *altBegin, indexer, out, isTupleAssign );
    8288                }
    8389        }
    8490
    8591        template< typename OutputIterator >
    86         void explode( const ResolvExpr::AltList & alts, const SymTab::Indexer & indexer, OutputIterator out ) {
    87                 explode( alts.begin(), alts.end(), indexer, out );
     92        void explode( const ResolvExpr::AltList & alts, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign = false ) {
     93                explode( alts.begin(), alts.end(), indexer, out, isTupleAssign );
    8894        }
    8995} // namespace Tuples
Note: See TracChangeset for help on using the changeset viewer.