/* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2013 Jay Freeman (saurik)
+ * Copyright (C) 2009-2015 Jay Freeman (saurik)
*/
-/* GNU 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 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
+ * 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Cycript. If not, see <http://www.gnu.org/licenses/>.
+ * 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 <http://www.gnu.org/licenses/>.
**/
/* }}} */
#include <sstream>
-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));
), name_->ClassName(context, true)));
}
-CYExpression *CYClass::Replace_(CYContext &context) {
+CYStatement *CYClassStatement::Replace(CYContext &context) {
CYVariable *cyc($V("$cyc")), *cys($V("$cys"));
- CYExpression *name(name_ != NULL ? name_->ClassName(context, false) : $C1($V("$cyq"), $S("CY$")));
+ CYExpression *name(name_->ClassName(context, false));
- return $C1($F(NULL, $P6($L("$cys"), $L("$cyp"), $L("$cyc"), $L("$cyn"), $L("$cyt"), $L("$cym")), $$->*
+ 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, $C3($V("objc_allocateClassPair"), cys, name, $D(0))))->*
$E($ CYAssign($V("$cym"), $C1($V("object_getClass"), cyc)))->*
messages_->Replace(context, false)->*
$E($C1($V("objc_registerClassPair"), cyc))->*
$ CYReturn(cyc)
- ), super_ == NULL ? $ CYNull() : super_);
-}
-
-CYExpression *CYClassExpression::Replace(CYContext &context) {
- return Replace_(context);
+ ), super_ == NULL ? $ CYNull() : super_));
}
-CYStatement *CYClassStatement::Replace(CYContext &context) {
- return $E(Replace_(context));
-}
-
-CYStatement *CYField::Replace(CYContext &context) const { $T(NULL)
+CYStatement *CYClassField::Replace(CYContext &context) const { $T(NULL)
CYVariable *cyn($V("$cyn"));
CYVariable *cyt($V("$cyt"));
);
}
-CYStatement *CYImport::Replace(CYContext &context) {
- return $ CYVar($L1($L(module_->part_->Word(), $C1($V("require"), module_->Replace(context, "/")))));
-}
-
CYExpression *CYInstanceLiteral::Replace(CYContext &context) {
return $N1($V("Instance"), number_);
}
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("objc_super"), self, _class))))->*
- $ CYReturn($C1($M($F(NULL, NULL, code_), $S("call")), self))
+ $ CYReturn($C1($M($F(NULL, NULL, code_.code_), $S("call")), self))
), cyt),
cyt
))
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 {
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 {
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_));
+ return $C1($ CYEncodedType(($ CYTypedIdentifier(*typed_))->Modify($ CYTypeBlockWith(parameters_))), $ CYFunctionExpression(NULL, parameters_->Parameters(context), code_));
}
CYStatement *CYProtocol::Replace(CYContext &context) const { $T(NULL)
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) {