Changes in src/Tuples/Explode.h [03321e4:0b5d871]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/Explode.h
r03321e4 r0b5d871 16 16 #pragma once 17 17 18 #include <iterator> // for back_inserter, back_insert_iterator 18 #include "ResolvExpr/AlternativeFinder.h" 19 #include "ResolvExpr/Resolver.h" 19 20 20 #include "ResolvExpr/Alternative.h" // for Alternative, AltList 21 #include "SynTree/Expression.h" // for Expression, UniqueExpr, AddressExpr 22 #include "SynTree/Type.h" // for TupleType, Type 23 #include "Tuples.h" // for maybeImpure 21 #include "SynTree/Expression.h" 22 #include "SynTree/Declaration.h" 23 #include "SynTree/Type.h" 24 24 25 namespace SymTab { 26 class Indexer; 27 } // namespace SymTab 25 #include "Tuples.h" 28 26 29 27 namespace Tuples { 30 /// helper function used by explode to properly distribute 31 /// '&' across a tuple expression 32 Expression * distributeAddr( Expression * expr ); 28 Expression * distributeReference( Expression * ); 33 29 34 30 /// helper function used by explode … … 36 32 void explodeUnique( Expression * expr, const ResolvExpr::Alternative & alt, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign ) { 37 33 if ( isTupleAssign ) { 38 // tuple assignment needs AddressExprs to be recursively exploded to easily get at all of the components39 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( expr ) ) {34 // tuple assignment needs CastExprs to be recursively exploded to easily get at all of the components 35 if ( CastExpr * castExpr = dynamic_cast< CastExpr * >( expr ) ) { 40 36 ResolvExpr::AltList alts; 41 explodeUnique( addrExpr->get_arg(), alt, indexer, back_inserter( alts ), isTupleAssign );37 explodeUnique( castExpr->get_arg(), alt, indexer, back_inserter( alts ), isTupleAssign ); 42 38 for ( ResolvExpr::Alternative & alt : alts ) { 43 // distribute '&'over all components44 alt.expr = distribute Addr( alt.expr );39 // distribute reference cast over all components 40 alt.expr = distributeReference( alt.expr ); 45 41 *out++ = alt; 46 42 } … … 49 45 } 50 46 } 51 Type * res = expr->get_result() ;47 Type * res = expr->get_result()->stripReferences(); 52 48 if ( TupleType * tupleType = dynamic_cast< TupleType * > ( res ) ) { 53 49 if ( TupleExpr * tupleExpr = dynamic_cast< TupleExpr * >( expr ) ) { … … 57 53 } 58 54 } else { 59 // tuple type, but not tuple expr - recursively index into its components 55 // tuple type, but not tuple expr - recursively index into its components. 56 // if expr type is reference, convert to value type 60 57 Expression * arg = expr->clone(); 61 if ( Tuples::maybeImpure ( arg ) && ! dynamic_cast< UniqueExpr * >( arg ) ) {58 if ( Tuples::maybeImpureIgnoreUnique( arg ) ) { 62 59 // expressions which may contain side effects require a single unique instance of the expression. 63 60 arg = new UniqueExpr( arg ); 61 } 62 // cast reference to value type to facilitate further explosion 63 if ( dynamic_cast<ReferenceType *>( arg->get_result() ) ) { 64 arg = new CastExpr( arg, tupleType->clone() ); 64 65 } 65 66 for ( unsigned int i = 0; i < tupleType->size(); i++ ) {
Note:
See TracChangeset
for help on using the changeset viewer.