Ignore:
Timestamp:
Aug 25, 2017, 10:38:34 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
800d275
Parents:
af08051 (diff), 3eab308c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/Explode.h

    raf08051 r28e58fd  
    2828
    2929namespace Tuples {
    30         /// helper function used by explode to properly distribute
    31         /// '&' across a tuple expression
    32         Expression * distributeAddr( Expression * expr );
     30        Expression * distributeReference( Expression * );
    3331
    3432        /// helper function used by explode
     
    3634        void explodeUnique( Expression * expr, const ResolvExpr::Alternative & alt, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign ) {
    3735                if ( isTupleAssign ) {
    38                         // tuple assignment needs AddressExprs to be recursively exploded to easily get at all of the components
    39                         if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( expr ) ) {
     36                        // tuple assignment needs CastExprs to be recursively exploded to easily get at all of the components
     37                        if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) {
    4038                                ResolvExpr::AltList alts;
    41                                 explodeUnique( addrExpr->get_arg(), alt, indexer, back_inserter( alts ), isTupleAssign );
     39                                explodeUnique( castExpr->get_arg(), alt, indexer, back_inserter( alts ), isTupleAssign );
    4240                                for ( ResolvExpr::Alternative & alt : alts ) {
    43                                         // distribute '&' over all components
    44                                         alt.expr = distributeAddr( alt.expr );
     41                                        // distribute reference cast over all components
     42                                        alt.expr = distributeReference( alt.expr );
    4543                                        *out++ = alt;
    4644                                }
     
    4947                        }
    5048                }
    51                 Type * res = expr->get_result();
     49                Type * res = expr->get_result()->stripReferences();
    5250                if ( TupleType * tupleType = dynamic_cast< TupleType * > ( res ) ) {
    5351                        if ( TupleExpr * tupleExpr = dynamic_cast< TupleExpr * >( expr ) ) {
     
    5755                                }
    5856                        } else {
    59                                 // tuple type, but not tuple expr - recursively index into its components
     57                                // tuple type, but not tuple expr - recursively index into its components.
     58                                // if expr type is reference, convert to value type
    6059                                Expression * arg = expr->clone();
    61                                 if ( Tuples::maybeImpure( arg ) && ! dynamic_cast< UniqueExpr * >( arg ) ) {
     60                                if ( Tuples::maybeImpureIgnoreUnique( arg ) ) {
    6261                                        // expressions which may contain side effects require a single unique instance of the expression.
    6362                                        arg = new UniqueExpr( arg );
     63                                }
     64                                // cast reference to value type to facilitate further explosion
     65                                if ( dynamic_cast<ReferenceType *>( arg->get_result() ) ) {
     66                                        arg = new CastExpr( arg, tupleType->clone() );
    6467                                }
    6568                                for ( unsigned int i = 0; i < tupleType->size(); i++ ) {
Note: See TracChangeset for help on using the changeset viewer.