X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/37954781d9756ece500551055562183a1e28e943..9cad30fab188a57c3db8df0912a1691099468e64:/Replace.cpp diff --git a/Replace.cpp b/Replace.cpp index 5a2ed37..8039118 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -1,4 +1,4 @@ -/* Cycript - Remove Execution Server and Disassembler +/* Cycript - Inlining/Optimizing JavaScript Compiler * Copyright (C) 2009 Jay Freeman (saurik) */ @@ -134,6 +134,10 @@ void CYClause::Replace(CYContext &context) { $T() next_->Replace(context); } +CYStatement *CYComment::Replace(CYContext &context) { + return NULL; +} + CYExpression *CYCompound::Replace(CYContext &context) { expressions_ = expressions_->ReplaceAll(context); return NULL; @@ -171,6 +175,10 @@ void CYDeclaration::Replace(CYContext &context) { context.Replace(initialiser_); } +CYProperty *CYDeclarations::Property(CYContext &context) { $T(NULL) + return $ CYProperty(declaration_->identifier_, declaration_->initialiser_ ?: $U, next_->Property(context)); +} + void CYDeclarations::Replace(CYContext &context) { $T() declaration_->Replace(context); next_->Replace(context); @@ -259,13 +267,12 @@ CYStatement *CYForInComprehension::Replace(CYContext &context, CYStatement *stat CYStatement *CYForEachIn::Replace(CYContext &context) { CYVariable *cys($V("$cys")), *cyt($V("$cyt")); - return $ CYWith($ CYObject($ CYProperty($S("$cys"), $D(0), $ CYProperty($S("$cyt"), $D(0)))), $ CYBlock($$->* - $E($ CYAssign(cys, set_))->* + return $ CYLet($L2($L($I("$cys"), set_), $L($I("$cyt"))), $$->* $ CYForIn(cyt, cys, $ CYBlock($$->* $E($ CYAssign(initialiser_->ForEachIn(context), $M(cys, cyt)))->* code_ )) - )); + ); } CYFunctionParameter *CYForEachInComprehension::Parameter(CYContext &context) const { @@ -334,6 +341,10 @@ CYStatement *CYLabel::Replace(CYContext &context) { return NULL; } +CYStatement *CYLet::Replace(CYContext &context) { + return $ CYWith($ CYObject(declarations_->Property(context)), &code_); +} + void CYMember::Replace_(CYContext &context) { context.Replace(object_); context.Replace(property_); @@ -409,7 +420,7 @@ CYString *CYString::Concat(CYContext &context, CYString *rhs) const { memcpy(value, value_, size_); memcpy(value + size_, rhs->value_, rhs->size_); value[size] = '\0'; - return $S(value); + return $S(value, size); } CYNumber *CYString::Number(CYContext &context) {