Changeset 77971f6 for src/Tuples
- Timestamp:
- Oct 27, 2016, 3:24:02 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:
- 3f0c6a5
- Parents:
- a1e67dd
- git-author:
- Rob Schluntz <rschlunt@…> (10/27/16 15:11:00)
- git-committer:
- Rob Schluntz <rschlunt@…> (10/27/16 15:24:02)
- Location:
- src/Tuples
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/TupleAssignment.cc
ra1e67dd r77971f6 179 179 180 180 // explode the lhs so that each field of the tuple-valued-expr is assigned. 181 explode( lhsAlt, back_inserter(lhs) );181 explode( lhsAlt, spotter.currentFinder.get_indexer(), back_inserter(lhs) ); 182 182 // and finally, re-add the cast to each lhs expr, so that qualified tuple fields can be constructed 183 183 if ( isCast ) { … … 204 204 TupleAssignSpotter::MultipleAssignMatcher::MultipleAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList & alts ) : Matcher( spotter, alts ) { 205 205 // explode the rhs so that each field of the tuple-valued-expr is assigned. 206 explode( std::next(alts.begin(), 1), alts.end(), back_inserter(rhs) );206 explode( std::next(alts.begin(), 1), alts.end(), spotter.currentFinder.get_indexer(), back_inserter(rhs) ); 207 207 } 208 208 -
src/Tuples/TupleExpansion.cc
ra1e67dd r77971f6 141 141 142 142 Expression * UniqueExprExpander::mutate( UniqueExpr * unqExpr ) { 143 static UniqueName tempNamer( "_unq_expr_" );144 143 unqExpr = safe_dynamic_cast< UniqueExpr * > ( Parent::mutate( unqExpr ) ); 145 144 if ( ! decls.count( unqExpr->get_id() ) ) { … … 160 159 // } 161 160 162 // xxx - attach a resolved ConstructorInit node? 163 // xxx - is it possible to make the objDecl's type const? 164 ObjectDecl * objDecl = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, unqExpr->get_result()->clone(), nullptr ); 165 // must be done on two lines because genCtorInit accesses objDecl's fields 166 objDecl->set_init( InitTweak::genCtorInit( objDecl ) ); 167 161 ObjectDecl * objDecl = unqExpr->get_object(); 162 unqExpr->set_object( nullptr ); 168 163 decls[unqExpr->get_id()] = objDecl; 169 164 addDeclaration( objDecl ); -
src/Tuples/Tuples.h
ra1e67dd r77971f6 20 20 #include <vector> 21 21 #include "ResolvExpr/AlternativeFinder.h" 22 #include "ResolvExpr/Resolver.h" 22 23 23 24 #include "SynTree/Expression.h" … … 48 49 /// helper function used by explode 49 50 template< typename OutputIterator > 50 void explodeUnique( Expression * expr, const ResolvExpr::Alternative & alt, OutputIterator out ) {51 void explodeUnique( Expression * expr, const ResolvExpr::Alternative & alt, const SymTab::Indexer & indexer, OutputIterator out ) { 51 52 Type * res = expr->get_result(); 52 53 if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( expr ) ) { 53 54 ResolvExpr::AltList alts; 54 explodeUnique( addrExpr->get_arg(), alt, back_inserter( alts ) );55 explodeUnique( addrExpr->get_arg(), alt, indexer, back_inserter( alts ) ); 55 56 for ( ResolvExpr::Alternative & alt : alts ) { 56 57 // distribute '&' over all components … … 62 63 // can open tuple expr and dump its exploded components 63 64 for ( Expression * expr : tupleExpr->get_exprs() ) { 64 explodeUnique( expr, alt, out );65 explodeUnique( expr, alt, indexer, out ); 65 66 } 66 67 } else { … … 68 69 Expression * arg = expr->clone(); 69 70 if ( Tuples::maybeImpure( arg ) ) { 70 // expressions which may contain side effects require a single unique instance of the expression 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. 71 74 arg = new UniqueExpr( arg ); 75 arg = ResolvExpr::resolveInVoidContext( arg, indexer ); 72 76 } 73 77 for ( unsigned int i = 0; i < tupleType->size(); i++ ) { 74 78 TupleIndexExpr * idx = new TupleIndexExpr( arg->clone(), i ); 75 explodeUnique( idx, alt, out );79 explodeUnique( idx, alt, indexer, out ); 76 80 delete idx; 77 81 } … … 86 90 /// expands a tuple-valued alternative into multiple alternatives, each with a non-tuple-type 87 91 template< typename OutputIterator > 88 void explode( const ResolvExpr::Alternative &alt, OutputIterator out ) {89 explodeUnique( alt.expr, alt, out );92 void explode( const ResolvExpr::Alternative &alt, const SymTab::Indexer & indexer, OutputIterator out ) { 93 explodeUnique( alt.expr, alt, indexer, out ); 90 94 } 91 95 92 96 // explode list of alternatives 93 97 template< typename AltIterator, typename OutputIterator > 94 void explode( AltIterator altBegin, AltIterator altEnd, OutputIterator out ) {98 void explode( AltIterator altBegin, AltIterator altEnd, const SymTab::Indexer & indexer, OutputIterator out ) { 95 99 for ( ; altBegin != altEnd; ++altBegin ) { 96 explode( *altBegin, out );100 explode( *altBegin, indexer, out ); 97 101 } 98 102 } 99 103 100 104 template< typename OutputIterator > 101 void explode( const ResolvExpr::AltList & alts, OutputIterator out ) {102 explode( alts.begin(), alts.end(), out );105 void explode( const ResolvExpr::AltList & alts, const SymTab::Indexer & indexer, OutputIterator out ) { 106 explode( alts.begin(), alts.end(), indexer, out ); 103 107 } 104 108 } // namespace Tuples
Note: See TracChangeset
for help on using the changeset viewer.