]>
Commit | Line | Data |
---|---|---|
b3378a02 | 1 | /* Cycript - Optimizing JavaScript Compiler/Runtime |
c15969fd | 2 | * Copyright (C) 2009-2013 Jay Freeman (saurik) |
4644480a JF |
3 | */ |
4 | ||
c15969fd | 5 | /* GNU General Public License, Version 3 {{{ */ |
4644480a | 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. | |
4644480a | 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. | |
4644480a | 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 | **/ | |
4644480a JF |
20 | /* }}} */ |
21 | ||
3c1c3635 JF |
22 | #ifndef CYCRIPT_OBJECTIVEC_SYNTAX_HPP |
23 | #define CYCRIPT_OBJECTIVEC_SYNTAX_HPP | |
4de0686f JF |
24 | |
25 | #include "Parser.hpp" | |
26 | ||
56e02e5b JF |
27 | struct CYObjCBlock : |
28 | CYExpression | |
29 | { | |
9a39f705 | 30 | CYTypedIdentifier *typed_; |
56e02e5b JF |
31 | CYTypedParameter *parameters_; |
32 | CYStatement *statements_; | |
33 | ||
9a39f705 JF |
34 | CYObjCBlock(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *statements) : |
35 | typed_(typed), | |
56e02e5b JF |
36 | parameters_(parameters), |
37 | statements_(statements) | |
38 | { | |
39 | } | |
40 | ||
41 | CYPrecedence(1) | |
42 | ||
43 | virtual CYExpression *Replace(CYContext &context); | |
44 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
45 | }; | |
46 | ||
f2f0d1d1 JF |
47 | struct CYBox : |
48 | CYExpression | |
49 | { | |
50 | CYExpression *value_; | |
51 | ||
52 | CYBox(CYExpression *value) : | |
53 | value_(value) | |
54 | { | |
55 | } | |
56 | ||
57 | CYPrecedence(1) | |
58 | ||
59 | virtual CYExpression *Replace(CYContext &context); | |
60 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
61 | }; | |
62 | ||
4de0686f JF |
63 | struct CYSelectorPart : |
64 | CYNext<CYSelectorPart>, | |
65 | CYThing | |
66 | { | |
67 | CYWord *name_; | |
68 | bool value_; | |
69 | ||
2385c806 | 70 | CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next = NULL) : |
4de0686f JF |
71 | CYNext<CYSelectorPart>(next), |
72 | name_(name), | |
73 | value_(value) | |
74 | { | |
75 | } | |
76 | ||
77 | CYString *Replace(CYContext &context); | |
78 | virtual void Output(CYOutput &out) const; | |
79 | }; | |
80 | ||
81 | struct CYSelector : | |
82 | CYLiteral | |
83 | { | |
84 | CYSelectorPart *name_; | |
85 | ||
86 | CYSelector(CYSelectorPart *name) : | |
87 | name_(name) | |
88 | { | |
89 | } | |
90 | ||
91 | CYPrecedence(1) | |
92 | ||
93 | virtual CYExpression *Replace(CYContext &context); | |
94 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
95 | }; | |
96 | ||
97 | struct CYField : | |
98 | CYNext<CYField> | |
99 | { | |
cfd73c6d JF |
100 | CYExpression *type_; |
101 | CYIdentifier *name_; | |
102 | ||
103 | CYField(CYExpression *type, CYIdentifier *name, CYField *next = NULL) : | |
104 | CYNext<CYField>(next), | |
105 | type_(type), | |
106 | name_(name) | |
107 | { | |
108 | } | |
109 | ||
4de0686f JF |
110 | CYStatement *Replace(CYContext &context) const; |
111 | void Output(CYOutput &out) const; | |
112 | }; | |
113 | ||
114 | struct CYMessageParameter : | |
115 | CYNext<CYMessageParameter> | |
116 | { | |
117 | CYWord *tag_; | |
118 | CYExpression *type_; | |
119 | CYIdentifier *name_; | |
120 | ||
121 | CYMessageParameter(CYWord *tag, CYExpression *type, CYIdentifier *name) : | |
122 | tag_(tag), | |
123 | type_(type), | |
124 | name_(name) | |
125 | { | |
126 | } | |
127 | ||
128 | CYFunctionParameter *Parameters(CYContext &context) const; | |
129 | CYSelector *Selector(CYContext &context) const; | |
130 | CYSelectorPart *SelectorPart(CYContext &context) const; | |
9a7c375c | 131 | CYExpression *TypeSignature(CYContext &context) const; |
4de0686f JF |
132 | }; |
133 | ||
134 | struct CYMessage : | |
135 | CYNext<CYMessage> | |
136 | { | |
137 | bool instance_; | |
138 | CYExpression *type_; | |
139 | CYMessageParameter *parameters_; | |
4644480a | 140 | CYBlock code_; |
4de0686f JF |
141 | |
142 | CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *statements) : | |
143 | instance_(instance), | |
144 | type_(type), | |
145 | parameters_(parameter), | |
4644480a | 146 | code_(statements) |
4de0686f JF |
147 | { |
148 | } | |
149 | ||
150 | CYStatement *Replace(CYContext &context, bool replace) const; | |
151 | void Output(CYOutput &out, bool replace) const; | |
9a7c375c JF |
152 | |
153 | CYExpression *TypeSignature(CYContext &context) const; | |
4de0686f JF |
154 | }; |
155 | ||
64b8d29f JF |
156 | struct CYProtocol : |
157 | CYNext<CYProtocol>, | |
158 | CYThing | |
159 | { | |
160 | CYExpression *name_; | |
161 | ||
162 | CYProtocol(CYExpression *name, CYProtocol *next = NULL) : | |
163 | CYNext<CYProtocol>(next), | |
164 | name_(name) | |
165 | { | |
166 | } | |
167 | ||
168 | CYStatement *Replace(CYContext &context) const; | |
169 | void Output(CYOutput &out) const; | |
170 | }; | |
171 | ||
1ba6903e JF |
172 | struct CYImport : |
173 | CYStatement | |
174 | { | |
175 | virtual CYStatement *Replace(CYContext &context); | |
176 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
177 | }; | |
178 | ||
4de0686f JF |
179 | struct CYClass { |
180 | CYClassName *name_; | |
181 | CYExpression *super_; | |
64b8d29f | 182 | CYProtocol *protocols_; |
4de0686f JF |
183 | CYField *fields_; |
184 | CYMessage *messages_; | |
185 | ||
64b8d29f | 186 | CYClass(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) : |
4de0686f JF |
187 | name_(name), |
188 | super_(super), | |
64b8d29f | 189 | protocols_(protocols), |
4de0686f JF |
190 | fields_(fields), |
191 | messages_(messages) | |
192 | { | |
193 | } | |
194 | ||
7c6c5b0a JF |
195 | virtual ~CYClass() { |
196 | } | |
197 | ||
4de0686f JF |
198 | CYExpression *Replace_(CYContext &context); |
199 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
200 | }; | |
201 | ||
202 | struct CYClassExpression : | |
203 | CYClass, | |
204 | CYExpression | |
205 | { | |
64b8d29f JF |
206 | CYClassExpression(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) : |
207 | CYClass(name, super, protocols, fields, messages) | |
4de0686f JF |
208 | { |
209 | } | |
210 | ||
211 | CYPrecedence(0) | |
212 | ||
213 | virtual CYExpression *Replace(CYContext &context); | |
214 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
215 | }; | |
216 | ||
217 | struct CYClassStatement : | |
218 | CYClass, | |
219 | CYStatement | |
220 | { | |
64b8d29f JF |
221 | CYClassStatement(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) : |
222 | CYClass(name, super, protocols, fields, messages) | |
4de0686f JF |
223 | { |
224 | } | |
225 | ||
226 | virtual CYStatement *Replace(CYContext &context); | |
227 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
228 | }; | |
229 | ||
230 | struct CYCategory : | |
231 | CYStatement | |
232 | { | |
233 | CYClassName *name_; | |
234 | CYMessage *messages_; | |
235 | ||
236 | CYCategory(CYClassName *name, CYMessage *messages) : | |
237 | name_(name), | |
238 | messages_(messages) | |
239 | { | |
240 | } | |
241 | ||
242 | virtual CYStatement *Replace(CYContext &context); | |
243 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
244 | }; | |
245 | ||
246 | struct CYSend : | |
247 | CYExpression | |
248 | { | |
4de0686f JF |
249 | CYArgument *arguments_; |
250 | ||
cacd1a88 | 251 | CYSend(CYArgument *arguments) : |
4de0686f JF |
252 | arguments_(arguments) |
253 | { | |
254 | } | |
255 | ||
256 | CYPrecedence(0) | |
257 | ||
cacd1a88 JF |
258 | virtual void Output(CYOutput &out, CYFlags flags) const; |
259 | }; | |
260 | ||
261 | struct CYSendDirect : | |
262 | CYSend | |
263 | { | |
264 | CYExpression *self_; | |
265 | ||
266 | CYSendDirect(CYExpression *self, CYArgument *arguments) : | |
267 | CYSend(arguments), | |
268 | self_(self) | |
269 | { | |
270 | } | |
271 | ||
272 | virtual CYExpression *Replace(CYContext &context); | |
273 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
274 | }; | |
275 | ||
276 | struct CYSendSuper : | |
277 | CYSend | |
278 | { | |
279 | CYSendSuper(CYArgument *arguments) : | |
280 | CYSend(arguments) | |
281 | { | |
282 | } | |
283 | ||
4de0686f JF |
284 | virtual CYExpression *Replace(CYContext &context); |
285 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
286 | }; | |
287 | ||
3c1c3635 | 288 | #endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/ |