]> git.saurik.com Git - cycript.git/blame_incremental - ObjectiveC/Syntax.hpp
Avoid crash when using toCYON on String.prototype.
[cycript.git] / ObjectiveC / Syntax.hpp
... / ...
CommitLineData
1/* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
3*/
4
5/* GNU Affero General Public License, Version 3 {{{ */
6/*
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
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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/>.
19**/
20/* }}} */
21
22#ifndef CYCRIPT_OBJECTIVEC_SYNTAX_HPP
23#define CYCRIPT_OBJECTIVEC_SYNTAX_HPP
24
25#include "../Syntax.hpp"
26
27struct CYInstanceLiteral :
28 CYTarget
29{
30 CYNumber *number_;
31
32 CYInstanceLiteral(CYNumber *number) :
33 number_(number)
34 {
35 }
36
37 CYPrecedence(1)
38
39 virtual CYTarget *Replace(CYContext &context);
40 virtual void Output(CYOutput &out, CYFlags flags) const;
41};
42
43struct CYObjCBlock :
44 CYTarget
45{
46 CYTypedIdentifier *typed_;
47 CYTypedParameter *parameters_;
48 CYStatement *code_;
49
50 CYObjCBlock(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *code) :
51 typed_(typed),
52 parameters_(parameters),
53 code_(code)
54 {
55 }
56
57 CYPrecedence(1)
58
59 virtual CYTarget *Replace(CYContext &context);
60 virtual void Output(CYOutput &out, CYFlags flags) const;
61};
62
63struct CYBox :
64 CYTarget
65{
66 CYExpression *value_;
67
68 CYBox(CYExpression *value) :
69 value_(value)
70 {
71 }
72
73 CYPrecedence(1)
74
75 virtual CYTarget *Replace(CYContext &context);
76 virtual void Output(CYOutput &out, CYFlags flags) const;
77};
78
79struct 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
97struct CYSelector :
98 CYLiteral
99{
100 CYSelectorPart *parts_;
101
102 CYSelector(CYSelectorPart *parts) :
103 parts_(parts)
104 {
105 }
106
107 CYPrecedence(1)
108
109 virtual CYTarget *Replace(CYContext &context);
110 virtual void Output(CYOutput &out, CYFlags flags) const;
111};
112
113struct CYImplementationField :
114 CYNext<CYImplementationField>
115{
116 CYTypedIdentifier *typed_;
117
118 CYImplementationField(CYTypedIdentifier *typed, CYImplementationField *next = NULL) :
119 CYNext<CYImplementationField>(next),
120 typed_(typed)
121 {
122 }
123
124 CYStatement *Replace(CYContext &context) const;
125 void Output(CYOutput &out) const;
126};
127
128struct CYMessageParameter :
129 CYNext<CYMessageParameter>
130{
131 CYWord *name_;
132 CYTypedIdentifier *type_;
133
134 CYMessageParameter(CYWord *name, CYTypedIdentifier *type) :
135 name_(name),
136 type_(type)
137 {
138 }
139
140 CYFunctionParameter *Parameters(CYContext &context) const;
141 CYSelector *Selector(CYContext &context) const;
142 CYSelectorPart *SelectorPart(CYContext &context) const;
143 CYExpression *TypeSignature(CYContext &context) const;
144};
145
146struct CYMessage :
147 CYNext<CYMessage>
148{
149 bool instance_;
150 CYTypedIdentifier *type_;
151 CYMessageParameter *parameters_;
152 CYBlock code_;
153
154 CYMessage(bool instance, CYTypedIdentifier *type, CYMessageParameter *parameters, CYStatement *code) :
155 instance_(instance),
156 type_(type),
157 parameters_(parameters),
158 code_(code)
159 {
160 }
161
162 CYStatement *Replace(CYContext &context, bool replace) const;
163 void Output(CYOutput &out) const;
164
165 CYExpression *TypeSignature(CYContext &context) const;
166};
167
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
184struct CYImplementation :
185 CYStatement
186{
187 CYIdentifier *name_;
188 CYExpression *extends_;
189 CYProtocol *protocols_;
190 CYImplementationField *fields_;
191 CYMessage *messages_;
192
193 CYImplementation(CYIdentifier *name, CYExpression *extends, CYProtocol *protocols, CYImplementationField *fields, CYMessage *messages) :
194 name_(name),
195 extends_(extends),
196 protocols_(protocols),
197 fields_(fields),
198 messages_(messages)
199 {
200 }
201
202 CYCompact(None)
203
204 virtual CYStatement *Replace(CYContext &context);
205 virtual void Output(CYOutput &out, CYFlags flags) const;
206};
207
208struct CYCategory :
209 CYStatement
210{
211 CYIdentifier *name_;
212 CYMessage *messages_;
213
214 CYCategory(CYIdentifier *name, CYMessage *messages) :
215 name_(name),
216 messages_(messages)
217 {
218 }
219
220 CYCompact(None)
221
222 virtual CYStatement *Replace(CYContext &context);
223 virtual void Output(CYOutput &out, CYFlags flags) const;
224};
225
226struct CYSend :
227 CYTarget
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
241struct 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 CYTarget *Replace(CYContext &context);
253 virtual void Output(CYOutput &out, CYFlags flags) const;
254};
255
256struct CYSendSuper :
257 CYSend
258{
259 CYSendSuper(CYArgument *arguments) :
260 CYSend(arguments)
261 {
262 }
263
264 virtual CYTarget *Replace(CYContext &context);
265 virtual void Output(CYOutput &out, CYFlags flags) const;
266};
267
268#endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/