]> git.saurik.com Git - cycript.git/blame - ObjectiveC/Syntax.hpp
Allow Type objects to have associated identifiers.
[cycript.git] / ObjectiveC / Syntax.hpp
CommitLineData
b3378a02 1/* Cycript - Optimizing JavaScript Compiler/Runtime
8d7447c1 2 * Copyright (C) 2009-2012 Jay Freeman (saurik)
4644480a
JF
3*/
4
b3378a02 5/* GNU Lesser General Public License, Version 3 {{{ */
4644480a 6/*
b3378a02
JF
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.
4644480a 11 *
b3378a02
JF
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.
4644480a 16 *
b3378a02
JF
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**/
4644480a
JF
20/* }}} */
21
3c1c3635
JF
22#ifndef CYCRIPT_OBJECTIVEC_SYNTAX_HPP
23#define CYCRIPT_OBJECTIVEC_SYNTAX_HPP
4de0686f
JF
24
25#include "Parser.hpp"
26
46f4f308
JF
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
f2f0d1d1
JF
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
4de0686f
JF
77struct CYSelectorPart :
78 CYNext<CYSelectorPart>,
79 CYThing
80{
81 CYWord *name_;
82 bool value_;
83
2385c806 84 CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next = NULL) :
4de0686f
JF
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{
cfd73c6d
JF
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
4de0686f
JF
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;
9a7c375c 145 CYExpression *TypeSignature(CYContext &context) const;
4de0686f
JF
146};
147
148struct CYMessage :
149 CYNext<CYMessage>
150{
151 bool instance_;
152 CYExpression *type_;
153 CYMessageParameter *parameters_;
4644480a 154 CYBlock code_;
4de0686f
JF
155
156 CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *statements) :
157 instance_(instance),
158 type_(type),
159 parameters_(parameter),
4644480a 160 code_(statements)
4de0686f
JF
161 {
162 }
163
164 CYStatement *Replace(CYContext &context, bool replace) const;
165 void Output(CYOutput &out, bool replace) const;
9a7c375c
JF
166
167 CYExpression *TypeSignature(CYContext &context) const;
4de0686f
JF
168};
169
64b8d29f
JF
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
1ba6903e
JF
186struct CYImport :
187 CYStatement
188{
189 virtual CYStatement *Replace(CYContext &context);
190 virtual void Output(CYOutput &out, CYFlags flags) const;
191};
192
4de0686f
JF
193struct CYClass {
194 CYClassName *name_;
195 CYExpression *super_;
64b8d29f 196 CYProtocol *protocols_;
4de0686f
JF
197 CYField *fields_;
198 CYMessage *messages_;
199
64b8d29f 200 CYClass(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
4de0686f
JF
201 name_(name),
202 super_(super),
64b8d29f 203 protocols_(protocols),
4de0686f
JF
204 fields_(fields),
205 messages_(messages)
206 {
207 }
208
7c6c5b0a
JF
209 virtual ~CYClass() {
210 }
211
4de0686f
JF
212 CYExpression *Replace_(CYContext &context);
213 virtual void Output(CYOutput &out, CYFlags flags) const;
214};
215
216struct CYClassExpression :
217 CYClass,
218 CYExpression
219{
64b8d29f
JF
220 CYClassExpression(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
221 CYClass(name, super, protocols, fields, messages)
4de0686f
JF
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{
64b8d29f
JF
235 CYClassStatement(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
236 CYClass(name, super, protocols, fields, messages)
4de0686f
JF
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{
4de0686f
JF
263 CYArgument *arguments_;
264
cacd1a88 265 CYSend(CYArgument *arguments) :
4de0686f
JF
266 arguments_(arguments)
267 {
268 }
269
270 CYPrecedence(0)
271
cacd1a88
JF
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
4de0686f
JF
298 virtual CYExpression *Replace(CYContext &context);
299 virtual void Output(CYOutput &out, CYFlags flags) const;
300};
301
3c1c3635 302#endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/