Changeset 62194cb for src/Tuples
- Timestamp:
- Nov 23, 2017, 4:24:48 PM (7 years ago)
- 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:
- 178e4ec
- Parents:
- a8b27c6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/Explode.h
ra8b27c6 r62194cb 16 16 #pragma once 17 17 18 #include <iterator> // for back_inserter, back_insert_iterator 18 #include <iterator> // for back_inserter, back_insert_iterator 19 #include <utility> // for forward 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 "ResolvExpr/Alternative.h" // for Alternative, AltList 22 #include "ResolvExpr/ExplodedActual.h" // for ExplodedActual 23 #include "SynTree/Expression.h" // for Expression, UniqueExpr, AddressExpr 24 #include "SynTree/Type.h" // for TupleType, Type 25 #include "Tuples.h" // for maybeImpure 24 26 25 27 namespace SymTab { … … 39 41 } 40 42 43 /// Append alternative to an OutputIterator of Alternatives 44 template<typename OutputIterator> 45 void append( OutputIterator out, Expression* expr, const ResolvExpr::TypeEnvironment& env, 46 const ResolvExpr::Cost& cost, const ResolvExpr::Cost& cvtCost ) { 47 *out++ = ResolvExpr::Alternative{ expr, env, cost, cvtCost }; 48 } 49 50 /// Append alternative to an ExplodedActual 51 static inline void append( ResolvExpr::ExplodedActual& ea, Expression* expr, 52 const ResolvExpr::TypeEnvironment&, const ResolvExpr::Cost&, const ResolvExpr::Cost& ) { 53 ea.exprs.emplace_back( expr ); 54 /// xxx -- merge environment, cost? 55 } 56 41 57 /// helper function used by explode 42 template< typename OutputIterator > 43 void explodeUnique( Expression * expr, const ResolvExpr::Alternative & alt, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign ) { 58 template< typename Output > 59 void explodeUnique( Expression * expr, const ResolvExpr::Alternative & alt, 60 const SymTab::Indexer & indexer, Output&& out, bool isTupleAssign ) { 44 61 if ( isTupleAssign ) { 45 62 // tuple assignment needs CastExprs to be recursively exploded to easily get at all of the components 46 63 if ( CastExpr * castExpr = isReferenceCast( expr ) ) { 47 64 ResolvExpr::AltList alts; 48 explodeUnique( castExpr->get_arg(), alt, indexer, back_inserter( alts ), isTupleAssign ); 65 explodeUnique( 66 castExpr->get_arg(), alt, indexer, back_inserter( alts ), isTupleAssign ); 49 67 for ( ResolvExpr::Alternative & alt : alts ) { 50 68 // distribute reference cast over all components 51 a lt.expr = distributeReference( alt.expr );52 *out++ = alt;69 append( std::forward<Output>(out), distributeReference( alt.release_expr() ), 70 alt.env, alt.cost, alt.cvtCost ); 53 71 } 54 72 // 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) … … 61 79 // can open tuple expr and dump its exploded components 62 80 for ( Expression * expr : tupleExpr->get_exprs() ) { 63 explodeUnique( expr, alt, indexer, out, isTupleAssign );81 explodeUnique( expr, alt, indexer, std::forward<Output>(out), isTupleAssign ); 64 82 } 65 83 } else { … … 77 95 for ( unsigned int i = 0; i < tupleType->size(); i++ ) { 78 96 TupleIndexExpr * idx = new TupleIndexExpr( arg->clone(), i ); 79 explodeUnique( idx, alt, indexer, out, isTupleAssign );97 explodeUnique( idx, alt, indexer, std::forward<Output>(out), isTupleAssign ); 80 98 delete idx; 81 99 } … … 84 102 } else { 85 103 // atomic (non-tuple) type - output a clone of the expression in a new alternative 86 *out++ = ResolvExpr::Alternative(expr->clone(), alt.env, alt.cost, alt.cvtCost );104 append( std::forward<Output>(out), expr->clone(), alt.env, alt.cost, alt.cvtCost ); 87 105 } 88 106 } 89 107 90 108 /// expands a tuple-valued alternative into multiple alternatives, each with a non-tuple-type 91 template< typename OutputIterator > 92 void explode( const ResolvExpr::Alternative &alt, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign = false ) { 93 explodeUnique( alt.expr, alt, indexer, out, isTupleAssign ); 109 template< typename Output > 110 void explode( const ResolvExpr::Alternative &alt, const SymTab::Indexer & indexer, 111 Output&& out, bool isTupleAssign = false ) { 112 explodeUnique( alt.expr, alt, indexer, std::forward<Output>(out), isTupleAssign ); 94 113 } 95 114 96 115 // explode list of alternatives 97 template< typename AltIterator, typename OutputIterator > 98 void explode( AltIterator altBegin, AltIterator altEnd, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign = false ) { 116 template< typename AltIterator, typename Output > 117 void explode( AltIterator altBegin, AltIterator altEnd, const SymTab::Indexer & indexer, 118 Output&& out, bool isTupleAssign = false ) { 99 119 for ( ; altBegin != altEnd; ++altBegin ) { 100 explode( *altBegin, indexer, out, isTupleAssign );120 explode( *altBegin, indexer, std::forward<Output>(out), isTupleAssign ); 101 121 } 102 122 } 103 123 104 template< typename OutputIterator > 105 void explode( const ResolvExpr::AltList & alts, const SymTab::Indexer & indexer, OutputIterator out, bool isTupleAssign = false ) { 106 explode( alts.begin(), alts.end(), indexer, out, isTupleAssign ); 124 template< typename Output > 125 void explode( const ResolvExpr::AltList & alts, const SymTab::Indexer & indexer, Output&& out, 126 bool isTupleAssign = false ) { 127 explode( alts.begin(), alts.end(), indexer, std::forward<Output>(out), isTupleAssign ); 107 128 } 108 129 } // namespace Tuples
Note: See TracChangeset
for help on using the changeset viewer.