1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2013 Jay Freeman (saurik)
5 /* GNU General Public License, Version 3 {{{ */
7 * Cycript is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
12 * Cycript is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Cycript. If not, see <http://www.gnu.org/licenses/>.
22 #include "Replace.hpp"
23 #include "ObjectiveC/Syntax.hpp"
25 #include <Foundation/Foundation.h>
28 void CYCategory::Output(CYOutput &out, CYFlags flags) const {
29 out << "(function($cys,$cyp,$cyc,$cyn,$cyt){";
30 out << "$cyp=object_getClass($cys);";
32 if (messages_ != NULL)
33 messages_->Output(out, true);
35 name_->ClassName(out, true);
40 void CYClass::Output(CYOutput &out, CYFlags flags) const {
41 // XXX: I don't necc. need the ()s
42 out << "(function($cys,$cyp,$cyc,$cyn,$cyt,$cym){";
43 out << "$cyp=object_getClass($cys);";
44 out << "$cyc=objc_allocateClassPair($cys,";
46 name_->ClassName(out, false);
48 out << "$cyq(\"CY$\")";
50 out << "$cym=object_getClass($cyc);";
53 if (messages_ != NULL)
54 messages_->Output(out, false);
55 if (protocols_ != NULL) {
60 out << "objc_registerClassPair($cyc);";
61 out << "return $cyc;";
64 super_->Output(out, CYAssign::Precedence_, CYNoFlags);
70 void CYClassExpression::Output(CYOutput &out, CYFlags flags) const {
71 CYClass::Output(out, flags);
74 void CYClassStatement::Output(CYOutput &out, CYFlags flags) const {
75 CYClass::Output(out, flags);
78 void CYEncodedType::Output(CYOutput &out, CYFlags flags) const {
80 // XXX: this is seriously wrong
84 void CYField::Output(CYOutput &out) const {
87 void CYImport::Output(CYOutput &out, CYFlags flags) const {
91 void CYMessage::Output(CYOutput &out, bool replace) const {
92 out << (instance_ ? '-' : '+');
94 CYForEach (parameter, parameters_)
95 if (parameter->tag_ != NULL) {
96 out << ' ' << *parameter->tag_;
97 if (parameter->name_ != NULL)
98 out << ':' << *parameter->name_;
104 void CYBox::Output(CYOutput &out, CYFlags flags) const {
106 value_->Output(out, Precedence(), CYRight(flags));
109 void CYObjCBlock::Output(CYOutput &out, CYFlags flags) const {
110 // XXX: this is seriously wrong
117 void CYProtocol::Output(CYOutput &out) const {
118 name_->Output(out, CYAssign::Precedence_, CYNoFlags);
120 out << ',' << ' ' << *next_;
123 void CYSelector::Output(CYOutput &out, CYFlags flags) const {
124 out << "@selector" << '(' << name_ << ')';
127 void CYSelectorPart::Output(CYOutput &out) const {
134 void CYSend::Output(CYOutput &out, CYFlags flags) const {
135 CYForEach (argument, arguments_)
136 if (argument->name_ != NULL) {
137 out << ' ' << *argument->name_;
138 if (argument->value_ != NULL)
139 out << ':' << *argument->value_;
143 void CYSendDirect::Output(CYOutput &out, CYFlags flags) const {
145 self_->Output(out, CYAssign::Precedence_, CYNoFlags);
146 CYSend::Output(out, flags);
150 void CYSendSuper::Output(CYOutput &out, CYFlags flags) const {
151 out << '[' << "super";
152 CYSend::Output(out, flags);