]>
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/>.
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 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);
46 out
<< "$cym=object_getClass($cyc);";
49 if (messages_
!= NULL
)
50 messages_
->Output(out
, false);
51 if (protocols_
!= NULL
) {
56 out
<< "objc_registerClassPair($cyc);";
57 out
<< "return $cyc;";
60 super_
->Output(out
, CYAssign::Precedence_
, CYNoFlags
);
66 void CYClassField::Output(CYOutput
&out
) const {
69 void CYInstanceLiteral::Output(CYOutput
&out
, CYFlags flags
) const {
71 number_
->Output(out
, CYRight(flags
));
74 void CYMessage::Output(CYOutput
&out
, bool replace
) const {
75 out
<< (instance_
? '-' : '+');
77 CYForEach (parameter
, parameters_
)
78 if (parameter
->tag_
!= NULL
) {
79 out
<< ' ' << *parameter
->tag_
;
80 if (parameter
->type_
!= NULL
)
81 out
<< ':' << *parameter
->type_
->identifier_
;
87 void CYBox::Output(CYOutput
&out
, CYFlags flags
) const {
89 value_
->Output(out
, Precedence(), CYRight(flags
));
92 void CYObjCBlock::Output(CYOutput
&out
, CYFlags flags
) const {
93 // XXX: this is seriously wrong
100 void CYProtocol::Output(CYOutput
&out
) const {
101 name_
->Output(out
, CYAssign::Precedence_
, CYNoFlags
);
103 out
<< ',' << ' ' << *next_
;
106 void CYSelector::Output(CYOutput
&out
, CYFlags flags
) const {
107 out
<< "@selector" << '(' << name_
<< ')';
110 void CYSelectorPart::Output(CYOutput
&out
) const {
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_
;
126 void CYSendDirect::Output(CYOutput
&out
, CYFlags flags
) const {
128 self_
->Output(out
, CYAssign::Precedence_
, CYNoFlags
);
129 CYSend::Output(out
, flags
);
133 void CYSendSuper::Output(CYOutput
&out
, CYFlags flags
) const {
134 out
<< '[' << "super";
135 CYSend::Output(out
, flags
);