]> git.saurik.com Git - cycript.git/blame - ObjectiveC/Syntax.hpp
Updated copyright (2010) and license (LGPLv3).
[cycript.git] / ObjectiveC / Syntax.hpp
CommitLineData
b3378a02
JF
1/* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2010 Jay Freeman (saurik)
4644480a
JF
3*/
4
b3378a02 5/* GNU Lesser General Public License, Version 3 {{{ */
4644480a 6/*
b3378a02
JF
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.
4644480a 11 *
b3378a02
JF
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.
4644480a 16 *
b3378a02
JF
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**/
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
27struct CYSelectorPart :
28 CYNext<CYSelectorPart>,
29 CYThing
30{
31 CYWord *name_;
32 bool value_;
33
2385c806 34 CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next = NULL) :
4de0686f
JF
35 CYNext<CYSelectorPart>(next),
36 name_(name),
37 value_(value)
38 {
39 }
40
41 CYString *Replace(CYContext &context);
42 virtual void Output(CYOutput &out) const;
43};
44
45struct CYSelector :
46 CYLiteral
47{
48 CYSelectorPart *name_;
49
50 CYSelector(CYSelectorPart *name) :
51 name_(name)
52 {
53 }
54
55 CYPrecedence(1)
56
57 virtual CYExpression *Replace(CYContext &context);
58 virtual void Output(CYOutput &out, CYFlags flags) const;
59};
60
61struct CYField :
62 CYNext<CYField>
63{
64 CYStatement *Replace(CYContext &context) const;
65 void Output(CYOutput &out) const;
66};
67
68struct CYMessageParameter :
69 CYNext<CYMessageParameter>
70{
71 CYWord *tag_;
72 CYExpression *type_;
73 CYIdentifier *name_;
74
75 CYMessageParameter(CYWord *tag, CYExpression *type, CYIdentifier *name) :
76 tag_(tag),
77 type_(type),
78 name_(name)
79 {
80 }
81
82 CYFunctionParameter *Parameters(CYContext &context) const;
83 CYSelector *Selector(CYContext &context) const;
84 CYSelectorPart *SelectorPart(CYContext &context) const;
85};
86
87struct CYMessage :
88 CYNext<CYMessage>
89{
90 bool instance_;
91 CYExpression *type_;
92 CYMessageParameter *parameters_;
4644480a 93 CYBlock code_;
4de0686f
JF
94
95 CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *statements) :
96 instance_(instance),
97 type_(type),
98 parameters_(parameter),
4644480a 99 code_(statements)
4de0686f
JF
100 {
101 }
102
103 CYStatement *Replace(CYContext &context, bool replace) const;
104 void Output(CYOutput &out, bool replace) const;
105};
106
64b8d29f
JF
107struct CYProtocol :
108 CYNext<CYProtocol>,
109 CYThing
110{
111 CYExpression *name_;
112
113 CYProtocol(CYExpression *name, CYProtocol *next = NULL) :
114 CYNext<CYProtocol>(next),
115 name_(name)
116 {
117 }
118
119 CYStatement *Replace(CYContext &context) const;
120 void Output(CYOutput &out) const;
121};
122
1ba6903e
JF
123struct CYImport :
124 CYStatement
125{
126 virtual CYStatement *Replace(CYContext &context);
127 virtual void Output(CYOutput &out, CYFlags flags) const;
128};
129
4de0686f
JF
130struct CYClass {
131 CYClassName *name_;
132 CYExpression *super_;
64b8d29f 133 CYProtocol *protocols_;
4de0686f
JF
134 CYField *fields_;
135 CYMessage *messages_;
136
64b8d29f 137 CYClass(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
4de0686f
JF
138 name_(name),
139 super_(super),
64b8d29f 140 protocols_(protocols),
4de0686f
JF
141 fields_(fields),
142 messages_(messages)
143 {
144 }
145
7c6c5b0a
JF
146 virtual ~CYClass() {
147 }
148
4de0686f
JF
149 CYExpression *Replace_(CYContext &context);
150 virtual void Output(CYOutput &out, CYFlags flags) const;
151};
152
153struct CYClassExpression :
154 CYClass,
155 CYExpression
156{
64b8d29f
JF
157 CYClassExpression(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
158 CYClass(name, super, protocols, fields, messages)
4de0686f
JF
159 {
160 }
161
162 CYPrecedence(0)
163
164 virtual CYExpression *Replace(CYContext &context);
165 virtual void Output(CYOutput &out, CYFlags flags) const;
166};
167
168struct CYClassStatement :
169 CYClass,
170 CYStatement
171{
64b8d29f
JF
172 CYClassStatement(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) :
173 CYClass(name, super, protocols, fields, messages)
4de0686f
JF
174 {
175 }
176
177 virtual CYStatement *Replace(CYContext &context);
178 virtual void Output(CYOutput &out, CYFlags flags) const;
179};
180
181struct CYCategory :
182 CYStatement
183{
184 CYClassName *name_;
185 CYMessage *messages_;
186
187 CYCategory(CYClassName *name, CYMessage *messages) :
188 name_(name),
189 messages_(messages)
190 {
191 }
192
193 virtual CYStatement *Replace(CYContext &context);
194 virtual void Output(CYOutput &out, CYFlags flags) const;
195};
196
197struct CYSend :
198 CYExpression
199{
4de0686f
JF
200 CYArgument *arguments_;
201
cacd1a88 202 CYSend(CYArgument *arguments) :
4de0686f
JF
203 arguments_(arguments)
204 {
205 }
206
207 CYPrecedence(0)
208
cacd1a88
JF
209 virtual void Output(CYOutput &out, CYFlags flags) const;
210};
211
212struct CYSendDirect :
213 CYSend
214{
215 CYExpression *self_;
216
217 CYSendDirect(CYExpression *self, CYArgument *arguments) :
218 CYSend(arguments),
219 self_(self)
220 {
221 }
222
223 virtual CYExpression *Replace(CYContext &context);
224 virtual void Output(CYOutput &out, CYFlags flags) const;
225};
226
227struct CYSendSuper :
228 CYSend
229{
230 CYSendSuper(CYArgument *arguments) :
231 CYSend(arguments)
232 {
233 }
234
4de0686f
JF
235 virtual CYExpression *Replace(CYContext &context);
236 virtual void Output(CYOutput &out, CYFlags flags) const;
237};
238
3c1c3635 239#endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/