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