]> git.saurik.com Git - cycript.git/blob - ObjectiveC/Syntax.hpp
Allow type signatures to be specified on messages.
[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 CYStatement *Replace(CYContext &context) const;
81 void Output(CYOutput &out) const;
82 };
83
84 struct CYMessageParameter :
85 CYNext<CYMessageParameter>
86 {
87 CYWord *tag_;
88 CYExpression *type_;
89 CYIdentifier *name_;
90
91 CYMessageParameter(CYWord *tag, CYExpression *type, CYIdentifier *name) :
92 tag_(tag),
93 type_(type),
94 name_(name)
95 {
96 }
97
98 CYFunctionParameter *Parameters(CYContext &context) const;
99 CYSelector *Selector(CYContext &context) const;
100 CYSelectorPart *SelectorPart(CYContext &context) const;
101 CYExpression *TypeSignature(CYContext &context) const;
102 };
103
104 struct CYMessage :
105 CYNext<CYMessage>
106 {
107 bool instance_;
108 CYExpression *type_;
109 CYMessageParameter *parameters_;
110 CYBlock code_;
111
112 CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *statements) :
113 instance_(instance),
114 type_(type),
115 parameters_(parameter),
116 code_(statements)
117 {
118 }
119
120 CYStatement *Replace(CYContext &context, bool replace) const;
121 void Output(CYOutput &out, bool replace) const;
122
123 CYExpression *TypeSignature(CYContext &context) const;
124 };
125
126 struct CYProtocol :
127 CYNext<CYProtocol>,
128 CYThing
129 {
130 CYExpression *name_;
131
132 CYProtocol(CYExpression *name, CYProtocol *next = NULL) :
133 CYNext<CYProtocol>(next),
134 name_(name)
135 {
136 }
137
138 CYStatement *Replace(CYContext &context) const;
139 void Output(CYOutput &out) const;
140 };
141
142 struct CYImport :
143 CYStatement
144 {
145 virtual CYStatement *Replace(CYContext &context);
146 virtual void Output(CYOutput &out, CYFlags flags) const;
147 };
148
149 struct CYClass {
150 CYClassName *name_;
151 CYExpression *super_;
152 CYProtocol *protocols_;
153 CYField *fields_;
154 CYMessage *messages_;
155
156 CYClass(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
157 name_(name),
158 super_(super),
159 protocols_(protocols),
160 fields_(fields),
161 messages_(messages)
162 {
163 }
164
165 virtual ~CYClass() {
166 }
167
168 CYExpression *Replace_(CYContext &context);
169 virtual void Output(CYOutput &out, CYFlags flags) const;
170 };
171
172 struct CYClassExpression :
173 CYClass,
174 CYExpression
175 {
176 CYClassExpression(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
177 CYClass(name, super, protocols, fields, messages)
178 {
179 }
180
181 CYPrecedence(0)
182
183 virtual CYExpression *Replace(CYContext &context);
184 virtual void Output(CYOutput &out, CYFlags flags) const;
185 };
186
187 struct CYClassStatement :
188 CYClass,
189 CYStatement
190 {
191 CYClassStatement(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
192 CYClass(name, super, protocols, fields, messages)
193 {
194 }
195
196 virtual CYStatement *Replace(CYContext &context);
197 virtual void Output(CYOutput &out, CYFlags flags) const;
198 };
199
200 struct CYCategory :
201 CYStatement
202 {
203 CYClassName *name_;
204 CYMessage *messages_;
205
206 CYCategory(CYClassName *name, CYMessage *messages) :
207 name_(name),
208 messages_(messages)
209 {
210 }
211
212 virtual CYStatement *Replace(CYContext &context);
213 virtual void Output(CYOutput &out, CYFlags flags) const;
214 };
215
216 struct CYSend :
217 CYExpression
218 {
219 CYArgument *arguments_;
220
221 CYSend(CYArgument *arguments) :
222 arguments_(arguments)
223 {
224 }
225
226 CYPrecedence(0)
227
228 virtual void Output(CYOutput &out, CYFlags flags) const;
229 };
230
231 struct CYSendDirect :
232 CYSend
233 {
234 CYExpression *self_;
235
236 CYSendDirect(CYExpression *self, CYArgument *arguments) :
237 CYSend(arguments),
238 self_(self)
239 {
240 }
241
242 virtual CYExpression *Replace(CYContext &context);
243 virtual void Output(CYOutput &out, CYFlags flags) const;
244 };
245
246 struct CYSendSuper :
247 CYSend
248 {
249 CYSendSuper(CYArgument *arguments) :
250 CYSend(arguments)
251 {
252 }
253
254 virtual CYExpression *Replace(CYContext &context);
255 virtual void Output(CYOutput &out, CYFlags flags) const;
256 };
257
258 #endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/