]>
git.saurik.com Git - cycript.git/blob - ObjectiveC/Output.cpp
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"
27 void CYCategory::Output(CYOutput
&out
, CYFlags flags
) const {
28 out
<< "(function($cys,$cyp,$cyc,$cyn,$cyt){";
29 out
<< "$cyp=object_getClass($cys);";
31 if (messages_
!= NULL
)
32 messages_
->Output(out
, true);
34 name_
->ClassName(out
, true);
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,";
45 name_
->ClassName(out
, false);
47 out
<< "$cyq(\"CY$\")";
49 out
<< "$cym=object_getClass($cyc);";
52 if (messages_
!= NULL
)
53 messages_
->Output(out
, false);
54 if (protocols_
!= NULL
) {
59 out
<< "objc_registerClassPair($cyc);";
60 out
<< "return $cyc;";
63 super_
->Output(out
, CYAssign::Precedence_
, CYNoFlags
);
69 void CYClassExpression::Output(CYOutput
&out
, CYFlags flags
) const {
70 CYClass::Output(out
, flags
);
73 void CYClassStatement::Output(CYOutput
&out
, CYFlags flags
) const {
74 CYClass::Output(out
, flags
);
77 void CYField::Output(CYOutput
&out
) const {
80 void CYImport::Output(CYOutput
&out
, CYFlags flags
) const {
84 void CYInstanceLiteral::Output(CYOutput
&out
, CYFlags flags
) const {
86 number_
->Output(out
, CYRight(flags
));
89 void CYMessage::Output(CYOutput
&out
, bool replace
) const {
90 out
<< (instance_
? '-' : '+');
92 CYForEach (parameter
, parameters_
)
93 if (parameter
->tag_
!= NULL
) {
94 out
<< ' ' << *parameter
->tag_
;
95 if (parameter
->name_
!= NULL
)
96 out
<< ':' << *parameter
->name_
;
102 void CYModule::Output(CYOutput
&out
) const {
108 void CYBox::Output(CYOutput
&out
, CYFlags flags
) const {
110 value_
->Output(out
, Precedence(), CYRight(flags
));
113 void CYObjCBlock::Output(CYOutput
&out
, CYFlags flags
) const {
114 // XXX: this is seriously wrong
121 void CYProtocol::Output(CYOutput
&out
) const {
122 name_
->Output(out
, CYAssign::Precedence_
, CYNoFlags
);
124 out
<< ',' << ' ' << *next_
;
127 void CYSelector::Output(CYOutput
&out
, CYFlags flags
) const {
128 out
<< "@selector" << '(' << name_
<< ')';
131 void CYSelectorPart::Output(CYOutput
&out
) const {
138 void CYSend::Output(CYOutput
&out
, CYFlags flags
) const {
139 CYForEach (argument
, arguments_
)
140 if (argument
->name_
!= NULL
) {
141 out
<< ' ' << *argument
->name_
;
142 if (argument
->value_
!= NULL
)
143 out
<< ':' << *argument
->value_
;
147 void CYSendDirect::Output(CYOutput
&out
, CYFlags flags
) const {
149 self_
->Output(out
, CYAssign::Precedence_
, CYNoFlags
);
150 CYSend::Output(out
, flags
);
154 void CYSendSuper::Output(CYOutput
&out
, CYFlags flags
) const {
155 out
<< '[' << "super";
156 CYSend::Output(out
, flags
);