]> git.saurik.com Git - cycript.git/blob - ObjectiveC/Syntax.hpp
Isolate linkage of libreadline and libtermcap.
[cycript.git] / ObjectiveC / Syntax.hpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2012 Jay Freeman (saurik)
3 */
4
5 /* GNU Lesser General Public License, Version 3 {{{ */
6 /*
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.
11 *
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.
16 *
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 **/
20 /* }}} */
21
22 #ifndef CYCRIPT_OBJECTIVEC_SYNTAX_HPP
23 #define CYCRIPT_OBJECTIVEC_SYNTAX_HPP
24
25 #include "Parser.hpp"
26
27 struct CYTypeModifier :
28 CYNext<CYTypeModifier>
29 {
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 CYExpression *size_;
42
43 CYTypeArrayOf(CYExpression *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_;
84
85 CYTypeVariable(CYExpression *expression) :
86 CYTypeModifier(NULL),
87 expression_(expression)
88 {
89 }
90
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 }
107 };
108
109 struct CYTypedParameter :
110 CYNext<CYTypedParameter>
111 {
112 CYTypedIdentifier *typed_;
113
114 CYTypedParameter(CYTypedIdentifier *typed, CYTypedParameter *next) :
115 CYNext<CYTypedParameter>(next),
116 typed_(typed)
117 {
118 }
119
120 CYFunctionParameter *Parameters(CYContext &context);
121 CYExpression *TypeSignature(CYContext &context, CYExpression *prefix);
122 };
123
124 struct CYObjCBlock :
125 CYExpression
126 {
127 CYTypeModifier *type_;
128 CYTypedParameter *parameters_;
129 CYStatement *statements_;
130
131 CYObjCBlock(CYTypeModifier *type, CYTypedParameter *parameters, CYStatement *statements) :
132 type_(type),
133 parameters_(parameters),
134 statements_(statements)
135 {
136 }
137
138 CYPrecedence(1)
139
140 virtual CYExpression *Replace(CYContext &context);
141 virtual void Output(CYOutput &out, CYFlags flags) const;
142 };
143
144 struct CYEncodedType :
145 CYExpression
146 {
147 CYTypeModifier *type_;
148
149 CYEncodedType(CYTypeModifier *type) :
150 type_(type)
151 {
152 }
153
154 CYPrecedence(1)
155
156 virtual CYExpression *Replace(CYContext &context);
157 virtual void Output(CYOutput &out, CYFlags flags) const;
158 };
159
160 struct CYBox :
161 CYExpression
162 {
163 CYExpression *value_;
164
165 CYBox(CYExpression *value) :
166 value_(value)
167 {
168 }
169
170 CYPrecedence(1)
171
172 virtual CYExpression *Replace(CYContext &context);
173 virtual void Output(CYOutput &out, CYFlags flags) const;
174 };
175
176 struct CYSelectorPart :
177 CYNext<CYSelectorPart>,
178 CYThing
179 {
180 CYWord *name_;
181 bool value_;
182
183 CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next = NULL) :
184 CYNext<CYSelectorPart>(next),
185 name_(name),
186 value_(value)
187 {
188 }
189
190 CYString *Replace(CYContext &context);
191 virtual void Output(CYOutput &out) const;
192 };
193
194 struct CYSelector :
195 CYLiteral
196 {
197 CYSelectorPart *name_;
198
199 CYSelector(CYSelectorPart *name) :
200 name_(name)
201 {
202 }
203
204 CYPrecedence(1)
205
206 virtual CYExpression *Replace(CYContext &context);
207 virtual void Output(CYOutput &out, CYFlags flags) const;
208 };
209
210 struct CYField :
211 CYNext<CYField>
212 {
213 CYExpression *type_;
214 CYIdentifier *name_;
215
216 CYField(CYExpression *type, CYIdentifier *name, CYField *next = NULL) :
217 CYNext<CYField>(next),
218 type_(type),
219 name_(name)
220 {
221 }
222
223 CYStatement *Replace(CYContext &context) const;
224 void Output(CYOutput &out) const;
225 };
226
227 struct CYMessageParameter :
228 CYNext<CYMessageParameter>
229 {
230 CYWord *tag_;
231 CYExpression *type_;
232 CYIdentifier *name_;
233
234 CYMessageParameter(CYWord *tag, CYExpression *type, CYIdentifier *name) :
235 tag_(tag),
236 type_(type),
237 name_(name)
238 {
239 }
240
241 CYFunctionParameter *Parameters(CYContext &context) const;
242 CYSelector *Selector(CYContext &context) const;
243 CYSelectorPart *SelectorPart(CYContext &context) const;
244 CYExpression *TypeSignature(CYContext &context) const;
245 };
246
247 struct CYMessage :
248 CYNext<CYMessage>
249 {
250 bool instance_;
251 CYExpression *type_;
252 CYMessageParameter *parameters_;
253 CYBlock code_;
254
255 CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *statements) :
256 instance_(instance),
257 type_(type),
258 parameters_(parameter),
259 code_(statements)
260 {
261 }
262
263 CYStatement *Replace(CYContext &context, bool replace) const;
264 void Output(CYOutput &out, bool replace) const;
265
266 CYExpression *TypeSignature(CYContext &context) const;
267 };
268
269 struct CYProtocol :
270 CYNext<CYProtocol>,
271 CYThing
272 {
273 CYExpression *name_;
274
275 CYProtocol(CYExpression *name, CYProtocol *next = NULL) :
276 CYNext<CYProtocol>(next),
277 name_(name)
278 {
279 }
280
281 CYStatement *Replace(CYContext &context) const;
282 void Output(CYOutput &out) const;
283 };
284
285 struct CYImport :
286 CYStatement
287 {
288 virtual CYStatement *Replace(CYContext &context);
289 virtual void Output(CYOutput &out, CYFlags flags) const;
290 };
291
292 struct CYClass {
293 CYClassName *name_;
294 CYExpression *super_;
295 CYProtocol *protocols_;
296 CYField *fields_;
297 CYMessage *messages_;
298
299 CYClass(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
300 name_(name),
301 super_(super),
302 protocols_(protocols),
303 fields_(fields),
304 messages_(messages)
305 {
306 }
307
308 virtual ~CYClass() {
309 }
310
311 CYExpression *Replace_(CYContext &context);
312 virtual void Output(CYOutput &out, CYFlags flags) const;
313 };
314
315 struct CYClassExpression :
316 CYClass,
317 CYExpression
318 {
319 CYClassExpression(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
320 CYClass(name, super, protocols, fields, messages)
321 {
322 }
323
324 CYPrecedence(0)
325
326 virtual CYExpression *Replace(CYContext &context);
327 virtual void Output(CYOutput &out, CYFlags flags) const;
328 };
329
330 struct CYClassStatement :
331 CYClass,
332 CYStatement
333 {
334 CYClassStatement(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
335 CYClass(name, super, protocols, fields, messages)
336 {
337 }
338
339 virtual CYStatement *Replace(CYContext &context);
340 virtual void Output(CYOutput &out, CYFlags flags) const;
341 };
342
343 struct CYCategory :
344 CYStatement
345 {
346 CYClassName *name_;
347 CYMessage *messages_;
348
349 CYCategory(CYClassName *name, CYMessage *messages) :
350 name_(name),
351 messages_(messages)
352 {
353 }
354
355 virtual CYStatement *Replace(CYContext &context);
356 virtual void Output(CYOutput &out, CYFlags flags) const;
357 };
358
359 struct CYSend :
360 CYExpression
361 {
362 CYArgument *arguments_;
363
364 CYSend(CYArgument *arguments) :
365 arguments_(arguments)
366 {
367 }
368
369 CYPrecedence(0)
370
371 virtual void Output(CYOutput &out, CYFlags flags) const;
372 };
373
374 struct CYSendDirect :
375 CYSend
376 {
377 CYExpression *self_;
378
379 CYSendDirect(CYExpression *self, CYArgument *arguments) :
380 CYSend(arguments),
381 self_(self)
382 {
383 }
384
385 virtual CYExpression *Replace(CYContext &context);
386 virtual void Output(CYOutput &out, CYFlags flags) const;
387 };
388
389 struct CYSendSuper :
390 CYSend
391 {
392 CYSendSuper(CYArgument *arguments) :
393 CYSend(arguments)
394 {
395 }
396
397 virtual CYExpression *Replace(CYContext &context);
398 virtual void Output(CYOutput &out, CYFlags flags) const;
399 };
400
401 #endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/