]>
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 | ||
20052ff7 JF |
22 | #include <sstream> |
23 | ||
4de0686f | 24 | #include "Replace.hpp" |
4de0686f | 25 | |
20052ff7 | 26 | #include "ObjectiveC/Syntax.hpp" |
4de0686f JF |
27 | |
28 | void CYCategory::Output(CYOutput &out, CYFlags flags) const { | |
29 | out << "(function($cys,$cyp,$cyc,$cyn,$cyt){"; | |
30 | out << "$cyp=object_getClass($cys);"; | |
31 | out << "$cyc=$cys;"; | |
32 | if (messages_ != NULL) | |
33 | messages_->Output(out, true); | |
34 | out << "})("; | |
35 | name_->ClassName(out, true); | |
36 | out << ')'; | |
37 | out << ';'; | |
38 | } | |
39 | ||
ec18682d | 40 | void CYClassStatement::Output(CYOutput &out, CYFlags flags) const { |
4de0686f JF |
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,"; | |
ec18682d | 45 | name_->ClassName(out, false); |
4de0686f JF |
46 | out << ",0);"; |
47 | out << "$cym=object_getClass($cyc);"; | |
48 | if (fields_ != NULL) | |
49 | fields_->Output(out); | |
50 | if (messages_ != NULL) | |
51 | messages_->Output(out, false); | |
64b8d29f JF |
52 | if (protocols_ != NULL) { |
53 | out << '<'; | |
54 | out << *protocols_; | |
55 | out << '>'; | |
56 | } | |
4de0686f JF |
57 | out << "objc_registerClassPair($cyc);"; |
58 | out << "return $cyc;"; | |
59 | out << "}("; | |
60 | if (super_ != NULL) | |
8351aa30 | 61 | super_->Output(out, CYAssign::Precedence_, CYNoFlags); |
4de0686f JF |
62 | else |
63 | out << "null"; | |
64 | out << "))"; | |
65 | } | |
66 | ||
b6a67580 | 67 | void CYClassField::Output(CYOutput &out) const { |
4de0686f JF |
68 | } |
69 | ||
61769f4f JF |
70 | void CYInstanceLiteral::Output(CYOutput &out, CYFlags flags) const { |
71 | out << '#'; | |
72 | number_->Output(out, CYRight(flags)); | |
73 | } | |
74 | ||
4de0686f | 75 | void CYMessage::Output(CYOutput &out, bool replace) const { |
4644480a JF |
76 | out << (instance_ ? '-' : '+'); |
77 | ||
c2c9f509 | 78 | CYForEach (parameter, parameters_) |
4de0686f | 79 | if (parameter->tag_ != NULL) { |
4644480a | 80 | out << ' ' << *parameter->tag_; |
104cc5f5 JF |
81 | if (parameter->type_ != NULL) |
82 | out << ':' << *parameter->type_->identifier_; | |
4de0686f | 83 | } |
4644480a JF |
84 | |
85 | out << code_; | |
4de0686f JF |
86 | } |
87 | ||
f2f0d1d1 JF |
88 | void CYBox::Output(CYOutput &out, CYFlags flags) const { |
89 | out << '@'; | |
90 | value_->Output(out, Precedence(), CYRight(flags)); | |
91 | } | |
92 | ||
56e02e5b JF |
93 | void CYObjCBlock::Output(CYOutput &out, CYFlags flags) const { |
94 | // XXX: this is seriously wrong | |
95 | out << "^("; | |
96 | out << ")"; | |
97 | out << "{"; | |
98 | out << "}"; | |
99 | } | |
100 | ||
64b8d29f | 101 | void CYProtocol::Output(CYOutput &out) const { |
8351aa30 | 102 | name_->Output(out, CYAssign::Precedence_, CYNoFlags); |
64b8d29f JF |
103 | if (next_ != NULL) |
104 | out << ',' << ' ' << *next_; | |
105 | } | |
106 | ||
4de0686f JF |
107 | void CYSelector::Output(CYOutput &out, CYFlags flags) const { |
108 | out << "@selector" << '(' << name_ << ')'; | |
109 | } | |
110 | ||
111 | void CYSelectorPart::Output(CYOutput &out) const { | |
112 | out << name_; | |
113 | if (value_) | |
114 | out << ':'; | |
115 | out << next_; | |
116 | } | |
117 | ||
118 | void CYSend::Output(CYOutput &out, CYFlags flags) const { | |
c2c9f509 | 119 | CYForEach (argument, arguments_) |
4de0686f | 120 | if (argument->name_ != NULL) { |
4644480a | 121 | out << ' ' << *argument->name_; |
4de0686f | 122 | if (argument->value_ != NULL) |
4644480a | 123 | out << ':' << *argument->value_; |
4de0686f | 124 | } |
cacd1a88 JF |
125 | } |
126 | ||
127 | void CYSendDirect::Output(CYOutput &out, CYFlags flags) const { | |
128 | out << '['; | |
8351aa30 | 129 | self_->Output(out, CYAssign::Precedence_, CYNoFlags); |
cacd1a88 JF |
130 | CYSend::Output(out, flags); |
131 | out << ']'; | |
132 | } | |
4de0686f | 133 | |
cacd1a88 JF |
134 | void CYSendSuper::Output(CYOutput &out, CYFlags flags) const { |
135 | out << '[' << "super"; | |
136 | CYSend::Output(out, flags); | |
4644480a | 137 | out << ']'; |
4de0686f | 138 | } |