]>
git.saurik.com Git - cycript.git/blob - ObjectiveC/Output.cpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
5 /* GNU Affero General Public License, Version 3 {{{ */
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.
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.
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/>.
24 #include "Replace.hpp"
26 #include "ObjectiveC/Syntax.hpp"
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 CYClassStatement::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,";
45 name_
->ClassName(out
, false);
47 out
<< "$cym=object_getClass($cyc);";
50 if (messages_
!= NULL
)
51 messages_
->Output(out
, false);
52 if (protocols_
!= NULL
) {
57 out
<< "objc_registerClassPair($cyc);";
58 out
<< "return $cyc;";
61 super_
->Output(out
, CYAssign::Precedence_
, CYNoFlags
);
67 void CYClassField::Output(CYOutput
&out
) const {
70 void CYInstanceLiteral::Output(CYOutput
&out
, CYFlags flags
) const {
72 number_
->Output(out
, CYRight(flags
));
75 void CYMessage::Output(CYOutput
&out
, bool replace
) const {
76 out
<< (instance_
? '-' : '+');
78 CYForEach (parameter
, parameters_
)
79 if (parameter
->tag_
!= NULL
) {
80 out
<< ' ' << *parameter
->tag_
;
81 if (parameter
->type_
!= NULL
)
82 out
<< ':' << *parameter
->type_
->identifier_
;
88 void CYBox::Output(CYOutput
&out
, CYFlags flags
) const {
90 value_
->Output(out
, Precedence(), CYRight(flags
));
93 void CYObjCBlock::Output(CYOutput
&out
, CYFlags flags
) const {
94 // XXX: this is seriously wrong
101 void CYProtocol::Output(CYOutput
&out
) const {
102 name_
->Output(out
, CYAssign::Precedence_
, CYNoFlags
);
104 out
<< ',' << ' ' << *next_
;
107 void CYSelector::Output(CYOutput
&out
, CYFlags flags
) const {
108 out
<< "@selector" << '(' << name_
<< ')';
111 void CYSelectorPart::Output(CYOutput
&out
) const {
118 void CYSend::Output(CYOutput
&out
, CYFlags flags
) const {
119 CYForEach (argument
, arguments_
)
120 if (argument
->name_
!= NULL
) {
121 out
<< ' ' << *argument
->name_
;
122 if (argument
->value_
!= NULL
)
123 out
<< ':' << *argument
->value_
;
127 void CYSendDirect::Output(CYOutput
&out
, CYFlags flags
) const {
129 self_
->Output(out
, CYAssign::Precedence_
, CYNoFlags
);
130 CYSend::Output(out
, flags
);
134 void CYSendSuper::Output(CYOutput
&out
, CYFlags flags
) const {
135 out
<< '[' << "super";
136 CYSend::Output(out
, flags
);