From: Jay Freeman (saurik) Date: Sat, 12 Dec 2015 14:47:18 +0000 (-0800) Subject: Support ECMAScript 1-5 for-in initializers syntax. X-Git-Tag: v0.9.590~222 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/23111dca236b4e9ef5351abb990b1e489edf9e05 Support ECMAScript 1-5 for-in initializers syntax. --- diff --git a/Output.cpp b/Output.cpp index 4506db6..22e2149 100644 --- a/Output.cpp +++ b/Output.cpp @@ -408,6 +408,13 @@ void CYForIn::Output(CYOutput &out, CYFlags flags) const { code_->Single(out, CYRight(flags), CYCompactShort); } +void CYForInitialized::Output(CYOutput &out, CYFlags flags) const { + out << "for" << ' ' << '(' << "var" << ' '; + declaration_->Output(out, CYNoIn | CYNoRightHand); + out << ' ' << "in" << ' ' << *set_ << ')'; + code_->Single(out, CYRight(flags), CYCompactShort); +} + void CYForInComprehension::Output(CYOutput &out) const { out << "for" << ' ' << '('; declaration_->Output(out, CYNoIn | CYNoRightHand); diff --git a/Parser.ypp.in b/Parser.ypp.in index 9797492..e453814 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -1402,6 +1402,7 @@ IterationStatement : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); } | "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); } | "for" "(" LexPushInOn ForStatementInitializer LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $6, $8, $10); } + | "for" "(" LexPushInOn LexSetRegExp Var_ BindingIdentifier Initializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForInitialized(CYNew CYDeclaration($6, $7), $10, $12); } | "for" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); } | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn AssignmentExpression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); } ; diff --git a/Replace.cpp b/Replace.cpp index 6cd3561..337e00e 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -449,6 +449,13 @@ CYStatement *CYForIn::Replace(CYContext &context) { return this; } +CYStatement *CYForInitialized::Replace(CYContext &context) { + CYAssignment *assignment(declaration_->Replace(context, CYIdentifierVariable)); + return $ CYBlock($$ + ->* (assignment == NULL ? NULL : $ CYExpress(assignment)) + ->* $ CYForIn(declaration_->Target(context), set_, code_)); +} + CYFunctionParameter *CYForInComprehension::Parameter(CYContext &context) const { return $ CYFunctionParameter(declaration_); } diff --git a/Syntax.hpp b/Syntax.hpp index db2b816..ec94441 100644 --- a/Syntax.hpp +++ b/Syntax.hpp @@ -1328,6 +1328,26 @@ struct CYForIn : virtual void Output(CYOutput &out, CYFlags flags) const; }; +struct CYForInitialized : + CYStatement +{ + CYDeclaration *declaration_; + CYExpression *set_; + CYStatement *code_; + + CYForInitialized(CYDeclaration *declaration, CYExpression *set, CYStatement *code) : + declaration_(declaration), + set_(set), + code_(code) + { + } + + CYCompact(Long) + + virtual CYStatement *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYForOf : CYStatement {