]> git.saurik.com Git - cycript.git/blob - ObjectiveC/Syntax.hpp
Maintain type flags in Type subclass Copy() logic.
[cycript.git] / ObjectiveC / Syntax.hpp
1 /* Cycript - The Truly Universal Scripting Language
2 * Copyright (C) 2009-2016 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 CYType *typed_;
47 CYTypedParameter *parameters_;
48 CYStatement *code_;
49
50 CYObjCBlock(CYType *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 CYType *type_;
163 CYPropertyName *name_;
164
165 CYImplementationField(CYType *type, CYPropertyName *name, CYImplementationField *next = NULL) :
166 CYNext<CYImplementationField>(next),
167 type_(type),
168 name_(name)
169 {
170 }
171
172 CYStatement *Replace(CYContext &context) const;
173 void Output(CYOutput &out) const;
174 };
175
176 struct CYMessageParameter :
177 CYNext<CYMessageParameter>
178 {
179 CYWord *name_;
180 CYType *type_;
181 CYIdentifier *identifier_;
182
183 CYMessageParameter(CYWord *name, CYType *type = NULL, CYIdentifier *identifier = NULL, CYMessageParameter *next = NULL) :
184 CYNext<CYMessageParameter>(next),
185 name_(name),
186 type_(type),
187 identifier_(identifier)
188 {
189 }
190
191 CYFunctionParameter *Parameters(CYContext &context) const;
192 CYSelector *Selector(CYContext &context) const;
193 CYSelectorPart *SelectorPart(CYContext &context) const;
194 CYExpression *TypeSignature(CYContext &context) const;
195 };
196
197 struct CYMessage :
198 CYNext<CYMessage>
199 {
200 bool instance_;
201 CYType *type_;
202 CYMessageParameter *parameters_;
203 CYBlock code_;
204
205 CYMessage(bool instance, CYType *type, CYMessageParameter *parameters, CYStatement *code) :
206 instance_(instance),
207 type_(type),
208 parameters_(parameters),
209 code_(code)
210 {
211 }
212
213 CYStatement *Replace(CYContext &context, bool replace) const;
214 void Output(CYOutput &out) const;
215
216 CYExpression *TypeSignature(CYContext &context) const;
217 };
218
219 struct CYProtocol :
220 CYNext<CYProtocol>,
221 CYThing
222 {
223 CYExpression *name_;
224
225 CYProtocol(CYExpression *name, CYProtocol *next = NULL) :
226 CYNext<CYProtocol>(next),
227 name_(name)
228 {
229 }
230
231 CYStatement *Replace(CYContext &context) const;
232 void Output(CYOutput &out) const;
233 };
234
235 struct CYImplementation :
236 CYStatement
237 {
238 CYIdentifier *name_;
239 CYExpression *extends_;
240 CYProtocol *protocols_;
241 CYImplementationField *fields_;
242 CYMessage *messages_;
243
244 CYImplementation(CYIdentifier *name, CYExpression *extends, CYProtocol *protocols, CYImplementationField *fields, CYMessage *messages) :
245 name_(name),
246 extends_(extends),
247 protocols_(protocols),
248 fields_(fields),
249 messages_(messages)
250 {
251 }
252
253 CYCompact(None)
254
255 virtual CYStatement *Replace(CYContext &context);
256 virtual void Output(CYOutput &out, CYFlags flags) const;
257 };
258
259 struct CYCategory :
260 CYStatement
261 {
262 CYIdentifier *name_;
263 CYMessage *messages_;
264
265 CYCategory(CYIdentifier *name, CYMessage *messages) :
266 name_(name),
267 messages_(messages)
268 {
269 }
270
271 CYCompact(None)
272
273 virtual CYStatement *Replace(CYContext &context);
274 virtual void Output(CYOutput &out, CYFlags flags) const;
275 };
276
277 struct CYSend :
278 CYTarget
279 {
280 CYArgument *arguments_;
281
282 CYSend(CYArgument *arguments) :
283 arguments_(arguments)
284 {
285 }
286
287 CYPrecedence(0)
288
289 virtual void Output(CYOutput &out, CYFlags flags) const;
290 };
291
292 struct CYSendDirect :
293 CYSend
294 {
295 CYExpression *self_;
296
297 CYSendDirect(CYExpression *self, CYArgument *arguments) :
298 CYSend(arguments),
299 self_(self)
300 {
301 }
302
303 virtual CYTarget *Replace(CYContext &context);
304 virtual void Output(CYOutput &out, CYFlags flags) const;
305 };
306
307 struct CYSendSuper :
308 CYSend
309 {
310 CYSendSuper(CYArgument *arguments) :
311 CYSend(arguments)
312 {
313 }
314
315 virtual CYTarget *Replace(CYContext &context);
316 virtual void Output(CYOutput &out, CYFlags flags) const;
317 };
318
319 #endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/