Changeset 82f3226
- Timestamp:
- Dec 1, 2017, 10:37:40 AM (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:
- ad6cd6d
- Parents:
- 2449aef
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/TupleAssignment.cc
r2449aef r82f3226 62 62 struct Matcher { 63 63 public: 64 Matcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, const 64 Matcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, const 65 65 ResolvExpr::AltList& rhs ); 66 66 virtual ~Matcher() {} … … 76 76 struct MassAssignMatcher : public Matcher { 77 77 public: 78 MassAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 78 MassAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 79 79 const ResolvExpr::AltList& rhs ) : Matcher(spotter, lhs, rhs) {} 80 80 virtual void match( std::list< Expression * > &out ); … … 83 83 struct MultipleAssignMatcher : public Matcher { 84 84 public: 85 MultipleAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 85 MultipleAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 86 86 const ResolvExpr::AltList& rhs ) : Matcher(spotter, lhs, rhs) {} 87 87 virtual void match( std::list< Expression * > &out ); … … 120 120 } 121 121 122 void handleTupleAssignment( ResolvExpr::AlternativeFinder & currentFinder, UntypedExpr * expr, 122 void handleTupleAssignment( ResolvExpr::AlternativeFinder & currentFinder, UntypedExpr * expr, 123 123 std::vector<ResolvExpr::AlternativeFinder> &args ) { 124 124 TupleAssignSpotter spotter( currentFinder ); … … 129 129 : currentFinder(f) {} 130 130 131 void TupleAssignSpotter::spot( UntypedExpr * expr, 131 void TupleAssignSpotter::spot( UntypedExpr * expr, 132 132 std::vector<ResolvExpr::AlternativeFinder> &args ) { 133 133 if ( NameExpr *op = dynamic_cast< NameExpr * >(expr->get_function()) ) { … … 138 138 if ( args.size() == 0 ) return; 139 139 140 // if an assignment only takes 1 argument, that's odd, but maybe someone wrote 140 // if an assignment only takes 1 argument, that's odd, but maybe someone wrote 141 141 // the function, in which case AlternativeFinder will handle it normally 142 142 if ( args.size() == 1 && CodeGen::isAssignment( fname ) ) return; … … 147 147 if ( ! refToTuple(lhsAlt.expr) ) continue; 148 148 149 // explode is aware of casts - ensure every LHS expression is sent into explode 149 // explode is aware of casts - ensure every LHS expression is sent into explode 150 150 // with a reference cast 151 // xxx - this seems to change the alternatives before the normal 151 // xxx - this seems to change the alternatives before the normal 152 152 // AlternativeFinder flow; maybe this is desired? 153 153 if ( ! dynamic_cast<CastExpr*>( lhsAlt.expr ) ) { 154 lhsAlt.expr = new CastExpr( lhsAlt.expr, 155 new ReferenceType( Type::Qualifiers(), 154 lhsAlt.expr = new CastExpr( lhsAlt.expr, 155 new ReferenceType( Type::Qualifiers(), 156 156 lhsAlt.expr->get_result()->clone() ) ); 157 157 } … … 161 161 explode( lhsAlt, currentFinder.get_indexer(), back_inserter(lhs), true ); 162 162 for ( ResolvExpr::Alternative& alt : lhs ) { 163 // each LHS value must be a reference - some come in with a cast expression, 163 // each LHS value must be a reference - some come in with a cast expression, 164 164 // if not just cast to reference here 165 165 if ( ! dynamic_cast<ReferenceType*>( alt.expr->get_result() ) ) { 166 alt.expr = new CastExpr( alt.expr, 167 new ReferenceType( Type::Qualifiers(), 166 alt.expr = new CastExpr( alt.expr, 167 new ReferenceType( Type::Qualifiers(), 168 168 alt.expr->get_result()->clone() ) ); 169 169 } … … 179 179 // TODO build iterative version of this instead of using combos 180 180 std::vector< ResolvExpr::AltList > rhsAlts; 181 combos( std::next(args.begin(), 1), args.end(), 181 combos( std::next(args.begin(), 1), args.end(), 182 182 std::back_inserter( rhsAlts ) ); 183 183 for ( const ResolvExpr::AltList& rhsAlt : rhsAlts ) { 184 184 // multiple assignment 185 185 ResolvExpr::AltList rhs; 186 explode( rhsAlt, currentFinder.get_indexer(), 186 explode( rhsAlt, currentFinder.get_indexer(), 187 187 std::back_inserter(rhs), true ); 188 188 matcher.reset( new MultipleAssignMatcher( *this, lhs, rhs ) ); … … 194 194 if ( isTuple(rhsAlt.expr) ) { 195 195 // multiple assignment 196 explode( rhsAlt, currentFinder.get_indexer(), 196 explode( rhsAlt, currentFinder.get_indexer(), 197 197 std::back_inserter(rhs), true ); 198 198 matcher.reset( new MultipleAssignMatcher( *this, lhs, rhs ) ); … … 223 223 ResolvExpr::AltList current; 224 224 // now resolve new assignments 225 for ( std::list< Expression * >::iterator i = new_assigns.begin(); 225 for ( std::list< Expression * >::iterator i = new_assigns.begin(); 226 226 i != new_assigns.end(); ++i ) { 227 227 PRINT( … … 230 230 ) 231 231 232 ResolvExpr::AlternativeFinder finder{ currentFinder.get_indexer(), 232 ResolvExpr::AlternativeFinder finder{ currentFinder.get_indexer(), 233 233 currentFinder.get_environ() }; 234 234 try { … … 254 254 // xxx -- was push_front 255 255 currentFinder.get_alternatives().push_back( ResolvExpr::Alternative( 256 new TupleAssignExpr(solved_assigns, matcher->tmpDecls), matcher->compositeEnv, 256 new TupleAssignExpr(solved_assigns, matcher->tmpDecls), matcher->compositeEnv, 257 257 ResolvExpr::sumCost( current ) + matcher->baseCost ) ); 258 258 } 259 259 260 TupleAssignSpotter::Matcher::Matcher( TupleAssignSpotter &spotter, 261 const ResolvExpr::AltList &lhs, const ResolvExpr::AltList &rhs ) 262 : lhs(lhs), rhs(rhs), spotter(spotter), 260 TupleAssignSpotter::Matcher::Matcher( TupleAssignSpotter &spotter, 261 const ResolvExpr::AltList &lhs, const ResolvExpr::AltList &rhs ) 262 : lhs(lhs), rhs(rhs), spotter(spotter), 263 263 baseCost( ResolvExpr::sumCost( lhs ) + ResolvExpr::sumCost( rhs ) ) { 264 264 simpleCombineEnvironments( lhs.begin(), lhs.end(), compositeEnv );
Note: See TracChangeset
for help on using the changeset viewer.