X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/56e02e5b879e679302c8d9a20654b8a193791a3a..104cc5f53dbc8b068040a1249b5b0580ee34b3c1:/ObjectiveC/Replace.cpp diff --git a/ObjectiveC/Replace.cpp b/ObjectiveC/Replace.cpp index 96f6663..15361f2 100644 --- a/ObjectiveC/Replace.cpp +++ b/ObjectiveC/Replace.cpp @@ -1,21 +1,21 @@ /* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2012 Jay Freeman (saurik) + * Copyright (C) 2009-2015 Jay Freeman (saurik) */ -/* GNU Lesser General Public License, Version 3 {{{ */ +/* GNU Affero 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 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. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Cycript. If not, see . + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program 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 Affero General Public License for more details. + + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . **/ /* }}} */ @@ -24,15 +24,12 @@ #include -static CYExpression *MessageType(CYContext &context, CYExpression *type, CYMessageParameter *next, CYExpression *extra = NULL) { - if (type == NULL) - return NULL; - - CYExpression *left($C0($M(type, $S("toString")))); +static CYExpression *MessageType(CYContext &context, CYTypedIdentifier *type, CYMessageParameter *next, CYExpression *extra = NULL) { + CYExpression *left($C0($M(type->Replace(context), $S("toString")))); if (extra != NULL) left = $ CYAdd(left, extra); - if (next == NULL || next->name_ == NULL) + if (next == NULL || next->type_ == NULL) return left; CYExpression *right(next->TypeSignature(context)); @@ -78,42 +75,22 @@ CYStatement *CYClassStatement::Replace(CYContext &context) { return $E(Replace_(context)); } -CYExpression *CYTypeArrayOf::Replace(CYContext &context) { - return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("arrayOf")), $ CYArgument($ CYNumber(size_))); -} - -CYExpression *CYTypeConstant::Replace(CYContext &context) { - return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("constant"))); -} - -CYExpression *CYTypePointerTo::Replace(CYContext &context) { - return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("pointerTo"))); -} - -CYExpression *CYTypeVariable::Replace(CYContext &context) { - return expression_; -} - -CYExpression *CYEncodedType::Replace(CYContext &context) { - return type_->Replace(context); -} - CYStatement *CYField::Replace(CYContext &context) const { $T(NULL) CYVariable *cyn($V("$cyn")); CYVariable *cyt($V("$cyt")); - CYExpression *type($C0($M(type_, $S("toString")))); + CYExpression *type($C0($M(typed_->Replace(context), $S("toString")))); return $ CYBlock($$->* - next_->Replace(context)->* $E($ CYAssign(cyt, type))->* $E($ CYAssign(cyn, $N1($V("Type"), cyt)))->* - $E($C5($V("class_addIvar"), $V("$cyc"), $S(name_->Word()), $M(cyn, $S("size")), $M(cyn, $S("alignment")), cyt)) + $E($C5($V("class_addIvar"), $V("$cyc"), $S(typed_->identifier_->Word()), $M(cyn, $S("size")), $M(cyn, $S("alignment")), cyt))->* + next_->Replace(context) ); } -CYStatement *CYImport::Replace(CYContext &context) { - return this; +CYExpression *CYInstanceLiteral::Replace(CYContext &context) { + return $N1($V("Instance"), number_); } CYStatement *CYMessage::Replace(CYContext &context, bool replace) const { $T(NULL) @@ -122,17 +99,15 @@ CYStatement *CYMessage::Replace(CYContext &context, bool replace) const { $T(NUL CYVariable *self($V("self")); CYVariable *_class($V(instance_ ? "$cys" : "$cyp")); - CYExpression *type(TypeSignature(context) ?: $C1($M(cyn, $S("type")), _class)); - return $ CYBlock($$->* next_->Replace(context, replace)->* $E($ CYAssign(cyn, parameters_->Selector(context)))->* - $E($ CYAssign(cyt, type))->* + $E($ CYAssign(cyt, TypeSignature(context)))->* $E($C4($V(replace ? "class_replaceMethod" : "class_addMethod"), $V(instance_ ? "$cyc" : "$cym"), cyn, $N2($V("Functor"), $F(NULL, $P2($L("self"), $L("_cmd"), parameters_->Parameters(context)), $$->* - $ CYVar($L1($L("$cyr", $N2($V("Super"), self, _class))))->* + $ CYVar($L1($L("$cyr", $N2($V("objc_super"), self, _class))))->* $ CYReturn($C1($M($F(NULL, NULL, code_), $S("call")), self)) ), cyt), cyt @@ -146,7 +121,7 @@ CYExpression *CYMessage::TypeSignature(CYContext &context) const { CYFunctionParameter *CYMessageParameter::Parameters(CYContext &context) const { $T(NULL) CYFunctionParameter *next(next_->Parameters(context)); - return name_ == NULL ? next : $ CYFunctionParameter($ CYDeclaration(name_), next); + return type_ == NULL ? next : $ CYFunctionParameter($ CYDeclaration(type_->identifier_), next); } CYSelector *CYMessageParameter::Selector(CYContext &context) const { @@ -155,7 +130,7 @@ CYSelector *CYMessageParameter::Selector(CYContext &context) const { CYSelectorPart *CYMessageParameter::SelectorPart(CYContext &context) const { $T(NULL) CYSelectorPart *next(next_->SelectorPart(context)); - return tag_ == NULL ? next : $ CYSelectorPart(tag_, name_ != NULL, next); + return tag_ == NULL ? next : $ CYSelectorPart(tag_, type_ != NULL, next); } CYExpression *CYMessageParameter::TypeSignature(CYContext &context) const { @@ -167,7 +142,7 @@ CYExpression *CYBox::Replace(CYContext &context) { } CYExpression *CYObjCBlock::Replace(CYContext &context) { - return $N2($V("Functor"), $ CYFunctionExpression(NULL, parameters_->Parameters(context), statements_), parameters_->TypeSignature(context, type_->Replace(context))); + return $C1($ CYEncodedType(($ CYTypedIdentifier(*typed_))->Modify($ CYTypeBlockWith(parameters_))), $ CYFunctionExpression(NULL, parameters_->Parameters(context), statements_)); } CYStatement *CYProtocol::Replace(CYContext &context) const { $T(NULL) @@ -191,7 +166,7 @@ CYString *CYSelectorPart::Replace(CYContext &context) { if (part->value_) str << ':'; } - return $S(apr_pstrdup($pool, str.str().c_str())); + return $S($pool.strdup(str.str().c_str())); } CYExpression *CYSendDirect::Replace(CYContext &context) { @@ -216,17 +191,9 @@ CYExpression *CYSendDirect::Replace(CYContext &context) { argument = &(*argument)->next_; } - return $C2($V("objc_msgSend"), self_, ($ CYSelector(selector))->Replace(context), arguments_); + return $C2($V("objc_msgSend"), self_, selector->Replace(context), arguments_); } CYExpression *CYSendSuper::Replace(CYContext &context) { return $ CYSendDirect($V("$cyr"), arguments_); } - -CYFunctionParameter *CYTypedParameter::Parameters(CYContext &context) { $T(NULL) - return $ CYFunctionParameter($ CYDeclaration(typed_->identifier_), next_->Parameters(context)); -} - -CYExpression *CYTypedParameter::TypeSignature(CYContext &context, CYExpression *prefix) { $T(prefix) - return next_->TypeSignature(context, $ CYAdd(prefix, typed_->type_->Replace(context))); -}