]>
Commit | Line | Data |
---|---|---|
b3378a02 | 1 | /* Cycript - Optimizing JavaScript Compiler/Runtime |
c1d3e52e | 2 | * Copyright (C) 2009-2015 Jay Freeman (saurik) |
b53b30c1 JF |
3 | */ |
4 | ||
f95d2598 | 5 | /* GNU Affero General Public License, Version 3 {{{ */ |
b53b30c1 | 6 | /* |
f95d2598 JF |
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 | |
c15969fd | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f95d2598 JF |
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/>. | |
b3378a02 | 19 | **/ |
b53b30c1 JF |
20 | /* }}} */ |
21 | ||
4de0686f | 22 | #include "Replace.hpp" |
3c1c3635 | 23 | #include "ObjectiveC/Syntax.hpp" |
4de0686f | 24 | |
4de0686f JF |
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 | ||
ec18682d | 39 | void CYClassStatement::Output(CYOutput &out, CYFlags flags) const { |
4de0686f JF |
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,"; | |
ec18682d | 44 | name_->ClassName(out, false); |
4de0686f JF |
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); | |
64b8d29f JF |
51 | if (protocols_ != NULL) { |
52 | out << '<'; | |
53 | out << *protocols_; | |
54 | out << '>'; | |
55 | } | |
4de0686f JF |
56 | out << "objc_registerClassPair($cyc);"; |
57 | out << "return $cyc;"; | |
58 | out << "}("; | |
59 | if (super_ != NULL) | |
8351aa30 | 60 | super_->Output(out, CYAssign::Precedence_, CYNoFlags); |
4de0686f JF |
61 | else |
62 | out << "null"; | |
63 | out << "))"; | |
64 | } | |
65 | ||
b6a67580 | 66 | void CYClassField::Output(CYOutput &out) const { |
4de0686f JF |
67 | } |
68 | ||
61769f4f JF |
69 | void CYInstanceLiteral::Output(CYOutput &out, CYFlags flags) const { |
70 | out << '#'; | |
71 | number_->Output(out, CYRight(flags)); | |
72 | } | |
73 | ||
4de0686f | 74 | void CYMessage::Output(CYOutput &out, bool replace) const { |
4644480a JF |
75 | out << (instance_ ? '-' : '+'); |
76 | ||
c2c9f509 | 77 | CYForEach (parameter, parameters_) |
4de0686f | 78 | if (parameter->tag_ != NULL) { |
4644480a | 79 | out << ' ' << *parameter->tag_; |
104cc5f5 JF |
80 | if (parameter->type_ != NULL) |
81 | out << ':' << *parameter->type_->identifier_; | |
4de0686f | 82 | } |
4644480a JF |
83 | |
84 | out << code_; | |
4de0686f JF |
85 | } |
86 | ||
f2f0d1d1 JF |
87 | void CYBox::Output(CYOutput &out, CYFlags flags) const { |
88 | out << '@'; | |
89 | value_->Output(out, Precedence(), CYRight(flags)); | |
90 | } | |
91 | ||
56e02e5b JF |
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 | ||
64b8d29f | 100 | void CYProtocol::Output(CYOutput &out) const { |
8351aa30 | 101 | name_->Output(out, CYAssign::Precedence_, CYNoFlags); |
64b8d29f JF |
102 | if (next_ != NULL) |
103 | out << ',' << ' ' << *next_; | |
104 | } | |
105 | ||
4de0686f JF |
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 { | |
c2c9f509 | 118 | CYForEach (argument, arguments_) |
4de0686f | 119 | if (argument->name_ != NULL) { |
4644480a | 120 | out << ' ' << *argument->name_; |
4de0686f | 121 | if (argument->value_ != NULL) |
4644480a | 122 | out << ':' << *argument->value_; |
4de0686f | 123 | } |
cacd1a88 JF |
124 | } |
125 | ||
126 | void CYSendDirect::Output(CYOutput &out, CYFlags flags) const { | |
127 | out << '['; | |
8351aa30 | 128 | self_->Output(out, CYAssign::Precedence_, CYNoFlags); |
cacd1a88 JF |
129 | CYSend::Output(out, flags); |
130 | out << ']'; | |
131 | } | |
4de0686f | 132 | |
cacd1a88 JF |
133 | void CYSendSuper::Output(CYOutput &out, CYFlags flags) const { |
134 | out << '[' << "super"; | |
135 | CYSend::Output(out, flags); | |
4644480a | 136 | out << ']'; |
4de0686f | 137 | } |