]>
Commit | Line | Data |
---|---|---|
d15b59f5 | 1 | /* Cycript - Inlining/Optimizing JavaScript Compiler |
b53b30c1 JF |
2 | * Copyright (C) 2009 Jay Freeman (saurik) |
3 | */ | |
4 | ||
5 | /* Modified BSD License {{{ */ | |
6 | /* | |
7 | * Redistribution and use in source and binary | |
8 | * forms, with or without modification, are permitted | |
9 | * provided that the following conditions are met: | |
10 | * | |
11 | * 1. Redistributions of source code must retain the | |
12 | * above copyright notice, this list of conditions | |
13 | * and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the | |
15 | * above copyright notice, this list of conditions | |
16 | * and the following disclaimer in the documentation | |
17 | * and/or other materials provided with the | |
18 | * distribution. | |
19 | * 3. The name of the author may not be used to endorse | |
20 | * or promote products derived from this software | |
21 | * without specific prior written permission. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' | |
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
25 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE | |
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
30 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
34 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
36 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
37 | */ | |
38 | /* }}} */ | |
39 | ||
4de0686f | 40 | #include "Replace.hpp" |
3c1c3635 | 41 | #include "ObjectiveC/Syntax.hpp" |
4de0686f | 42 | |
aabea98c | 43 | #include <Foundation/Foundation.h> |
4de0686f JF |
44 | #include <sstream> |
45 | ||
46 | void CYCategory::Output(CYOutput &out, CYFlags flags) const { | |
47 | out << "(function($cys,$cyp,$cyc,$cyn,$cyt){"; | |
48 | out << "$cyp=object_getClass($cys);"; | |
49 | out << "$cyc=$cys;"; | |
50 | if (messages_ != NULL) | |
51 | messages_->Output(out, true); | |
52 | out << "})("; | |
53 | name_->ClassName(out, true); | |
54 | out << ')'; | |
55 | out << ';'; | |
56 | } | |
57 | ||
58 | void CYClass::Output(CYOutput &out, CYFlags flags) const { | |
59 | // XXX: I don't necc. need the ()s | |
60 | out << "(function($cys,$cyp,$cyc,$cyn,$cyt,$cym){"; | |
61 | out << "$cyp=object_getClass($cys);"; | |
62 | out << "$cyc=objc_allocateClassPair($cys,"; | |
63 | if (name_ != NULL) | |
64 | name_->ClassName(out, false); | |
65 | else | |
66 | out << "$cyq(\"CY$\")"; | |
67 | out << ",0);"; | |
68 | out << "$cym=object_getClass($cyc);"; | |
69 | if (fields_ != NULL) | |
70 | fields_->Output(out); | |
71 | if (messages_ != NULL) | |
72 | messages_->Output(out, false); | |
64b8d29f JF |
73 | if (protocols_ != NULL) { |
74 | out << '<'; | |
75 | out << *protocols_; | |
76 | out << '>'; | |
77 | } | |
4de0686f JF |
78 | out << "objc_registerClassPair($cyc);"; |
79 | out << "return $cyc;"; | |
80 | out << "}("; | |
81 | if (super_ != NULL) | |
82 | super_->Output(out, CYPA, CYNoFlags); | |
83 | else | |
84 | out << "null"; | |
85 | out << "))"; | |
86 | } | |
87 | ||
88 | void CYClassExpression::Output(CYOutput &out, CYFlags flags) const { | |
89 | CYClass::Output(out, flags); | |
90 | } | |
91 | ||
92 | void CYClassStatement::Output(CYOutput &out, CYFlags flags) const { | |
93 | CYClass::Output(out, flags); | |
94 | } | |
95 | ||
96 | void CYField::Output(CYOutput &out) const { | |
4de0686f JF |
97 | } |
98 | ||
99 | void CYMessage::Output(CYOutput &out, bool replace) const { | |
4644480a JF |
100 | out << (instance_ ? '-' : '+'); |
101 | ||
4de0686f JF |
102 | for (CYMessageParameter *parameter(parameters_); parameter != NULL; parameter = parameter->next_) |
103 | if (parameter->tag_ != NULL) { | |
4644480a | 104 | out << ' ' << *parameter->tag_; |
4de0686f | 105 | if (parameter->name_ != NULL) |
4644480a | 106 | out << ':' << *parameter->name_; |
4de0686f | 107 | } |
4644480a JF |
108 | |
109 | out << code_; | |
4de0686f JF |
110 | } |
111 | ||
64b8d29f JF |
112 | void CYProtocol::Output(CYOutput &out) const { |
113 | name_->Output(out, CYPA, CYNoFlags); | |
114 | if (next_ != NULL) | |
115 | out << ',' << ' ' << *next_; | |
116 | } | |
117 | ||
4de0686f JF |
118 | void CYSelector::Output(CYOutput &out, CYFlags flags) const { |
119 | out << "@selector" << '(' << name_ << ')'; | |
120 | } | |
121 | ||
122 | void CYSelectorPart::Output(CYOutput &out) const { | |
123 | out << name_; | |
124 | if (value_) | |
125 | out << ':'; | |
126 | out << next_; | |
127 | } | |
128 | ||
129 | void CYSend::Output(CYOutput &out, CYFlags flags) const { | |
4de0686f JF |
130 | for (CYArgument *argument(arguments_); argument != NULL; argument = argument->next_) |
131 | if (argument->name_ != NULL) { | |
4644480a | 132 | out << ' ' << *argument->name_; |
4de0686f | 133 | if (argument->value_ != NULL) |
4644480a | 134 | out << ':' << *argument->value_; |
4de0686f | 135 | } |
cacd1a88 JF |
136 | } |
137 | ||
138 | void CYSendDirect::Output(CYOutput &out, CYFlags flags) const { | |
139 | out << '['; | |
140 | self_->Output(out, CYPA, CYNoFlags); | |
141 | CYSend::Output(out, flags); | |
142 | out << ']'; | |
143 | } | |
4de0686f | 144 | |
cacd1a88 JF |
145 | void CYSendSuper::Output(CYOutput &out, CYFlags flags) const { |
146 | out << '[' << "super"; | |
147 | CYSend::Output(out, flags); | |
4644480a | 148 | out << ']'; |
4de0686f | 149 | } |