]> git.saurik.com Git - cycript.git/blob - ObjectiveC/Output.cpp
Hide all symbols of embedded developer framework.
[cycript.git] / ObjectiveC / Output.cpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2013 Jay Freeman (saurik)
3 */
4
5 /* GNU General Public License, Version 3 {{{ */
6 /*
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.
11 *
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.
16 *
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/>.
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 CYClass::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 if (name_ != NULL)
45 name_->ClassName(out, false);
46 else
47 out << "$cyq(\"CY$\")";
48 out << ",0);";
49 out << "$cym=object_getClass($cyc);";
50 if (fields_ != NULL)
51 fields_->Output(out);
52 if (messages_ != NULL)
53 messages_->Output(out, false);
54 if (protocols_ != NULL) {
55 out << '<';
56 out << *protocols_;
57 out << '>';
58 }
59 out << "objc_registerClassPair($cyc);";
60 out << "return $cyc;";
61 out << "}(";
62 if (super_ != NULL)
63 super_->Output(out, CYAssign::Precedence_, CYNoFlags);
64 else
65 out << "null";
66 out << "))";
67 }
68
69 void CYClassExpression::Output(CYOutput &out, CYFlags flags) const {
70 CYClass::Output(out, flags);
71 }
72
73 void CYClassStatement::Output(CYOutput &out, CYFlags flags) const {
74 CYClass::Output(out, flags);
75 }
76
77 void CYField::Output(CYOutput &out) const {
78 }
79
80 void CYImport::Output(CYOutput &out, CYFlags flags) const {
81 out << "@import";
82 }
83
84 void CYMessage::Output(CYOutput &out, bool replace) const {
85 out << (instance_ ? '-' : '+');
86
87 CYForEach (parameter, parameters_)
88 if (parameter->tag_ != NULL) {
89 out << ' ' << *parameter->tag_;
90 if (parameter->name_ != NULL)
91 out << ':' << *parameter->name_;
92 }
93
94 out << code_;
95 }
96
97 void CYBox::Output(CYOutput &out, CYFlags flags) const {
98 out << '@';
99 value_->Output(out, Precedence(), CYRight(flags));
100 }
101
102 void CYObjCBlock::Output(CYOutput &out, CYFlags flags) const {
103 // XXX: this is seriously wrong
104 out << "^(";
105 out << ")";
106 out << "{";
107 out << "}";
108 }
109
110 void CYProtocol::Output(CYOutput &out) const {
111 name_->Output(out, CYAssign::Precedence_, CYNoFlags);
112 if (next_ != NULL)
113 out << ',' << ' ' << *next_;
114 }
115
116 void CYSelector::Output(CYOutput &out, CYFlags flags) const {
117 out << "@selector" << '(' << name_ << ')';
118 }
119
120 void CYSelectorPart::Output(CYOutput &out) const {
121 out << name_;
122 if (value_)
123 out << ':';
124 out << next_;
125 }
126
127 void CYSend::Output(CYOutput &out, CYFlags flags) const {
128 CYForEach (argument, arguments_)
129 if (argument->name_ != NULL) {
130 out << ' ' << *argument->name_;
131 if (argument->value_ != NULL)
132 out << ':' << *argument->value_;
133 }
134 }
135
136 void CYSendDirect::Output(CYOutput &out, CYFlags flags) const {
137 out << '[';
138 self_->Output(out, CYAssign::Precedence_, CYNoFlags);
139 CYSend::Output(out, flags);
140 out << ']';
141 }
142
143 void CYSendSuper::Output(CYOutput &out, CYFlags flags) const {
144 out << '[' << "super";
145 CYSend::Output(out, flags);
146 out << ']';
147 }