]> git.saurik.com Git - cycript.git/blob - ObjectiveC/Output.cpp
Drop support for ObjC @implementation expressions.
[cycript.git] / ObjectiveC / Output.cpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU Affero General Public License, Version 3 {{{ */
6 /*
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #include "Replace.hpp"
23 #include "ObjectiveC/Syntax.hpp"
24
25 #include <sstream>
26
27 void CYCategory::Output(CYOutput &out, CYFlags flags) const {
28 out << "(function($cys,$cyp,$cyc,$cyn,$cyt){";
29 out << "$cyp=object_getClass($cys);";
30 out << "$cyc=$cys;";
31 if (messages_ != NULL)
32 messages_->Output(out, true);
33 out << "})(";
34 name_->ClassName(out, true);
35 out << ')';
36 out << ';';
37 }
38
39 void CYClassStatement::Output(CYOutput &out, CYFlags flags) const {
40 // XXX: I don't necc. need the ()s
41 out << "(function($cys,$cyp,$cyc,$cyn,$cyt,$cym){";
42 out << "$cyp=object_getClass($cys);";
43 out << "$cyc=objc_allocateClassPair($cys,";
44 name_->ClassName(out, false);
45 out << ",0);";
46 out << "$cym=object_getClass($cyc);";
47 if (fields_ != NULL)
48 fields_->Output(out);
49 if (messages_ != NULL)
50 messages_->Output(out, false);
51 if (protocols_ != NULL) {
52 out << '<';
53 out << *protocols_;
54 out << '>';
55 }
56 out << "objc_registerClassPair($cyc);";
57 out << "return $cyc;";
58 out << "}(";
59 if (super_ != NULL)
60 super_->Output(out, CYAssign::Precedence_, CYNoFlags);
61 else
62 out << "null";
63 out << "))";
64 }
65
66 void CYClassField::Output(CYOutput &out) const {
67 }
68
69 void CYInstanceLiteral::Output(CYOutput &out, CYFlags flags) const {
70 out << '#';
71 number_->Output(out, CYRight(flags));
72 }
73
74 void CYMessage::Output(CYOutput &out, bool replace) const {
75 out << (instance_ ? '-' : '+');
76
77 CYForEach (parameter, parameters_)
78 if (parameter->tag_ != NULL) {
79 out << ' ' << *parameter->tag_;
80 if (parameter->type_ != NULL)
81 out << ':' << *parameter->type_->identifier_;
82 }
83
84 out << code_;
85 }
86
87 void CYBox::Output(CYOutput &out, CYFlags flags) const {
88 out << '@';
89 value_->Output(out, Precedence(), CYRight(flags));
90 }
91
92 void CYObjCBlock::Output(CYOutput &out, CYFlags flags) const {
93 // XXX: this is seriously wrong
94 out << "^(";
95 out << ")";
96 out << "{";
97 out << "}";
98 }
99
100 void CYProtocol::Output(CYOutput &out) const {
101 name_->Output(out, CYAssign::Precedence_, CYNoFlags);
102 if (next_ != NULL)
103 out << ',' << ' ' << *next_;
104 }
105
106 void CYSelector::Output(CYOutput &out, CYFlags flags) const {
107 out << "@selector" << '(' << name_ << ')';
108 }
109
110 void CYSelectorPart::Output(CYOutput &out) const {
111 out << name_;
112 if (value_)
113 out << ':';
114 out << next_;
115 }
116
117 void CYSend::Output(CYOutput &out, CYFlags flags) const {
118 CYForEach (argument, arguments_)
119 if (argument->name_ != NULL) {
120 out << ' ' << *argument->name_;
121 if (argument->value_ != NULL)
122 out << ':' << *argument->value_;
123 }
124 }
125
126 void CYSendDirect::Output(CYOutput &out, CYFlags flags) const {
127 out << '[';
128 self_->Output(out, CYAssign::Precedence_, CYNoFlags);
129 CYSend::Output(out, flags);
130 out << ']';
131 }
132
133 void CYSendSuper::Output(CYOutput &out, CYFlags flags) const {
134 out << '[' << "super";
135 CYSend::Output(out, flags);
136 out << ']';
137 }