Changes in src/Tuples/TupleAssignment.cc [f831177:1d2b64f]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/TupleAssignment.cc
rf831177 r1d2b64f 73 73 }; 74 74 75 /// true if expr is an expression of tuple type 75 /// true if expr is an expression of tuple type, i.e. a tuple expression, tuple variable, or MRV (multiple-return-value) function 76 76 bool isTuple( Expression *expr ) { 77 77 if ( ! expr ) return false; 78 78 assert( expr->has_result() ); 79 return dynamic_cast< TupleType * >( expr->get_result() );79 return dynamic_cast<TupleExpr *>(expr) || expr->get_result()->size() > 1; 80 80 } 81 81 … … 142 142 matcher->match( new_assigns ); 143 143 144 if ( ! matcher->lhs.empty() || ! matcher->rhs.empty() ) { 145 // if both lhs and rhs are empty then this is the empty tuple case, wherein it's okay for new_assigns to be empty. 146 // if not the empty tuple case, return early so that no new alternatives are generated. 147 if ( new_assigns.empty() ) return; 148 } 144 if ( new_assigns.empty() ) return; 149 145 ResolvExpr::AltList current; 150 146 // now resolve new assignments … … 190 186 191 187 // explode the lhs so that each field of the tuple-valued-expr is assigned. 192 explode( lhsAlt, spotter.currentFinder.get_indexer(), back_inserter(lhs) , true);188 explode( lhsAlt, spotter.currentFinder.get_indexer(), back_inserter(lhs) ); 193 189 194 190 // and finally, re-add the cast to each lhs expr, so that qualified tuple fields can be constructed … … 215 211 TupleAssignSpotter::MultipleAssignMatcher::MultipleAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList & alts ) : Matcher( spotter, alts ) { 216 212 // explode the rhs so that each field of the tuple-valued-expr is assigned. 217 explode( std::next(alts.begin(), 1), alts.end(), spotter.currentFinder.get_indexer(), back_inserter(rhs) , true);213 explode( std::next(alts.begin(), 1), alts.end(), spotter.currentFinder.get_indexer(), back_inserter(rhs) ); 218 214 } 219 215 … … 252 248 static UniqueName lhsNamer( "__massassign_L" ); 253 249 static UniqueName rhsNamer( "__massassign_R" ); 254 // empty tuple case falls into this matcher, hence the second part of the assert 255 assert( (! lhs.empty() && rhs.size() <= 1) || (lhs.empty() && rhs.empty()) ); 250 assert ( ! lhs.empty() && rhs.size() <= 1); 256 251 257 252 ObjectDecl * rtmp = rhs.size() == 1 ? newObject( rhsNamer, rhs.front().expr ) : nullptr; 258 253 for ( ResolvExpr::Alternative & lhsAlt : lhs ) { 259 // create a temporary object for each value in the lhs and create a call involving the rhs260 254 ObjectDecl * ltmp = newObject( lhsNamer, lhsAlt.expr ); 261 255 out.push_back( createFunc( spotter.fname, ltmp, rtmp ) ); … … 269 263 static UniqueName rhsNamer( "__multassign_R" ); 270 264 265 // xxx - need more complicated matching? 271 266 if ( lhs.size() == rhs.size() ) { 272 // produce a new temporary object for each value in the lhs and rhs and pairwise create the calls273 267 std::list< ObjectDecl * > ltmp; 274 268 std::list< ObjectDecl * > rtmp;
Note:
See TracChangeset
for help on using the changeset viewer.