]>
Commit | Line | Data |
---|---|---|
b3378a02 | 1 | /* Cycript - Optimizing JavaScript Compiler/Runtime |
8d7447c1 | 2 | * Copyright (C) 2009-2012 Jay Freeman (saurik) |
4644480a JF |
3 | */ |
4 | ||
b3378a02 | 5 | /* GNU Lesser General Public License, Version 3 {{{ */ |
4644480a | 6 | /* |
b3378a02 JF |
7 | * Cycript is free software: you can redistribute it and/or modify it under |
8 | * the terms of the GNU Lesser General Public License as published by the | |
9 | * Free Software Foundation, either version 3 of the License, or (at your | |
10 | * option) any later version. | |
4644480a | 11 | * |
b3378a02 JF |
12 | * Cycript is distributed in the hope that it will be useful, but WITHOUT |
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public | |
15 | * License for more details. | |
4644480a | 16 | * |
b3378a02 JF |
17 | * You should have received a copy of the GNU Lesser General Public License |
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 | ||
561e7f1c JF |
27 | struct CYTypeModifier : |
28 | CYNext<CYTypeModifier> | |
46f4f308 | 29 | { |
561e7f1c JF |
30 | CYTypeModifier(CYTypeModifier *next) : |
31 | CYNext<CYTypeModifier>(next) | |
32 | { | |
33 | } | |
34 | ||
35 | virtual CYExpression *Replace(CYContext &context) = 0; | |
36 | }; | |
37 | ||
38 | struct CYTypeArrayOf : | |
39 | CYTypeModifier | |
40 | { | |
41 | size_t size_; | |
42 | ||
43 | CYTypeArrayOf(size_t size, CYTypeModifier *next = NULL) : | |
44 | CYTypeModifier(next), | |
45 | size_(size) | |
46 | { | |
47 | } | |
48 | ||
49 | CYPrecedence(2) | |
50 | ||
51 | virtual CYExpression *Replace(CYContext &context); | |
52 | }; | |
53 | ||
54 | struct CYTypeConstant : | |
55 | CYTypeModifier | |
56 | { | |
57 | CYTypeConstant(CYTypeModifier *next = NULL) : | |
58 | CYTypeModifier(next) | |
59 | { | |
60 | } | |
61 | ||
62 | CYPrecedence(3) | |
63 | ||
64 | virtual CYExpression *Replace(CYContext &context); | |
65 | }; | |
66 | ||
67 | struct CYTypePointerTo : | |
68 | CYTypeModifier | |
69 | { | |
70 | CYTypePointerTo(CYTypeModifier *next = NULL) : | |
71 | CYTypeModifier(next) | |
72 | { | |
73 | } | |
74 | ||
75 | CYPrecedence(3) | |
76 | ||
77 | virtual CYExpression *Replace(CYContext &context); | |
78 | }; | |
79 | ||
80 | struct CYTypeVariable : | |
81 | CYTypeModifier | |
82 | { | |
83 | CYExpression *expression_; | |
46f4f308 | 84 | |
561e7f1c JF |
85 | CYTypeVariable(CYExpression *expression) : |
86 | CYTypeModifier(NULL), | |
87 | expression_(expression) | |
46f4f308 JF |
88 | { |
89 | } | |
90 | ||
561e7f1c JF |
91 | CYPrecedence(1) |
92 | ||
93 | virtual CYExpression *Replace(CYContext &context); | |
94 | }; | |
95 | ||
96 | struct CYTypedIdentifier : | |
97 | CYNext<CYTypedIdentifier> | |
98 | { | |
99 | CYIdentifier *identifier_; | |
100 | CYTypeModifier *type_; | |
101 | ||
102 | CYTypedIdentifier(CYIdentifier *identifier) : | |
103 | identifier_(identifier), | |
104 | type_(NULL) | |
105 | { | |
106 | } | |
46f4f308 JF |
107 | }; |
108 | ||
109 | struct CYEncodedType : | |
110 | CYExpression | |
111 | { | |
561e7f1c | 112 | CYTypeModifier *type_; |
46f4f308 | 113 | |
561e7f1c JF |
114 | CYEncodedType(CYTypeModifier *type) : |
115 | type_(type) | |
46f4f308 JF |
116 | { |
117 | } | |
118 | ||
119 | CYPrecedence(1) | |
120 | ||
121 | virtual CYExpression *Replace(CYContext &context); | |
122 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
123 | }; | |
124 | ||
f2f0d1d1 JF |
125 | struct CYBox : |
126 | CYExpression | |
127 | { | |
128 | CYExpression *value_; | |
129 | ||
130 | CYBox(CYExpression *value) : | |
131 | value_(value) | |
132 | { | |
133 | } | |
134 | ||
135 | CYPrecedence(1) | |
136 | ||
137 | virtual CYExpression *Replace(CYContext &context); | |
138 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
139 | }; | |
140 | ||
4de0686f JF |
141 | struct CYSelectorPart : |
142 | CYNext<CYSelectorPart>, | |
143 | CYThing | |
144 | { | |
145 | CYWord *name_; | |
146 | bool value_; | |
147 | ||
2385c806 | 148 | CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next = NULL) : |
4de0686f JF |
149 | CYNext<CYSelectorPart>(next), |
150 | name_(name), | |
151 | value_(value) | |
152 | { | |
153 | } | |
154 | ||
155 | CYString *Replace(CYContext &context); | |
156 | virtual void Output(CYOutput &out) const; | |
157 | }; | |
158 | ||
159 | struct CYSelector : | |
160 | CYLiteral | |
161 | { | |
162 | CYSelectorPart *name_; | |
163 | ||
164 | CYSelector(CYSelectorPart *name) : | |
165 | name_(name) | |
166 | { | |
167 | } | |
168 | ||
169 | CYPrecedence(1) | |
170 | ||
171 | virtual CYExpression *Replace(CYContext &context); | |
172 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
173 | }; | |
174 | ||
175 | struct CYField : | |
176 | CYNext<CYField> | |
177 | { | |
cfd73c6d JF |
178 | CYExpression *type_; |
179 | CYIdentifier *name_; | |
180 | ||
181 | CYField(CYExpression *type, CYIdentifier *name, CYField *next = NULL) : | |
182 | CYNext<CYField>(next), | |
183 | type_(type), | |
184 | name_(name) | |
185 | { | |
186 | } | |
187 | ||
4de0686f JF |
188 | CYStatement *Replace(CYContext &context) const; |
189 | void Output(CYOutput &out) const; | |
190 | }; | |
191 | ||
192 | struct CYMessageParameter : | |
193 | CYNext<CYMessageParameter> | |
194 | { | |
195 | CYWord *tag_; | |
196 | CYExpression *type_; | |
197 | CYIdentifier *name_; | |
198 | ||
199 | CYMessageParameter(CYWord *tag, CYExpression *type, CYIdentifier *name) : | |
200 | tag_(tag), | |
201 | type_(type), | |
202 | name_(name) | |
203 | { | |
204 | } | |
205 | ||
206 | CYFunctionParameter *Parameters(CYContext &context) const; | |
207 | CYSelector *Selector(CYContext &context) const; | |
208 | CYSelectorPart *SelectorPart(CYContext &context) const; | |
9a7c375c | 209 | CYExpression *TypeSignature(CYContext &context) const; |
4de0686f JF |
210 | }; |
211 | ||
212 | struct CYMessage : | |
213 | CYNext<CYMessage> | |
214 | { | |
215 | bool instance_; | |
216 | CYExpression *type_; | |
217 | CYMessageParameter *parameters_; | |
4644480a | 218 | CYBlock code_; |
4de0686f JF |
219 | |
220 | CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *statements) : | |
221 | instance_(instance), | |
222 | type_(type), | |
223 | parameters_(parameter), | |
4644480a | 224 | code_(statements) |
4de0686f JF |
225 | { |
226 | } | |
227 | ||
228 | CYStatement *Replace(CYContext &context, bool replace) const; | |
229 | void Output(CYOutput &out, bool replace) const; | |
9a7c375c JF |
230 | |
231 | CYExpression *TypeSignature(CYContext &context) const; | |
4de0686f JF |
232 | }; |
233 | ||
64b8d29f JF |
234 | struct CYProtocol : |
235 | CYNext<CYProtocol>, | |
236 | CYThing | |
237 | { | |
238 | CYExpression *name_; | |
239 | ||
240 | CYProtocol(CYExpression *name, CYProtocol *next = NULL) : | |
241 | CYNext<CYProtocol>(next), | |
242 | name_(name) | |
243 | { | |
244 | } | |
245 | ||
246 | CYStatement *Replace(CYContext &context) const; | |
247 | void Output(CYOutput &out) const; | |
248 | }; | |
249 | ||
1ba6903e JF |
250 | struct CYImport : |
251 | CYStatement | |
252 | { | |
253 | virtual CYStatement *Replace(CYContext &context); | |
254 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
255 | }; | |
256 | ||
4de0686f JF |
257 | struct CYClass { |
258 | CYClassName *name_; | |
259 | CYExpression *super_; | |
64b8d29f | 260 | CYProtocol *protocols_; |
4de0686f JF |
261 | CYField *fields_; |
262 | CYMessage *messages_; | |
263 | ||
64b8d29f | 264 | CYClass(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) : |
4de0686f JF |
265 | name_(name), |
266 | super_(super), | |
64b8d29f | 267 | protocols_(protocols), |
4de0686f JF |
268 | fields_(fields), |
269 | messages_(messages) | |
270 | { | |
271 | } | |
272 | ||
7c6c5b0a JF |
273 | virtual ~CYClass() { |
274 | } | |
275 | ||
4de0686f JF |
276 | CYExpression *Replace_(CYContext &context); |
277 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
278 | }; | |
279 | ||
280 | struct CYClassExpression : | |
281 | CYClass, | |
282 | CYExpression | |
283 | { | |
64b8d29f JF |
284 | CYClassExpression(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) : |
285 | CYClass(name, super, protocols, fields, messages) | |
4de0686f JF |
286 | { |
287 | } | |
288 | ||
289 | CYPrecedence(0) | |
290 | ||
291 | virtual CYExpression *Replace(CYContext &context); | |
292 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
293 | }; | |
294 | ||
295 | struct CYClassStatement : | |
296 | CYClass, | |
297 | CYStatement | |
298 | { | |
64b8d29f JF |
299 | CYClassStatement(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) : |
300 | CYClass(name, super, protocols, fields, messages) | |
4de0686f JF |
301 | { |
302 | } | |
303 | ||
304 | virtual CYStatement *Replace(CYContext &context); | |
305 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
306 | }; | |
307 | ||
308 | struct CYCategory : | |
309 | CYStatement | |
310 | { | |
311 | CYClassName *name_; | |
312 | CYMessage *messages_; | |
313 | ||
314 | CYCategory(CYClassName *name, CYMessage *messages) : | |
315 | name_(name), | |
316 | messages_(messages) | |
317 | { | |
318 | } | |
319 | ||
320 | virtual CYStatement *Replace(CYContext &context); | |
321 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
322 | }; | |
323 | ||
324 | struct CYSend : | |
325 | CYExpression | |
326 | { | |
4de0686f JF |
327 | CYArgument *arguments_; |
328 | ||
cacd1a88 | 329 | CYSend(CYArgument *arguments) : |
4de0686f JF |
330 | arguments_(arguments) |
331 | { | |
332 | } | |
333 | ||
334 | CYPrecedence(0) | |
335 | ||
cacd1a88 JF |
336 | virtual void Output(CYOutput &out, CYFlags flags) const; |
337 | }; | |
338 | ||
339 | struct CYSendDirect : | |
340 | CYSend | |
341 | { | |
342 | CYExpression *self_; | |
343 | ||
344 | CYSendDirect(CYExpression *self, CYArgument *arguments) : | |
345 | CYSend(arguments), | |
346 | self_(self) | |
347 | { | |
348 | } | |
349 | ||
350 | virtual CYExpression *Replace(CYContext &context); | |
351 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
352 | }; | |
353 | ||
354 | struct CYSendSuper : | |
355 | CYSend | |
356 | { | |
357 | CYSendSuper(CYArgument *arguments) : | |
358 | CYSend(arguments) | |
359 | { | |
360 | } | |
361 | ||
4de0686f JF |
362 | virtual CYExpression *Replace(CYContext &context); |
363 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
364 | }; | |
365 | ||
3c1c3635 | 366 | #endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/ |