X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/8d7447c170dd11c91d0a07768f32a2699177fa54..5b75838211f16d9c88fb1bae3193e3693a1bee39:/ObjectiveC/Replace.cpp diff --git a/ObjectiveC/Replace.cpp b/ObjectiveC/Replace.cpp index f500bd8..e0601db 100644 --- a/ObjectiveC/Replace.cpp +++ b/ObjectiveC/Replace.cpp @@ -24,10 +24,28 @@ #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")))); + if (extra != NULL) + left = $ CYAdd(left, extra); + + if (next == NULL || next->name_ == NULL) + return left; + + CYExpression *right(next->TypeSignature(context)); + if (right == NULL) + return NULL; + + return $ CYAdd(left, right); +} + CYStatement *CYCategory::Replace(CYContext &context) { CYVariable *cyc($V("$cyc")), *cys($V("$cys")); - return $E($C1($F(NULL, $P5($L("$cys"), $L("$cyp"), $L("$cyc"), $L("$cyn"), $L("$cyt")), $$->* + return $E($C1($F(NULL, $P6($L("$cys"), $L("$cyp"), $L("$cyc"), $L("$cyn"), $L("$cyt"), $L("$cym")), $$->* $E($ CYAssign($V("$cyp"), $C1($V("object_getClass"), cys)))->* $E($ CYAssign(cyc, cys))->* $E($ CYAssign($V("$cym"), $C1($V("object_getClass"), cyc)))->* @@ -60,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($ 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")))); + + 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) { @@ -74,10 +122,12 @@ 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, $C1($M(cyn, $S("type")), _class)))->* + $E($ CYAssign(cyt, type))->* $E($C4($V(replace ? "class_replaceMethod" : "class_addMethod"), $V(instance_ ? "$cyc" : "$cym"), cyn, @@ -90,6 +140,10 @@ CYStatement *CYMessage::Replace(CYContext &context, bool replace) const { $T(NUL ); } +CYExpression *CYMessage::TypeSignature(CYContext &context) const { + return MessageType(context, type_, parameters_, $S("@:")); +} + CYFunctionParameter *CYMessageParameter::Parameters(CYContext &context) const { $T(NULL) CYFunctionParameter *next(next_->Parameters(context)); return name_ == NULL ? next : $ CYFunctionParameter($ CYDeclaration(name_), next); @@ -104,10 +158,18 @@ CYSelectorPart *CYMessageParameter::SelectorPart(CYContext &context) const { $T( return tag_ == NULL ? next : $ CYSelectorPart(tag_, name_ != NULL, next); } +CYExpression *CYMessageParameter::TypeSignature(CYContext &context) const { + return MessageType(context, type_, next_); +} + 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)->* @@ -118,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) { @@ -160,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))); +}