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