From ca6a1b2b2dce57a7ad9e11bdd3649f00ca855a15 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 7 Dec 2015 02:13:33 -0800 Subject: [PATCH] Remove CYLetStatement and provide a stub of CYLet. --- Output.cpp | 9 +++++---- Parser.ypp.in | 12 +----------- Replace.cpp | 21 ++++++++++++--------- Syntax.hpp | 10 ++++------ 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/Output.cpp b/Output.cpp index ce8e00c..e43d038 100644 --- a/Output.cpp +++ b/Output.cpp @@ -629,9 +629,10 @@ void CYTypeDefinition::Output(CYOutput &out, CYFlags flags) const { out << "typedef" << ' ' << *typed_; } -void CYLetStatement::Output(CYOutput &out, CYFlags flags) const { - out << "let" << ' ' << '(' << *declarations_ << ')'; - code_->Single(out, CYRight(flags), CYCompactShort); +void CYLet::Output(CYOutput &out, CYFlags flags) const { + out << "let" << ' '; + declarations_->Output(out, flags); // XXX: flags + out << ';'; } void CYModule::Output(CYOutput &out) const { @@ -918,7 +919,7 @@ void CYTypeVoid::Output(CYOutput &out) const { void CYVar::Output(CYOutput &out, CYFlags flags) const { out << "var" << ' '; - declarations_->Output(out, flags); + declarations_->Output(out, flags); // XXX: flags out << ';'; } diff --git a/Parser.ypp.in b/Parser.ypp.in index 6028184..92e6424 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -487,7 +487,6 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type LabelledItem %type LabelledStatement %type LeftHandSideExpression -%type LetStatement %type LexicalBinding %type LexicalDeclaration %type Literal @@ -1268,7 +1267,7 @@ StatementListItem /* }}} */ /* 13.3 Let and Const Declarations {{{ */ LexicalDeclaration - : LetOrConst BindingList Terminator { $$ = CYNew CYVar($2); } + : LetOrConst BindingList Terminator { $$ = CYNew CYLet($2); } ; LetOrConst @@ -2284,15 +2283,6 @@ IterationStatement : "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); } ; /* }}} */ -/* JavaScript FTL: let Statements {{{ */ -LetStatement - : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); } - ; - -Statement__ - : LetStatement - ; -/* }}} */ /* JavaScript FTW: Array Comprehensions {{{ */ PrimaryExpression diff --git a/Replace.cpp b/Replace.cpp index ef481e6..ac673ad 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -457,14 +457,14 @@ CYStatement *CYForOf::Replace(CYContext &context) { this ); - CYIdentifier *cys($I("$cys")), *cyt($I("$cyt")); + CYIdentifier *cys(context.Unique()), *cyt(context.Unique()); - return $ CYLetStatement($L2($ CYDeclaration(cys, set_), $ CYDeclaration(cyt)), $$->* - $ CYForIn($V(cyt), $V(cys), $ CYBlock($$->* - initialiser_->ForEachIn(context, $M($V(cys), $V(cyt)))->* - code_ - )) - ); + return $ CYBlock($$ + ->* $ CYLet($L2($L(cys, set_), $L(cyt))) + ->* $ CYForIn($V(cyt), $V(cys), $ CYBlock($$ + ->* initialiser_->ForEachIn(context, $M($V(cys), $V(cyt))) + ->* code_ + ))); } CYFunctionParameter *CYForOfComprehension::Parameter(CYContext &context) const { @@ -618,8 +618,11 @@ CYExpression *CYLambda::Replace(CYContext &context) { return $N2($V("Functor"), $ CYFunctionExpression(NULL, parameters_->Parameters(context), code_), parameters_->TypeSignature(context, typed_->Replace(context))); } -CYStatement *CYLetStatement::Replace(CYContext &context) { - return $E($ CYCall(CYNonLocalize(context, $ CYFunctionExpression(NULL, declarations_->Parameter(context), code_)), declarations_->Argument(context))); +CYStatement *CYLet::Replace(CYContext &context) { + declarations_->Replace(context); + if (CYExpression *expression = declarations_->Expression(context)) + return $E(expression); + return $ CYEmpty(); } CYFunctionExpression *CYMethod::Constructor() { diff --git a/Syntax.hpp b/Syntax.hpp index d278729..5e792b7 100644 --- a/Syntax.hpp +++ b/Syntax.hpp @@ -1191,19 +1191,17 @@ struct CYVar : virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYLetStatement : +struct CYLet : CYStatement { CYDeclarations *declarations_; - CYStatement *code_; - CYLetStatement(CYDeclarations *declarations, CYStatement *code) : - declarations_(declarations), - code_(code) + CYLet(CYDeclarations *declarations) : + declarations_(declarations) { } - CYCompact(Long) + CYCompact(None) virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; -- 2.45.2