-/* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2015 Jay Freeman (saurik)
+/* Cycript - The Truly Universal Scripting Language
+ * Copyright (C) 2009-2016 Jay Freeman (saurik)
*/
/* GNU Affero General Public License, Version 3 {{{ */
#include "ObjectiveC/Syntax.hpp"
-static CYExpression *MessageType(CYContext &context, CYTypedIdentifier *type, CYMessageParameter *next, CYExpression *extra = NULL) {
+static CYExpression *MessageType(CYContext &context, CYType *type, CYMessageParameter *next, CYExpression *extra = NULL) {
CYExpression *left($C0($M(type->Replace(context), $S("toString"))));
if (extra != NULL)
left = $ CYAdd(left, extra);
CYVariable *cyn($V("$cyn"));
CYVariable *cyt($V("$cyt"));
- CYExpression *type($C0($M(typed_->Replace(context), $S("toString"))));
+ CYExpression *type($C0($M(type_->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))->*
+ $E($C5($V("class_addIvar"), $V("$cyc"), name_->PropertyName(context), $M(cyn, $S("size")), $M(cyn, $S("alignment")), cyt))->*
next_->Replace(context)
);
}
CYFunctionParameter *CYMessageParameter::Parameters(CYContext &context) const { $T(NULL)
CYFunctionParameter *next(next_->Parameters(context));
- return type_ == NULL ? next : $ CYFunctionParameter($B(type_->identifier_), next);
+ return type_ == NULL ? next : $ CYFunctionParameter($B(identifier_), next);
}
CYSelector *CYMessageParameter::Selector(CYContext &context) const {
return $C1($M($V("Instance"), $S("box")), value_);
}
+CYTarget *CYObjCArray::Replace(CYContext &context) {
+ size_t count(0);
+ CYForEach (element, elements_)
+ ++count;
+ return $ CYSendDirect($V("NSArray"), $C_($ CYWord("arrayWithObjects"), $ CYArray(elements_), $C_($ CYWord("count"), $D(count))));
+}
+
+CYTarget *CYObjCDictionary::Replace(CYContext &context) {
+ CYList<CYElement> keys;
+ CYList<CYElement> values;
+ size_t count(0);
+
+ CYForEach (pair, pairs_) {
+ keys->*$ CYElementValue(pair->key_);
+ values->*$ CYElementValue(pair->value_);
+ ++count;
+ }
+
+ return $ CYSendDirect($V("NSDictionary"), $C_($ CYWord("dictionaryWithObjects"), $ CYArray(values), $C_($ CYWord("forKeys"), $ CYArray(keys), $C_($ CYWord("count"), $D(count)))));
+}
+
CYTarget *CYObjCBlock::Replace(CYContext &context) {
- return $C1($ CYTypeExpression(($ CYTypedIdentifier(*typed_))->Modify($ CYTypeBlockWith(parameters_))), $ CYFunctionExpression(NULL, parameters_->Parameters(context), code_));
+ // XXX: wtf is happening here?
+ return $C1($ CYTypeExpression(($ CYType(*typed_))->Modify($ CYTypeBlockWith(parameters_))), $ CYFunctionExpression(NULL, parameters_->Parameters(context), code_));
}
CYStatement *CYProtocol::Replace(CYContext &context) const { $T(NULL)