]> git.saurik.com Git - cycript.git/blob - ObjectiveC/Syntax.hpp
Add an empty Execute.cpp for Java support backend.
[cycript.git] / ObjectiveC / Syntax.hpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2013 Jay Freeman (saurik)
3 */
4
5 /* GNU General Public License, Version 3 {{{ */
6 /*
7 * Cycript is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
11 *
12 * Cycript is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU 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
27 struct CYInstanceLiteral :
28 CYExpression
29 {
30 CYNumber *number_;
31
32 CYInstanceLiteral(CYNumber *number) :
33 number_(number)
34 {
35 }
36
37 CYPrecedence(1)
38
39 virtual CYExpression *Replace(CYContext &context);
40 virtual void Output(CYOutput &out, CYFlags flags) const;
41 };
42
43 struct CYObjCBlock :
44 CYExpression
45 {
46 CYTypedIdentifier *typed_;
47 CYTypedParameter *parameters_;
48 CYStatement *statements_;
49
50 CYObjCBlock(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *statements) :
51 typed_(typed),
52 parameters_(parameters),
53 statements_(statements)
54 {
55 }
56
57 CYPrecedence(1)
58
59 virtual CYExpression *Replace(CYContext &context);
60 virtual void Output(CYOutput &out, CYFlags flags) const;
61 };
62
63 struct CYBox :
64 CYExpression
65 {
66 CYExpression *value_;
67
68 CYBox(CYExpression *value) :
69 value_(value)
70 {
71 }
72
73 CYPrecedence(1)
74
75 virtual CYExpression *Replace(CYContext &context);
76 virtual void Output(CYOutput &out, CYFlags flags) const;
77 };
78
79 struct CYSelectorPart :
80 CYNext<CYSelectorPart>,
81 CYThing
82 {
83 CYWord *name_;
84 bool value_;
85
86 CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next = NULL) :
87 CYNext<CYSelectorPart>(next),
88 name_(name),
89 value_(value)
90 {
91 }
92
93 CYString *Replace(CYContext &context);
94 virtual void Output(CYOutput &out) const;
95 };
96
97 struct CYSelector :
98 CYLiteral
99 {
100 CYSelectorPart *name_;
101
102 CYSelector(CYSelectorPart *name) :
103 name_(name)
104 {
105 }
106
107 CYPrecedence(1)
108
109 virtual CYExpression *Replace(CYContext &context);
110 virtual void Output(CYOutput &out, CYFlags flags) const;
111 };
112
113 struct CYField :
114 CYNext<CYField>
115 {
116 CYTypedIdentifier *typed_;
117
118 CYField(CYTypedIdentifier *typed, CYField *next = NULL) :
119 CYNext<CYField>(next),
120 typed_(typed)
121 {
122 }
123
124 CYStatement *Replace(CYContext &context) const;
125 void Output(CYOutput &out) const;
126 };
127
128 struct 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
148 struct 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
170 struct 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
186 struct CYClass {
187 CYClassName *name_;
188 CYExpression *super_;
189 CYProtocol *protocols_;
190 CYField *fields_;
191 CYMessage *messages_;
192
193 CYClass(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
194 name_(name),
195 super_(super),
196 protocols_(protocols),
197 fields_(fields),
198 messages_(messages)
199 {
200 }
201
202 virtual ~CYClass() {
203 }
204
205 CYExpression *Replace_(CYContext &context);
206 virtual void Output(CYOutput &out, CYFlags flags) const;
207 };
208
209 struct CYClassExpression :
210 CYClass,
211 CYExpression
212 {
213 CYClassExpression(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
214 CYClass(name, super, protocols, fields, messages)
215 {
216 }
217
218 CYPrecedence(0)
219
220 virtual CYExpression *Replace(CYContext &context);
221 virtual void Output(CYOutput &out, CYFlags flags) const;
222 };
223
224 struct CYClassStatement :
225 CYClass,
226 CYStatement
227 {
228 CYClassStatement(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
229 CYClass(name, super, protocols, fields, messages)
230 {
231 }
232
233 virtual CYStatement *Replace(CYContext &context);
234 virtual void Output(CYOutput &out, CYFlags flags) const;
235 };
236
237 struct CYCategory :
238 CYStatement
239 {
240 CYClassName *name_;
241 CYMessage *messages_;
242
243 CYCategory(CYClassName *name, CYMessage *messages) :
244 name_(name),
245 messages_(messages)
246 {
247 }
248
249 virtual CYStatement *Replace(CYContext &context);
250 virtual void Output(CYOutput &out, CYFlags flags) const;
251 };
252
253 struct CYSend :
254 CYExpression
255 {
256 CYArgument *arguments_;
257
258 CYSend(CYArgument *arguments) :
259 arguments_(arguments)
260 {
261 }
262
263 CYPrecedence(0)
264
265 virtual void Output(CYOutput &out, CYFlags flags) const;
266 };
267
268 struct CYSendDirect :
269 CYSend
270 {
271 CYExpression *self_;
272
273 CYSendDirect(CYExpression *self, CYArgument *arguments) :
274 CYSend(arguments),
275 self_(self)
276 {
277 }
278
279 virtual CYExpression *Replace(CYContext &context);
280 virtual void Output(CYOutput &out, CYFlags flags) const;
281 };
282
283 struct CYSendSuper :
284 CYSend
285 {
286 CYSendSuper(CYArgument *arguments) :
287 CYSend(arguments)
288 {
289 }
290
291 virtual CYExpression *Replace(CYContext &context);
292 virtual void Output(CYOutput &out, CYFlags flags) const;
293 };
294
295 #endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/