From 0afc9ba3d8503ca442fb3d92054f5a0f21d0b924 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 18 Nov 2015 15:06:59 -0800 Subject: [PATCH] Support parenthesized "fat arrow" parameter lists. --- Cycript.yy.in | 9 ++------- Parser.hpp | 8 ++++++++ Replace.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/Cycript.yy.in b/Cycript.yy.in index efa6aa3..0c5d044 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -435,7 +435,6 @@ int cylex(YYSTYPE *, CYLocation *, void *); %type NullLiteral %type ObjectLiteral %type Parenthetical -//%type ParentheticalOpt %type PostfixExpression %type PrimaryExpression %type Program @@ -770,11 +769,6 @@ Parenthetical : "(" LexPushInOff Expression ")" LexPopIn { $$ = $3; } ; -/*ParentheticalOpt - : Parenthetical { $$ = $1; } - | { $$ = NULL; } - ;*/ - Variable : Identifier { $$ = CYNew CYVariable($1); } ; @@ -1380,7 +1374,8 @@ ArrowFunction ArrowParameters : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); } - //| ParentheticalOpt { $$ = $1; } + | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; } + | Parenthetical { $$ = $1->Parameters(); if ($$ == NULL) error(@1, "invalid parameter list"); } ; ConciseBody diff --git a/Parser.hpp b/Parser.hpp index 01a510f..de8d5a5 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -482,6 +482,8 @@ struct CYForInInitialiser { virtual void Output(CYOutput &out, CYFlags flags) const = 0; }; +struct CYFunctionParameter; + struct CYNumber; struct CYString; @@ -516,6 +518,9 @@ struct CYExpression : return NULL; } + virtual CYFunctionParameter *Parameter() const; + virtual CYFunctionParameter *Parameters() const; + virtual CYNumber *Number(CYContext &context) { return NULL; } @@ -566,6 +571,7 @@ struct CYCompound : void Output(CYOutput &out, CYFlags flags) const; virtual CYExpression *Primitive(CYContext &context); + virtual CYFunctionParameter *Parameters() const; }; struct CYDeclaration; @@ -911,6 +917,8 @@ struct CYVariable : virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; + + virtual CYFunctionParameter *Parameter() const; }; struct CYPrefix : diff --git a/Replace.cpp b/Replace.cpp index 34c5cab..bcaffca 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -169,6 +169,24 @@ CYExpression *CYCompound::Primitive(CYContext &context) { return expression->Primitive(context); } +CYFunctionParameter *CYCompound::Parameters() const { + CYFunctionParameter *next; + if (next_ == NULL) + next = NULL; + else { + next = next_->Parameters(); + if (next == NULL) + return NULL; + } + + CYFunctionParameter *parameter(expression_->Parameter()); + if (parameter == NULL) + return NULL; + + parameter->SetNext(next); + return parameter; +} + CYFunctionParameter *CYComprehension::Parameters(CYContext &context) const { $T(NULL) CYFunctionParameter *next(next_->Parameters(context)); if (CYFunctionParameter *parameter = Parameter(context)) { @@ -327,6 +345,14 @@ CYAssignment *CYExpression::Assignment(CYContext &context) { return NULL; } +CYFunctionParameter *CYExpression::Parameter() const { + return NULL; +} + +CYFunctionParameter *CYExpression::Parameters() const { + return NULL; +} + CYStatement *CYExternal::Replace(CYContext &context) { return $E($ CYAssign($V(typed_->identifier_), $C1(typed_->Replace(context), $C2($V("dlsym"), $V("RTLD_DEFAULT"), $S(typed_->identifier_->Word()))))); } @@ -996,6 +1022,10 @@ CYExpression *CYVariable::Replace(CYContext &context) { return this; } +CYFunctionParameter *CYVariable::Parameter() const { + return $ CYFunctionParameter($ CYDeclaration(name_)); +} + CYStatement *CYWhile::Replace(CYContext &context) { context.Replace(test_); context.Replace(code_); -- 2.45.2