]> git.saurik.com Git - cycript.git/blob - ObjectiveC/Syntax.hpp
Move x.type() to typeid(x) and implement variadic.
[cycript.git] / ObjectiveC / Syntax.hpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU Affero General Public License, Version 3 {{{ */
6 /*
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. 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 "../Syntax.hpp"
26
27 struct CYInstanceLiteral :
28 CYTarget
29 {
30 CYNumber *number_;
31
32 CYInstanceLiteral(CYNumber *number) :
33 number_(number)
34 {
35 }
36
37 CYPrecedence(1)
38
39 virtual CYTarget *Replace(CYContext &context);
40 virtual void Output(CYOutput &out, CYFlags flags) const;
41 };
42
43 struct CYObjCBlock :
44 CYTarget
45 {
46 CYTypedIdentifier *typed_;
47 CYTypedParameter *parameters_;
48 CYStatement *code_;
49
50 CYObjCBlock(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *code) :
51 typed_(typed),
52 parameters_(parameters),
53 code_(code)
54 {
55 }
56
57 CYPrecedence(1)
58
59 virtual CYTarget *Replace(CYContext &context);
60 virtual void Output(CYOutput &out, CYFlags flags) const;
61 };
62
63 struct CYBox :
64 CYTarget
65 {
66 CYExpression *value_;
67
68 CYBox(CYExpression *value) :
69 value_(value)
70 {
71 }
72
73 CYPrecedence(1)
74
75 virtual CYTarget *Replace(CYContext &context);
76 virtual void Output(CYOutput &out, CYFlags flags) const;
77 };
78
79 struct CYObjCArray :
80 CYTarget
81 {
82 CYElement *elements_;
83
84 CYObjCArray(CYElement *elements = NULL) :
85 elements_(elements)
86 {
87 }
88
89 CYPrecedence(0)
90
91 virtual CYTarget *Replace(CYContext &context);
92 virtual void Output(CYOutput &out, CYFlags flags) const;
93 };
94
95 struct CYObjCKeyValue :
96 CYNext<CYObjCKeyValue>
97 {
98 CYExpression *key_;
99 CYExpression *value_;
100
101 CYObjCKeyValue(CYExpression *key, CYExpression *value, CYObjCKeyValue *next) :
102 CYNext<CYObjCKeyValue>(next),
103 key_(key),
104 value_(value)
105 {
106 }
107 };
108
109 struct CYObjCDictionary :
110 CYTarget
111 {
112 CYObjCKeyValue *pairs_;
113
114 CYObjCDictionary(CYObjCKeyValue *pairs) :
115 pairs_(pairs)
116 {
117 }
118
119 CYPrecedence(0)
120
121 virtual CYTarget *Replace(CYContext &context);
122 virtual void Output(CYOutput &out, CYFlags flags) const;
123 };
124
125 struct CYSelectorPart :
126 CYNext<CYSelectorPart>,
127 CYThing
128 {
129 CYWord *name_;
130 bool value_;
131
132 CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next = NULL) :
133 CYNext<CYSelectorPart>(next),
134 name_(name),
135 value_(value)
136 {
137 }
138
139 CYString *Replace(CYContext &context);
140 virtual void Output(CYOutput &out) const;
141 };
142
143 struct CYSelector :
144 CYLiteral
145 {
146 CYSelectorPart *parts_;
147
148 CYSelector(CYSelectorPart *parts) :
149 parts_(parts)
150 {
151 }
152
153 CYPrecedence(1)
154
155 virtual CYTarget *Replace(CYContext &context);
156 virtual void Output(CYOutput &out, CYFlags flags) const;
157 };
158
159 struct CYImplementationField :
160 CYNext<CYImplementationField>
161 {
162 CYTypedIdentifier *typed_;
163
164 CYImplementationField(CYTypedIdentifier *typed, CYImplementationField *next = NULL) :
165 CYNext<CYImplementationField>(next),
166 typed_(typed)
167 {
168 }
169
170 CYStatement *Replace(CYContext &context) const;
171 void Output(CYOutput &out) const;
172 };
173
174 struct CYMessageParameter :
175 CYNext<CYMessageParameter>
176 {
177 CYWord *name_;
178 CYTypedIdentifier *type_;
179
180 CYMessageParameter(CYWord *name, CYTypedIdentifier *type, CYMessageParameter *next = NULL) :
181 CYNext<CYMessageParameter>(next),
182 name_(name),
183 type_(type)
184 {
185 }
186
187 CYFunctionParameter *Parameters(CYContext &context) const;
188 CYSelector *Selector(CYContext &context) const;
189 CYSelectorPart *SelectorPart(CYContext &context) const;
190 CYExpression *TypeSignature(CYContext &context) const;
191 };
192
193 struct CYMessage :
194 CYNext<CYMessage>
195 {
196 bool instance_;
197 CYTypedIdentifier *type_;
198 CYMessageParameter *parameters_;
199 CYBlock code_;
200
201 CYMessage(bool instance, CYTypedIdentifier *type, CYMessageParameter *parameters, CYStatement *code) :
202 instance_(instance),
203 type_(type),
204 parameters_(parameters),
205 code_(code)
206 {
207 }
208
209 CYStatement *Replace(CYContext &context, bool replace) const;
210 void Output(CYOutput &out) const;
211
212 CYExpression *TypeSignature(CYContext &context) const;
213 };
214
215 struct CYProtocol :
216 CYNext<CYProtocol>,
217 CYThing
218 {
219 CYExpression *name_;
220
221 CYProtocol(CYExpression *name, CYProtocol *next = NULL) :
222 CYNext<CYProtocol>(next),
223 name_(name)
224 {
225 }
226
227 CYStatement *Replace(CYContext &context) const;
228 void Output(CYOutput &out) const;
229 };
230
231 struct CYImplementation :
232 CYStatement
233 {
234 CYIdentifier *name_;
235 CYExpression *extends_;
236 CYProtocol *protocols_;
237 CYImplementationField *fields_;
238 CYMessage *messages_;
239
240 CYImplementation(CYIdentifier *name, CYExpression *extends, CYProtocol *protocols, CYImplementationField *fields, CYMessage *messages) :
241 name_(name),
242 extends_(extends),
243 protocols_(protocols),
244 fields_(fields),
245 messages_(messages)
246 {
247 }
248
249 CYCompact(None)
250
251 virtual CYStatement *Replace(CYContext &context);
252 virtual void Output(CYOutput &out, CYFlags flags) const;
253 };
254
255 struct CYCategory :
256 CYStatement
257 {
258 CYIdentifier *name_;
259 CYMessage *messages_;
260
261 CYCategory(CYIdentifier *name, CYMessage *messages) :
262 name_(name),
263 messages_(messages)
264 {
265 }
266
267 CYCompact(None)
268
269 virtual CYStatement *Replace(CYContext &context);
270 virtual void Output(CYOutput &out, CYFlags flags) const;
271 };
272
273 struct CYSend :
274 CYTarget
275 {
276 CYArgument *arguments_;
277
278 CYSend(CYArgument *arguments) :
279 arguments_(arguments)
280 {
281 }
282
283 CYPrecedence(0)
284
285 virtual void Output(CYOutput &out, CYFlags flags) const;
286 };
287
288 struct CYSendDirect :
289 CYSend
290 {
291 CYExpression *self_;
292
293 CYSendDirect(CYExpression *self, CYArgument *arguments) :
294 CYSend(arguments),
295 self_(self)
296 {
297 }
298
299 virtual CYTarget *Replace(CYContext &context);
300 virtual void Output(CYOutput &out, CYFlags flags) const;
301 };
302
303 struct CYSendSuper :
304 CYSend
305 {
306 CYSendSuper(CYArgument *arguments) :
307 CYSend(arguments)
308 {
309 }
310
311 virtual CYTarget *Replace(CYContext &context);
312 virtual void Output(CYOutput &out, CYFlags flags) const;
313 };
314
315 #endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/