X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/b639f46ddbb1709551093894de01802d818ca30f..fc44232bcff15a35c016ddfc1dc34b6503125020:/ObjectiveC/Replace.cpp diff --git a/ObjectiveC/Replace.cpp b/ObjectiveC/Replace.cpp index 3e267ae..1502aa2 100644 --- a/ObjectiveC/Replace.cpp +++ b/ObjectiveC/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 . **/ /* }}} */ @@ -32,7 +32,7 @@ static CYExpression *MessageType(CYContext &context, CYExpression *type, CYMessa if (extra != NULL) left = $ CYAdd(left, extra); - if (next == NULL) + if (next == NULL || next->name_ == NULL) return left; CYExpression *right(next->TypeSignature(context)); @@ -78,12 +78,26 @@ CYStatement *CYClassStatement::Replace(CYContext &context) { return $E(Replace_(context)); } -CYStatement *CYField::Replace(CYContext &context) const { - return NULL; +CYStatement *CYField::Replace(CYContext &context) const { $T(NULL) + CYVariable *cyn($V("$cyn")); + CYVariable *cyt($V("$cyt")); + + CYExpression *type($C0($M(typed_->Replace(context), $S("toString")))); + + return $ CYBlock($$->* + $E($ CYAssign(cyt, type))->* + $E($ CYAssign(cyn, $N1($V("Type"), 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; + return $ CYVar($L1($L(module_->part_->Word(), $C1($V("require"), module_->Replace(context, "/"))))); +} + +CYExpression *CYInstanceLiteral::Replace(CYContext &context) { + return $N1($V("Instance"), number_); } CYStatement *CYMessage::Replace(CYContext &context, bool replace) const { $T(NULL) @@ -102,7 +116,7 @@ CYStatement *CYMessage::Replace(CYContext &context, bool replace) const { $T(NUL $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 @@ -132,10 +146,20 @@ CYExpression *CYMessageParameter::TypeSignature(CYContext &context) const { return MessageType(context, type_, next_); } +CYString *CYModule::Replace(CYContext &context, const char *separator) const { + if (next_ == NULL) + return $ CYString(part_); + return $ CYString($pool.strcat(next_->Replace(context, separator)->Value(), separator, part_->Word(), NULL)); +} + CYExpression *CYBox::Replace(CYContext &context) { return $C1($M($V("Instance"), $S("box")), value_); } +CYExpression *CYObjCBlock::Replace(CYContext &context) { + return $C1($ CYEncodedType(($ CYTypedIdentifier(*typed_))->Modify($ CYTypeBlockWith(parameters_))), $ CYFunctionExpression(NULL, parameters_->Parameters(context), statements_)); +} + CYStatement *CYProtocol::Replace(CYContext &context) const { $T(NULL) return $ CYBlock($$->* next_->Replace(context)->* @@ -146,7 +170,7 @@ CYStatement *CYProtocol::Replace(CYContext &context) const { $T(NULL) } CYExpression *CYSelector::Replace(CYContext &context) { - return $N1($V("Selector"), name_->Replace(context)); + return $C1($V("sel_registerName"), name_->Replace(context)); } CYString *CYSelectorPart::Replace(CYContext &context) { @@ -157,7 +181,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) { @@ -182,7 +206,7 @@ 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) {