]>
Commit | Line | Data |
---|---|---|
b4aa79af JF |
1 | /* Cycript - Remove Execution Server and Disassembler |
2 | * Copyright (C) 2009 Jay Freeman (saurik) | |
3 | */ | |
4 | ||
5 | /* Modified BSD License {{{ */ | |
6 | /* | |
7 | * Redistribution and use in source and binary | |
8 | * forms, with or without modification, are permitted | |
9 | * provided that the following conditions are met: | |
10 | * | |
11 | * 1. Redistributions of source code must retain the | |
12 | * above copyright notice, this list of conditions | |
13 | * and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the | |
15 | * above copyright notice, this list of conditions | |
16 | * and the following disclaimer in the documentation | |
17 | * and/or other materials provided with the | |
18 | * distribution. | |
19 | * 3. The name of the author may not be used to endorse | |
20 | * or promote products derived from this software | |
21 | * without specific prior written permission. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' | |
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
25 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE | |
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
30 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
34 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
36 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
37 | */ | |
38 | /* }}} */ | |
39 | ||
63b4c5a8 JF |
40 | #ifndef CYPARSER_HPP |
41 | #define CYPARSER_HPP | |
42 | ||
cf7d4c69 | 43 | #include <cstdlib> |
5999c315 | 44 | #include <string> |
c3c20102 | 45 | #include <vector> |
cf7d4c69 | 46 | |
5befe15e | 47 | #include "location.hh" |
5999c315 | 48 | #include "Pooling.hpp" |
924f67b2 | 49 | |
5999c315 JF |
50 | template <typename Type_> |
51 | struct CYNext { | |
52 | Type_ *next_; | |
63b4c5a8 | 53 | |
5999c315 JF |
54 | CYNext() : |
55 | next_(NULL) | |
56 | { | |
57 | } | |
cf7d4c69 | 58 | |
62014ea9 JF |
59 | CYNext(Type_ *next) : |
60 | next_(next) | |
61 | { | |
62 | } | |
63 | ||
5999c315 | 64 | void SetNext(Type_ *next) { |
cf7d4c69 JF |
65 | next_ = next; |
66 | } | |
67 | }; | |
68 | ||
5999c315 | 69 | struct CYThing { |
652ec1ba | 70 | virtual void Output(struct CYOutput &out) const = 0; |
5999c315 JF |
71 | }; |
72 | ||
652ec1ba JF |
73 | struct CYOutput { |
74 | std::ostream &out_; | |
11c1cc16 JF |
75 | bool pretty_; |
76 | unsigned indent_; | |
652ec1ba | 77 | |
96a7e5c2 JF |
78 | enum { |
79 | NoMode, | |
80 | NoLetter, | |
c0bc320e | 81 | NoPlus, |
96a7e5c2 JF |
82 | NoHyphen, |
83 | Terminated | |
84 | } mode_; | |
85 | ||
652ec1ba | 86 | CYOutput(std::ostream &out) : |
11c1cc16 JF |
87 | out_(out), |
88 | pretty_(false), | |
96a7e5c2 JF |
89 | indent_(0), |
90 | mode_(NoMode) | |
652ec1ba JF |
91 | { |
92 | } | |
93 | ||
96a7e5c2 | 94 | void Check(char value); |
1fdca2fa | 95 | void Terminate(); |
652ec1ba | 96 | |
96a7e5c2 JF |
97 | CYOutput &operator <<(char rhs); |
98 | CYOutput &operator <<(const char *rhs); | |
99 | ||
100 | _finline CYOutput &operator <<(const CYThing *rhs) { | |
101 | if (rhs != NULL) | |
102 | rhs->Output(*this); | |
652ec1ba JF |
103 | return *this; |
104 | } | |
105 | ||
106 | _finline CYOutput &operator <<(const CYThing &rhs) { | |
107 | rhs.Output(*this); | |
108 | return *this; | |
109 | } | |
110 | }; | |
5999c315 | 111 | |
e5bc40db | 112 | struct CYPropertyName { |
652ec1ba | 113 | virtual void PropertyName(CYOutput &out) const = 0; |
e5bc40db JF |
114 | }; |
115 | ||
3b52fd1a JF |
116 | struct CYExpression; |
117 | ||
118 | enum CYNeeded { | |
119 | CYNever = -1, | |
120 | CYSometimes = 0, | |
121 | CYAlways = 1, | |
122 | }; | |
123 | ||
124 | enum CYFlags { | |
125 | CYNoFlags = 0, | |
126 | CYNoBrace = (1 << 0), | |
127 | CYNoFunction = (1 << 1), | |
128 | CYNoIn = (1 << 2), | |
129 | CYNoCall = (1 << 3), | |
130 | CYNoRightHand = (1 << 4), | |
131 | CYNoDangle = (1 << 5), | |
132 | CYNoBF = (CYNoBrace | CYNoFunction), | |
133 | }; | |
134 | ||
135 | struct CYContext { | |
136 | apr_pool_t *pool_; | |
137 | ||
138 | CYContext(apr_pool_t *pool) : | |
139 | pool_(pool) | |
140 | { | |
141 | } | |
142 | ||
143 | template <typename Type_> | |
144 | void Replace(Type_ *&value) { | |
145 | if (value != NULL) | |
146 | while (Type_ *replace = value->Replace(*this)) | |
147 | value = replace; | |
148 | } | |
149 | }; | |
150 | ||
151 | struct CYStatement : | |
152 | CYNext<CYStatement> | |
153 | { | |
154 | void Single(CYOutput &out, CYFlags flags) const; | |
155 | void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const; | |
156 | ||
157 | CYStatement *ReplaceAll(CYContext &context); | |
158 | ||
159 | virtual CYStatement *Replace(CYContext &context) = 0; | |
160 | ||
161 | private: | |
162 | virtual void Output(CYOutput &out, CYFlags flags) const = 0; | |
163 | }; | |
164 | ||
165 | struct CYStatements { | |
166 | CYStatement *first_; | |
167 | CYStatement *last_; | |
168 | ||
169 | CYStatements() : | |
170 | first_(NULL), | |
171 | last_(NULL) | |
172 | { | |
173 | } | |
174 | ||
175 | operator CYStatement *() const { | |
176 | return first_; | |
177 | } | |
178 | ||
179 | CYStatements &operator ->*(CYStatement *next) { | |
180 | if (next != NULL) | |
181 | if (first_ == NULL) { | |
182 | first_ = next; | |
183 | last_ = next; | |
184 | } else for (;; last_ = last_->next_) | |
185 | if (last_->next_ == NULL) { | |
186 | last_->next_ = next; | |
187 | last_ = next; | |
188 | break; | |
189 | } | |
190 | return *this; | |
191 | } | |
192 | }; | |
193 | ||
e5bc40db | 194 | struct CYClassName { |
3b52fd1a | 195 | virtual CYExpression *ClassName(CYContext &context, bool object) = 0; |
652ec1ba | 196 | virtual void ClassName(CYOutput &out, bool object) const = 0; |
63b4c5a8 JF |
197 | }; |
198 | ||
cf7d4c69 | 199 | struct CYWord : |
e5bc40db JF |
200 | CYThing, |
201 | CYPropertyName, | |
202 | CYClassName | |
63b4c5a8 | 203 | { |
cf7d4c69 JF |
204 | const char *word_; |
205 | ||
206 | CYWord(const char *word) : | |
207 | word_(word) | |
208 | { | |
209 | } | |
210 | ||
5999c315 | 211 | const char *Value() const { |
cf7d4c69 JF |
212 | return word_; |
213 | } | |
214 | ||
652ec1ba | 215 | virtual void Output(CYOutput &out) const; |
e5bc40db | 216 | |
3b52fd1a | 217 | virtual CYExpression *ClassName(CYContext &context, bool object); |
652ec1ba JF |
218 | virtual void ClassName(CYOutput &out, bool object) const; |
219 | virtual void PropertyName(CYOutput &out) const; | |
63b4c5a8 JF |
220 | }; |
221 | ||
652ec1ba JF |
222 | _finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) { |
223 | return lhs << rhs.Value(); | |
224 | } | |
225 | ||
cf7d4c69 JF |
226 | struct CYIdentifier : |
227 | CYWord | |
63b4c5a8 | 228 | { |
5999c315 JF |
229 | CYIdentifier(const char *word) : |
230 | CYWord(word) | |
231 | { | |
cf7d4c69 | 232 | } |
63b4c5a8 JF |
233 | }; |
234 | ||
62014ea9 | 235 | struct CYLabel : |
3b52fd1a | 236 | CYStatement |
62014ea9 | 237 | { |
9e562cfc | 238 | CYIdentifier *name_; |
3b52fd1a | 239 | CYStatement *statement_; |
cf7d4c69 | 240 | |
3b52fd1a JF |
241 | CYLabel(CYIdentifier *name, CYStatement *statement) : |
242 | name_(name), | |
243 | statement_(statement) | |
cf7d4c69 JF |
244 | { |
245 | } | |
fb98ac0c | 246 | |
3b52fd1a JF |
247 | virtual CYStatement *Replace(CYContext &context); |
248 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
fb98ac0c JF |
249 | }; |
250 | ||
3b52fd1a JF |
251 | struct CYProgram : |
252 | CYThing | |
63b4c5a8 | 253 | { |
3b52fd1a | 254 | CYStatement *statements_; |
9e562cfc | 255 | |
3b52fd1a JF |
256 | CYProgram(CYStatement *statements) : |
257 | statements_(statements) | |
9e562cfc JF |
258 | { |
259 | } | |
cf7d4c69 | 260 | |
3b52fd1a | 261 | virtual void Replace(CYContext &context); |
fb98ac0c | 262 | |
3b52fd1a | 263 | virtual void Output(CYOutput &out) const; |
9e562cfc JF |
264 | }; |
265 | ||
266 | struct CYBlock : | |
3b52fd1a JF |
267 | CYStatement, |
268 | CYThing | |
9e562cfc JF |
269 | { |
270 | CYStatement *statements_; | |
271 | ||
272 | CYBlock(CYStatement *statements) : | |
273 | statements_(statements) | |
274 | { | |
cf7d4c69 | 275 | } |
9e562cfc | 276 | |
3b52fd1a JF |
277 | virtual CYStatement *Replace(CYContext &context); |
278 | ||
279 | virtual void Output(CYOutput &out) const; | |
fb98ac0c | 280 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
281 | }; |
282 | ||
db5e2840 JF |
283 | enum CYState { |
284 | CYClear, | |
285 | CYRestricted, | |
286 | CYNewLine | |
287 | }; | |
288 | ||
5999c315 JF |
289 | class CYDriver { |
290 | public: | |
291 | CYPool pool_; | |
e7ed5354 | 292 | |
db5e2840 | 293 | CYState state_; |
e7ed5354 JF |
294 | void *scanner_; |
295 | ||
296 | const char *data_; | |
297 | size_t size_; | |
48e3be8a | 298 | FILE *file_; |
e7ed5354 | 299 | |
b10bd496 JF |
300 | bool strict_; |
301 | ||
63cd45c9 JF |
302 | enum Condition { |
303 | RegExStart, | |
304 | RegExRest | |
305 | }; | |
306 | ||
5999c315 | 307 | std::string filename_; |
e7ed5354 | 308 | |
5befe15e | 309 | struct Error { |
b10bd496 | 310 | bool warning_; |
5befe15e JF |
311 | cy::location location_; |
312 | std::string message_; | |
313 | }; | |
314 | ||
315 | typedef std::vector<Error> Errors; | |
316 | ||
3b52fd1a | 317 | CYProgram *program_; |
5befe15e | 318 | Errors errors_; |
5999c315 JF |
319 | |
320 | private: | |
321 | void ScannerInit(); | |
322 | void ScannerDestroy(); | |
323 | ||
324 | public: | |
325 | CYDriver(const std::string &filename); | |
326 | ~CYDriver(); | |
63cd45c9 JF |
327 | |
328 | void SetCondition(Condition condition); | |
b10bd496 JF |
329 | |
330 | void Warning(const cy::location &location, const char *message); | |
5999c315 JF |
331 | }; |
332 | ||
cac61857 | 333 | struct CYForInitialiser { |
652ec1ba | 334 | virtual void For(CYOutput &out) const = 0; |
dea834b0 JF |
335 | }; |
336 | ||
cac61857 | 337 | struct CYForInInitialiser { |
652ec1ba | 338 | virtual void ForIn(CYOutput &out, CYFlags flags) const = 0; |
75b0a457 | 339 | virtual const char *ForEachIn() const = 0; |
652ec1ba | 340 | virtual void ForEachIn(CYOutput &out) const = 0; |
3b52fd1a | 341 | virtual CYExpression *ForEachIn(CYContext &out) = 0; |
b09da87b JF |
342 | }; |
343 | ||
cf7d4c69 | 344 | struct CYExpression : |
5999c315 | 345 | CYNext<CYExpression>, |
cf7d4c69 | 346 | CYForInitialiser, |
e5bc40db | 347 | CYForInInitialiser, |
96a7e5c2 JF |
348 | CYClassName, |
349 | CYThing | |
63b4c5a8 | 350 | { |
d35a3b07 | 351 | virtual unsigned Precedence() const = 0; |
75b0a457 | 352 | |
fb98ac0c JF |
353 | virtual bool RightHand() const { |
354 | return true; | |
355 | } | |
356 | ||
652ec1ba JF |
357 | virtual void For(CYOutput &out) const; |
358 | virtual void ForIn(CYOutput &out, CYFlags flags) const; | |
75b0a457 | 359 | |
cac61857 | 360 | virtual const char *ForEachIn() const; |
652ec1ba | 361 | virtual void ForEachIn(CYOutput &out) const; |
3b52fd1a | 362 | virtual CYExpression *ForEachIn(CYContext &out); |
75b0a457 | 363 | |
96a7e5c2 | 364 | virtual void Output(CYOutput &out) const; |
652ec1ba JF |
365 | virtual void Output(CYOutput &out, CYFlags flags) const = 0; |
366 | void Output(CYOutput &out, unsigned precedence, CYFlags flags) const; | |
dea834b0 | 367 | |
3b52fd1a | 368 | virtual CYExpression *ClassName(CYContext &context, bool object); |
652ec1ba | 369 | virtual void ClassName(CYOutput &out, bool object) const; |
e5bc40db | 370 | |
3b52fd1a JF |
371 | CYExpression *ReplaceAll(CYContext &context); |
372 | ||
373 | virtual CYExpression *Replace(CYContext &context) = 0; | |
374 | ||
dea834b0 JF |
375 | virtual const char *Word() const { |
376 | return NULL; | |
377 | } | |
63b4c5a8 JF |
378 | }; |
379 | ||
b09da87b JF |
380 | #define CYAlphabetic(value) \ |
381 | virtual bool Alphabetic() const { \ | |
382 | return value; \ | |
383 | } | |
384 | ||
d35a3b07 JF |
385 | #define CYPrecedence(value) \ |
386 | virtual unsigned Precedence() const { \ | |
387 | return value; \ | |
388 | } | |
389 | ||
fb98ac0c JF |
390 | #define CYRightHand(value) \ |
391 | virtual bool RightHand() const { \ | |
392 | return value; \ | |
393 | } | |
394 | ||
d35a3b07 JF |
395 | struct CYCompound : |
396 | CYExpression | |
397 | { | |
398 | CYExpression *expressions_; | |
399 | ||
400 | CYCompound(CYExpression *expressions) : | |
401 | expressions_(expressions) | |
402 | { | |
403 | } | |
404 | ||
405 | void AddPrev(CYExpression *expression) { | |
406 | CYExpression *last(expression); | |
407 | while (last->next_ != NULL) | |
408 | last = last->next_; | |
409 | last->SetNext(expressions_); | |
410 | expressions_ = expression; | |
411 | } | |
412 | ||
413 | CYPrecedence(17) | |
414 | ||
3b52fd1a | 415 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 416 | void Output(CYOutput &out, CYFlags flags) const; |
d35a3b07 | 417 | }; |
5999c315 | 418 | |
3b52fd1a JF |
419 | struct CYFunctionParameter : |
420 | CYNext<CYFunctionParameter>, | |
421 | CYThing | |
422 | { | |
423 | CYIdentifier *name_; | |
424 | ||
425 | CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) : | |
426 | CYNext<CYFunctionParameter>(next), | |
427 | name_(name) | |
428 | { | |
429 | } | |
430 | ||
431 | virtual void Output(CYOutput &out) const; | |
432 | }; | |
433 | ||
75b0a457 | 434 | struct CYComprehension : |
96a7e5c2 JF |
435 | CYNext<CYComprehension>, |
436 | CYThing | |
75b0a457 | 437 | { |
652ec1ba | 438 | void Output(CYOutput &out) const; |
75b0a457 JF |
439 | virtual const char *Name() const = 0; |
440 | ||
652ec1ba | 441 | virtual void Begin_(CYOutput &out) const = 0; |
75b0a457 | 442 | |
652ec1ba | 443 | virtual void End_(CYOutput &out) const { |
75b0a457 | 444 | } |
3b52fd1a JF |
445 | |
446 | virtual CYFunctionParameter *Parameter(CYContext &context) const = 0; | |
447 | CYFunctionParameter *Parameters(CYContext &context) const; | |
448 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
75b0a457 JF |
449 | }; |
450 | ||
451 | struct CYForInComprehension : | |
452 | CYComprehension | |
453 | { | |
454 | CYIdentifier *name_; | |
455 | CYExpression *set_; | |
456 | ||
457 | CYForInComprehension(CYIdentifier *name, CYExpression *set) : | |
458 | name_(name), | |
459 | set_(set) | |
460 | { | |
461 | } | |
462 | ||
463 | virtual const char *Name() const { | |
464 | return name_->Value(); | |
465 | } | |
466 | ||
652ec1ba | 467 | virtual void Begin_(CYOutput &out) const; |
3b52fd1a JF |
468 | |
469 | virtual CYFunctionParameter *Parameter(CYContext &context) const; | |
470 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
75b0a457 JF |
471 | }; |
472 | ||
473 | struct CYForEachInComprehension : | |
474 | CYComprehension | |
475 | { | |
476 | CYIdentifier *name_; | |
477 | CYExpression *set_; | |
478 | ||
479 | CYForEachInComprehension(CYIdentifier *name, CYExpression *set) : | |
480 | name_(name), | |
481 | set_(set) | |
482 | { | |
483 | } | |
484 | ||
485 | virtual const char *Name() const { | |
486 | return name_->Value(); | |
487 | } | |
488 | ||
652ec1ba JF |
489 | virtual void Begin_(CYOutput &out) const; |
490 | virtual void End_(CYOutput &out) const; | |
3b52fd1a JF |
491 | |
492 | virtual CYFunctionParameter *Parameter(CYContext &context) const; | |
493 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
75b0a457 JF |
494 | }; |
495 | ||
496 | struct CYIfComprehension : | |
497 | CYComprehension | |
498 | { | |
499 | CYExpression *test_; | |
500 | ||
501 | CYIfComprehension(CYExpression *test) : | |
502 | test_(test) | |
503 | { | |
504 | } | |
505 | ||
506 | virtual const char *Name() const { | |
507 | return NULL; | |
508 | } | |
509 | ||
652ec1ba | 510 | virtual void Begin_(CYOutput &out) const; |
3b52fd1a JF |
511 | |
512 | virtual CYFunctionParameter *Parameter(CYContext &context) const; | |
513 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
75b0a457 JF |
514 | }; |
515 | ||
516 | struct CYArrayComprehension : | |
517 | CYExpression | |
518 | { | |
519 | CYExpression *expression_; | |
520 | CYComprehension *comprehensions_; | |
521 | ||
522 | CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) : | |
523 | expression_(expression), | |
524 | comprehensions_(comprehensions) | |
525 | { | |
526 | } | |
527 | ||
528 | CYPrecedence(0) | |
529 | ||
3b52fd1a | 530 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 531 | virtual void Output(CYOutput &out, CYFlags flags) const; |
75b0a457 JF |
532 | }; |
533 | ||
cf7d4c69 JF |
534 | struct CYLiteral : |
535 | CYExpression | |
63b4c5a8 | 536 | { |
d35a3b07 | 537 | CYPrecedence(0) |
fb98ac0c | 538 | CYRightHand(false) |
cf7d4c69 | 539 | }; |
63b4c5a8 | 540 | |
3b52fd1a JF |
541 | struct CYTrivial : |
542 | CYLiteral | |
543 | { | |
544 | virtual CYExpression *Replace(CYContext &context); | |
545 | }; | |
546 | ||
478d4ed0 JF |
547 | struct CYMagic : |
548 | CYExpression | |
549 | { | |
550 | CYPrecedence(0) | |
fb98ac0c | 551 | CYRightHand(false) |
478d4ed0 JF |
552 | }; |
553 | ||
dea834b0 JF |
554 | struct CYRange { |
555 | uint64_t lo_; | |
556 | uint64_t hi_; | |
557 | ||
558 | CYRange(uint64_t lo, uint64_t hi) : | |
559 | lo_(lo), hi_(hi) | |
560 | { | |
561 | } | |
562 | ||
563 | bool operator [](uint8_t value) const { | |
564 | return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1; | |
565 | } | |
566 | ||
567 | void operator()(uint8_t value) { | |
568 | if (value >> 7) | |
569 | return; | |
570 | (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f); | |
571 | } | |
572 | }; | |
573 | ||
283e7e33 | 574 | extern CYRange DigitRange_; |
dea834b0 JF |
575 | extern CYRange WordStartRange_; |
576 | extern CYRange WordEndRange_; | |
577 | ||
cf7d4c69 | 578 | struct CYString : |
3b52fd1a | 579 | CYTrivial, |
e5bc40db | 580 | CYPropertyName |
cf7d4c69 JF |
581 | { |
582 | const char *value_; | |
5999c315 | 583 | size_t size_; |
cf7d4c69 | 584 | |
3b52fd1a JF |
585 | CYString() : |
586 | value_(NULL), | |
587 | size_(0) | |
588 | { | |
589 | } | |
590 | ||
591 | CYString(const char *value) : | |
592 | value_(value), | |
593 | size_(strlen(value)) | |
594 | { | |
595 | } | |
596 | ||
5999c315 JF |
597 | CYString(const char *value, size_t size) : |
598 | value_(value), | |
599 | size_(size) | |
cf7d4c69 JF |
600 | { |
601 | } | |
602 | ||
3b52fd1a JF |
603 | CYString(const CYWord *word) : |
604 | value_(word->Value()), | |
5999c315 | 605 | size_(strlen(value_)) |
cf7d4c69 JF |
606 | { |
607 | } | |
608 | ||
5999c315 | 609 | const char *Value() const { |
cf7d4c69 JF |
610 | return value_; |
611 | } | |
612 | ||
11c1cc16 | 613 | virtual const char *Word() const; |
dea834b0 | 614 | |
652ec1ba JF |
615 | virtual void Output(CYOutput &out, CYFlags flags) const; |
616 | virtual void PropertyName(CYOutput &out) const; | |
63b4c5a8 JF |
617 | }; |
618 | ||
3b52fd1a JF |
619 | struct CYSelectorPart : |
620 | CYNext<CYSelectorPart>, | |
621 | CYThing | |
622 | { | |
623 | CYWord *name_; | |
624 | bool value_; | |
625 | ||
626 | CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) : | |
627 | CYNext<CYSelectorPart>(next), | |
628 | name_(name), | |
629 | value_(value) | |
630 | { | |
631 | } | |
632 | ||
633 | CYString *Replace(CYContext &context); | |
634 | virtual void Output(CYOutput &out) const; | |
635 | }; | |
636 | ||
637 | struct CYSelector : | |
638 | CYLiteral | |
639 | { | |
640 | CYSelectorPart *name_; | |
641 | ||
642 | CYSelector(CYSelectorPart *name) : | |
643 | name_(name) | |
644 | { | |
645 | } | |
646 | ||
647 | CYPrecedence(1) | |
648 | ||
649 | virtual CYExpression *Replace(CYContext &context); | |
650 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
651 | }; | |
652 | ||
cf7d4c69 | 653 | struct CYNumber : |
3b52fd1a | 654 | CYTrivial, |
e5bc40db | 655 | CYPropertyName |
cf7d4c69 | 656 | { |
5999c315 JF |
657 | double value_; |
658 | ||
659 | CYNumber(double value) : | |
660 | value_(value) | |
661 | { | |
662 | } | |
663 | ||
664 | double Value() const { | |
665 | return value_; | |
cf7d4c69 JF |
666 | } |
667 | ||
652ec1ba JF |
668 | virtual void Output(CYOutput &out, CYFlags flags) const; |
669 | virtual void PropertyName(CYOutput &out) const; | |
cf7d4c69 JF |
670 | }; |
671 | ||
63cd45c9 | 672 | struct CYRegEx : |
3b52fd1a | 673 | CYTrivial |
63cd45c9 JF |
674 | { |
675 | const char *value_; | |
676 | ||
677 | CYRegEx(const char *value) : | |
678 | value_(value) | |
679 | { | |
680 | } | |
681 | ||
682 | const char *Value() const { | |
683 | return value_; | |
684 | } | |
685 | ||
686 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
687 | }; | |
688 | ||
cf7d4c69 JF |
689 | struct CYNull : |
690 | CYWord, | |
3b52fd1a | 691 | CYTrivial |
cf7d4c69 JF |
692 | { |
693 | CYNull() : | |
694 | CYWord("null") | |
695 | { | |
696 | } | |
5999c315 | 697 | |
652ec1ba | 698 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
699 | }; |
700 | ||
701 | struct CYThis : | |
702 | CYWord, | |
478d4ed0 | 703 | CYMagic |
cf7d4c69 JF |
704 | { |
705 | CYThis() : | |
706 | CYWord("this") | |
707 | { | |
708 | } | |
5999c315 | 709 | |
3b52fd1a | 710 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 711 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
712 | }; |
713 | ||
714 | struct CYBoolean : | |
3b52fd1a | 715 | CYTrivial |
cf7d4c69 | 716 | { |
5999c315 | 717 | virtual bool Value() const = 0; |
652ec1ba | 718 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
719 | }; |
720 | ||
721 | struct CYFalse : | |
722 | CYWord, | |
723 | CYBoolean | |
724 | { | |
725 | CYFalse() : | |
726 | CYWord("false") | |
727 | { | |
728 | } | |
5999c315 | 729 | |
11c1cc16 JF |
730 | virtual bool Value() const { |
731 | return false; | |
732 | } | |
cf7d4c69 JF |
733 | }; |
734 | ||
735 | struct CYTrue : | |
736 | CYWord, | |
737 | CYBoolean | |
738 | { | |
739 | CYTrue() : | |
740 | CYWord("true") | |
741 | { | |
742 | } | |
5999c315 | 743 | |
11c1cc16 JF |
744 | virtual bool Value() const { |
745 | return true; | |
746 | } | |
cf7d4c69 JF |
747 | }; |
748 | ||
749 | struct CYVariable : | |
750 | CYExpression | |
751 | { | |
752 | CYIdentifier *name_; | |
753 | ||
754 | CYVariable(CYIdentifier *name) : | |
755 | name_(name) | |
756 | { | |
757 | } | |
5999c315 | 758 | |
d35a3b07 | 759 | CYPrecedence(0) |
fb98ac0c | 760 | CYRightHand(false) |
d35a3b07 | 761 | |
3b52fd1a | 762 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 763 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
764 | }; |
765 | ||
766 | struct CYPrefix : | |
63b4c5a8 JF |
767 | CYExpression |
768 | { | |
769 | CYExpression *rhs_; | |
770 | ||
cf7d4c69 | 771 | CYPrefix(CYExpression *rhs) : |
63b4c5a8 JF |
772 | rhs_(rhs) |
773 | { | |
774 | } | |
5999c315 | 775 | |
b09da87b | 776 | virtual bool Alphabetic() const = 0; |
5999c315 JF |
777 | virtual const char *Operator() const = 0; |
778 | ||
3b52fd1a JF |
779 | CYPrecedence(4) |
780 | ||
781 | virtual CYExpression *Replace(CYContext &context); | |
652ec1ba | 782 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
783 | }; |
784 | ||
cf7d4c69 | 785 | struct CYInfix : |
63b4c5a8 JF |
786 | CYExpression |
787 | { | |
788 | CYExpression *lhs_; | |
789 | CYExpression *rhs_; | |
790 | ||
cf7d4c69 | 791 | CYInfix(CYExpression *lhs, CYExpression *rhs) : |
63b4c5a8 JF |
792 | lhs_(lhs), |
793 | rhs_(rhs) | |
794 | { | |
795 | } | |
5999c315 | 796 | |
0ff9f149 JF |
797 | void SetLeft(CYExpression *lhs) { |
798 | lhs_ = lhs; | |
799 | } | |
800 | ||
b09da87b | 801 | virtual bool Alphabetic() const = 0; |
5999c315 JF |
802 | virtual const char *Operator() const = 0; |
803 | ||
3b52fd1a | 804 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 805 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
806 | }; |
807 | ||
cf7d4c69 | 808 | struct CYPostfix : |
63b4c5a8 JF |
809 | CYExpression |
810 | { | |
811 | CYExpression *lhs_; | |
812 | ||
cf7d4c69 | 813 | CYPostfix(CYExpression *lhs) : |
63b4c5a8 JF |
814 | lhs_(lhs) |
815 | { | |
816 | } | |
5999c315 JF |
817 | |
818 | virtual const char *Operator() const = 0; | |
819 | ||
3b52fd1a JF |
820 | CYPrecedence(3) |
821 | ||
822 | virtual CYExpression *Replace(CYContext &context); | |
652ec1ba | 823 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
824 | }; |
825 | ||
cf7d4c69 | 826 | struct CYAssignment : |
d35a3b07 | 827 | CYExpression |
cf7d4c69 | 828 | { |
d35a3b07 JF |
829 | CYExpression *lhs_; |
830 | CYExpression *rhs_; | |
831 | ||
cf7d4c69 | 832 | CYAssignment(CYExpression *lhs, CYExpression *rhs) : |
d35a3b07 JF |
833 | lhs_(lhs), |
834 | rhs_(rhs) | |
cf7d4c69 JF |
835 | { |
836 | } | |
5999c315 | 837 | |
0ff9f149 JF |
838 | void SetLeft(CYExpression *lhs) { |
839 | lhs_ = lhs; | |
840 | } | |
841 | ||
5999c315 | 842 | virtual const char *Operator() const = 0; |
d35a3b07 | 843 | |
3b52fd1a | 844 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 845 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
846 | }; |
847 | ||
62014ea9 | 848 | struct CYArgument : |
96a7e5c2 JF |
849 | CYNext<CYArgument>, |
850 | CYThing | |
62014ea9 | 851 | { |
cf7d4c69 JF |
852 | CYWord *name_; |
853 | CYExpression *value_; | |
cf7d4c69 | 854 | |
3b52fd1a JF |
855 | CYArgument(CYExpression *value, CYArgument *next = NULL) : |
856 | CYNext<CYArgument>(next), | |
857 | name_(NULL), | |
858 | value_(value) | |
859 | { | |
860 | } | |
861 | ||
cf7d4c69 | 862 | CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) : |
62014ea9 | 863 | CYNext<CYArgument>(next), |
cf7d4c69 | 864 | name_(name), |
62014ea9 | 865 | value_(value) |
cf7d4c69 JF |
866 | { |
867 | } | |
5999c315 | 868 | |
3b52fd1a | 869 | void Replace(CYContext &context); |
652ec1ba | 870 | void Output(CYOutput &out) const; |
cf7d4c69 JF |
871 | }; |
872 | ||
873 | struct CYBlank : | |
874 | public CYWord | |
875 | { | |
876 | CYBlank() : | |
877 | CYWord("") | |
878 | { | |
879 | } | |
880 | }; | |
881 | ||
5999c315 JF |
882 | struct CYClause : |
883 | CYThing, | |
884 | CYNext<CYClause> | |
885 | { | |
cf7d4c69 | 886 | CYExpression *case_; |
3b52fd1a | 887 | CYStatement *statements_; |
cf7d4c69 | 888 | |
3b52fd1a | 889 | CYClause(CYExpression *_case, CYStatement *statements) : |
cf7d4c69 | 890 | case_(_case), |
3b52fd1a | 891 | statements_(statements) |
cf7d4c69 JF |
892 | { |
893 | } | |
894 | ||
3b52fd1a | 895 | virtual void Replace(CYContext &context); |
652ec1ba | 896 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
897 | }; |
898 | ||
62014ea9 | 899 | struct CYElement : |
96a7e5c2 JF |
900 | CYNext<CYElement>, |
901 | CYThing | |
62014ea9 | 902 | { |
cf7d4c69 | 903 | CYExpression *value_; |
cf7d4c69 JF |
904 | |
905 | CYElement(CYExpression *value, CYElement *next) : | |
62014ea9 JF |
906 | CYNext<CYElement>(next), |
907 | value_(value) | |
cf7d4c69 JF |
908 | { |
909 | } | |
5999c315 | 910 | |
3b52fd1a | 911 | void Replace(CYContext &context); |
652ec1ba | 912 | void Output(CYOutput &out) const; |
5befe15e JF |
913 | }; |
914 | ||
915 | struct CYArray : | |
916 | CYLiteral | |
917 | { | |
918 | CYElement *elements_; | |
919 | ||
3b52fd1a | 920 | CYArray(CYElement *elements = NULL) : |
5befe15e JF |
921 | elements_(elements) |
922 | { | |
923 | } | |
924 | ||
3b52fd1a | 925 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 926 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
927 | }; |
928 | ||
929 | struct CYDeclaration : | |
930 | CYForInInitialiser | |
931 | { | |
932 | CYIdentifier *identifier_; | |
933 | CYExpression *initialiser_; | |
934 | ||
935 | CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) : | |
936 | identifier_(identifier), | |
937 | initialiser_(initialiser) | |
938 | { | |
939 | } | |
5999c315 | 940 | |
652ec1ba | 941 | virtual void ForIn(CYOutput &out, CYFlags flags) const; |
75b0a457 | 942 | |
cac61857 | 943 | virtual const char *ForEachIn() const; |
652ec1ba | 944 | virtual void ForEachIn(CYOutput &out) const; |
3b52fd1a JF |
945 | virtual CYExpression *ForEachIn(CYContext &out); |
946 | ||
947 | void Replace(CYContext &context); | |
75b0a457 | 948 | |
652ec1ba | 949 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
950 | }; |
951 | ||
952 | struct CYDeclarations : | |
cac61857 | 953 | CYNext<CYDeclarations>, |
96a7e5c2 JF |
954 | CYForInitialiser, |
955 | CYThing | |
cf7d4c69 JF |
956 | { |
957 | CYDeclaration *declaration_; | |
cf7d4c69 JF |
958 | |
959 | CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) : | |
cac61857 JF |
960 | CYNext<CYDeclarations>(next), |
961 | declaration_(declaration) | |
962 | { | |
963 | } | |
964 | ||
652ec1ba | 965 | virtual void For(CYOutput &out) const; |
96a7e5c2 | 966 | |
3b52fd1a JF |
967 | void Replace(CYContext &context); |
968 | ||
96a7e5c2 | 969 | virtual void Output(CYOutput &out) const; |
652ec1ba | 970 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cac61857 JF |
971 | }; |
972 | ||
973 | struct CYVar : | |
974 | CYStatement | |
975 | { | |
976 | CYDeclarations *declarations_; | |
977 | ||
978 | CYVar(CYDeclarations *declarations) : | |
979 | declarations_(declarations) | |
980 | { | |
981 | } | |
982 | ||
3b52fd1a | 983 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 984 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cac61857 JF |
985 | }; |
986 | ||
987 | struct CYLet : | |
988 | CYStatement | |
989 | { | |
990 | CYDeclarations *declarations_; | |
3b52fd1a | 991 | CYBlock code_; |
cac61857 JF |
992 | |
993 | CYLet(CYDeclarations *declarations, CYStatement *statements) : | |
994 | declarations_(declarations), | |
3b52fd1a | 995 | code_(statements) |
cf7d4c69 JF |
996 | { |
997 | } | |
5999c315 | 998 | |
3b52fd1a | 999 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1000 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1001 | }; |
1002 | ||
b09da87b JF |
1003 | struct CYField : |
1004 | CYNext<CYField> | |
1005 | { | |
3b52fd1a JF |
1006 | CYStatement *Replace(CYContext &context) const; |
1007 | void Output(CYOutput &out) const; | |
b09da87b JF |
1008 | }; |
1009 | ||
1010 | struct CYMessageParameter : | |
1011 | CYNext<CYMessageParameter> | |
1012 | { | |
1013 | CYWord *tag_; | |
1014 | CYExpression *type_; | |
1015 | CYIdentifier *name_; | |
1016 | ||
1017 | CYMessageParameter(CYWord *tag, CYExpression *type, CYIdentifier *name) : | |
1018 | tag_(tag), | |
1019 | type_(type), | |
1020 | name_(name) | |
1021 | { | |
1022 | } | |
3b52fd1a JF |
1023 | |
1024 | CYFunctionParameter *Parameters(CYContext &context) const; | |
1025 | CYSelector *Selector(CYContext &context) const; | |
1026 | CYSelectorPart *SelectorPart(CYContext &context) const; | |
b09da87b JF |
1027 | }; |
1028 | ||
1029 | struct CYMessage : | |
e5bc40db | 1030 | CYNext<CYMessage> |
b09da87b JF |
1031 | { |
1032 | bool instance_; | |
1033 | CYExpression *type_; | |
3b52fd1a JF |
1034 | CYMessageParameter *parameters_; |
1035 | CYStatement *statements_; | |
b09da87b | 1036 | |
3b52fd1a | 1037 | CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *statements) : |
b09da87b JF |
1038 | instance_(instance), |
1039 | type_(type), | |
3b52fd1a JF |
1040 | parameters_(parameter), |
1041 | statements_(statements) | |
b09da87b JF |
1042 | { |
1043 | } | |
1044 | ||
3b52fd1a JF |
1045 | CYStatement *Replace(CYContext &context, bool replace) const; |
1046 | void Output(CYOutput &out, bool replace) const; | |
b09da87b JF |
1047 | }; |
1048 | ||
fb98ac0c | 1049 | struct CYClass { |
367eebb1 | 1050 | CYClassName *name_; |
b09da87b JF |
1051 | CYExpression *super_; |
1052 | CYField *fields_; | |
1053 | CYMessage *messages_; | |
1054 | ||
367eebb1 | 1055 | CYClass(CYClassName *name, CYExpression *super, CYField *fields, CYMessage *messages) : |
b09da87b JF |
1056 | name_(name), |
1057 | super_(super), | |
1058 | fields_(fields), | |
1059 | messages_(messages) | |
1060 | { | |
1061 | } | |
1062 | ||
3b52fd1a | 1063 | CYExpression *Replace_(CYContext &context); |
fb98ac0c JF |
1064 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1065 | }; | |
1066 | ||
1067 | struct CYClassExpression : | |
1068 | CYClass, | |
1069 | CYExpression | |
1070 | { | |
1071 | CYClassExpression(CYClassName *name, CYExpression *super, CYField *fields, CYMessage *messages) : | |
1072 | CYClass(name, super, fields, messages) | |
1073 | { | |
1074 | } | |
1075 | ||
367eebb1 JF |
1076 | CYPrecedence(0) |
1077 | ||
3b52fd1a | 1078 | virtual CYExpression *Replace(CYContext &context); |
fb98ac0c JF |
1079 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1080 | }; | |
1081 | ||
1082 | struct CYClassStatement : | |
1083 | CYClass, | |
1084 | CYStatement | |
1085 | { | |
1086 | CYClassStatement(CYClassName *name, CYExpression *super, CYField *fields, CYMessage *messages) : | |
1087 | CYClass(name, super, fields, messages) | |
1088 | { | |
1089 | } | |
1090 | ||
3b52fd1a | 1091 | virtual CYStatement *Replace(CYContext &context); |
652ec1ba | 1092 | virtual void Output(CYOutput &out, CYFlags flags) const; |
b09da87b JF |
1093 | }; |
1094 | ||
e5bc40db | 1095 | struct CYCategory : |
367eebb1 | 1096 | CYStatement |
e5bc40db JF |
1097 | { |
1098 | CYClassName *name_; | |
1099 | CYMessage *messages_; | |
1100 | ||
1101 | CYCategory(CYClassName *name, CYMessage *messages) : | |
1102 | name_(name), | |
1103 | messages_(messages) | |
1104 | { | |
1105 | } | |
1106 | ||
3b52fd1a | 1107 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1108 | virtual void Output(CYOutput &out, CYFlags flags) const; |
e5bc40db JF |
1109 | }; |
1110 | ||
cf7d4c69 JF |
1111 | struct CYFor : |
1112 | CYStatement | |
1113 | { | |
1114 | CYForInitialiser *initialiser_; | |
1115 | CYExpression *test_; | |
1116 | CYExpression *increment_; | |
1117 | CYStatement *code_; | |
1118 | ||
1119 | CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) : | |
1120 | initialiser_(initialiser), | |
1121 | test_(test), | |
1122 | increment_(increment), | |
1123 | code_(code) | |
1124 | { | |
1125 | } | |
5999c315 | 1126 | |
3b52fd1a | 1127 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1128 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1129 | }; |
1130 | ||
1131 | struct CYForIn : | |
1132 | CYStatement | |
1133 | { | |
1134 | CYForInInitialiser *initialiser_; | |
1135 | CYExpression *set_; | |
1136 | CYStatement *code_; | |
1137 | ||
1138 | CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) : | |
1139 | initialiser_(initialiser), | |
1140 | set_(set), | |
1141 | code_(code) | |
1142 | { | |
1143 | } | |
5999c315 | 1144 | |
3b52fd1a | 1145 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1146 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1147 | }; |
1148 | ||
75b0a457 JF |
1149 | struct CYForEachIn : |
1150 | CYStatement | |
1151 | { | |
1152 | CYForInInitialiser *initialiser_; | |
1153 | CYExpression *set_; | |
1154 | CYStatement *code_; | |
1155 | ||
1156 | CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) : | |
1157 | initialiser_(initialiser), | |
1158 | set_(set), | |
1159 | code_(code) | |
1160 | { | |
1161 | } | |
1162 | ||
3b52fd1a | 1163 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1164 | virtual void Output(CYOutput &out, CYFlags flags) const; |
75b0a457 JF |
1165 | }; |
1166 | ||
62014ea9 | 1167 | struct CYProperty : |
96a7e5c2 JF |
1168 | CYNext<CYProperty>, |
1169 | CYThing | |
62014ea9 | 1170 | { |
e5bc40db | 1171 | CYPropertyName *name_; |
cf7d4c69 | 1172 | CYExpression *value_; |
cf7d4c69 | 1173 | |
3b52fd1a | 1174 | CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) : |
62014ea9 | 1175 | CYNext<CYProperty>(next), |
cf7d4c69 | 1176 | name_(name), |
62014ea9 | 1177 | value_(value) |
cf7d4c69 JF |
1178 | { |
1179 | } | |
5999c315 | 1180 | |
3b52fd1a | 1181 | void Replace(CYContext &context); |
652ec1ba | 1182 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1183 | }; |
1184 | ||
693d501b JF |
1185 | struct CYObject : |
1186 | CYLiteral | |
1187 | { | |
3b52fd1a | 1188 | CYProperty *properties_; |
693d501b | 1189 | |
3b52fd1a JF |
1190 | CYObject(CYProperty *properties) : |
1191 | properties_(properties) | |
693d501b JF |
1192 | { |
1193 | } | |
1194 | ||
3b52fd1a | 1195 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1196 | void Output(CYOutput &out, CYFlags flags) const; |
693d501b JF |
1197 | }; |
1198 | ||
5999c315 JF |
1199 | struct CYCatch : |
1200 | CYThing | |
1201 | { | |
cf7d4c69 | 1202 | CYIdentifier *name_; |
3b52fd1a | 1203 | CYBlock code_; |
cf7d4c69 | 1204 | |
3b52fd1a | 1205 | CYCatch(CYIdentifier *name, CYStatement *statements) : |
cf7d4c69 | 1206 | name_(name), |
3b52fd1a | 1207 | code_(statements) |
cf7d4c69 JF |
1208 | { |
1209 | } | |
5999c315 | 1210 | |
3b52fd1a | 1211 | void Replace(CYContext &context); |
652ec1ba | 1212 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1213 | }; |
1214 | ||
b09da87b | 1215 | struct CYSend : |
63b4c5a8 JF |
1216 | CYExpression |
1217 | { | |
cf7d4c69 JF |
1218 | CYExpression *self_; |
1219 | CYArgument *arguments_; | |
63b4c5a8 | 1220 | |
b09da87b | 1221 | CYSend(CYExpression *self, CYArgument *arguments) : |
cf7d4c69 JF |
1222 | self_(self), |
1223 | arguments_(arguments) | |
63b4c5a8 JF |
1224 | { |
1225 | } | |
5999c315 | 1226 | |
d35a3b07 JF |
1227 | CYPrecedence(0) |
1228 | ||
3b52fd1a | 1229 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1230 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
1231 | }; |
1232 | ||
cf7d4c69 JF |
1233 | struct CYMember : |
1234 | CYExpression | |
1235 | { | |
1236 | CYExpression *object_; | |
1237 | CYExpression *property_; | |
1238 | ||
1239 | CYMember(CYExpression *object, CYExpression *property) : | |
1240 | object_(object), | |
1241 | property_(property) | |
1242 | { | |
1243 | } | |
5999c315 | 1244 | |
9b5527f0 JF |
1245 | void SetLeft(CYExpression *object) { |
1246 | object_ = object; | |
1247 | } | |
3b52fd1a JF |
1248 | |
1249 | void Replace_(CYContext &context); | |
9b5527f0 JF |
1250 | }; |
1251 | ||
1252 | struct CYDirectMember : | |
1253 | CYMember | |
1254 | { | |
1255 | CYDirectMember(CYExpression *object, CYExpression *property) : | |
1256 | CYMember(object, property) | |
1257 | { | |
1258 | } | |
1259 | ||
1260 | CYPrecedence(1) | |
fb98ac0c | 1261 | CYRightHand(false) |
9b5527f0 | 1262 | |
3b52fd1a | 1263 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1264 | virtual void Output(CYOutput &out, CYFlags flags) const; |
9b5527f0 JF |
1265 | }; |
1266 | ||
1267 | struct CYIndirectMember : | |
1268 | CYMember | |
1269 | { | |
1270 | CYIndirectMember(CYExpression *object, CYExpression *property) : | |
1271 | CYMember(object, property) | |
1272 | { | |
1273 | } | |
1274 | ||
d35a3b07 | 1275 | CYPrecedence(1) |
fb98ac0c | 1276 | CYRightHand(false) |
d35a3b07 | 1277 | |
3b52fd1a | 1278 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1279 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1280 | }; |
1281 | ||
1282 | struct CYNew : | |
1283 | CYExpression | |
1284 | { | |
1285 | CYExpression *constructor_; | |
1286 | CYArgument *arguments_; | |
1287 | ||
1288 | CYNew(CYExpression *constructor, CYArgument *arguments) : | |
1289 | constructor_(constructor), | |
1290 | arguments_(arguments) | |
1291 | { | |
1292 | } | |
5999c315 | 1293 | |
fb98ac0c JF |
1294 | virtual unsigned Precedence() const { |
1295 | return arguments_ == NULL ? 2 : 1; | |
1296 | } | |
1297 | ||
1298 | CYRightHand(false) | |
d35a3b07 | 1299 | |
3b52fd1a | 1300 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1301 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1302 | }; |
1303 | ||
1304 | struct CYCall : | |
1305 | CYExpression | |
1306 | { | |
1307 | CYExpression *function_; | |
1308 | CYArgument *arguments_; | |
1309 | ||
3b52fd1a | 1310 | CYCall(CYExpression *function, CYArgument *arguments = NULL) : |
cf7d4c69 JF |
1311 | function_(function), |
1312 | arguments_(arguments) | |
1313 | { | |
1314 | } | |
5999c315 | 1315 | |
fb98ac0c JF |
1316 | CYPrecedence(1) |
1317 | CYRightHand(false) | |
d35a3b07 | 1318 | |
3b52fd1a | 1319 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1320 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1321 | }; |
1322 | ||
1323 | struct CYIf : | |
1324 | CYStatement | |
1325 | { | |
1326 | CYExpression *test_; | |
1327 | CYStatement *true_; | |
1328 | CYStatement *false_; | |
1329 | ||
3b52fd1a | 1330 | CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) : |
cf7d4c69 JF |
1331 | test_(test), |
1332 | true_(_true), | |
1333 | false_(_false) | |
1334 | { | |
1335 | } | |
5999c315 | 1336 | |
3b52fd1a | 1337 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1338 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1339 | }; |
1340 | ||
1341 | struct CYDoWhile : | |
1342 | CYStatement | |
1343 | { | |
1344 | CYExpression *test_; | |
1345 | CYStatement *code_; | |
1346 | ||
1347 | CYDoWhile(CYExpression *test, CYStatement *code) : | |
1348 | test_(test), | |
1349 | code_(code) | |
1350 | { | |
1351 | } | |
5999c315 | 1352 | |
3b52fd1a | 1353 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1354 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1355 | }; |
1356 | ||
1357 | struct CYWhile : | |
1358 | CYStatement | |
1359 | { | |
1360 | CYExpression *test_; | |
1361 | CYStatement *code_; | |
1362 | ||
1363 | CYWhile(CYExpression *test, CYStatement *code) : | |
1364 | test_(test), | |
1365 | code_(code) | |
1366 | { | |
1367 | } | |
5999c315 | 1368 | |
3b52fd1a | 1369 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1370 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1371 | }; |
1372 | ||
fb98ac0c | 1373 | struct CYFunction { |
cf7d4c69 | 1374 | CYIdentifier *name_; |
b09da87b | 1375 | CYFunctionParameter *parameters_; |
3b52fd1a | 1376 | CYBlock code_; |
cf7d4c69 | 1377 | |
3b52fd1a | 1378 | CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : |
cf7d4c69 JF |
1379 | name_(name), |
1380 | parameters_(parameters), | |
3b52fd1a | 1381 | code_(statements) |
cf7d4c69 JF |
1382 | { |
1383 | } | |
5999c315 | 1384 | |
3b52fd1a | 1385 | virtual void Replace_(CYContext &context); |
fb98ac0c JF |
1386 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1387 | }; | |
1388 | ||
1389 | struct CYFunctionExpression : | |
1390 | CYFunction, | |
1391 | CYExpression | |
1392 | { | |
3b52fd1a JF |
1393 | CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : |
1394 | CYFunction(name, parameters, statements) | |
fb98ac0c JF |
1395 | { |
1396 | } | |
1397 | ||
d35a3b07 | 1398 | CYPrecedence(0) |
fb98ac0c | 1399 | CYRightHand(false) |
d35a3b07 | 1400 | |
3b52fd1a | 1401 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1402 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1403 | }; |
1404 | ||
fb98ac0c JF |
1405 | struct CYFunctionStatement : |
1406 | CYFunction, | |
b10bd496 | 1407 | CYStatement |
cf7d4c69 | 1408 | { |
3b52fd1a JF |
1409 | CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : |
1410 | CYFunction(name, parameters, statements) | |
cf7d4c69 JF |
1411 | { |
1412 | } | |
5999c315 | 1413 | |
3b52fd1a | 1414 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1415 | virtual void Output(CYOutput &out, CYFlags flags) const; |
5999c315 JF |
1416 | }; |
1417 | ||
1418 | struct CYExpress : | |
1419 | CYStatement | |
1420 | { | |
1421 | CYExpression *expression_; | |
1422 | ||
1423 | CYExpress(CYExpression *expression) : | |
1424 | expression_(expression) | |
1425 | { | |
1426 | } | |
1427 | ||
3b52fd1a | 1428 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1429 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1430 | }; |
1431 | ||
1432 | struct CYContinue : | |
1433 | CYStatement | |
1434 | { | |
1435 | CYIdentifier *label_; | |
1436 | ||
1437 | CYContinue(CYIdentifier *label) : | |
1438 | label_(label) | |
1439 | { | |
1440 | } | |
5999c315 | 1441 | |
3b52fd1a | 1442 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1443 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1444 | }; |
1445 | ||
1446 | struct CYBreak : | |
1447 | CYStatement | |
1448 | { | |
1449 | CYIdentifier *label_; | |
1450 | ||
1451 | CYBreak(CYIdentifier *label) : | |
1452 | label_(label) | |
1453 | { | |
1454 | } | |
5999c315 | 1455 | |
3b52fd1a | 1456 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1457 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1458 | }; |
1459 | ||
1460 | struct CYReturn : | |
1461 | CYStatement | |
1462 | { | |
1463 | CYExpression *value_; | |
1464 | ||
1465 | CYReturn(CYExpression *value) : | |
1466 | value_(value) | |
1467 | { | |
1468 | } | |
5999c315 | 1469 | |
3b52fd1a | 1470 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1471 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1472 | }; |
1473 | ||
1474 | struct CYEmpty : | |
1475 | CYStatement | |
1476 | { | |
3b52fd1a | 1477 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1478 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1479 | }; |
1480 | ||
96a7e5c2 JF |
1481 | struct CYFinally : |
1482 | CYThing | |
1483 | { | |
3b52fd1a | 1484 | CYBlock code_; |
b10bd496 | 1485 | |
3b52fd1a JF |
1486 | CYFinally(CYStatement *statements) : |
1487 | code_(statements) | |
b10bd496 JF |
1488 | { |
1489 | } | |
1490 | ||
3b52fd1a | 1491 | void Replace(CYContext &context); |
b10bd496 JF |
1492 | virtual void Output(CYOutput &out) const; |
1493 | }; | |
1494 | ||
cf7d4c69 JF |
1495 | struct CYTry : |
1496 | CYStatement | |
1497 | { | |
3b52fd1a | 1498 | CYBlock code_; |
cf7d4c69 | 1499 | CYCatch *catch_; |
b10bd496 | 1500 | CYFinally *finally_; |
cf7d4c69 | 1501 | |
3b52fd1a JF |
1502 | CYTry(CYStatement *statements, CYCatch *_catch, CYFinally *finally) : |
1503 | code_(statements), | |
cf7d4c69 JF |
1504 | catch_(_catch), |
1505 | finally_(finally) | |
1506 | { | |
1507 | } | |
5999c315 | 1508 | |
3b52fd1a | 1509 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1510 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1511 | }; |
1512 | ||
1513 | struct CYThrow : | |
1514 | CYStatement | |
1515 | { | |
1516 | CYExpression *value_; | |
1517 | ||
1518 | CYThrow(CYExpression *value) : | |
1519 | value_(value) | |
1520 | { | |
1521 | } | |
5999c315 | 1522 | |
3b52fd1a | 1523 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1524 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1525 | }; |
1526 | ||
1527 | struct CYWith : | |
1528 | CYStatement | |
1529 | { | |
1530 | CYExpression *scope_; | |
1531 | CYStatement *code_; | |
1532 | ||
1533 | CYWith(CYExpression *scope, CYStatement *code) : | |
1534 | scope_(scope), | |
1535 | code_(code) | |
1536 | { | |
1537 | } | |
5999c315 | 1538 | |
3b52fd1a | 1539 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1540 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1541 | }; |
1542 | ||
1543 | struct CYSwitch : | |
1544 | CYStatement | |
1545 | { | |
1546 | CYExpression *value_; | |
1547 | CYClause *clauses_; | |
1548 | ||
1549 | CYSwitch(CYExpression *value, CYClause *clauses) : | |
1550 | value_(value), | |
1551 | clauses_(clauses) | |
1552 | { | |
1553 | } | |
5999c315 | 1554 | |
3b52fd1a | 1555 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1556 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1557 | }; |
1558 | ||
1559 | struct CYCondition : | |
1560 | CYExpression | |
1561 | { | |
1562 | CYExpression *test_; | |
1563 | CYExpression *true_; | |
1564 | CYExpression *false_; | |
1565 | ||
1566 | CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) : | |
91a416e4 | 1567 | test_(test), |
cf7d4c69 JF |
1568 | true_(_true), |
1569 | false_(_false) | |
1570 | { | |
1571 | } | |
5999c315 | 1572 | |
d35a3b07 JF |
1573 | CYPrecedence(15) |
1574 | ||
3b52fd1a | 1575 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1576 | virtual void Output(CYOutput &out, CYFlags flags) const; |
5999c315 JF |
1577 | }; |
1578 | ||
1579 | struct CYAddressOf : | |
1580 | CYPrefix | |
1581 | { | |
1582 | CYAddressOf(CYExpression *rhs) : | |
1583 | CYPrefix(rhs) | |
1584 | { | |
1585 | } | |
1586 | ||
1587 | virtual const char *Operator() const { | |
1588 | return "&"; | |
1589 | } | |
1590 | ||
b09da87b | 1591 | CYAlphabetic(false) |
d35a3b07 | 1592 | |
3b52fd1a | 1593 | virtual CYExpression *Replace(CYContext &context); |
5999c315 JF |
1594 | }; |
1595 | ||
1596 | struct CYIndirect : | |
1597 | CYPrefix | |
1598 | { | |
1599 | CYIndirect(CYExpression *rhs) : | |
1600 | CYPrefix(rhs) | |
1601 | { | |
1602 | } | |
1603 | ||
1604 | virtual const char *Operator() const { | |
1605 | return "*"; | |
1606 | } | |
1607 | ||
b09da87b | 1608 | CYAlphabetic(false) |
d35a3b07 | 1609 | |
3b52fd1a | 1610 | virtual CYExpression *Replace(CYContext &context); |
cf7d4c69 JF |
1611 | }; |
1612 | ||
1613 | #define CYPostfix_(op, name) \ | |
1614 | struct CY ## name : \ | |
1615 | CYPostfix \ | |
1616 | { \ | |
1617 | CY ## name(CYExpression *lhs) : \ | |
1618 | CYPostfix(lhs) \ | |
1619 | { \ | |
1620 | } \ | |
5999c315 JF |
1621 | \ |
1622 | virtual const char *Operator() const { \ | |
1623 | return op; \ | |
1624 | } \ | |
cf7d4c69 JF |
1625 | }; |
1626 | ||
b09da87b | 1627 | #define CYPrefix_(alphabetic, op, name) \ |
cf7d4c69 JF |
1628 | struct CY ## name : \ |
1629 | CYPrefix \ | |
1630 | { \ | |
1631 | CY ## name(CYExpression *rhs) : \ | |
1632 | CYPrefix(rhs) \ | |
1633 | { \ | |
1634 | } \ | |
d35a3b07 | 1635 | \ |
b09da87b | 1636 | CYAlphabetic(alphabetic) \ |
5999c315 JF |
1637 | \ |
1638 | virtual const char *Operator() const { \ | |
1639 | return op; \ | |
1640 | } \ | |
cf7d4c69 JF |
1641 | }; |
1642 | ||
b09da87b | 1643 | #define CYInfix_(alphabetic, precedence, op, name) \ |
cf7d4c69 JF |
1644 | struct CY ## name : \ |
1645 | CYInfix \ | |
1646 | { \ | |
1647 | CY ## name(CYExpression *lhs, CYExpression *rhs) : \ | |
1648 | CYInfix(lhs, rhs) \ | |
1649 | { \ | |
1650 | } \ | |
d35a3b07 | 1651 | \ |
b09da87b | 1652 | CYAlphabetic(alphabetic) \ |
d35a3b07 | 1653 | CYPrecedence(precedence) \ |
5999c315 JF |
1654 | \ |
1655 | virtual const char *Operator() const { \ | |
1656 | return op; \ | |
1657 | } \ | |
cf7d4c69 JF |
1658 | }; |
1659 | ||
1660 | #define CYAssignment_(op, name) \ | |
1661 | struct CY ## name ## Assign : \ | |
1662 | CYAssignment \ | |
1663 | { \ | |
1664 | CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \ | |
1665 | CYAssignment(lhs, rhs) \ | |
1666 | { \ | |
1667 | } \ | |
d35a3b07 JF |
1668 | \ |
1669 | CYPrecedence(16) \ | |
5999c315 JF |
1670 | \ |
1671 | virtual const char *Operator() const { \ | |
1672 | return op; \ | |
1673 | } \ | |
cf7d4c69 JF |
1674 | }; |
1675 | ||
1676 | CYPostfix_("++", PostIncrement) | |
1677 | CYPostfix_("--", PostDecrement) | |
1678 | ||
b09da87b JF |
1679 | CYPrefix_(true, "delete", Delete) |
1680 | CYPrefix_(true, "void", Void) | |
1681 | CYPrefix_(true, "typeof", TypeOf) | |
1682 | CYPrefix_(false, "++", PreIncrement) | |
1683 | CYPrefix_(false, "--", PreDecrement) | |
c0bc320e | 1684 | CYPrefix_(false, "+", Affirm) |
b09da87b JF |
1685 | CYPrefix_(false, "-", Negate) |
1686 | CYPrefix_(false, "~", BitwiseNot) | |
1687 | CYPrefix_(false, "!", LogicalNot) | |
1688 | ||
1689 | CYInfix_(false, 5, "*", Multiply) | |
1690 | CYInfix_(false, 5, "/", Divide) | |
1691 | CYInfix_(false, 5, "%", Modulus) | |
1692 | CYInfix_(false, 6, "+", Add) | |
1693 | CYInfix_(false, 6, "-", Subtract) | |
1694 | CYInfix_(false, 7, "<<", ShiftLeft) | |
1695 | CYInfix_(false, 7, ">>", ShiftRightSigned) | |
1696 | CYInfix_(false, 7, ">>>", ShiftRightUnsigned) | |
1697 | CYInfix_(false, 8, "<", Less) | |
1698 | CYInfix_(false, 8, ">", Greater) | |
1699 | CYInfix_(false, 8, "<=", LessOrEqual) | |
1700 | CYInfix_(false, 8, ">=", GreaterOrEqual) | |
1701 | CYInfix_(true, 8, "instanceof", InstanceOf) | |
1702 | CYInfix_(true, 8, "in", In) | |
1703 | CYInfix_(false, 9, "==", Equal) | |
1704 | CYInfix_(false, 9, "!=", NotEqual) | |
1705 | CYInfix_(false, 9, "===", Identical) | |
1706 | CYInfix_(false, 9, "!==", NotIdentical) | |
1707 | CYInfix_(false, 10, "&", BitwiseAnd) | |
1708 | CYInfix_(false, 11, "^", BitwiseXOr) | |
1709 | CYInfix_(false, 12, "|", BitwiseOr) | |
1710 | CYInfix_(false, 13, "&&", LogicalAnd) | |
1711 | CYInfix_(false, 14, "||", LogicalOr) | |
cf7d4c69 JF |
1712 | |
1713 | CYAssignment_("=", ) | |
1714 | CYAssignment_("*=", Multiply) | |
1715 | CYAssignment_("/=", Divide) | |
1716 | CYAssignment_("%=", Modulus) | |
1717 | CYAssignment_("+=", Add) | |
1718 | CYAssignment_("-=", Subtract) | |
1719 | CYAssignment_("<<=", ShiftLeft) | |
1720 | CYAssignment_(">>=", ShiftRightSigned) | |
1721 | CYAssignment_(">>>=", ShiftRightUnsigned) | |
1722 | CYAssignment_("&=", BitwiseAnd) | |
1723 | CYAssignment_("^=", BitwiseXOr) | |
1724 | CYAssignment_("|=", BitwiseOr) | |
1725 | ||
63b4c5a8 | 1726 | #endif/*CYPARSER_HPP*/ |