Changeset 141b786 for src/Tuples/Tuples.h
- Timestamp:
- Nov 9, 2016, 2:21:05 PM (8 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:
- b726084
- Parents:
- 23bb1b9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/Tuples.h
r23bb1b9 r141b786 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon May 18 15:04:02 201513 // Update Count : 211 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Nov 9 13:17:58 2016 13 // Update Count : 15 14 14 // 15 15 … … 18 18 19 19 #include <string> 20 #include <vector>21 #include "ResolvExpr/AlternativeFinder.h"22 #include "ResolvExpr/Resolver.h"23 20 24 21 #include "SynTree/Expression.h" 25 22 #include "SynTree/Declaration.h" 26 23 #include "SynTree/Type.h" 24 25 #include "ResolvExpr/AlternativeFinder.h" 27 26 28 27 namespace Tuples { … … 45 44 /// returns true if the expression may contain side-effects. 46 45 bool maybeImpure( Expression * expr ); 47 48 49 /// helper function used by explode50 template< typename OutputIterator >51 void explodeUnique( Expression * expr, const ResolvExpr::Alternative & alt, const SymTab::Indexer & indexer, OutputIterator out ) {52 Type * res = expr->get_result();53 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( expr ) ) {54 ResolvExpr::AltList alts;55 explodeUnique( addrExpr->get_arg(), alt, indexer, back_inserter( alts ) );56 for ( ResolvExpr::Alternative & alt : alts ) {57 // distribute '&' over all components58 alt.expr = new AddressExpr( alt.expr );59 *out++ = alt;60 }61 } else if ( TupleType * tupleType = dynamic_cast< TupleType * > ( res ) ) {62 if ( TupleExpr * tupleExpr = dynamic_cast< TupleExpr * >( expr ) ) {63 // can open tuple expr and dump its exploded components64 for ( Expression * expr : tupleExpr->get_exprs() ) {65 explodeUnique( expr, alt, indexer, out );66 }67 } else {68 // tuple type, but not tuple expr - recursively index into its components69 Expression * arg = expr->clone();70 if ( Tuples::maybeImpure( arg ) ) {71 // expressions which may contain side effects require a single unique instance of the expression.72 // resolve the UniqueExpr (which should be relatively cheap, since the argument is already resolved)73 // so that its accompanying object is properly constructed and destructed.74 arg = new UniqueExpr( arg );75 arg = ResolvExpr::resolveInVoidContext( arg, indexer );76 }77 for ( unsigned int i = 0; i < tupleType->size(); i++ ) {78 TupleIndexExpr * idx = new TupleIndexExpr( arg->clone(), i );79 explodeUnique( idx, alt, indexer, out );80 delete idx;81 }82 delete arg;83 }84 } else {85 // atomic (non-tuple) type - output a clone of the expression in a new alternative86 *out++ = ResolvExpr::Alternative( expr->clone(), alt.env, alt.cost, alt.cvtCost );87 }88 }89 90 /// expands a tuple-valued alternative into multiple alternatives, each with a non-tuple-type91 template< typename OutputIterator >92 void explode( const ResolvExpr::Alternative &alt, const SymTab::Indexer & indexer, OutputIterator out ) {93 explodeUnique( alt.expr, alt, indexer, out );94 }95 96 // explode list of alternatives97 template< typename AltIterator, typename OutputIterator >98 void explode( AltIterator altBegin, AltIterator altEnd, const SymTab::Indexer & indexer, OutputIterator out ) {99 for ( ; altBegin != altEnd; ++altBegin ) {100 explode( *altBegin, indexer, out );101 }102 }103 104 template< typename OutputIterator >105 void explode( const ResolvExpr::AltList & alts, const SymTab::Indexer & indexer, OutputIterator out ) {106 explode( alts.begin(), alts.end(), indexer, out );107 }108 46 } // namespace Tuples 109 47
Note: See TracChangeset
for help on using the changeset viewer.