X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/b639f46ddbb1709551093894de01802d818ca30f..0cfdb323b24a4f14f7eef842675dc5ae1dc09201:/ObjectiveC/Replace.cpp diff --git a/ObjectiveC/Replace.cpp b/ObjectiveC/Replace.cpp index 3e267ae..a7b6610 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,8 +78,38 @@ CYStatement *CYClassStatement::Replace(CYContext &context) { return $E(Replace_(context)); } -CYStatement *CYField::Replace(CYContext &context) const { - return NULL; +CYExpression *CYTypeArrayOf::Replace(CYContext &context) { + return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("arrayOf")), $ CYArgument(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")))); + + 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)) + ); } CYStatement *CYImport::Replace(CYContext &context) { @@ -136,6 +166,10 @@ CYExpression *CYBox::Replace(CYContext &context) { return $C1($M($V("Instance"), $S("box")), value_); } +CYExpression *CYObjCBlock::Replace(CYContext &context) { + return $N2($V("Functor"), $ CYFunctionExpression(NULL, $ CYFunctionParameter($ CYDeclaration($ CYIdentifier("$cyt")), parameters_->Parameters(context)), statements_), parameters_->TypeSignature(context, $ CYAdd(type_->Replace(context), $ CYString("@")))); +} + CYStatement *CYProtocol::Replace(CYContext &context) const { $T(NULL) return $ CYBlock($$->* next_->Replace(context)->* @@ -146,7 +180,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) { @@ -188,3 +222,11 @@ CYExpression *CYSendDirect::Replace(CYContext &context) { CYExpression *CYSendSuper::Replace(CYContext &context) { return $ CYSendDirect($V("$cyr"), arguments_); } + +CYFunctionParameter *CYTypedParameter::Parameters(CYContext &context) { $T(NULL) + return $ CYFunctionParameter($ CYDeclaration(typed_->identifier_ ?: context.Unique()), next_->Parameters(context)); +} + +CYExpression *CYTypedParameter::TypeSignature(CYContext &context, CYExpression *prefix) { $T(prefix) + return next_->TypeSignature(context, $ CYAdd(prefix, typed_->type_->Replace(context))); +}