]>
Commit | Line | Data |
---|---|---|
1 | /* Cycript - Optimizing JavaScript Compiler/Runtime | |
2 | * Copyright (C) 2009-2010 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 CYSelectorPart : | |
28 | CYNext<CYSelectorPart>, | |
29 | CYThing | |
30 | { | |
31 | CYWord *name_; | |
32 | bool value_; | |
33 | ||
34 | CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next = NULL) : | |
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 | ||
45 | struct 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 | ||
61 | struct CYField : | |
62 | CYNext<CYField> | |
63 | { | |
64 | CYStatement *Replace(CYContext &context) const; | |
65 | void Output(CYOutput &out) const; | |
66 | }; | |
67 | ||
68 | struct 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 | ||
87 | struct CYMessage : | |
88 | CYNext<CYMessage> | |
89 | { | |
90 | bool instance_; | |
91 | CYExpression *type_; | |
92 | CYMessageParameter *parameters_; | |
93 | CYBlock code_; | |
94 | ||
95 | CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *statements) : | |
96 | instance_(instance), | |
97 | type_(type), | |
98 | parameters_(parameter), | |
99 | code_(statements) | |
100 | { | |
101 | } | |
102 | ||
103 | CYStatement *Replace(CYContext &context, bool replace) const; | |
104 | void Output(CYOutput &out, bool replace) const; | |
105 | }; | |
106 | ||
107 | struct 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 | ||
123 | struct CYImport : | |
124 | CYStatement | |
125 | { | |
126 | virtual CYStatement *Replace(CYContext &context); | |
127 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
128 | }; | |
129 | ||
130 | struct CYClass { | |
131 | CYClassName *name_; | |
132 | CYExpression *super_; | |
133 | CYProtocol *protocols_; | |
134 | CYField *fields_; | |
135 | CYMessage *messages_; | |
136 | ||
137 | CYClass(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) : | |
138 | name_(name), | |
139 | super_(super), | |
140 | protocols_(protocols), | |
141 | fields_(fields), | |
142 | messages_(messages) | |
143 | { | |
144 | } | |
145 | ||
146 | virtual ~CYClass() { | |
147 | } | |
148 | ||
149 | CYExpression *Replace_(CYContext &context); | |
150 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
151 | }; | |
152 | ||
153 | struct CYClassExpression : | |
154 | CYClass, | |
155 | CYExpression | |
156 | { | |
157 | CYClassExpression(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) : | |
158 | CYClass(name, super, protocols, fields, messages) | |
159 | { | |
160 | } | |
161 | ||
162 | CYPrecedence(0) | |
163 | ||
164 | virtual CYExpression *Replace(CYContext &context); | |
165 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
166 | }; | |
167 | ||
168 | struct CYClassStatement : | |
169 | CYClass, | |
170 | CYStatement | |
171 | { | |
172 | CYClassStatement(CYClassName *name, CYExpression *super, CYProtocol *protocols, CYField *fields, CYMessage *messages) : | |
173 | CYClass(name, super, protocols, fields, messages) | |
174 | { | |
175 | } | |
176 | ||
177 | virtual CYStatement *Replace(CYContext &context); | |
178 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
179 | }; | |
180 | ||
181 | struct 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 | ||
197 | struct CYSend : | |
198 | CYExpression | |
199 | { | |
200 | CYArgument *arguments_; | |
201 | ||
202 | CYSend(CYArgument *arguments) : | |
203 | arguments_(arguments) | |
204 | { | |
205 | } | |
206 | ||
207 | CYPrecedence(0) | |
208 | ||
209 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
210 | }; | |
211 | ||
212 | struct 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 | ||
227 | struct CYSendSuper : | |
228 | CYSend | |
229 | { | |
230 | CYSendSuper(CYArgument *arguments) : | |
231 | CYSend(arguments) | |
232 | { | |
233 | } | |
234 | ||
235 | virtual CYExpression *Replace(CYContext &context); | |
236 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
237 | }; | |
238 | ||
239 | #endif/*CYCRIPT_OBJECTIVEC_SYNTAX_HPP*/ |