]> git.saurik.com Git - cycript.git/blame_incremental - ObjectiveC/Syntax.hpp
Add @encode() support and use its grammar for types.
[cycript.git] / ObjectiveC / Syntax.hpp
... / ...
CommitLineData
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
27struct CYEncodedPart :
28 CYNext<CYEncodedPart>
29{
30 const char *name_;
31 CYArgument *arguments_;
32
33 CYEncodedPart(CYEncodedPart *next, const char *name, CYArgument *arguments = NULL) :
34 CYNext<CYEncodedPart>(next),
35 name_(name),
36 arguments_(arguments)
37 {
38 }
39
40 CYExpression *Replace(CYContext &context, CYExpression *base);
41};
42
43struct CYEncodedType :
44 CYExpression
45{
46 CYExpression *base_;
47 CYEncodedPart *parts_;
48
49 CYEncodedType(CYExpression *base, CYEncodedPart *parts = NULL) :
50 base_(base),
51 parts_(parts)
52 {
53 }
54
55 CYPrecedence(1)
56
57 virtual CYExpression *Replace(CYContext &context);
58 virtual void Output(CYOutput &out, CYFlags flags) const;
59};
60
61struct CYBox :
62 CYExpression
63{
64 CYExpression *value_;
65
66 CYBox(CYExpression *value) :
67 value_(value)
68 {
69 }
70
71 CYPrecedence(1)
72
73 virtual CYExpression *Replace(CYContext &context);
74 virtual void Output(CYOutput &out, CYFlags flags) const;
75};
76
77struct CYSelectorPart :
78 CYNext<CYSelectorPart>,
79 CYThing
80{
81 CYWord *name_;
82 bool value_;
83
84 CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next = NULL) :
85 CYNext<CYSelectorPart>(next),
86 name_(name),
87 value_(value)
88 {
89 }
90
91 CYString *Replace(CYContext &context);
92 virtual void Output(CYOutput &out) const;
93};
94
95struct CYSelector :
96 CYLiteral
97{
98 CYSelectorPart *name_;
99
100 CYSelector(CYSelectorPart *name) :
101 name_(name)
102 {
103 }
104
105 CYPrecedence(1)
106
107 virtual CYExpression *Replace(CYContext &context);
108 virtual void Output(CYOutput &out, CYFlags flags) const;
109};
110
111struct CYField :
112 CYNext<CYField>
113{
114 CYExpression *type_;
115 CYIdentifier *name_;
116
117 CYField(CYExpression *type, CYIdentifier *name, CYField *next = NULL) :
118 CYNext<CYField>(next),
119 type_(type),
120 name_(name)
121 {
122 }
123
124 CYStatement *Replace(CYContext &context) const;
125 void Output(CYOutput &out) const;
126};
127
128struct CYMessageParameter :
129 CYNext<CYMessageParameter>
130{
131 CYWord *tag_;
132 CYExpression *type_;
133 CYIdentifier *name_;
134
135 CYMessageParameter(CYWord *tag, CYExpression *type, CYIdentifier *name) :
136 tag_(tag),
137 type_(type),
138 name_(name)
139 {
140 }
141
142 CYFunctionParameter *Parameters(CYContext &context) const;
143 CYSelector *Selector(CYContext &context) const;
144 CYSelectorPart *SelectorPart(CYContext &context) const;
145 CYExpression *TypeSignature(CYContext &context) const;
146};
147
148struct CYMessage :
149 CYNext<CYMessage>
150{
151 bool instance_;
152 CYExpression *type_;
153 CYMessageParameter *parameters_;
154 CYBlock code_;
155
156 CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *statements) :
157 instance_(instance),
158 type_(type),
159 parameters_(parameter),
160 code_(statements)
161 {
162 }
163
164 CYStatement *Replace(CYContext &context, bool replace) const;
165 void Output(CYOutput &out, bool replace) const;
166
167 CYExpression *TypeSignature(CYContext &context) const;
168};
169
170struct CYProtocol :
171 CYNext<CYProtocol>,
172 CYThing
173{
174 CYExpression *name_;
175
176 CYProtocol(CYExpression *name, CYProtocol *next = NULL) :
177 CYNext<CYProtocol>(next),
178 name_(name)
179 {
180 }
181
182 CYStatement *Replace(CYContext &context) const;
183 void Output(CYOutput &out) const;
184};
185
186struct CYImport :
187 CYStatement
188{
189 virtual CYStatement *Replace(CYContext &context);
190 virtual void Output(CYOutput &out, CYFlags flags) const;
191};
192
193struct CYClass {
194 CYClassName *name_;
195 CYExpression *super_;
196 CYProtocol *protocols_;
197 CYField *fields_;
198 CYMessage *messages_;
199
200 CYClass(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
201 name_(name),
202 super_(super),
203 protocols_(protocols),
204 fields_(fields),
205 messages_(messages)
206 {
207 }
208
209 virtual ~CYClass() {
210 }
211
212 CYExpression *Replace_(CYContext &context);
213 virtual void Output(CYOutput &out, CYFlags flags) const;
214};
215
216struct CYClassExpression :
217 CYClass,
218 CYExpression
219{
220 CYClassExpression(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
221 CYClass(name, super, protocols, fields, messages)
222 {
223 }
224
225 CYPrecedence(0)
226
227 virtual CYExpression *Replace(CYContext &context);
228 virtual void Output(CYOutput &out, CYFlags flags) const;
229};
230
231struct CYClassStatement :
232 CYClass,
233 CYStatement
234{
235 CYClassStatement(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
236 CYClass(name, super, protocols, fields, messages)
237 {
238 }
239
240 virtual CYStatement *Replace(CYContext &context);
241 virtual void Output(CYOutput &out, CYFlags flags) const;
242};
243
244struct CYCategory :
245 CYStatement
246{
247 CYClassName *name_;
248 CYMessage *messages_;
249
250 CYCategory(CYClassName *name, CYMessage *messages) :
251 name_(name),
252 messages_(messages)
253 {
254 }
255
256 virtual CYStatement *Replace(CYContext &context);
257 virtual void Output(CYOutput &out, CYFlags flags) const;
258};
259
260struct CYSend :
261 CYExpression
262{
263 CYArgument *arguments_;
264
265 CYSend(CYArgument *arguments) :
266 arguments_(arguments)
267 {
268 }
269
270 CYPrecedence(0)
271
272 virtual void Output(CYOutput &out, CYFlags flags) const;
273};
274
275struct CYSendDirect :
276 CYSend
277{
278 CYExpression *self_;
279
280 CYSendDirect(CYExpression *self, CYArgument *arguments) :
281 CYSend(arguments),
282 self_(self)
283 {
284 }
285
286 virtual CYExpression *Replace(CYContext &context);
287 virtual void Output(CYOutput &out, CYFlags flags) const;
288};
289
290struct CYSendSuper :
291 CYSend
292{
293 CYSendSuper(CYArgument *arguments) :
294 CYSend(arguments)
295 {
296 }
297
298 virtual CYExpression *Replace(CYContext &context);
299 virtual void Output(CYOutput &out, CYFlags flags) const;
300};
301
302#endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/