]>
Commit | Line | Data |
---|---|---|
b3378a02 | 1 | /* Cycript - Optimizing JavaScript Compiler/Runtime |
c15969fd | 2 | * Copyright (C) 2009-2013 Jay Freeman (saurik) |
b53b30c1 JF |
3 | */ |
4 | ||
c15969fd | 5 | /* GNU General Public License, Version 3 {{{ */ |
b53b30c1 | 6 | /* |
c15969fd JF |
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. | |
b53b30c1 | 11 | * |
c15969fd JF |
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. | |
b53b30c1 | 16 | * |
c15969fd | 17 | * You should have received a copy of the GNU General Public License |
b3378a02 JF |
18 | * along with Cycript. If not, see <http://www.gnu.org/licenses/>. |
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 | ||
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,"; | |
44 | if (name_ != NULL) | |
45 | name_->ClassName(out, false); | |
46 | else | |
47 | out << "$cyq(\"CY$\")"; | |
48 | out << ",0);"; | |
49 | out << "$cym=object_getClass($cyc);"; | |
50 | if (fields_ != NULL) | |
51 | fields_->Output(out); | |
52 | if (messages_ != NULL) | |
53 | messages_->Output(out, false); | |
64b8d29f JF |
54 | if (protocols_ != NULL) { |
55 | out << '<'; | |
56 | out << *protocols_; | |
57 | out << '>'; | |
58 | } | |
4de0686f JF |
59 | out << "objc_registerClassPair($cyc);"; |
60 | out << "return $cyc;"; | |
61 | out << "}("; | |
62 | if (super_ != NULL) | |
8351aa30 | 63 | super_->Output(out, CYAssign::Precedence_, CYNoFlags); |
4de0686f JF |
64 | else |
65 | out << "null"; | |
66 | out << "))"; | |
67 | } | |
68 | ||
69 | void CYClassExpression::Output(CYOutput &out, CYFlags flags) const { | |
70 | CYClass::Output(out, flags); | |
71 | } | |
72 | ||
73 | void CYClassStatement::Output(CYOutput &out, CYFlags flags) const { | |
74 | CYClass::Output(out, flags); | |
75 | } | |
76 | ||
77 | void CYField::Output(CYOutput &out) const { | |
4de0686f JF |
78 | } |
79 | ||
1ba6903e JF |
80 | void CYImport::Output(CYOutput &out, CYFlags flags) const { |
81 | out << "@import"; | |
82 | } | |
83 | ||
61769f4f JF |
84 | void CYInstanceLiteral::Output(CYOutput &out, CYFlags flags) const { |
85 | out << '#'; | |
86 | number_->Output(out, CYRight(flags)); | |
87 | } | |
88 | ||
4de0686f | 89 | void CYMessage::Output(CYOutput &out, bool replace) const { |
4644480a JF |
90 | out << (instance_ ? '-' : '+'); |
91 | ||
c2c9f509 | 92 | CYForEach (parameter, parameters_) |
4de0686f | 93 | if (parameter->tag_ != NULL) { |
4644480a | 94 | out << ' ' << *parameter->tag_; |
4de0686f | 95 | if (parameter->name_ != NULL) |
4644480a | 96 | out << ':' << *parameter->name_; |
4de0686f | 97 | } |
4644480a JF |
98 | |
99 | out << code_; | |
4de0686f JF |
100 | } |
101 | ||
417dcc12 JF |
102 | void CYModule::Output(CYOutput &out) const { |
103 | out << part_; | |
104 | if (next_ != NULL) | |
105 | out << '.' << next_; | |
106 | } | |
107 | ||
f2f0d1d1 JF |
108 | void CYBox::Output(CYOutput &out, CYFlags flags) const { |
109 | out << '@'; | |
110 | value_->Output(out, Precedence(), CYRight(flags)); | |
111 | } | |
112 | ||
56e02e5b JF |
113 | void CYObjCBlock::Output(CYOutput &out, CYFlags flags) const { |
114 | // XXX: this is seriously wrong | |
115 | out << "^("; | |
116 | out << ")"; | |
117 | out << "{"; | |
118 | out << "}"; | |
119 | } | |
120 | ||
64b8d29f | 121 | void CYProtocol::Output(CYOutput &out) const { |
8351aa30 | 122 | name_->Output(out, CYAssign::Precedence_, CYNoFlags); |
64b8d29f JF |
123 | if (next_ != NULL) |
124 | out << ',' << ' ' << *next_; | |
125 | } | |
126 | ||
4de0686f JF |
127 | void CYSelector::Output(CYOutput &out, CYFlags flags) const { |
128 | out << "@selector" << '(' << name_ << ')'; | |
129 | } | |
130 | ||
131 | void CYSelectorPart::Output(CYOutput &out) const { | |
132 | out << name_; | |
133 | if (value_) | |
134 | out << ':'; | |
135 | out << next_; | |
136 | } | |
137 | ||
138 | void CYSend::Output(CYOutput &out, CYFlags flags) const { | |
c2c9f509 | 139 | CYForEach (argument, arguments_) |
4de0686f | 140 | if (argument->name_ != NULL) { |
4644480a | 141 | out << ' ' << *argument->name_; |
4de0686f | 142 | if (argument->value_ != NULL) |
4644480a | 143 | out << ':' << *argument->value_; |
4de0686f | 144 | } |
cacd1a88 JF |
145 | } |
146 | ||
147 | void CYSendDirect::Output(CYOutput &out, CYFlags flags) const { | |
148 | out << '['; | |
8351aa30 | 149 | self_->Output(out, CYAssign::Precedence_, CYNoFlags); |
cacd1a88 JF |
150 | CYSend::Output(out, flags); |
151 | out << ']'; | |
152 | } | |
4de0686f | 153 | |
cacd1a88 JF |
154 | void CYSendSuper::Output(CYOutput &out, CYFlags flags) const { |
155 | out << '[' << "super"; | |
156 | CYSend::Output(out, flags); | |
4644480a | 157 | out << ']'; |
4de0686f | 158 | } |