From: Jay Freeman (saurik) Date: Tue, 5 Jun 2012 06:56:42 +0000 (-0700) Subject: Preserve declaration initialisers replacing for-in. X-Git-Tag: v0.9.456~35 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/ae65d5948102335fae8a1fb7ca82e4acab81466f Preserve declaration initialisers replacing for-in. --- 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 {