Changeset 1d2b64f for src/Tuples
- Timestamp:
- Dec 13, 2016, 5:20:54 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:
- d5556a3
- Parents:
- 722617d
- git-author:
- Rob Schluntz <rschlunt@…> (12/13/16 17:16:27)
- git-committer:
- Rob Schluntz <rschlunt@…> (12/13/16 17:20:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/Tuples/TupleAssignment.cc ¶
r722617d r1d2b64f 23 23 #include "Common/SemanticError.h" 24 24 #include "InitTweak/InitTweak.h" 25 #include "InitTweak/GenInit.h" 25 26 26 27 #include <functional> … … 47 48 virtual ~Matcher() {} 48 49 virtual void match( std::list< Expression * > &out ) = 0; 50 ObjectDecl * newObject( UniqueName & namer, Expression * expr ); 49 51 ResolvExpr::AltList lhs, rhs; 50 52 TupleAssignSpotter &spotter; 53 ResolvExpr::Cost baseCost; 51 54 std::list< ObjectDecl * > tmpDecls; 55 ResolvExpr::TypeEnvironment compositeEnv; 52 56 }; 53 57 … … 146 150 finder.findWithAdjustment(*i); 147 151 } catch (...) { 148 return; // xxx -no match should not mean failure, it just means this particular tuple assignment isn't valid152 return; // no match should not mean failure, it just means this particular tuple assignment isn't valid 149 153 } 150 154 // prune expressions that don't coincide with … … 161 165 solved_assigns.push_back( alt.expr->clone() ); 162 166 } 163 // xxx - need to do this?? 164 ResolvExpr::TypeEnvironment compositeEnv; 165 simpleCombineEnvironments( current.begin(), current.end(), compositeEnv ); 166 currentFinder.get_alternatives().push_front( ResolvExpr::Alternative(new TupleAssignExpr(solved_assigns, matcher->tmpDecls), compositeEnv, ResolvExpr::sumCost( current ) ) ); 167 } 168 169 TupleAssignSpotter::Matcher::Matcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList &alts ) : spotter(spotter) { 167 // combine assignment environments into combined expression environment 168 simpleCombineEnvironments( current.begin(), current.end(), matcher->compositeEnv ); 169 currentFinder.get_alternatives().push_front( ResolvExpr::Alternative(new TupleAssignExpr(solved_assigns, matcher->tmpDecls), matcher->compositeEnv, ResolvExpr::sumCost( current ) + matcher->baseCost ) ); 170 } 171 172 TupleAssignSpotter::Matcher::Matcher( TupleAssignSpotter &spotter, const ResolvExpr::AltList &alts ) : spotter(spotter), baseCost( ResolvExpr::sumCost( alts ) ) { 170 173 assert( ! alts.empty() ); 174 // combine argument environments into combined expression environment 175 simpleCombineEnvironments( alts.begin(), alts.end(), compositeEnv ); 176 171 177 ResolvExpr::Alternative lhsAlt = alts.front(); 172 178 // peel off the cast that exists on ctor/dtor expressions … … 217 223 } 218 224 219 ObjectDecl * newObject( UniqueName & namer, Expression * expr ) { 225 // removes environments from subexpressions within statement exprs, which could throw off later passes like those in Box which rely on PolyMutator. 226 // xxx - maybe this should happen in alternative finder for every StmtExpr? 227 // 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 228 struct EnvRemover : public Visitor { 229 virtual void visit( ExprStmt * stmt ) { 230 delete stmt->get_expr()->get_env(); 231 stmt->get_expr()->set_env( nullptr ); 232 Visitor::visit( stmt ); 233 } 234 }; 235 236 ObjectDecl * TupleAssignSpotter::Matcher::newObject( UniqueName & namer, Expression * expr ) { 220 237 assert( expr->has_result() && ! expr->get_result()->isVoid() ); 221 return new ObjectDecl( namer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, expr->get_result()->clone(), new SingleInit( expr->clone() ) ); 238 ObjectDecl * ret = new ObjectDecl( namer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, nullptr, expr->get_result()->clone(), new SingleInit( expr->clone() ) ); 239 ConstructorInit * ctorInit = InitTweak::genCtorInit( ret ); 240 ret->set_init( ctorInit ); 241 ResolvExpr::resolveCtorInit( ctorInit, spotter.currentFinder.get_indexer() ); // resolve ctor/dtors for the new object 242 EnvRemover rm; // remove environments from subexpressions of StmtExprs 243 ctorInit->accept( rm ); 244 return ret; 222 245 } 223 246 … … 244 267 std::list< ObjectDecl * > ltmp; 245 268 std::list< ObjectDecl * > rtmp; 246 std::transform( lhs.begin(), lhs.end(), back_inserter( ltmp ), [ ]( ResolvExpr::Alternative & alt ){269 std::transform( lhs.begin(), lhs.end(), back_inserter( ltmp ), [&]( ResolvExpr::Alternative & alt ){ 247 270 return newObject( lhsNamer, alt.expr ); 248 271 }); 249 std::transform( rhs.begin(), rhs.end(), back_inserter( rtmp ), [ ]( ResolvExpr::Alternative & alt ){272 std::transform( rhs.begin(), rhs.end(), back_inserter( rtmp ), [&]( ResolvExpr::Alternative & alt ){ 250 273 return newObject( rhsNamer, alt.expr ); 251 274 });
Note: See TracChangeset
for help on using the changeset viewer.