]> git.saurik.com Git - cycript.git/blob - ObjectiveC/Syntax.hpp
Fix Objective-C dictionary/array literal lowering.
[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) :
181 name_(name),
182 type_(type)
183 {
184 }
185
186 CYFunctionParameter *Parameters(CYContext &context) const;
187 CYSelector *Selector(CYContext &context) const;
188 CYSelectorPart *SelectorPart(CYContext &context) const;
189 CYExpression *TypeSignature(CYContext &context) const;
190 };
191
192 struct CYMessage :
193 CYNext<CYMessage>
194 {
195 bool instance_;
196 CYTypedIdentifier *type_;
197 CYMessageParameter *parameters_;
198 CYBlock code_;
199
200 CYMessage(bool instance, CYTypedIdentifier *type, CYMessageParameter *parameters, CYStatement *code) :
201 instance_(instance),
202 type_(type),
203 parameters_(parameters),
204 code_(code)
205 {
206 }
207
208 CYStatement *Replace(CYContext &context, bool replace) const;
209 void Output(CYOutput &out) const;
210
211 CYExpression *TypeSignature(CYContext &context) const;
212 };
213
214 struct CYProtocol :
215 CYNext<CYProtocol>,
216 CYThing
217 {
218 CYExpression *name_;
219
220 CYProtocol(CYExpression *name, CYProtocol *next = NULL) :
221 CYNext<CYProtocol>(next),
222 name_(name)
223 {
224 }
225
226 CYStatement *Replace(CYContext &context) const;
227 void Output(CYOutput &out) const;
228 };
229
230 struct CYImplementation :
231 CYStatement
232 {
233 CYIdentifier *name_;
234 CYExpression *extends_;
235 CYProtocol *protocols_;
236 CYImplementationField *fields_;
237 CYMessage *messages_;
238
239 CYImplementation(CYIdentifier *name, CYExpression *extends, CYProtocol *protocols, CYImplementationField *fields, CYMessage *messages) :
240 name_(name),
241 extends_(extends),
242 protocols_(protocols),
243 fields_(fields),
244 messages_(messages)
245 {
246 }
247
248 CYCompact(None)
249
250 virtual CYStatement *Replace(CYContext &context);
251 virtual void Output(CYOutput &out, CYFlags flags) const;
252 };
253
254 struct CYCategory :
255 CYStatement
256 {
257 CYIdentifier *name_;
258 CYMessage *messages_;
259
260 CYCategory(CYIdentifier *name, CYMessage *messages) :
261 name_(name),
262 messages_(messages)
263 {
264 }
265
266 CYCompact(None)
267
268 virtual CYStatement *Replace(CYContext &context);
269 virtual void Output(CYOutput &out, CYFlags flags) const;
270 };
271
272 struct CYSend :
273 CYTarget
274 {
275 CYArgument *arguments_;
276
277 CYSend(CYArgument *arguments) :
278 arguments_(arguments)
279 {
280 }
281
282 CYPrecedence(0)
283
284 virtual void Output(CYOutput &out, CYFlags flags) const;
285 };
286
287 struct CYSendDirect :
288 CYSend
289 {
290 CYExpression *self_;
291
292 CYSendDirect(CYExpression *self, CYArgument *arguments) :
293 CYSend(arguments),
294 self_(self)
295 {
296 }
297
298 virtual CYTarget *Replace(CYContext &context);
299 virtual void Output(CYOutput &out, CYFlags flags) const;
300 };
301
302 struct CYSendSuper :
303 CYSend
304 {
305 CYSendSuper(CYArgument *arguments) :
306 CYSend(arguments)
307 {
308 }
309
310 virtual CYTarget *Replace(CYContext &context);
311 virtual void Output(CYOutput &out, CYFlags flags) const;
312 };
313
314 #endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/