]>
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_; | |
75 | ||
76 | CYOutput(std::ostream &out) : | |
77 | out_(out) | |
78 | { | |
79 | } | |
80 | ||
81 | _finline CYOutput &operator <<(char rhs) { | |
82 | out_ << rhs; | |
83 | return *this; | |
84 | } | |
85 | ||
86 | _finline CYOutput &operator <<(const char *rhs) { | |
87 | out_ << rhs; | |
88 | return *this; | |
89 | } | |
90 | ||
91 | _finline CYOutput &operator <<(const CYThing &rhs) { | |
92 | rhs.Output(*this); | |
93 | return *this; | |
94 | } | |
95 | }; | |
5999c315 | 96 | |
5999c315 | 97 | struct CYSource : |
b1ff2d78 | 98 | CYNext<CYSource> |
5999c315 | 99 | { |
9e562cfc JF |
100 | virtual bool IsBlock() const { |
101 | return next_ != NULL; | |
102 | } | |
103 | ||
652ec1ba JF |
104 | virtual void Show(CYOutput &out) const; |
105 | virtual void Output(CYOutput &out) const = 0; | |
106 | virtual void Output(CYOutput &out, bool block) const; | |
107 | virtual void Output_(CYOutput &out) const; | |
5999c315 JF |
108 | }; |
109 | ||
e5bc40db | 110 | struct CYPropertyName { |
652ec1ba | 111 | virtual void PropertyName(CYOutput &out) const = 0; |
e5bc40db JF |
112 | }; |
113 | ||
114 | struct CYClassName { | |
652ec1ba | 115 | virtual void ClassName(CYOutput &out, bool object) const = 0; |
63b4c5a8 JF |
116 | }; |
117 | ||
cf7d4c69 | 118 | struct CYWord : |
e5bc40db JF |
119 | CYThing, |
120 | CYPropertyName, | |
121 | CYClassName | |
63b4c5a8 | 122 | { |
cf7d4c69 JF |
123 | const char *word_; |
124 | ||
125 | CYWord(const char *word) : | |
126 | word_(word) | |
127 | { | |
128 | } | |
129 | ||
5999c315 | 130 | const char *Value() const { |
cf7d4c69 JF |
131 | return word_; |
132 | } | |
133 | ||
652ec1ba | 134 | virtual void Output(CYOutput &out) const; |
e5bc40db | 135 | |
652ec1ba JF |
136 | virtual void ClassName(CYOutput &out, bool object) const; |
137 | virtual void PropertyName(CYOutput &out) const; | |
63b4c5a8 JF |
138 | }; |
139 | ||
652ec1ba JF |
140 | _finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) { |
141 | return lhs << rhs.Value(); | |
142 | } | |
143 | ||
cf7d4c69 JF |
144 | struct CYIdentifier : |
145 | CYWord | |
63b4c5a8 | 146 | { |
5999c315 JF |
147 | CYIdentifier(const char *word) : |
148 | CYWord(word) | |
149 | { | |
cf7d4c69 | 150 | } |
63b4c5a8 JF |
151 | }; |
152 | ||
62014ea9 JF |
153 | struct CYLabel : |
154 | CYNext<CYLabel> | |
155 | { | |
9e562cfc | 156 | CYIdentifier *name_; |
cf7d4c69 | 157 | |
9e562cfc | 158 | CYLabel(CYIdentifier *name, CYLabel *next) : |
62014ea9 | 159 | CYNext<CYLabel>(next), |
9e562cfc | 160 | name_(name) |
cf7d4c69 JF |
161 | { |
162 | } | |
163 | }; | |
164 | ||
165 | struct CYStatement : | |
166 | CYSource | |
63b4c5a8 | 167 | { |
9e562cfc JF |
168 | CYLabel *labels_; |
169 | ||
170 | CYStatement() : | |
171 | labels_(NULL) | |
172 | { | |
173 | } | |
cf7d4c69 JF |
174 | |
175 | void AddLabel(CYIdentifier *identifier) { | |
9e562cfc JF |
176 | labels_ = new CYLabel(identifier, labels_); |
177 | } | |
178 | ||
652ec1ba | 179 | virtual void Output_(CYOutput &out) const; |
9e562cfc JF |
180 | }; |
181 | ||
182 | struct CYBlock : | |
183 | CYStatement | |
184 | { | |
185 | CYStatement *statements_; | |
186 | ||
187 | CYBlock(CYStatement *statements) : | |
188 | statements_(statements) | |
189 | { | |
cf7d4c69 | 190 | } |
9e562cfc JF |
191 | |
192 | virtual bool IsBlock() const { | |
193 | return true; | |
194 | } | |
195 | ||
652ec1ba | 196 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
197 | }; |
198 | ||
db5e2840 JF |
199 | enum CYState { |
200 | CYClear, | |
201 | CYRestricted, | |
202 | CYNewLine | |
203 | }; | |
204 | ||
5999c315 JF |
205 | class CYDriver { |
206 | public: | |
207 | CYPool pool_; | |
e7ed5354 | 208 | |
db5e2840 | 209 | CYState state_; |
e7ed5354 JF |
210 | void *scanner_; |
211 | ||
212 | const char *data_; | |
213 | size_t size_; | |
48e3be8a | 214 | FILE *file_; |
e7ed5354 | 215 | |
63cd45c9 JF |
216 | enum Condition { |
217 | RegExStart, | |
218 | RegExRest | |
219 | }; | |
220 | ||
5999c315 | 221 | std::string filename_; |
e7ed5354 | 222 | |
5befe15e JF |
223 | struct Error { |
224 | cy::location location_; | |
225 | std::string message_; | |
226 | }; | |
227 | ||
228 | typedef std::vector<Error> Errors; | |
229 | ||
230 | CYSource *source_; | |
231 | Errors errors_; | |
5999c315 JF |
232 | |
233 | private: | |
234 | void ScannerInit(); | |
235 | void ScannerDestroy(); | |
236 | ||
237 | public: | |
238 | CYDriver(const std::string &filename); | |
239 | ~CYDriver(); | |
63cd45c9 JF |
240 | |
241 | void SetCondition(Condition condition); | |
5999c315 JF |
242 | }; |
243 | ||
75b0a457 JF |
244 | enum CYFlags { |
245 | CYNoFlags = 0, | |
246 | CYNoBrace = (1 << 0), | |
247 | CYNoFunction = (1 << 1), | |
248 | CYNoLeader = (1 << 2), | |
249 | CYNoTrailer = (1 << 3), | |
250 | CYNoIn = (1 << 4), | |
251 | CYNoHyphen = (1 << 5), | |
252 | CYNoBF = (CYNoBrace | CYNoFunction), | |
253 | }; | |
254 | ||
cac61857 | 255 | struct CYForInitialiser { |
652ec1ba | 256 | virtual void For(CYOutput &out) const = 0; |
dea834b0 JF |
257 | }; |
258 | ||
cac61857 | 259 | struct CYForInInitialiser { |
652ec1ba | 260 | virtual void ForIn(CYOutput &out, CYFlags flags) const = 0; |
75b0a457 | 261 | virtual const char *ForEachIn() const = 0; |
652ec1ba | 262 | virtual void ForEachIn(CYOutput &out) const = 0; |
b09da87b JF |
263 | }; |
264 | ||
cf7d4c69 | 265 | struct CYExpression : |
5999c315 | 266 | CYNext<CYExpression>, |
cf7d4c69 | 267 | CYForInitialiser, |
e5bc40db JF |
268 | CYForInInitialiser, |
269 | CYClassName | |
63b4c5a8 | 270 | { |
d35a3b07 | 271 | virtual unsigned Precedence() const = 0; |
75b0a457 | 272 | |
652ec1ba JF |
273 | virtual void For(CYOutput &out) const; |
274 | virtual void ForIn(CYOutput &out, CYFlags flags) const; | |
75b0a457 | 275 | |
cac61857 | 276 | virtual const char *ForEachIn() const; |
652ec1ba | 277 | virtual void ForEachIn(CYOutput &out) const; |
75b0a457 | 278 | |
652ec1ba JF |
279 | virtual void Output(CYOutput &out, CYFlags flags) const = 0; |
280 | void Output(CYOutput &out, unsigned precedence, CYFlags flags) const; | |
dea834b0 | 281 | |
652ec1ba | 282 | virtual void ClassName(CYOutput &out, bool object) const; |
e5bc40db | 283 | |
dea834b0 JF |
284 | virtual const char *Word() const { |
285 | return NULL; | |
286 | } | |
63b4c5a8 JF |
287 | }; |
288 | ||
b09da87b JF |
289 | #define CYAlphabetic(value) \ |
290 | virtual bool Alphabetic() const { \ | |
291 | return value; \ | |
292 | } | |
293 | ||
d35a3b07 JF |
294 | #define CYPrecedence(value) \ |
295 | virtual unsigned Precedence() const { \ | |
296 | return value; \ | |
297 | } | |
298 | ||
299 | struct CYCompound : | |
300 | CYExpression | |
301 | { | |
302 | CYExpression *expressions_; | |
303 | ||
304 | CYCompound(CYExpression *expressions) : | |
305 | expressions_(expressions) | |
306 | { | |
307 | } | |
308 | ||
309 | void AddPrev(CYExpression *expression) { | |
310 | CYExpression *last(expression); | |
311 | while (last->next_ != NULL) | |
312 | last = last->next_; | |
313 | last->SetNext(expressions_); | |
314 | expressions_ = expression; | |
315 | } | |
316 | ||
317 | CYPrecedence(17) | |
318 | ||
652ec1ba | 319 | void Output(CYOutput &out, CYFlags flags) const; |
d35a3b07 | 320 | }; |
5999c315 | 321 | |
75b0a457 JF |
322 | struct CYComprehension : |
323 | CYNext<CYComprehension> | |
324 | { | |
652ec1ba | 325 | void Output(CYOutput &out) const; |
75b0a457 JF |
326 | virtual const char *Name() const = 0; |
327 | ||
652ec1ba | 328 | virtual void Begin_(CYOutput &out) const = 0; |
75b0a457 | 329 | |
652ec1ba | 330 | virtual void End_(CYOutput &out) const { |
75b0a457 JF |
331 | } |
332 | }; | |
333 | ||
334 | struct CYForInComprehension : | |
335 | CYComprehension | |
336 | { | |
337 | CYIdentifier *name_; | |
338 | CYExpression *set_; | |
339 | ||
340 | CYForInComprehension(CYIdentifier *name, CYExpression *set) : | |
341 | name_(name), | |
342 | set_(set) | |
343 | { | |
344 | } | |
345 | ||
346 | virtual const char *Name() const { | |
347 | return name_->Value(); | |
348 | } | |
349 | ||
652ec1ba | 350 | virtual void Begin_(CYOutput &out) const; |
75b0a457 JF |
351 | }; |
352 | ||
353 | struct CYForEachInComprehension : | |
354 | CYComprehension | |
355 | { | |
356 | CYIdentifier *name_; | |
357 | CYExpression *set_; | |
358 | ||
359 | CYForEachInComprehension(CYIdentifier *name, CYExpression *set) : | |
360 | name_(name), | |
361 | set_(set) | |
362 | { | |
363 | } | |
364 | ||
365 | virtual const char *Name() const { | |
366 | return name_->Value(); | |
367 | } | |
368 | ||
652ec1ba JF |
369 | virtual void Begin_(CYOutput &out) const; |
370 | virtual void End_(CYOutput &out) const; | |
75b0a457 JF |
371 | }; |
372 | ||
373 | struct CYIfComprehension : | |
374 | CYComprehension | |
375 | { | |
376 | CYExpression *test_; | |
377 | ||
378 | CYIfComprehension(CYExpression *test) : | |
379 | test_(test) | |
380 | { | |
381 | } | |
382 | ||
383 | virtual const char *Name() const { | |
384 | return NULL; | |
385 | } | |
386 | ||
652ec1ba | 387 | virtual void Begin_(CYOutput &out) const; |
75b0a457 JF |
388 | }; |
389 | ||
390 | struct CYArrayComprehension : | |
391 | CYExpression | |
392 | { | |
393 | CYExpression *expression_; | |
394 | CYComprehension *comprehensions_; | |
395 | ||
396 | CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) : | |
397 | expression_(expression), | |
398 | comprehensions_(comprehensions) | |
399 | { | |
400 | } | |
401 | ||
402 | CYPrecedence(0) | |
403 | ||
652ec1ba | 404 | virtual void Output(CYOutput &out, CYFlags flags) const; |
75b0a457 JF |
405 | }; |
406 | ||
cf7d4c69 JF |
407 | struct CYLiteral : |
408 | CYExpression | |
63b4c5a8 | 409 | { |
d35a3b07 | 410 | CYPrecedence(0) |
cf7d4c69 | 411 | }; |
63b4c5a8 | 412 | |
478d4ed0 JF |
413 | struct CYMagic : |
414 | CYExpression | |
415 | { | |
416 | CYPrecedence(0) | |
417 | }; | |
418 | ||
62014ea9 JF |
419 | struct CYSelectorPart : |
420 | CYNext<CYSelectorPart> | |
e7ed5354 JF |
421 | { |
422 | CYWord *name_; | |
423 | bool value_; | |
e7ed5354 | 424 | |
62014ea9 JF |
425 | CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) : |
426 | CYNext<CYSelectorPart>(next), | |
e7ed5354 | 427 | name_(name), |
62014ea9 JF |
428 | value_(value) |
429 | { | |
430 | } | |
431 | ||
652ec1ba | 432 | virtual void Output(CYOutput &out) const; |
62014ea9 JF |
433 | }; |
434 | ||
435 | struct CYSelector : | |
436 | CYLiteral | |
437 | { | |
438 | CYSelectorPart *name_; | |
439 | ||
440 | CYSelector(CYSelectorPart *name) : | |
441 | name_(name) | |
e7ed5354 JF |
442 | { |
443 | } | |
444 | ||
dea834b0 JF |
445 | CYPrecedence(1) |
446 | ||
652ec1ba | 447 | virtual void Output(CYOutput &out, CYFlags flags) const; |
e7ed5354 JF |
448 | }; |
449 | ||
dea834b0 JF |
450 | struct CYRange { |
451 | uint64_t lo_; | |
452 | uint64_t hi_; | |
453 | ||
454 | CYRange(uint64_t lo, uint64_t hi) : | |
455 | lo_(lo), hi_(hi) | |
456 | { | |
457 | } | |
458 | ||
459 | bool operator [](uint8_t value) const { | |
460 | return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1; | |
461 | } | |
462 | ||
463 | void operator()(uint8_t value) { | |
464 | if (value >> 7) | |
465 | return; | |
466 | (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f); | |
467 | } | |
468 | }; | |
469 | ||
283e7e33 | 470 | extern CYRange DigitRange_; |
dea834b0 JF |
471 | extern CYRange WordStartRange_; |
472 | extern CYRange WordEndRange_; | |
473 | ||
cf7d4c69 JF |
474 | struct CYString : |
475 | CYLiteral, | |
e5bc40db | 476 | CYPropertyName |
cf7d4c69 JF |
477 | { |
478 | const char *value_; | |
5999c315 | 479 | size_t size_; |
cf7d4c69 | 480 | |
5999c315 JF |
481 | CYString(const char *value, size_t size) : |
482 | value_(value), | |
483 | size_(size) | |
cf7d4c69 JF |
484 | { |
485 | } | |
486 | ||
487 | CYString(const CYIdentifier *identifier) : | |
5999c315 JF |
488 | value_(identifier->Value()), |
489 | size_(strlen(value_)) | |
cf7d4c69 JF |
490 | { |
491 | } | |
492 | ||
5999c315 | 493 | const char *Value() const { |
cf7d4c69 JF |
494 | return value_; |
495 | } | |
496 | ||
dea834b0 JF |
497 | virtual const char *Word() const { |
498 | if (size_ == 0 || !WordStartRange_[value_[0]]) | |
499 | return NULL; | |
500 | for (size_t i(1); i != size_; ++i) | |
501 | if (!WordEndRange_[value_[i]]) | |
502 | return NULL; | |
503 | return Value(); | |
504 | } | |
505 | ||
652ec1ba | 506 | virtual void Output(CYOutput &out) const { |
b09da87b JF |
507 | return Output(out, CYNoFlags); |
508 | } | |
509 | ||
652ec1ba JF |
510 | virtual void Output(CYOutput &out, CYFlags flags) const; |
511 | virtual void PropertyName(CYOutput &out) const; | |
63b4c5a8 JF |
512 | }; |
513 | ||
cf7d4c69 | 514 | struct CYNumber : |
cf7d4c69 | 515 | CYLiteral, |
e5bc40db | 516 | CYPropertyName |
cf7d4c69 | 517 | { |
5999c315 JF |
518 | double value_; |
519 | ||
520 | CYNumber(double value) : | |
521 | value_(value) | |
522 | { | |
523 | } | |
524 | ||
525 | double Value() const { | |
526 | return value_; | |
cf7d4c69 JF |
527 | } |
528 | ||
652ec1ba | 529 | virtual void Output(CYOutput &out) const { |
b09da87b JF |
530 | return Output(out, CYNoFlags); |
531 | } | |
532 | ||
652ec1ba JF |
533 | virtual void Output(CYOutput &out, CYFlags flags) const; |
534 | virtual void PropertyName(CYOutput &out) const; | |
cf7d4c69 JF |
535 | }; |
536 | ||
63cd45c9 JF |
537 | struct CYRegEx : |
538 | CYLiteral | |
539 | { | |
540 | const char *value_; | |
541 | ||
542 | CYRegEx(const char *value) : | |
543 | value_(value) | |
544 | { | |
545 | } | |
546 | ||
547 | const char *Value() const { | |
548 | return value_; | |
549 | } | |
550 | ||
551 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
552 | }; | |
553 | ||
cf7d4c69 JF |
554 | struct CYNull : |
555 | CYWord, | |
556 | CYLiteral | |
557 | { | |
558 | CYNull() : | |
559 | CYWord("null") | |
560 | { | |
561 | } | |
5999c315 | 562 | |
652ec1ba | 563 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
564 | }; |
565 | ||
566 | struct CYThis : | |
567 | CYWord, | |
478d4ed0 | 568 | CYMagic |
cf7d4c69 JF |
569 | { |
570 | CYThis() : | |
571 | CYWord("this") | |
572 | { | |
573 | } | |
5999c315 | 574 | |
652ec1ba | 575 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
576 | }; |
577 | ||
578 | struct CYBoolean : | |
579 | CYLiteral | |
580 | { | |
5999c315 | 581 | virtual bool Value() const = 0; |
652ec1ba | 582 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
583 | }; |
584 | ||
585 | struct CYFalse : | |
586 | CYWord, | |
587 | CYBoolean | |
588 | { | |
589 | CYFalse() : | |
590 | CYWord("false") | |
591 | { | |
592 | } | |
5999c315 | 593 | |
b09da87b | 594 | virtual bool Value() const; |
cf7d4c69 JF |
595 | }; |
596 | ||
597 | struct CYTrue : | |
598 | CYWord, | |
599 | CYBoolean | |
600 | { | |
601 | CYTrue() : | |
602 | CYWord("true") | |
603 | { | |
604 | } | |
5999c315 | 605 | |
b09da87b | 606 | virtual bool Value() const; |
cf7d4c69 JF |
607 | }; |
608 | ||
609 | struct CYVariable : | |
610 | CYExpression | |
611 | { | |
612 | CYIdentifier *name_; | |
613 | ||
614 | CYVariable(CYIdentifier *name) : | |
615 | name_(name) | |
616 | { | |
617 | } | |
5999c315 | 618 | |
d35a3b07 JF |
619 | CYPrecedence(0) |
620 | ||
652ec1ba | 621 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
622 | }; |
623 | ||
624 | struct CYPrefix : | |
63b4c5a8 JF |
625 | CYExpression |
626 | { | |
627 | CYExpression *rhs_; | |
628 | ||
cf7d4c69 | 629 | CYPrefix(CYExpression *rhs) : |
63b4c5a8 JF |
630 | rhs_(rhs) |
631 | { | |
632 | } | |
5999c315 | 633 | |
b09da87b | 634 | virtual bool Alphabetic() const = 0; |
5999c315 JF |
635 | virtual const char *Operator() const = 0; |
636 | ||
652ec1ba | 637 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
638 | }; |
639 | ||
cf7d4c69 | 640 | struct CYInfix : |
63b4c5a8 JF |
641 | CYExpression |
642 | { | |
643 | CYExpression *lhs_; | |
644 | CYExpression *rhs_; | |
645 | ||
cf7d4c69 | 646 | CYInfix(CYExpression *lhs, CYExpression *rhs) : |
63b4c5a8 JF |
647 | lhs_(lhs), |
648 | rhs_(rhs) | |
649 | { | |
650 | } | |
5999c315 | 651 | |
0ff9f149 JF |
652 | void SetLeft(CYExpression *lhs) { |
653 | lhs_ = lhs; | |
654 | } | |
655 | ||
b09da87b | 656 | virtual bool Alphabetic() const = 0; |
5999c315 JF |
657 | virtual const char *Operator() const = 0; |
658 | ||
652ec1ba | 659 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
660 | }; |
661 | ||
cf7d4c69 | 662 | struct CYPostfix : |
63b4c5a8 JF |
663 | CYExpression |
664 | { | |
665 | CYExpression *lhs_; | |
666 | ||
cf7d4c69 | 667 | CYPostfix(CYExpression *lhs) : |
63b4c5a8 JF |
668 | lhs_(lhs) |
669 | { | |
670 | } | |
5999c315 JF |
671 | |
672 | virtual const char *Operator() const = 0; | |
673 | ||
652ec1ba | 674 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
675 | }; |
676 | ||
cf7d4c69 | 677 | struct CYAssignment : |
d35a3b07 | 678 | CYExpression |
cf7d4c69 | 679 | { |
d35a3b07 JF |
680 | CYExpression *lhs_; |
681 | CYExpression *rhs_; | |
682 | ||
cf7d4c69 | 683 | CYAssignment(CYExpression *lhs, CYExpression *rhs) : |
d35a3b07 JF |
684 | lhs_(lhs), |
685 | rhs_(rhs) | |
cf7d4c69 JF |
686 | { |
687 | } | |
5999c315 | 688 | |
0ff9f149 JF |
689 | void SetLeft(CYExpression *lhs) { |
690 | lhs_ = lhs; | |
691 | } | |
692 | ||
5999c315 | 693 | virtual const char *Operator() const = 0; |
d35a3b07 | 694 | |
652ec1ba | 695 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
696 | }; |
697 | ||
62014ea9 JF |
698 | struct CYArgument : |
699 | CYNext<CYArgument> | |
700 | { | |
cf7d4c69 JF |
701 | CYWord *name_; |
702 | CYExpression *value_; | |
cf7d4c69 JF |
703 | |
704 | CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) : | |
62014ea9 | 705 | CYNext<CYArgument>(next), |
cf7d4c69 | 706 | name_(name), |
62014ea9 | 707 | value_(value) |
cf7d4c69 JF |
708 | { |
709 | } | |
5999c315 | 710 | |
652ec1ba | 711 | void Output(CYOutput &out) const; |
cf7d4c69 JF |
712 | }; |
713 | ||
714 | struct CYBlank : | |
715 | public CYWord | |
716 | { | |
717 | CYBlank() : | |
718 | CYWord("") | |
719 | { | |
720 | } | |
721 | }; | |
722 | ||
5999c315 JF |
723 | struct CYClause : |
724 | CYThing, | |
725 | CYNext<CYClause> | |
726 | { | |
cf7d4c69 JF |
727 | CYExpression *case_; |
728 | CYStatement *code_; | |
cf7d4c69 JF |
729 | |
730 | CYClause(CYExpression *_case, CYStatement *code) : | |
731 | case_(_case), | |
732 | code_(code) | |
733 | { | |
734 | } | |
735 | ||
652ec1ba | 736 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
737 | }; |
738 | ||
62014ea9 JF |
739 | struct CYElement : |
740 | CYNext<CYElement> | |
741 | { | |
cf7d4c69 | 742 | CYExpression *value_; |
cf7d4c69 JF |
743 | |
744 | CYElement(CYExpression *value, CYElement *next) : | |
62014ea9 JF |
745 | CYNext<CYElement>(next), |
746 | value_(value) | |
cf7d4c69 JF |
747 | { |
748 | } | |
5999c315 | 749 | |
652ec1ba | 750 | void Output(CYOutput &out) const; |
5befe15e JF |
751 | }; |
752 | ||
753 | struct CYArray : | |
754 | CYLiteral | |
755 | { | |
756 | CYElement *elements_; | |
757 | ||
758 | CYArray(CYElement *elements) : | |
759 | elements_(elements) | |
760 | { | |
761 | } | |
762 | ||
652ec1ba | 763 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
764 | }; |
765 | ||
766 | struct CYDeclaration : | |
767 | CYForInInitialiser | |
768 | { | |
769 | CYIdentifier *identifier_; | |
770 | CYExpression *initialiser_; | |
771 | ||
772 | CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) : | |
773 | identifier_(identifier), | |
774 | initialiser_(initialiser) | |
775 | { | |
776 | } | |
5999c315 | 777 | |
652ec1ba | 778 | virtual void ForIn(CYOutput &out, CYFlags flags) const; |
75b0a457 | 779 | |
cac61857 | 780 | virtual const char *ForEachIn() const; |
652ec1ba | 781 | virtual void ForEachIn(CYOutput &out) const; |
75b0a457 | 782 | |
652ec1ba | 783 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
784 | }; |
785 | ||
786 | struct CYDeclarations : | |
cac61857 | 787 | CYNext<CYDeclarations>, |
cf7d4c69 JF |
788 | CYForInitialiser |
789 | { | |
790 | CYDeclaration *declaration_; | |
cf7d4c69 JF |
791 | |
792 | CYDeclarations(CYDeclaration *declaration, CYDeclarations *next) : | |
cac61857 JF |
793 | CYNext<CYDeclarations>(next), |
794 | declaration_(declaration) | |
795 | { | |
796 | } | |
797 | ||
652ec1ba JF |
798 | virtual void For(CYOutput &out) const; |
799 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
cac61857 JF |
800 | }; |
801 | ||
802 | struct CYVar : | |
803 | CYStatement | |
804 | { | |
805 | CYDeclarations *declarations_; | |
806 | ||
807 | CYVar(CYDeclarations *declarations) : | |
808 | declarations_(declarations) | |
809 | { | |
810 | } | |
811 | ||
652ec1ba | 812 | virtual void Output(CYOutput &out) const; |
cac61857 JF |
813 | }; |
814 | ||
815 | struct CYLet : | |
816 | CYStatement | |
817 | { | |
818 | CYDeclarations *declarations_; | |
819 | CYStatement *statements_; | |
820 | ||
821 | CYLet(CYDeclarations *declarations, CYStatement *statements) : | |
822 | declarations_(declarations), | |
823 | statements_(statements) | |
cf7d4c69 JF |
824 | { |
825 | } | |
5999c315 | 826 | |
652ec1ba | 827 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
828 | }; |
829 | ||
b09da87b JF |
830 | struct CYField : |
831 | CYNext<CYField> | |
832 | { | |
652ec1ba | 833 | virtual void Output(CYOutput &out) const; |
b09da87b JF |
834 | }; |
835 | ||
836 | struct CYMessageParameter : | |
837 | CYNext<CYMessageParameter> | |
838 | { | |
839 | CYWord *tag_; | |
840 | CYExpression *type_; | |
841 | CYIdentifier *name_; | |
842 | ||
843 | CYMessageParameter(CYWord *tag, CYExpression *type, CYIdentifier *name) : | |
844 | tag_(tag), | |
845 | type_(type), | |
846 | name_(name) | |
847 | { | |
848 | } | |
849 | }; | |
850 | ||
851 | struct CYMessage : | |
e5bc40db | 852 | CYNext<CYMessage> |
b09da87b JF |
853 | { |
854 | bool instance_; | |
855 | CYExpression *type_; | |
856 | CYMessageParameter *parameter_; | |
857 | CYSource *body_; | |
858 | ||
859 | CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYSource *body) : | |
860 | instance_(instance), | |
861 | type_(type), | |
862 | parameter_(parameter), | |
863 | body_(body) | |
864 | { | |
865 | } | |
866 | ||
652ec1ba | 867 | virtual void Output(CYOutput &out, bool replace) const; |
b09da87b JF |
868 | }; |
869 | ||
870 | struct CYClass : | |
365abb0a JF |
871 | CYExpression, |
872 | CYStatement | |
b09da87b | 873 | { |
367eebb1 | 874 | CYClassName *name_; |
b09da87b JF |
875 | CYExpression *super_; |
876 | CYField *fields_; | |
877 | CYMessage *messages_; | |
878 | ||
367eebb1 | 879 | CYClass(CYClassName *name, CYExpression *super, CYField *fields, CYMessage *messages) : |
b09da87b JF |
880 | name_(name), |
881 | super_(super), | |
882 | fields_(fields), | |
883 | messages_(messages) | |
884 | { | |
885 | } | |
886 | ||
367eebb1 JF |
887 | CYPrecedence(0) |
888 | ||
652ec1ba JF |
889 | virtual void Output(CYOutput &out) const; |
890 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
b09da87b JF |
891 | }; |
892 | ||
e5bc40db | 893 | struct CYCategory : |
367eebb1 | 894 | CYStatement |
e5bc40db JF |
895 | { |
896 | CYClassName *name_; | |
897 | CYMessage *messages_; | |
898 | ||
899 | CYCategory(CYClassName *name, CYMessage *messages) : | |
900 | name_(name), | |
901 | messages_(messages) | |
902 | { | |
903 | } | |
904 | ||
652ec1ba | 905 | virtual void Output(CYOutput &out) const; |
e5bc40db JF |
906 | }; |
907 | ||
b09da87b JF |
908 | struct CYFunctionParameter : |
909 | CYNext<CYFunctionParameter>, | |
5999c315 JF |
910 | CYThing |
911 | { | |
cf7d4c69 | 912 | CYIdentifier *name_; |
cf7d4c69 | 913 | |
b09da87b JF |
914 | CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next) : |
915 | CYNext<CYFunctionParameter>(next), | |
62014ea9 | 916 | name_(name) |
cf7d4c69 JF |
917 | { |
918 | } | |
5999c315 | 919 | |
652ec1ba | 920 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
921 | }; |
922 | ||
923 | struct CYFor : | |
924 | CYStatement | |
925 | { | |
926 | CYForInitialiser *initialiser_; | |
927 | CYExpression *test_; | |
928 | CYExpression *increment_; | |
929 | CYStatement *code_; | |
930 | ||
931 | CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) : | |
932 | initialiser_(initialiser), | |
933 | test_(test), | |
934 | increment_(increment), | |
935 | code_(code) | |
936 | { | |
937 | } | |
5999c315 | 938 | |
652ec1ba | 939 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
940 | }; |
941 | ||
942 | struct CYForIn : | |
943 | CYStatement | |
944 | { | |
945 | CYForInInitialiser *initialiser_; | |
946 | CYExpression *set_; | |
947 | CYStatement *code_; | |
948 | ||
949 | CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) : | |
950 | initialiser_(initialiser), | |
951 | set_(set), | |
952 | code_(code) | |
953 | { | |
954 | } | |
5999c315 | 955 | |
652ec1ba | 956 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
957 | }; |
958 | ||
75b0a457 JF |
959 | struct CYForEachIn : |
960 | CYStatement | |
961 | { | |
962 | CYForInInitialiser *initialiser_; | |
963 | CYExpression *set_; | |
964 | CYStatement *code_; | |
965 | ||
966 | CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) : | |
967 | initialiser_(initialiser), | |
968 | set_(set), | |
969 | code_(code) | |
970 | { | |
971 | } | |
972 | ||
652ec1ba | 973 | virtual void Output(CYOutput &out) const; |
75b0a457 JF |
974 | }; |
975 | ||
62014ea9 JF |
976 | struct CYProperty : |
977 | CYNext<CYProperty> | |
978 | { | |
e5bc40db | 979 | CYPropertyName *name_; |
cf7d4c69 | 980 | CYExpression *value_; |
cf7d4c69 | 981 | |
e5bc40db | 982 | CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next) : |
62014ea9 | 983 | CYNext<CYProperty>(next), |
cf7d4c69 | 984 | name_(name), |
62014ea9 | 985 | value_(value) |
cf7d4c69 JF |
986 | { |
987 | } | |
5999c315 | 988 | |
652ec1ba | 989 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
990 | }; |
991 | ||
693d501b JF |
992 | struct CYObject : |
993 | CYLiteral | |
994 | { | |
995 | CYProperty *property_; | |
996 | ||
997 | CYObject(CYProperty *property) : | |
998 | property_(property) | |
999 | { | |
1000 | } | |
1001 | ||
652ec1ba | 1002 | void Output(CYOutput &out, CYFlags flags) const; |
693d501b JF |
1003 | }; |
1004 | ||
5999c315 JF |
1005 | struct CYCatch : |
1006 | CYThing | |
1007 | { | |
cf7d4c69 JF |
1008 | CYIdentifier *name_; |
1009 | CYStatement *code_; | |
1010 | ||
1011 | CYCatch(CYIdentifier *name, CYStatement *code) : | |
1012 | name_(name), | |
1013 | code_(code) | |
1014 | { | |
1015 | } | |
5999c315 | 1016 | |
652ec1ba | 1017 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1018 | }; |
1019 | ||
b09da87b | 1020 | struct CYSend : |
63b4c5a8 JF |
1021 | CYExpression |
1022 | { | |
cf7d4c69 JF |
1023 | CYExpression *self_; |
1024 | CYArgument *arguments_; | |
63b4c5a8 | 1025 | |
b09da87b | 1026 | CYSend(CYExpression *self, CYArgument *arguments) : |
cf7d4c69 JF |
1027 | self_(self), |
1028 | arguments_(arguments) | |
63b4c5a8 JF |
1029 | { |
1030 | } | |
5999c315 | 1031 | |
d35a3b07 JF |
1032 | CYPrecedence(0) |
1033 | ||
652ec1ba | 1034 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
1035 | }; |
1036 | ||
cf7d4c69 JF |
1037 | struct CYMember : |
1038 | CYExpression | |
1039 | { | |
1040 | CYExpression *object_; | |
1041 | CYExpression *property_; | |
1042 | ||
1043 | CYMember(CYExpression *object, CYExpression *property) : | |
1044 | object_(object), | |
1045 | property_(property) | |
1046 | { | |
1047 | } | |
5999c315 | 1048 | |
9b5527f0 JF |
1049 | void SetLeft(CYExpression *object) { |
1050 | object_ = object; | |
1051 | } | |
1052 | }; | |
1053 | ||
1054 | struct CYDirectMember : | |
1055 | CYMember | |
1056 | { | |
1057 | CYDirectMember(CYExpression *object, CYExpression *property) : | |
1058 | CYMember(object, property) | |
1059 | { | |
1060 | } | |
1061 | ||
1062 | CYPrecedence(1) | |
1063 | ||
652ec1ba | 1064 | virtual void Output(CYOutput &out, CYFlags flags) const; |
9b5527f0 JF |
1065 | }; |
1066 | ||
1067 | struct CYIndirectMember : | |
1068 | CYMember | |
1069 | { | |
1070 | CYIndirectMember(CYExpression *object, CYExpression *property) : | |
1071 | CYMember(object, property) | |
1072 | { | |
1073 | } | |
1074 | ||
d35a3b07 JF |
1075 | CYPrecedence(1) |
1076 | ||
652ec1ba | 1077 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1078 | }; |
1079 | ||
1080 | struct CYNew : | |
1081 | CYExpression | |
1082 | { | |
1083 | CYExpression *constructor_; | |
1084 | CYArgument *arguments_; | |
1085 | ||
1086 | CYNew(CYExpression *constructor, CYArgument *arguments) : | |
1087 | constructor_(constructor), | |
1088 | arguments_(arguments) | |
1089 | { | |
1090 | } | |
5999c315 | 1091 | |
d35a3b07 JF |
1092 | CYPrecedence(1) |
1093 | ||
652ec1ba | 1094 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1095 | }; |
1096 | ||
1097 | struct CYCall : | |
1098 | CYExpression | |
1099 | { | |
1100 | CYExpression *function_; | |
1101 | CYArgument *arguments_; | |
1102 | ||
1103 | CYCall(CYExpression *function, CYArgument *arguments) : | |
1104 | function_(function), | |
1105 | arguments_(arguments) | |
1106 | { | |
1107 | } | |
5999c315 | 1108 | |
d35a3b07 JF |
1109 | CYPrecedence(2) |
1110 | ||
652ec1ba | 1111 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1112 | }; |
1113 | ||
1114 | struct CYIf : | |
1115 | CYStatement | |
1116 | { | |
1117 | CYExpression *test_; | |
1118 | CYStatement *true_; | |
1119 | CYStatement *false_; | |
1120 | ||
1121 | CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) : | |
1122 | test_(test), | |
1123 | true_(_true), | |
1124 | false_(_false) | |
1125 | { | |
1126 | } | |
5999c315 | 1127 | |
652ec1ba | 1128 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1129 | }; |
1130 | ||
1131 | struct CYDoWhile : | |
1132 | CYStatement | |
1133 | { | |
1134 | CYExpression *test_; | |
1135 | CYStatement *code_; | |
1136 | ||
1137 | CYDoWhile(CYExpression *test, CYStatement *code) : | |
1138 | test_(test), | |
1139 | code_(code) | |
1140 | { | |
1141 | } | |
5999c315 | 1142 | |
652ec1ba | 1143 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1144 | }; |
1145 | ||
1146 | struct CYWhile : | |
1147 | CYStatement | |
1148 | { | |
1149 | CYExpression *test_; | |
1150 | CYStatement *code_; | |
1151 | ||
1152 | CYWhile(CYExpression *test, CYStatement *code) : | |
1153 | test_(test), | |
1154 | code_(code) | |
1155 | { | |
1156 | } | |
5999c315 | 1157 | |
652ec1ba | 1158 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1159 | }; |
1160 | ||
1161 | struct CYLambda : | |
1162 | CYExpression | |
1163 | { | |
1164 | CYIdentifier *name_; | |
b09da87b | 1165 | CYFunctionParameter *parameters_; |
cf7d4c69 JF |
1166 | CYSource *body_; |
1167 | ||
b09da87b | 1168 | CYLambda(CYIdentifier *name, CYFunctionParameter *parameters, CYSource *body) : |
cf7d4c69 JF |
1169 | name_(name), |
1170 | parameters_(parameters), | |
1171 | body_(body) | |
1172 | { | |
1173 | } | |
5999c315 | 1174 | |
d35a3b07 JF |
1175 | CYPrecedence(0) |
1176 | ||
652ec1ba | 1177 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1178 | }; |
1179 | ||
1180 | struct CYFunction : | |
5999c315 JF |
1181 | CYLambda, |
1182 | CYSource | |
cf7d4c69 | 1183 | { |
b09da87b | 1184 | CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYSource *body) : |
cf7d4c69 JF |
1185 | CYLambda(name, parameters, body) |
1186 | { | |
1187 | } | |
5999c315 | 1188 | |
652ec1ba | 1189 | virtual void Output(CYOutput &out) const; |
5999c315 JF |
1190 | }; |
1191 | ||
1192 | struct CYExpress : | |
1193 | CYStatement | |
1194 | { | |
1195 | CYExpression *expression_; | |
1196 | ||
1197 | CYExpress(CYExpression *expression) : | |
1198 | expression_(expression) | |
1199 | { | |
1200 | } | |
1201 | ||
652ec1ba | 1202 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1203 | }; |
1204 | ||
1205 | struct CYContinue : | |
1206 | CYStatement | |
1207 | { | |
1208 | CYIdentifier *label_; | |
1209 | ||
1210 | CYContinue(CYIdentifier *label) : | |
1211 | label_(label) | |
1212 | { | |
1213 | } | |
5999c315 | 1214 | |
652ec1ba | 1215 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1216 | }; |
1217 | ||
1218 | struct CYBreak : | |
1219 | CYStatement | |
1220 | { | |
1221 | CYIdentifier *label_; | |
1222 | ||
1223 | CYBreak(CYIdentifier *label) : | |
1224 | label_(label) | |
1225 | { | |
1226 | } | |
5999c315 | 1227 | |
652ec1ba | 1228 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1229 | }; |
1230 | ||
1231 | struct CYReturn : | |
1232 | CYStatement | |
1233 | { | |
1234 | CYExpression *value_; | |
1235 | ||
1236 | CYReturn(CYExpression *value) : | |
1237 | value_(value) | |
1238 | { | |
1239 | } | |
5999c315 | 1240 | |
652ec1ba | 1241 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1242 | }; |
1243 | ||
1244 | struct CYEmpty : | |
1245 | CYStatement | |
1246 | { | |
652ec1ba JF |
1247 | virtual void Output(CYOutput &out) const; |
1248 | virtual void Output(CYOutput &out, bool block) const; | |
cf7d4c69 JF |
1249 | }; |
1250 | ||
1251 | struct CYTry : | |
1252 | CYStatement | |
1253 | { | |
1254 | CYStatement *try_; | |
1255 | CYCatch *catch_; | |
1256 | CYStatement *finally_; | |
1257 | ||
1258 | CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) : | |
1259 | try_(_try), | |
1260 | catch_(_catch), | |
1261 | finally_(finally) | |
1262 | { | |
1263 | } | |
5999c315 | 1264 | |
652ec1ba | 1265 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1266 | }; |
1267 | ||
1268 | struct CYThrow : | |
1269 | CYStatement | |
1270 | { | |
1271 | CYExpression *value_; | |
1272 | ||
1273 | CYThrow(CYExpression *value) : | |
1274 | value_(value) | |
1275 | { | |
1276 | } | |
5999c315 | 1277 | |
652ec1ba | 1278 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1279 | }; |
1280 | ||
1281 | struct CYWith : | |
1282 | CYStatement | |
1283 | { | |
1284 | CYExpression *scope_; | |
1285 | CYStatement *code_; | |
1286 | ||
1287 | CYWith(CYExpression *scope, CYStatement *code) : | |
1288 | scope_(scope), | |
1289 | code_(code) | |
1290 | { | |
1291 | } | |
5999c315 | 1292 | |
652ec1ba | 1293 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1294 | }; |
1295 | ||
1296 | struct CYSwitch : | |
1297 | CYStatement | |
1298 | { | |
1299 | CYExpression *value_; | |
1300 | CYClause *clauses_; | |
1301 | ||
1302 | CYSwitch(CYExpression *value, CYClause *clauses) : | |
1303 | value_(value), | |
1304 | clauses_(clauses) | |
1305 | { | |
1306 | } | |
5999c315 | 1307 | |
652ec1ba | 1308 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1309 | }; |
1310 | ||
1311 | struct CYCondition : | |
1312 | CYExpression | |
1313 | { | |
1314 | CYExpression *test_; | |
1315 | CYExpression *true_; | |
1316 | CYExpression *false_; | |
1317 | ||
1318 | CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) : | |
91a416e4 | 1319 | test_(test), |
cf7d4c69 JF |
1320 | true_(_true), |
1321 | false_(_false) | |
1322 | { | |
1323 | } | |
5999c315 | 1324 | |
d35a3b07 JF |
1325 | CYPrecedence(15) |
1326 | ||
652ec1ba | 1327 | virtual void Output(CYOutput &out, CYFlags flags) const; |
5999c315 JF |
1328 | }; |
1329 | ||
1330 | struct CYAddressOf : | |
1331 | CYPrefix | |
1332 | { | |
1333 | CYAddressOf(CYExpression *rhs) : | |
1334 | CYPrefix(rhs) | |
1335 | { | |
1336 | } | |
1337 | ||
1338 | virtual const char *Operator() const { | |
1339 | return "&"; | |
1340 | } | |
1341 | ||
b09da87b | 1342 | CYAlphabetic(false) |
d35a3b07 JF |
1343 | CYPrecedence(2) |
1344 | ||
652ec1ba | 1345 | virtual void Output(CYOutput &out, CYFlags flags) const; |
5999c315 JF |
1346 | }; |
1347 | ||
1348 | struct CYIndirect : | |
1349 | CYPrefix | |
1350 | { | |
1351 | CYIndirect(CYExpression *rhs) : | |
1352 | CYPrefix(rhs) | |
1353 | { | |
1354 | } | |
1355 | ||
1356 | virtual const char *Operator() const { | |
1357 | return "*"; | |
1358 | } | |
1359 | ||
b09da87b | 1360 | CYAlphabetic(false) |
d35a3b07 JF |
1361 | CYPrecedence(1) |
1362 | ||
652ec1ba | 1363 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1364 | }; |
1365 | ||
1366 | #define CYPostfix_(op, name) \ | |
1367 | struct CY ## name : \ | |
1368 | CYPostfix \ | |
1369 | { \ | |
1370 | CY ## name(CYExpression *lhs) : \ | |
1371 | CYPostfix(lhs) \ | |
1372 | { \ | |
1373 | } \ | |
d35a3b07 JF |
1374 | \ |
1375 | CYPrecedence(3) \ | |
5999c315 JF |
1376 | \ |
1377 | virtual const char *Operator() const { \ | |
1378 | return op; \ | |
1379 | } \ | |
cf7d4c69 JF |
1380 | }; |
1381 | ||
b09da87b | 1382 | #define CYPrefix_(alphabetic, op, name) \ |
cf7d4c69 JF |
1383 | struct CY ## name : \ |
1384 | CYPrefix \ | |
1385 | { \ | |
1386 | CY ## name(CYExpression *rhs) : \ | |
1387 | CYPrefix(rhs) \ | |
1388 | { \ | |
1389 | } \ | |
d35a3b07 | 1390 | \ |
b09da87b | 1391 | CYAlphabetic(alphabetic) \ |
d35a3b07 | 1392 | CYPrecedence(4) \ |
5999c315 JF |
1393 | \ |
1394 | virtual const char *Operator() const { \ | |
1395 | return op; \ | |
1396 | } \ | |
cf7d4c69 JF |
1397 | }; |
1398 | ||
b09da87b | 1399 | #define CYInfix_(alphabetic, precedence, op, name) \ |
cf7d4c69 JF |
1400 | struct CY ## name : \ |
1401 | CYInfix \ | |
1402 | { \ | |
1403 | CY ## name(CYExpression *lhs, CYExpression *rhs) : \ | |
1404 | CYInfix(lhs, rhs) \ | |
1405 | { \ | |
1406 | } \ | |
d35a3b07 | 1407 | \ |
b09da87b | 1408 | CYAlphabetic(alphabetic) \ |
d35a3b07 | 1409 | CYPrecedence(precedence) \ |
5999c315 JF |
1410 | \ |
1411 | virtual const char *Operator() const { \ | |
1412 | return op; \ | |
1413 | } \ | |
cf7d4c69 JF |
1414 | }; |
1415 | ||
1416 | #define CYAssignment_(op, name) \ | |
1417 | struct CY ## name ## Assign : \ | |
1418 | CYAssignment \ | |
1419 | { \ | |
1420 | CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \ | |
1421 | CYAssignment(lhs, rhs) \ | |
1422 | { \ | |
1423 | } \ | |
d35a3b07 JF |
1424 | \ |
1425 | CYPrecedence(16) \ | |
5999c315 JF |
1426 | \ |
1427 | virtual const char *Operator() const { \ | |
1428 | return op; \ | |
1429 | } \ | |
cf7d4c69 JF |
1430 | }; |
1431 | ||
1432 | CYPostfix_("++", PostIncrement) | |
1433 | CYPostfix_("--", PostDecrement) | |
1434 | ||
b09da87b JF |
1435 | CYPrefix_(true, "delete", Delete) |
1436 | CYPrefix_(true, "void", Void) | |
1437 | CYPrefix_(true, "typeof", TypeOf) | |
1438 | CYPrefix_(false, "++", PreIncrement) | |
1439 | CYPrefix_(false, "--", PreDecrement) | |
1440 | CYPrefix_(false, "-", Negate) | |
1441 | CYPrefix_(false, "~", BitwiseNot) | |
1442 | CYPrefix_(false, "!", LogicalNot) | |
1443 | ||
1444 | CYInfix_(false, 5, "*", Multiply) | |
1445 | CYInfix_(false, 5, "/", Divide) | |
1446 | CYInfix_(false, 5, "%", Modulus) | |
1447 | CYInfix_(false, 6, "+", Add) | |
1448 | CYInfix_(false, 6, "-", Subtract) | |
1449 | CYInfix_(false, 7, "<<", ShiftLeft) | |
1450 | CYInfix_(false, 7, ">>", ShiftRightSigned) | |
1451 | CYInfix_(false, 7, ">>>", ShiftRightUnsigned) | |
1452 | CYInfix_(false, 8, "<", Less) | |
1453 | CYInfix_(false, 8, ">", Greater) | |
1454 | CYInfix_(false, 8, "<=", LessOrEqual) | |
1455 | CYInfix_(false, 8, ">=", GreaterOrEqual) | |
1456 | CYInfix_(true, 8, "instanceof", InstanceOf) | |
1457 | CYInfix_(true, 8, "in", In) | |
1458 | CYInfix_(false, 9, "==", Equal) | |
1459 | CYInfix_(false, 9, "!=", NotEqual) | |
1460 | CYInfix_(false, 9, "===", Identical) | |
1461 | CYInfix_(false, 9, "!==", NotIdentical) | |
1462 | CYInfix_(false, 10, "&", BitwiseAnd) | |
1463 | CYInfix_(false, 11, "^", BitwiseXOr) | |
1464 | CYInfix_(false, 12, "|", BitwiseOr) | |
1465 | CYInfix_(false, 13, "&&", LogicalAnd) | |
1466 | CYInfix_(false, 14, "||", LogicalOr) | |
cf7d4c69 JF |
1467 | |
1468 | CYAssignment_("=", ) | |
1469 | CYAssignment_("*=", Multiply) | |
1470 | CYAssignment_("/=", Divide) | |
1471 | CYAssignment_("%=", Modulus) | |
1472 | CYAssignment_("+=", Add) | |
1473 | CYAssignment_("-=", Subtract) | |
1474 | CYAssignment_("<<=", ShiftLeft) | |
1475 | CYAssignment_(">>=", ShiftRightSigned) | |
1476 | CYAssignment_(">>>=", ShiftRightUnsigned) | |
1477 | CYAssignment_("&=", BitwiseAnd) | |
1478 | CYAssignment_("^=", BitwiseXOr) | |
1479 | CYAssignment_("|=", BitwiseOr) | |
1480 | ||
63b4c5a8 | 1481 | #endif/*CYPARSER_HPP*/ |