From ad3b38bb9a44094065b05115c4b2518f47054a3f Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 4 Jun 2012 16:56:04 -0700 Subject: [PATCH] Preserve var semantics while desugaring for-each. --- Parser.hpp | 6 +++--- Replace.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Parser.hpp b/Parser.hpp index 24b3564..b133af2 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -539,7 +539,7 @@ struct CYForInInitialiser { virtual void ForIn(CYOutput &out, CYFlags flags) const = 0; virtual const char *ForEachIn() const = 0; - virtual CYExpression *ForEachIn(CYContext &out) = 0; + virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value) = 0; virtual CYExpression *Replace(CYContext &context) = 0; }; @@ -563,7 +563,7 @@ struct CYExpression : virtual void ForIn(CYOutput &out, CYFlags flags) const; virtual const char *ForEachIn() const; - virtual CYExpression *ForEachIn(CYContext &out); + virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value); virtual CYExpression *AddArgument(CYContext &context, CYExpression *value); @@ -1169,7 +1169,7 @@ struct CYDeclaration : virtual void ForIn(CYOutput &out, CYFlags flags) const; virtual const char *ForEachIn() const; - virtual CYExpression *ForEachIn(CYContext &out); + virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value); virtual CYExpression *Replace(CYContext &context); virtual CYAssignment *Assignment(CYContext &context); diff --git a/Replace.cpp b/Replace.cpp index e6b761f..00f6419 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -198,8 +198,8 @@ CYAssignment *CYDeclaration::Assignment(CYContext &context) { return initialiser_ == NULL ? NULL : $ CYAssign(variable, initialiser_); } -CYExpression *CYDeclaration::ForEachIn(CYContext &context) { - return $V(identifier_); +CYStatement *CYDeclaration::ForEachIn(CYContext &context, CYExpression *value) { + return $ CYVar($L1($L(identifier_, value))); } CYExpression *CYDeclaration::Replace(CYContext &context) { @@ -271,8 +271,8 @@ CYExpression *CYExpression::ClassName(CYContext &context, bool object) { return this; } -CYExpression *CYExpression::ForEachIn(CYContext &context) { - return this; +CYStatement *CYExpression::ForEachIn(CYContext &context, CYExpression *value) { + return $E($ CYAssign(this, value)); } CYNumber *CYFalse::Number(CYContext &context) { @@ -316,7 +316,7 @@ CYStatement *CYForEachIn::Replace(CYContext &context) { return $ CYLet($L2($L(cys, set_), $L(cyt)), $$->* $ CYForIn($V(cyt), $V(cys), $ CYBlock($$->* - $E($ CYAssign(initialiser_->ForEachIn(context), $M($V(cys), $V(cyt))))->* + initialiser_->ForEachIn(context, $M($V(cys), $V(cyt)))->* code_ )) ); -- 2.45.2