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