From ae65d5948102335fae8a1fb7ca82e4acab81466f Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 4 Jun 2012 23:56:42 -0700 Subject: [PATCH] Preserve declaration initialisers replacing for-in. --- Parser.hpp | 3 +++ Replace.cpp | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Parser.hpp b/Parser.hpp index 19addb8..d711d1d 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -98,6 +98,7 @@ struct CYPropertyName { }; struct CYExpression; +struct CYAssignment; enum CYNeeded { CYNever = -1, @@ -541,6 +542,7 @@ struct CYForInInitialiser { virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value) = 0; virtual CYExpression *Replace(CYContext &context) = 0; + virtual CYAssignment *Assignment(CYContext &context) = 0; }; struct CYNumber; @@ -573,6 +575,7 @@ struct CYExpression : virtual void ClassName(CYOutput &out, bool object) const; virtual CYExpression *Replace(CYContext &context) = 0; + virtual CYAssignment *Assignment(CYContext &context); virtual CYExpression *Primitive(CYContext &context) { return this; diff --git a/Replace.cpp b/Replace.cpp index fb83630..3818c0b 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -270,6 +270,10 @@ CYStatement *CYExpression::ForEachIn(CYContext &context, CYExpression *value) { return $E($ CYAssign(this, value)); } +CYAssignment *CYExpression::Assignment(CYContext &context) { + return NULL; +} + CYNumber *CYFalse::Number(CYContext &context) { return $D(0); } @@ -291,11 +295,19 @@ CYStatement *CYFor::Replace(CYContext &context) { } CYStatement *CYForIn::Replace(CYContext &context) { - // XXX: this actually might need a prefix statement + CYAssignment *assignment(initialiser_->Assignment(context)); + context.Replace(initialiser_); context.Replace(set_); context.Replace(code_); - return this; + + if (assignment == NULL) + return this; + + return $ CYBlock($$->* + $E(assignment)->* + this + ); } CYFunctionParameter *CYForInComprehension::Parameter(CYContext &context) const { -- 2.49.0