X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/c8a0500b2fc78101e1a7f3b2c99939f88a33aa4d..99bf4160db74c508e5ef00dff1dc053ecf0f5997:/Replace.cpp diff --git a/Replace.cpp b/Replace.cpp index d4037f8..98fd48a 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -1,20 +1,20 @@ /* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2010 Jay Freeman (saurik) + * Copyright (C) 2009-2013 Jay Freeman (saurik) */ -/* GNU Lesser General Public License, Version 3 {{{ */ +/* GNU General Public License, Version 3 {{{ */ /* - * Cycript is free software: you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or (at your - * option) any later version. + * Cycript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. * - * Cycript is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. + * Cycript is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License + * You should have received a copy of the GNU General Public License * along with Cycript. If not, see . **/ /* }}} */ @@ -155,6 +155,15 @@ CYExpression *CYCompound::Replace(CYContext &context) { return this; } +CYExpression *CYCompound::Primitive(CYContext &context) { + CYExpression *expression(expressions_); + if (expression == NULL) + return NULL; + while (expression->next_ != NULL) + expression = expression->next_; + return expression->Primitive(context); +} + CYFunctionParameter *CYComprehension::Parameters(CYContext &context) const { $T(NULL) CYFunctionParameter *next(next_->Parameters(context)); if (CYFunctionParameter *parameter = Parameter(context)) { @@ -321,6 +330,12 @@ CYString *CYFalse::String(CYContext &context) { return $S("false"); } +CYExpression *CYFatArrow::Replace(CYContext &context) { + CYFunctionExpression *function($ CYFunctionExpression(NULL, parameters_, code_)); + function->this_.SetNext(context.this_); + return function; +} + void CYFinally::Replace(CYContext &context) { $T() code_.Replace(context); } @@ -360,7 +375,7 @@ CYStatement *CYForInComprehension::Replace(CYContext &context, CYStatement *stat return $ CYForIn($V(name_), set_, CYComprehension::Replace(context, statement)); } -CYStatement *CYForEachIn::Replace(CYContext &context) { +CYStatement *CYForOf::Replace(CYContext &context) { if (CYAssignment *assignment = initialiser_->Assignment(context)) return $ CYBlock($$->* $E(assignment)->* @@ -377,11 +392,11 @@ CYStatement *CYForEachIn::Replace(CYContext &context) { ); } -CYFunctionParameter *CYForEachInComprehension::Parameter(CYContext &context) const { +CYFunctionParameter *CYForOfComprehension::Parameter(CYContext &context) const { return $ CYFunctionParameter($ CYDeclaration(name_)); } -CYStatement *CYForEachInComprehension::Replace(CYContext &context, CYStatement *statement) const { +CYStatement *CYForOfComprehension::Replace(CYContext &context, CYStatement *statement) const { CYIdentifier *cys($I("cys")); return $E($C0($F(NULL, $P1($L("$cys")), $$->* @@ -402,6 +417,9 @@ void CYFunction::Replace_(CYContext &context, bool outer) { if (outer) Inject(context); + CYThisScope *_this(context.this_); + context.this_ = CYGetLast(&this_); + CYNonLocal *nonlocal(context.nonlocal_); CYNonLocal *nextlocal(context.nextlocal_); @@ -423,12 +441,19 @@ void CYFunction::Replace_(CYContext &context, bool outer) { parameters_->Replace(context, code_); code_.Replace(context); + if (CYIdentifier *identifier = this_.identifier_) + code_.statements_ = $$->* + $ CYVar($L1($ CYDeclaration(identifier, $ CYThis())))->* + code_.statements_; + if (localize) context.NonLocal(code_.statements_); context.nextlocal_ = nextlocal; context.nonlocal_ = nonlocal; + context.this_ = _this; + scope.Close(); } @@ -504,7 +529,7 @@ namespace cy { namespace Syntax { CYExpression *New::AddArgument(CYContext &context, CYExpression *value) { - CYSetLast(arguments_, $ CYArgument(value)); + CYSetLast(arguments_) = $ CYArgument(value); return this; } @@ -797,6 +822,8 @@ CYStatement *CYSwitch::Replace(CYContext &context) { } CYExpression *CYThis::Replace(CYContext &context) { + if (context.this_ != NULL) + return $V(context.this_->Identifier(context)); return this; }