Changeset 86ad276 for src/Tuples/TupleAssignment.cc
- Timestamp:
- Dec 5, 2017, 1:36:23 PM (6 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:
- 12d2dc8
- Parents:
- f3b9efc (diff), 5da9d6a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Tuples/TupleAssignment.cc
rf3b9efc r86ad276 23 23 24 24 #include "CodeGen/OperatorTable.h" 25 #include "Common/PassVisitor.h" 25 26 #include "Common/UniqueName.h" // for UniqueName 26 27 #include "Common/utility.h" // for zipWith … … 61 62 struct Matcher { 62 63 public: 63 Matcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, const 64 Matcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, const 64 65 ResolvExpr::AltList& rhs ); 65 66 virtual ~Matcher() {} … … 75 76 struct MassAssignMatcher : public Matcher { 76 77 public: 77 MassAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 78 MassAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 78 79 const ResolvExpr::AltList& rhs ) : Matcher(spotter, lhs, rhs) {} 79 80 virtual void match( std::list< Expression * > &out ); … … 82 83 struct MultipleAssignMatcher : public Matcher { 83 84 public: 84 MultipleAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 85 MultipleAssignMatcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList& lhs, 85 86 const ResolvExpr::AltList& rhs ) : Matcher(spotter, lhs, rhs) {} 86 87 virtual void match( std::list< Expression * > &out ); … … 119 120 } 120 121 121 void handleTupleAssignment( ResolvExpr::AlternativeFinder & currentFinder, UntypedExpr * expr, 122 void handleTupleAssignment( ResolvExpr::AlternativeFinder & currentFinder, UntypedExpr * expr, 122 123 std::vector<ResolvExpr::AlternativeFinder> &args ) { 123 124 TupleAssignSpotter spotter( currentFinder ); … … 128 129 : currentFinder(f) {} 129 130 130 void TupleAssignSpotter::spot( UntypedExpr * expr, 131 void TupleAssignSpotter::spot( UntypedExpr * expr, 131 132 std::vector<ResolvExpr::AlternativeFinder> &args ) { 132 133 if ( NameExpr *op = dynamic_cast< NameExpr * >(expr->get_function()) ) { … … 137 138 if ( args.size() == 0 ) return; 138 139 139 // 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 140 141 // the function, in which case AlternativeFinder will handle it normally 141 142 if ( args.size() == 1 && CodeGen::isAssignment( fname ) ) return; … … 146 147 if ( ! refToTuple(lhsAlt.expr) ) continue; 147 148 148 // 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 149 150 // with a reference cast 150 // xxx - this seems to change the alternatives before the normal 151 // xxx - this seems to change the alternatives before the normal 151 152 // AlternativeFinder flow; maybe this is desired? 152 153 if ( ! dynamic_cast<CastExpr*>( lhsAlt.expr ) ) { 153 lhsAlt.expr = new CastExpr( lhsAlt.expr, 154 new ReferenceType( Type::Qualifiers(), 154 lhsAlt.expr = new CastExpr( lhsAlt.expr, 155 new ReferenceType( Type::Qualifiers(), 155 156 lhsAlt.expr->get_result()->clone() ) ); 156 157 } … … 160 161 explode( lhsAlt, currentFinder.get_indexer(), back_inserter(lhs), true ); 161 162 for ( ResolvExpr::Alternative& alt : lhs ) { 162 // 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, 163 164 // if not just cast to reference here 164 165 if ( ! dynamic_cast<ReferenceType*>( alt.expr->get_result() ) ) { 165 alt.expr = new CastExpr( alt.expr, 166 new ReferenceType( Type::Qualifiers(), 166 alt.expr = new CastExpr( alt.expr, 167 new ReferenceType( Type::Qualifiers(), 167 168 alt.expr->get_result()->clone() ) ); 168 169 } … … 178 179 // TODO build iterative version of this instead of using combos 179 180 std::vector< ResolvExpr::AltList > rhsAlts; 180 combos( std::next(args.begin(), 1), args.end(), 181 combos( std::next(args.begin(), 1), args.end(), 181 182 std::back_inserter( rhsAlts ) ); 182 183 for ( const ResolvExpr::AltList& rhsAlt : rhsAlts ) { 183 184 // multiple assignment 184 185 ResolvExpr::AltList rhs; 185 explode( rhsAlt, currentFinder.get_indexer(), 186 explode( rhsAlt, currentFinder.get_indexer(), 186 187 std::back_inserter(rhs), true ); 187 188 matcher.reset( new MultipleAssignMatcher( *this, lhs, rhs ) ); … … 193 194 if ( isTuple(rhsAlt.expr) ) { 194 195 // multiple assignment 195 explode( rhsAlt, currentFinder.get_indexer(), 196 explode( rhsAlt, currentFinder.get_indexer(), 196 197 std::back_inserter(rhs), true ); 197 198 matcher.reset( new MultipleAssignMatcher( *this, lhs, rhs ) ); … … 222 223 ResolvExpr::AltList current; 223 224 // now resolve new assignments 224 for ( std::list< Expression * >::iterator i = new_assigns.begin(); 225 for ( std::list< Expression * >::iterator i = new_assigns.begin(); 225 226 i != new_assigns.end(); ++i ) { 226 227 PRINT( … … 229 230 ) 230 231 231 ResolvExpr::AlternativeFinder finder{ currentFinder.get_indexer(), 232 ResolvExpr::AlternativeFinder finder{ currentFinder.get_indexer(), 232 233 currentFinder.get_environ() }; 233 234 try { … … 253 254 // xxx -- was push_front 254 255 currentFinder.get_alternatives().push_back( ResolvExpr::Alternative( 255 new TupleAssignExpr(solved_assigns, matcher->tmpDecls), matcher->compositeEnv, 256 new TupleAssignExpr(solved_assigns, matcher->tmpDecls), matcher->compositeEnv, 256 257 ResolvExpr::sumCost( current ) + matcher->baseCost ) ); 257 258 } 258 259 259 TupleAssignSpotter::Matcher::Matcher( TupleAssignSpotter &spotter, 260 const ResolvExpr::AltList &lhs, const ResolvExpr::AltList &rhs ) 261 : 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), 262 263 baseCost( ResolvExpr::sumCost( lhs ) + ResolvExpr::sumCost( rhs ) ) { 263 264 simpleCombineEnvironments( lhs.begin(), lhs.end(), compositeEnv ); … … 277 278 // xxx - maybe this should happen in alternative finder for every StmtExpr? 278 279 // xxx - it's possible that these environments could contain some useful information. Maybe the right thing to do is aggregate the environments and pass the aggregate back to be added into the compositeEnv 279 struct EnvRemover : public Visitor { 280 virtual void visit( ExprStmt * stmt ) { 281 delete stmt->get_expr()->get_env(); 282 stmt->get_expr()->set_env( nullptr ); 283 Visitor::visit( stmt ); 280 struct EnvRemover { 281 void previsit( ExprStmt * stmt ) { 282 delete stmt->expr->env; 283 stmt->expr->env = nullptr; 284 284 } 285 285 }; … … 293 293 ret->set_init( ctorInit ); 294 294 ResolvExpr::resolveCtorInit( ctorInit, spotter.currentFinder.get_indexer() ); // resolve ctor/dtors for the new object 295 EnvRemoverrm; // remove environments from subexpressions of StmtExprs295 PassVisitor<EnvRemover> rm; // remove environments from subexpressions of StmtExprs 296 296 ctorInit->accept( rm ); 297 297 }
Note: See TracChangeset
for help on using the changeset viewer.