X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/abadba191738e5d27797718fccf50d82ffe7b0b6..2e2ed904884fa1dc0a0670364d44cdc3dc9a0775:/Replace.cpp?ds=sidebyside diff --git a/Replace.cpp b/Replace.cpp index c70aab8..acf4d51 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -330,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); } @@ -411,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_); @@ -432,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(); } @@ -513,7 +529,7 @@ namespace cy { namespace Syntax { CYExpression *New::AddArgument(CYContext &context, CYExpression *value) { - CYLast(arguments_) = $ CYArgument(value); + CYSetLast(arguments_) = $ CYArgument(value); return this; } @@ -806,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; }