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