X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/bf45251b6ef1230ffdbd79319b9c4a60c5ae6913..b799113bd4ec270504dd9f552142c1adfd6e583a:/Replace.cpp diff --git a/Replace.cpp b/Replace.cpp index 3e06308..1e0a5ca 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -1,20 +1,20 @@ /* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2012 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 . **/ /* }}} */ @@ -210,7 +210,7 @@ void CYContext::NonLocal(CYStatement *&statements) { } CYIdentifier *CYContext::Unique() { - return $ CYIdentifier(apr_psprintf($pool, "$cy%u", unique_++)); + return $ CYIdentifier($pool.sprintf("$cy%u", unique_++)); } CYStatement *CYContinue::Replace(CYContext &context) { @@ -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(); } @@ -539,7 +555,7 @@ CYNumber *CYNumber::Number(CYContext &context) { CYString *CYNumber::String(CYContext &context) { // XXX: there is a precise algorithm for this - return $S(apr_psprintf($pool, "%.17g", Value())); + return $S($pool.sprintf("%.17g", Value())); } CYExpression *CYObject::Replace(CYContext &context) { @@ -603,7 +619,7 @@ void CYProgram::Replace(CYContext &context) { const char *name; if (context.options_.verbose_) - name = apr_psprintf($pool, "$%"APR_SIZE_T_FMT"", offset); + name = $pool.sprintf("$%"APR_SIZE_T_FMT"", offset); else { char id[8]; id[7] = '\0'; @@ -622,7 +638,7 @@ void CYProgram::Replace(CYContext &context) { goto id; } - name = apr_pstrmemdup($pool, id + position, 7 - position); + name = $pool.strmemdup(id + position, 7 - position); // XXX: at some point, this could become a keyword } @@ -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; }