]> git.saurik.com Git - cycript.git/blame - ObjectiveC/Syntax.hpp
Drastically improve pretty printed code structure.
[cycript.git] / ObjectiveC / Syntax.hpp
CommitLineData
b3378a02 1/* Cycript - Optimizing JavaScript Compiler/Runtime
c1d3e52e 2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
4644480a
JF
3*/
4
f95d2598 5/* GNU Affero General Public License, Version 3 {{{ */
4644480a 6/*
f95d2598
JF
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c15969fd 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f95d2598
JF
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b3378a02 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
61769f4f
JF
27struct 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
56e02e5b
JF
43struct CYObjCBlock :
44 CYExpression
45{
9a39f705 46 CYTypedIdentifier *typed_;
56e02e5b 47 CYTypedParameter *parameters_;
b0385401 48 CYStatement *code_;
56e02e5b 49
b0385401 50 CYObjCBlock(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *code) :
9a39f705 51 typed_(typed),
56e02e5b 52 parameters_(parameters),
b0385401 53 code_(code)
56e02e5b
JF
54 {
55 }
56
57 CYPrecedence(1)
58
59 virtual CYExpression *Replace(CYContext &context);
60 virtual void Output(CYOutput &out, CYFlags flags) const;
61};
62
f2f0d1d1
JF
63struct 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
4de0686f
JF
79struct CYSelectorPart :
80 CYNext<CYSelectorPart>,
81 CYThing
82{
83 CYWord *name_;
84 bool value_;
85
2385c806 86 CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next = NULL) :
4de0686f
JF
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
97struct 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
b6a67580
JF
113struct CYClassField :
114 CYNext<CYClassField>
4de0686f 115{
d2f6e642 116 CYTypedIdentifier *typed_;
cfd73c6d 117
b6a67580
JF
118 CYClassField(CYTypedIdentifier *typed, CYClassField *next = NULL) :
119 CYNext<CYClassField>(next),
d2f6e642 120 typed_(typed)
cfd73c6d
JF
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_;
57d55714 132 CYTypedIdentifier *type_;
4de0686f 133
104cc5f5 134 CYMessageParameter(CYWord *tag, CYTypedIdentifier *type) :
4de0686f 135 tag_(tag),
104cc5f5 136 type_(type)
4de0686f
JF
137 {
138 }
139
140 CYFunctionParameter *Parameters(CYContext &context) const;
141 CYSelector *Selector(CYContext &context) const;
142 CYSelectorPart *SelectorPart(CYContext &context) const;
9a7c375c 143 CYExpression *TypeSignature(CYContext &context) const;
4de0686f
JF
144};
145
146struct CYMessage :
147 CYNext<CYMessage>
148{
149 bool instance_;
57d55714 150 CYTypedIdentifier *type_;
4de0686f 151 CYMessageParameter *parameters_;
4644480a 152 CYBlock code_;
4de0686f 153
b0385401 154 CYMessage(bool instance, CYTypedIdentifier *type, CYMessageParameter *parameter, CYStatement *code) :
4de0686f
JF
155 instance_(instance),
156 type_(type),
157 parameters_(parameter),
b0385401 158 code_(code)
4de0686f
JF
159 {
160 }
161
162 CYStatement *Replace(CYContext &context, bool replace) const;
163 void Output(CYOutput &out, bool replace) const;
9a7c375c
JF
164
165 CYExpression *TypeSignature(CYContext &context) const;
4de0686f
JF
166};
167
64b8d29f
JF
168struct CYProtocol :
169 CYNext<CYProtocol>,
170 CYThing
171{
172 CYExpression *name_;
173
174 CYProtocol(CYExpression *name, CYProtocol *next = NULL) :
175 CYNext<CYProtocol>(next),
176 name_(name)
177 {
178 }
179
180 CYStatement *Replace(CYContext &context) const;
181 void Output(CYOutput &out) const;
182};
183
4de0686f
JF
184struct CYClass {
185 CYClassName *name_;
186 CYExpression *super_;
64b8d29f 187 CYProtocol *protocols_;
b6a67580 188 CYClassField *fields_;
4de0686f
JF
189 CYMessage *messages_;
190
b6a67580 191 CYClass(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYClassField *fields, CYMessage *messages) :
4de0686f
JF
192 name_(name),
193 super_(super),
64b8d29f 194 protocols_(protocols),
4de0686f
JF
195 fields_(fields),
196 messages_(messages)
197 {
198 }
199
7c6c5b0a
JF
200 virtual ~CYClass() {
201 }
202
4de0686f
JF
203 CYExpression *Replace_(CYContext &context);
204 virtual void Output(CYOutput &out, CYFlags flags) const;
205};
206
207struct CYClassExpression :
208 CYClass,
209 CYExpression
210{
b6a67580 211 CYClassExpression(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYClassField *fields, CYMessage *messages) :
64b8d29f 212 CYClass(name, super, protocols, fields, messages)
4de0686f
JF
213 {
214 }
215
216 CYPrecedence(0)
217
218 virtual CYExpression *Replace(CYContext &context);
219 virtual void Output(CYOutput &out, CYFlags flags) const;
220};
221
222struct CYClassStatement :
223 CYClass,
224 CYStatement
225{
b6a67580 226 CYClassStatement(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYClassField *fields, CYMessage *messages) :
64b8d29f 227 CYClass(name, super, protocols, fields, messages)
4de0686f
JF
228 {
229 }
230
efd689d8
JF
231 CYCompact(None)
232
4de0686f
JF
233 virtual CYStatement *Replace(CYContext &context);
234 virtual void Output(CYOutput &out, CYFlags flags) const;
235};
236
237struct 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
efd689d8
JF
249 CYCompact(None)
250
4de0686f
JF
251 virtual CYStatement *Replace(CYContext &context);
252 virtual void Output(CYOutput &out, CYFlags flags) const;
253};
254
255struct CYSend :
256 CYExpression
257{
4de0686f
JF
258 CYArgument *arguments_;
259
cacd1a88 260 CYSend(CYArgument *arguments) :
4de0686f
JF
261 arguments_(arguments)
262 {
263 }
264
265 CYPrecedence(0)
266
cacd1a88
JF
267 virtual void Output(CYOutput &out, CYFlags flags) const;
268};
269
270struct CYSendDirect :
271 CYSend
272{
273 CYExpression *self_;
274
275 CYSendDirect(CYExpression *self, CYArgument *arguments) :
276 CYSend(arguments),
277 self_(self)
278 {
279 }
280
281 virtual CYExpression *Replace(CYContext &context);
282 virtual void Output(CYOutput &out, CYFlags flags) const;
283};
284
285struct CYSendSuper :
286 CYSend
287{
288 CYSendSuper(CYArgument *arguments) :
289 CYSend(arguments)
290 {
291 }
292
4de0686f
JF
293 virtual CYExpression *Replace(CYContext &context);
294 virtual void Output(CYOutput &out, CYFlags flags) const;
295};
296
3c1c3635 297#endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/