]> git.saurik.com Git - cycript.git/blob - Syntax.hpp
Avoid naming functors without symbols as just "1".
[cycript.git] / Syntax.hpp
1 /* Cycript - The Truly Universal Scripting Language
2 * Copyright (C) 2009-2016 Jay Freeman (saurik)
3 */
4
5 /* GNU Affero General Public License, Version 3 {{{ */
6 /*
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #ifndef CYCRIPT_SYNTAX_HPP
23 #define CYCRIPT_SYNTAX_HPP
24
25 #include <cstdio>
26 #include <cstdlib>
27
28 #include <streambuf>
29 #include <string>
30 #include <vector>
31
32 #include "List.hpp"
33 #include "Location.hpp"
34 #include "Options.hpp"
35 #include "Pooling.hpp"
36 #include "String.hpp"
37
38 double CYCastDouble(const char *value, size_t size);
39 double CYCastDouble(const char *value);
40 double CYCastDouble(CYUTF8String value);
41
42 void CYNumerify(std::ostringstream &str, double value);
43 void CYStringify(std::ostringstream &str, const char *data, size_t size, bool c = false);
44
45 // XXX: this really should not be here ... :/
46 void *CYPoolFile(CYPool &pool, const char *path, size_t *psize);
47 CYUTF8String CYPoolFileUTF8String(CYPool &pool, const char *path);
48
49 struct CYContext;
50
51 struct CYThing {
52 virtual void Output(struct CYOutput &out) const = 0;
53 };
54
55 struct CYOutput {
56 std::streambuf &out_;
57 CYPosition position_;
58
59 CYOptions &options_;
60 bool pretty_;
61 unsigned indent_;
62 unsigned recent_;
63 bool right_;
64
65 enum {
66 NoMode,
67 NoLetter,
68 NoPlus,
69 NoHyphen,
70 Terminated
71 } mode_;
72
73 CYOutput(std::streambuf &out, CYOptions &options) :
74 out_(out),
75 options_(options),
76 pretty_(false),
77 indent_(0),
78 recent_(0),
79 right_(false),
80 mode_(NoMode)
81 {
82 }
83
84 void Check(char value);
85 void Terminate();
86
87 _finline void operator ()(char value) {
88 _assert(out_.sputc(value) != EOF);
89 recent_ = indent_;
90 if (value == '\n')
91 position_.Lines(1);
92 else
93 position_.Columns(1);
94 }
95
96 _finline void operator ()(const char *data, std::streamsize size) {
97 _assert(out_.sputn(data, size) == size);
98 recent_ = indent_;
99 position_.Columns(size);
100 }
101
102 _finline void operator ()(const char *data) {
103 return operator ()(data, strlen(data));
104 }
105
106 CYOutput &operator <<(char rhs);
107 CYOutput &operator <<(const char *rhs);
108
109 _finline CYOutput &operator <<(const CYThing *rhs) {
110 if (rhs != NULL)
111 rhs->Output(*this);
112 return *this;
113 }
114
115 _finline CYOutput &operator <<(const CYThing &rhs) {
116 rhs.Output(*this);
117 return *this;
118 }
119 };
120
121 struct CYExpression;
122 struct CYAssignment;
123 struct CYIdentifier;
124 struct CYNumber;
125
126 struct CYPropertyName {
127 virtual bool Computed() const {
128 return false;
129 }
130
131 virtual bool Constructor() const {
132 return false;
133 }
134
135 virtual CYIdentifier *Identifier() {
136 return NULL;
137 }
138
139 virtual CYNumber *Number(CYContext &context) {
140 return NULL;
141 }
142
143 virtual CYExpression *PropertyName(CYContext &context) = 0;
144 virtual void PropertyName(CYOutput &out) const = 0;
145 };
146
147 enum CYNeeded {
148 CYNever = -1,
149 CYSometimes = 0,
150 CYAlways = 1,
151 };
152
153 enum CYFlags {
154 CYNoFlags = 0,
155 CYNoBrace = (1 << 0),
156 CYNoFunction = (1 << 1),
157 CYNoClass = (1 << 2),
158 CYNoIn = (1 << 3),
159 CYNoCall = (1 << 4),
160 CYNoRightHand = (1 << 5),
161 CYNoDangle = (1 << 6),
162 CYNoInteger = (1 << 7),
163 CYNoColon = (1 << 8),
164 CYNoBFC = (CYNoBrace | CYNoFunction | CYNoClass),
165 };
166
167 _finline CYFlags operator ~(CYFlags rhs) {
168 return static_cast<CYFlags>(~static_cast<unsigned>(rhs));
169 }
170
171 _finline CYFlags operator &(CYFlags lhs, CYFlags rhs) {
172 return static_cast<CYFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs));
173 }
174
175 _finline CYFlags operator |(CYFlags lhs, CYFlags rhs) {
176 return static_cast<CYFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs));
177 }
178
179 _finline CYFlags &operator |=(CYFlags &lhs, CYFlags rhs) {
180 return lhs = lhs | rhs;
181 }
182
183 _finline CYFlags CYLeft(CYFlags flags) {
184 return flags & ~(CYNoDangle | CYNoInteger);
185 }
186
187 _finline CYFlags CYRight(CYFlags flags) {
188 return flags & ~CYNoBFC;
189 }
190
191 _finline CYFlags CYCenter(CYFlags flags) {
192 return CYLeft(CYRight(flags));
193 }
194
195 enum CYCompactType {
196 CYCompactNone,
197 CYCompactLong,
198 CYCompactShort,
199 };
200
201 #define CYCompact(type) \
202 virtual CYCompactType Compact() const { \
203 return CYCompact ## type; \
204 }
205
206 struct CYStatement :
207 CYNext<CYStatement>,
208 CYThing
209 {
210 void Single(CYOutput &out, CYFlags flags, CYCompactType request) const;
211 void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
212 virtual void Output(CYOutput &out) const;
213
214 virtual CYStatement *Replace(CYContext &context) = 0;
215
216 virtual CYCompactType Compact() const = 0;
217 virtual CYStatement *Return();
218
219 private:
220 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
221 };
222
223 typedef CYList<CYStatement> CYStatements;
224
225 struct CYForInitializer :
226 CYStatement
227 {
228 virtual CYForInitializer *Replace(CYContext &context) = 0;
229 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
230 };
231
232 struct CYWord :
233 CYThing,
234 CYPropertyName
235 {
236 const char *word_;
237
238 CYWord(const char *word) :
239 word_(word)
240 {
241 }
242
243 virtual bool Constructor() const {
244 return strcmp(word_, "constructor") == 0;
245 }
246
247 virtual const char *Word() const;
248 virtual void Output(CYOutput &out) const;
249
250 virtual CYExpression *PropertyName(CYContext &context);
251 virtual void PropertyName(CYOutput &out) const;
252 };
253
254 _finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) {
255 lhs << &rhs << '=';
256 return lhs << rhs.Word();
257 }
258
259 enum CYIdentifierKind {
260 CYIdentifierArgument,
261 CYIdentifierCatch,
262 CYIdentifierGlobal,
263 CYIdentifierLexical,
264 CYIdentifierMagic,
265 CYIdentifierOther,
266 CYIdentifierVariable,
267 };
268
269 struct CYIdentifier :
270 CYNext<CYIdentifier>,
271 CYWord
272 {
273 CYLocation location_;
274 size_t offset_;
275 size_t usage_;
276
277 CYIdentifier(const char *word) :
278 CYWord(word),
279 offset_(0),
280 usage_(0)
281 {
282 }
283
284 CYIdentifier *Identifier() override {
285 return this;
286 }
287
288 virtual const char *Word() const;
289 CYIdentifier *Replace(CYContext &context, CYIdentifierKind);
290 };
291
292 struct CYLabel :
293 CYStatement
294 {
295 CYIdentifier *name_;
296 CYStatement *statement_;
297
298 CYLabel(CYIdentifier *name, CYStatement *statement) :
299 name_(name),
300 statement_(statement)
301 {
302 }
303
304 CYCompact(Short)
305
306 virtual CYStatement *Replace(CYContext &context);
307 virtual void Output(CYOutput &out, CYFlags flags) const;
308 };
309
310 struct CYCStringLess :
311 std::binary_function<const char *, const char *, bool>
312 {
313 _finline bool operator ()(const char *lhs, const char *rhs) const {
314 return strcmp(lhs, rhs) < 0;
315 }
316 };
317
318 struct CYIdentifierValueLess :
319 std::binary_function<CYIdentifier *, CYIdentifier *, bool>
320 {
321 _finline bool operator ()(CYIdentifier *lhs, CYIdentifier *rhs) const {
322 return CYCStringLess()(lhs->Word(), rhs->Word());
323 }
324 };
325
326 struct CYIdentifierFlags :
327 CYNext<CYIdentifierFlags>
328 {
329 CYIdentifier *identifier_;
330 CYIdentifierKind kind_;
331 unsigned count_;
332 unsigned offset_;
333
334 CYIdentifierFlags(CYIdentifier *identifier, CYIdentifierKind kind, CYIdentifierFlags *next = NULL) :
335 CYNext<CYIdentifierFlags>(next),
336 identifier_(identifier),
337 kind_(kind),
338 count_(0),
339 offset_(0)
340 {
341 }
342 };
343
344 struct CYScope {
345 bool transparent_;
346 CYScope *parent_;
347 bool damaged_;
348 CYIdentifierFlags *shadow_;
349
350 CYIdentifierFlags *internal_;
351
352 CYScope(bool transparent, CYContext &context);
353
354 CYIdentifierFlags *Lookup(CYContext &context, const char *word);
355 CYIdentifierFlags *Lookup(CYContext &context, CYIdentifier *identifier);
356
357 CYIdentifierFlags *Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierKind kind);
358 void Merge(CYContext &context, const CYIdentifierFlags *flags);
359
360 void Close(CYContext &context, CYStatement *&statements);
361 void Close(CYContext &context);
362 void Damage();
363 };
364
365 struct CYScript :
366 CYThing
367 {
368 CYStatement *code_;
369
370 CYScript(CYStatement *code) :
371 code_(code)
372 {
373 }
374
375 virtual void Replace(CYContext &context);
376 virtual void Output(CYOutput &out) const;
377 };
378
379 struct CYNonLocal;
380 struct CYThisScope;
381
382 struct CYContext {
383 CYOptions &options_;
384
385 CYScope *scope_;
386 CYThisScope *this_;
387 CYIdentifier *super_;
388
389 CYNonLocal *nonlocal_;
390 CYNonLocal *nextlocal_;
391 unsigned unique_;
392
393 std::vector<CYIdentifier *> replace_;
394
395 CYContext(CYOptions &options) :
396 options_(options),
397 scope_(NULL),
398 this_(NULL),
399 super_(NULL),
400 nonlocal_(NULL),
401 nextlocal_(NULL),
402 unique_(0)
403 {
404 }
405
406 void ReplaceAll(CYStatement *&statement) {
407 if (statement == NULL)
408 return;
409 CYStatement *next(statement->next_);
410
411 Replace(statement);
412 ReplaceAll(next);
413
414 if (statement == NULL)
415 statement = next;
416 else
417 statement->SetNext(next);
418 }
419
420 template <typename Type_>
421 void Replace(Type_ *&value) {
422 for (;;) if (value == NULL)
423 break;
424 else {
425 Type_ *replace(value->Replace(*this));
426 if (replace != value)
427 value = replace;
428 else break;
429 }
430 }
431
432 void NonLocal(CYStatement *&statements);
433 CYIdentifier *Unique();
434 };
435
436 struct CYNonLocal {
437 CYIdentifier *identifier_;
438
439 CYNonLocal() :
440 identifier_(NULL)
441 {
442 }
443
444 CYIdentifier *Target(CYContext &context) {
445 if (identifier_ == NULL)
446 identifier_ = context.Unique();
447 return identifier_;
448 }
449 };
450
451 struct CYThisScope :
452 CYNext<CYThisScope>
453 {
454 CYIdentifier *identifier_;
455
456 CYThisScope() :
457 identifier_(NULL)
458 {
459 }
460
461 CYIdentifier *Identifier(CYContext &context) {
462 if (next_ != NULL)
463 return next_->Identifier(context);
464 if (identifier_ == NULL)
465 identifier_ = context.Unique();
466 return identifier_;
467 }
468 };
469
470 struct CYBlock :
471 CYStatement
472 {
473 CYStatement *code_;
474
475 CYBlock(CYStatement *code) :
476 code_(code)
477 {
478 }
479
480 CYCompact(Short)
481
482 virtual CYStatement *Replace(CYContext &context);
483
484 virtual void Output(CYOutput &out, CYFlags flags) const;
485
486 virtual CYStatement *Return();
487 };
488
489 struct CYTarget;
490 struct CYVar;
491
492 struct CYForInInitializer {
493 virtual CYStatement *Initialize(CYContext &context, CYExpression *value) = 0;
494
495 virtual CYTarget *Replace(CYContext &context) = 0;
496 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
497 };
498
499 struct CYFunctionParameter;
500
501 struct CYNumber;
502 struct CYString;
503
504 struct CYExpression :
505 CYThing
506 {
507 virtual int Precedence() const = 0;
508
509 virtual bool RightHand() const {
510 return true;
511 }
512
513 virtual bool Eval() const {
514 return false;
515 }
516
517 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
518
519 virtual void Output(CYOutput &out) const;
520 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
521 void Output(CYOutput &out, int precedence, CYFlags flags) const;
522
523 virtual CYExpression *Replace(CYContext &context) = 0;
524
525 virtual CYExpression *Primitive(CYContext &context) {
526 return NULL;
527 }
528
529 virtual CYFunctionParameter *Parameter() const;
530
531 virtual CYNumber *Number(CYContext &context) {
532 return NULL;
533 }
534
535 virtual CYString *String(CYContext &context) {
536 return NULL;
537 }
538
539 virtual const char *Word() const {
540 return NULL;
541 }
542 };
543
544 struct CYTarget :
545 CYExpression,
546 CYForInInitializer
547 {
548 virtual bool RightHand() const {
549 return false;
550 }
551
552 virtual bool IsNew() const {
553 return false;
554 }
555
556 virtual CYStatement *Initialize(CYContext &context, CYExpression *value);
557
558 virtual CYTarget *Replace(CYContext &context) = 0;
559 using CYExpression::Output;
560 };
561
562 #define CYAlphabetic(value) \
563 virtual bool Alphabetic() const { \
564 return value; \
565 }
566
567 #define CYPrecedence(value) \
568 static const int Precedence_ = value; \
569 virtual int Precedence() const { \
570 return Precedence_; \
571 }
572
573 struct CYCompound :
574 CYExpression
575 {
576 CYExpression *expression_;
577 CYExpression *next_;
578
579 CYCompound(CYExpression *expression, CYExpression *next) :
580 expression_(expression),
581 next_(next)
582 {
583 _assert(expression_ != NULL);
584 _assert(next != NULL);
585 }
586
587 CYPrecedence(17)
588
589 virtual CYExpression *Replace(CYContext &context);
590 void Output(CYOutput &out, CYFlags flags) const;
591
592 virtual CYFunctionParameter *Parameter() const;
593 };
594
595 struct CYParenthetical :
596 CYTarget
597 {
598 CYExpression *expression_;
599
600 CYParenthetical(CYExpression *expression) :
601 expression_(expression)
602 {
603 }
604
605 CYPrecedence(0)
606
607 virtual CYTarget *Replace(CYContext &context);
608 void Output(CYOutput &out, CYFlags flags) const;
609 };
610
611 struct CYBinding;
612
613 struct CYFunctionParameter :
614 CYNext<CYFunctionParameter>,
615 CYThing
616 {
617 CYBinding *binding_;
618
619 CYFunctionParameter(CYBinding *binding, CYFunctionParameter *next = NULL) :
620 CYNext<CYFunctionParameter>(next),
621 binding_(binding)
622 {
623 }
624
625 void Replace(CYContext &context, CYStatement *&statements);
626 void Output(CYOutput &out) const;
627 };
628
629 struct CYComprehension :
630 CYNext<CYComprehension>,
631 CYThing
632 {
633 CYComprehension(CYComprehension *next = NULL) :
634 CYNext<CYComprehension>(next)
635 {
636 }
637
638 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
639 CYFunctionParameter *Parameters(CYContext &context) const;
640 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
641 virtual void Output(CYOutput &out) const = 0;
642 };
643
644 struct CYForInComprehension :
645 CYComprehension
646 {
647 CYBinding *binding_;
648 CYExpression *iterable_;
649
650 CYForInComprehension(CYBinding *binding, CYExpression *iterable, CYComprehension *next = NULL) :
651 CYComprehension(next),
652 binding_(binding),
653 iterable_(iterable)
654 {
655 }
656
657 virtual CYFunctionParameter *Parameter(CYContext &context) const;
658 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
659 virtual void Output(CYOutput &out) const;
660 };
661
662 struct CYForOfComprehension :
663 CYComprehension
664 {
665 CYBinding *binding_;
666 CYExpression *iterable_;
667
668 CYForOfComprehension(CYBinding *binding, CYExpression *iterable, CYComprehension *next = NULL) :
669 CYComprehension(next),
670 binding_(binding),
671 iterable_(iterable)
672 {
673 }
674
675 virtual CYFunctionParameter *Parameter(CYContext &context) const;
676 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
677 virtual void Output(CYOutput &out) const;
678 };
679
680 struct CYIfComprehension :
681 CYComprehension
682 {
683 CYExpression *test_;
684
685 CYIfComprehension(CYExpression *test, CYComprehension *next = NULL) :
686 CYComprehension(next),
687 test_(test)
688 {
689 }
690
691 virtual CYFunctionParameter *Parameter(CYContext &context) const;
692 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
693 virtual void Output(CYOutput &out) const;
694 };
695
696 struct CYArrayComprehension :
697 CYTarget
698 {
699 CYExpression *expression_;
700 CYComprehension *comprehensions_;
701
702 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
703 expression_(expression),
704 comprehensions_(comprehensions)
705 {
706 }
707
708 CYPrecedence(0)
709
710 virtual CYTarget *Replace(CYContext &context);
711 virtual void Output(CYOutput &out, CYFlags flags) const;
712 };
713
714 struct CYLiteral :
715 CYTarget
716 {
717 CYLocation location_;
718
719 CYPrecedence(0)
720
721 virtual CYExpression *Primitive(CYContext &context) {
722 return this;
723 }
724 };
725
726 struct CYTrivial :
727 CYLiteral
728 {
729 virtual CYTarget *Replace(CYContext &context);
730 };
731
732 struct CYMagic :
733 CYTarget
734 {
735 CYPrecedence(0)
736 };
737
738 struct CYRange {
739 uint64_t lo_;
740 uint64_t hi_;
741
742 CYRange(uint64_t lo, uint64_t hi) :
743 lo_(lo), hi_(hi)
744 {
745 }
746
747 bool operator [](uint8_t value) const {
748 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
749 }
750
751 void operator()(uint8_t value) {
752 if (value >> 7)
753 return;
754 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
755 }
756 };
757
758 extern CYRange DigitRange_;
759 extern CYRange WordStartRange_;
760 extern CYRange WordEndRange_;
761
762 struct CYString :
763 CYTrivial,
764 CYPropertyName
765 {
766 const char *value_;
767 size_t size_;
768
769 CYString() :
770 value_(NULL),
771 size_(0)
772 {
773 }
774
775 CYString(const char *value) :
776 value_(value),
777 size_(strlen(value))
778 {
779 }
780
781 CYString(const char *value, size_t size) :
782 value_(value),
783 size_(size)
784 {
785 }
786
787 CYString(const CYWord *word) :
788 value_(word->Word()),
789 size_(strlen(value_))
790 {
791 }
792
793 const char *Value() const {
794 return value_;
795 }
796
797 virtual CYIdentifier *Identifier() const;
798 virtual const char *Word() const;
799
800 virtual CYNumber *Number(CYContext &context);
801 virtual CYString *String(CYContext &context);
802
803 CYString *Concat(CYContext &out, CYString *rhs) const;
804 virtual void Output(CYOutput &out, CYFlags flags) const;
805
806 virtual CYExpression *PropertyName(CYContext &context);
807 virtual void PropertyName(CYOutput &out) const;
808 };
809
810 struct CYElementValue;
811
812 struct CYSpan :
813 CYNext<CYSpan>
814 {
815 CYExpression *expression_;
816 CYString *string_;
817
818 CYSpan(CYExpression *expression, CYString *string, CYSpan *next) :
819 CYNext<CYSpan>(next),
820 expression_(expression),
821 string_(string)
822 {
823 }
824
825 CYElementValue *Replace(CYContext &context);
826 };
827
828 struct CYTemplate :
829 CYTarget
830 {
831 CYString *string_;
832 CYSpan *spans_;
833
834 CYTemplate(CYString *string, CYSpan *spans) :
835 string_(string),
836 spans_(spans)
837 {
838 }
839
840 CYPrecedence(0)
841
842 virtual CYTarget *Replace(CYContext &context);
843 virtual void Output(CYOutput &out, CYFlags flags) const;
844 };
845
846 struct CYNumber :
847 CYTrivial,
848 CYPropertyName
849 {
850 double value_;
851
852 CYNumber(double value) :
853 value_(value)
854 {
855 }
856
857 double Value() const {
858 return value_;
859 }
860
861 virtual CYNumber *Number(CYContext &context);
862 virtual CYString *String(CYContext &context);
863
864 virtual void Output(CYOutput &out, CYFlags flags) const;
865
866 virtual CYExpression *PropertyName(CYContext &context);
867 virtual void PropertyName(CYOutput &out) const;
868 };
869
870 struct CYComputed :
871 CYPropertyName
872 {
873 CYExpression *expression_;
874
875 CYComputed(CYExpression *expression) :
876 expression_(expression)
877 {
878 }
879
880 virtual bool Computed() const {
881 return true;
882 }
883
884 virtual CYExpression *PropertyName(CYContext &context);
885 virtual void PropertyName(CYOutput &out) const;
886 };
887
888 struct CYRegEx :
889 CYTrivial
890 {
891 const char *value_;
892 size_t size_;
893
894 CYRegEx(const char *value, size_t size) :
895 value_(value),
896 size_(size)
897 {
898 }
899
900 const char *Value() const {
901 return value_;
902 }
903
904 virtual void Output(CYOutput &out, CYFlags flags) const;
905 };
906
907 struct CYNull :
908 CYTrivial
909 {
910 virtual CYNumber *Number(CYContext &context);
911 virtual CYString *String(CYContext &context);
912
913 virtual void Output(CYOutput &out, CYFlags flags) const;
914 };
915
916 struct CYThis :
917 CYMagic
918 {
919 virtual CYTarget *Replace(CYContext &context);
920 virtual void Output(CYOutput &out, CYFlags flags) const;
921 };
922
923 struct CYBoolean :
924 CYTrivial
925 {
926 CYPrecedence(4)
927
928 virtual bool RightHand() const {
929 return true;
930 }
931
932 virtual bool Value() const = 0;
933 virtual void Output(CYOutput &out, CYFlags flags) const;
934 };
935
936 struct CYFalse :
937 CYBoolean
938 {
939 virtual bool Value() const {
940 return false;
941 }
942
943 virtual CYNumber *Number(CYContext &context);
944 virtual CYString *String(CYContext &context);
945 };
946
947 struct CYTrue :
948 CYBoolean
949 {
950 virtual bool Value() const {
951 return true;
952 }
953
954 virtual CYNumber *Number(CYContext &context);
955 virtual CYString *String(CYContext &context);
956 };
957
958 struct CYVariable :
959 CYTarget
960 {
961 CYIdentifier *name_;
962
963 CYVariable(CYIdentifier *name) :
964 name_(name)
965 {
966 }
967
968 CYVariable(const char *name) :
969 name_(new($pool) CYIdentifier(name))
970 {
971 }
972
973 CYPrecedence(0)
974
975 virtual bool Eval() const {
976 return strcmp(name_->Word(), "eval") == 0;
977 }
978
979 virtual CYTarget *Replace(CYContext &context);
980 virtual void Output(CYOutput &out, CYFlags flags) const;
981
982 virtual CYFunctionParameter *Parameter() const;
983 };
984
985 struct CYSymbol :
986 CYTarget
987 {
988 const char *name_;
989
990 CYSymbol(const char *name) :
991 name_(name)
992 {
993 }
994
995 CYPrecedence(0)
996
997 virtual CYTarget *Replace(CYContext &context);
998 virtual void Output(CYOutput &out, CYFlags flags) const;
999 };
1000
1001 struct CYPrefix :
1002 CYExpression
1003 {
1004 CYExpression *rhs_;
1005
1006 CYPrefix(CYExpression *rhs) :
1007 rhs_(rhs)
1008 {
1009 }
1010
1011 virtual bool Alphabetic() const = 0;
1012 virtual const char *Operator() const = 0;
1013
1014 CYPrecedence(4)
1015
1016 virtual CYExpression *Replace(CYContext &context);
1017 virtual void Output(CYOutput &out, CYFlags flags) const;
1018 };
1019
1020 struct CYInfix :
1021 CYExpression
1022 {
1023 CYExpression *lhs_;
1024 CYExpression *rhs_;
1025
1026 CYInfix(CYExpression *lhs, CYExpression *rhs) :
1027 lhs_(lhs),
1028 rhs_(rhs)
1029 {
1030 }
1031
1032 void SetLeft(CYExpression *lhs) {
1033 lhs_ = lhs;
1034 }
1035
1036 virtual bool Alphabetic() const = 0;
1037 virtual const char *Operator() const = 0;
1038
1039 virtual CYExpression *Replace(CYContext &context);
1040 virtual void Output(CYOutput &out, CYFlags flags) const;
1041 };
1042
1043 struct CYPostfix :
1044 CYExpression
1045 {
1046 CYExpression *lhs_;
1047
1048 CYPostfix(CYExpression *lhs) :
1049 lhs_(lhs)
1050 {
1051 }
1052
1053 virtual const char *Operator() const = 0;
1054
1055 CYPrecedence(3)
1056
1057 virtual CYExpression *Replace(CYContext &context);
1058 virtual void Output(CYOutput &out, CYFlags flags) const;
1059 };
1060
1061 struct CYAssignment :
1062 CYExpression
1063 {
1064 CYTarget *lhs_;
1065 CYExpression *rhs_;
1066
1067 CYAssignment(CYTarget *lhs, CYExpression *rhs) :
1068 lhs_(lhs),
1069 rhs_(rhs)
1070 {
1071 }
1072
1073 void SetRight(CYExpression *rhs) {
1074 rhs_ = rhs;
1075 }
1076
1077 virtual const char *Operator() const = 0;
1078
1079 CYPrecedence(16)
1080
1081 virtual CYExpression *Replace(CYContext &context);
1082 virtual void Output(CYOutput &out, CYFlags flags) const;
1083 };
1084
1085 struct CYArgument :
1086 CYNext<CYArgument>,
1087 CYThing
1088 {
1089 CYWord *name_;
1090 CYExpression *value_;
1091
1092 CYArgument(CYExpression *value, CYArgument *next = NULL) :
1093 CYNext<CYArgument>(next),
1094 name_(NULL),
1095 value_(value)
1096 {
1097 }
1098
1099 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
1100 CYNext<CYArgument>(next),
1101 name_(name),
1102 value_(value)
1103 {
1104 }
1105
1106 CYArgument *Replace(CYContext &context);
1107 void Output(CYOutput &out) const;
1108 };
1109
1110 struct CYClause :
1111 CYThing,
1112 CYNext<CYClause>
1113 {
1114 CYExpression *value_;
1115 CYStatement *code_;
1116
1117 CYClause(CYExpression *value, CYStatement *code) :
1118 value_(value),
1119 code_(code)
1120 {
1121 }
1122
1123 void Replace(CYContext &context);
1124 virtual void Output(CYOutput &out) const;
1125 };
1126
1127 struct CYElement :
1128 CYNext<CYElement>,
1129 CYThing
1130 {
1131 CYElement(CYElement *next) :
1132 CYNext<CYElement>(next)
1133 {
1134 }
1135
1136 virtual bool Elision() const = 0;
1137
1138 virtual void Replace(CYContext &context) = 0;
1139 };
1140
1141 struct CYElementValue :
1142 CYElement
1143 {
1144 CYExpression *value_;
1145
1146 CYElementValue(CYExpression *value, CYElement *next = NULL) :
1147 CYElement(next),
1148 value_(value)
1149 {
1150 }
1151
1152 virtual bool Elision() const {
1153 return value_ == NULL;
1154 }
1155
1156 virtual void Replace(CYContext &context);
1157 virtual void Output(CYOutput &out) const;
1158 };
1159
1160 struct CYElementSpread :
1161 CYElement
1162 {
1163 CYExpression *value_;
1164
1165 CYElementSpread(CYExpression *value, CYElement *next = NULL) :
1166 CYElement(next),
1167 value_(value)
1168 {
1169 }
1170
1171 virtual bool Elision() const {
1172 return false;
1173 }
1174
1175 virtual void Replace(CYContext &context);
1176 virtual void Output(CYOutput &out) const;
1177 };
1178
1179 struct CYArray :
1180 CYLiteral
1181 {
1182 CYElement *elements_;
1183
1184 CYArray(CYElement *elements = NULL) :
1185 elements_(elements)
1186 {
1187 }
1188
1189 virtual CYTarget *Replace(CYContext &context);
1190 virtual void Output(CYOutput &out, CYFlags flags) const;
1191 };
1192
1193 struct CYBinding {
1194 CYIdentifier *identifier_;
1195 CYExpression *initializer_;
1196
1197 CYBinding(CYIdentifier *identifier, CYExpression *initializer = NULL) :
1198 identifier_(identifier),
1199 initializer_(initializer)
1200 {
1201 }
1202
1203 CYTarget *Target(CYContext &context);
1204
1205 virtual CYAssignment *Replace(CYContext &context, CYIdentifierKind kind);
1206 virtual void Output(CYOutput &out, CYFlags flags) const;
1207 };
1208
1209 struct CYForLexical :
1210 CYForInInitializer
1211 {
1212 bool constant_;
1213 CYBinding *binding_;
1214
1215 CYForLexical(bool constant, CYBinding *binding) :
1216 constant_(constant),
1217 binding_(binding)
1218 {
1219 }
1220
1221 virtual CYStatement *Initialize(CYContext &context, CYExpression *value);
1222
1223 virtual CYTarget *Replace(CYContext &context);
1224 virtual void Output(CYOutput &out, CYFlags flags) const;
1225 };
1226
1227 struct CYForVariable :
1228 CYForInInitializer
1229 {
1230 CYBinding *binding_;
1231
1232 CYForVariable(CYBinding *binding) :
1233 binding_(binding)
1234 {
1235 }
1236
1237 virtual CYStatement *Initialize(CYContext &context, CYExpression *value);
1238
1239 virtual CYTarget *Replace(CYContext &context);
1240 virtual void Output(CYOutput &out, CYFlags flags) const;
1241 };
1242
1243 struct CYBindings :
1244 CYNext<CYBindings>,
1245 CYThing
1246 {
1247 CYBinding *binding_;
1248
1249 CYBindings(CYBinding *binding, CYBindings *next = NULL) :
1250 CYNext<CYBindings>(next),
1251 binding_(binding)
1252 {
1253 }
1254
1255 CYExpression *Replace(CYContext &context, CYIdentifierKind kind);
1256
1257 CYArgument *Argument(CYContext &context);
1258 CYFunctionParameter *Parameter(CYContext &context);
1259
1260 virtual void Output(CYOutput &out) const;
1261 virtual void Output(CYOutput &out, CYFlags flags) const;
1262 };
1263
1264 struct CYVar :
1265 CYForInitializer
1266 {
1267 CYBindings *bindings_;
1268
1269 CYVar(CYBindings *bindings) :
1270 bindings_(bindings)
1271 {
1272 }
1273
1274 CYCompact(None)
1275
1276 virtual CYForInitializer *Replace(CYContext &context);
1277 virtual void Output(CYOutput &out, CYFlags flags) const;
1278 };
1279
1280 struct CYLexical :
1281 CYForInitializer
1282 {
1283 bool constant_;
1284 CYBindings *bindings_;
1285
1286 CYLexical(bool constant, CYBindings *bindings) :
1287 constant_(constant),
1288 bindings_(bindings)
1289 {
1290 }
1291
1292 CYCompact(None)
1293
1294 virtual CYForInitializer *Replace(CYContext &context);
1295 virtual void Output(CYOutput &out, CYFlags flags) const;
1296 };
1297
1298 struct CYBuilder {
1299 CYList<CYBindings> bindings_;
1300 CYList<CYStatement> statements_;
1301
1302 operator bool() const {
1303 return statements_ != NULL;
1304 }
1305 };
1306
1307 struct CYProperty :
1308 CYNext<CYProperty>,
1309 CYThing
1310 {
1311 CYPropertyName *name_;
1312
1313 CYProperty(CYPropertyName *name, CYProperty *next = NULL) :
1314 CYNext<CYProperty>(next),
1315 name_(name)
1316 {
1317 }
1318
1319 virtual bool Update() const;
1320
1321 CYProperty *ReplaceAll(CYContext &context, CYBuilder &builder, CYExpression *self, bool update);
1322 void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, bool protect);
1323
1324 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect) = 0;
1325
1326 virtual void Replace(CYContext &context) = 0;
1327 virtual void Output(CYOutput &out) const;
1328 };
1329
1330 struct CYPropertyValue :
1331 CYProperty
1332 {
1333 CYExpression *value_;
1334
1335 CYPropertyValue(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1336 CYProperty(name, next),
1337 value_(value)
1338 {
1339 }
1340
1341 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
1342 virtual void Replace(CYContext &context);
1343 virtual void Output(CYOutput &out) const;
1344 };
1345
1346 struct CYFor :
1347 CYStatement
1348 {
1349 CYForInitializer *initializer_;
1350 CYExpression *test_;
1351 CYExpression *increment_;
1352 CYStatement *code_;
1353
1354 CYFor(CYForInitializer *initializer, CYExpression *test, CYExpression *increment, CYStatement *code) :
1355 initializer_(initializer),
1356 test_(test),
1357 increment_(increment),
1358 code_(code)
1359 {
1360 }
1361
1362 CYCompact(Long)
1363
1364 virtual CYStatement *Replace(CYContext &context);
1365 virtual void Output(CYOutput &out, CYFlags flags) const;
1366 };
1367
1368 struct CYForIn :
1369 CYStatement
1370 {
1371 CYForInInitializer *initializer_;
1372 CYExpression *iterable_;
1373 CYStatement *code_;
1374
1375 CYForIn(CYForInInitializer *initializer, CYExpression *iterable, CYStatement *code) :
1376 initializer_(initializer),
1377 iterable_(iterable),
1378 code_(code)
1379 {
1380 }
1381
1382 CYCompact(Long)
1383
1384 virtual CYStatement *Replace(CYContext &context);
1385 virtual void Output(CYOutput &out, CYFlags flags) const;
1386 };
1387
1388 struct CYForInitialized :
1389 CYStatement
1390 {
1391 CYBinding *binding_;
1392 CYExpression *iterable_;
1393 CYStatement *code_;
1394
1395 CYForInitialized(CYBinding *binding, CYExpression *iterable, CYStatement *code) :
1396 binding_(binding),
1397 iterable_(iterable),
1398 code_(code)
1399 {
1400 }
1401
1402 CYCompact(Long)
1403
1404 virtual CYStatement *Replace(CYContext &context);
1405 virtual void Output(CYOutput &out, CYFlags flags) const;
1406 };
1407
1408 struct CYForOf :
1409 CYStatement
1410 {
1411 CYForInInitializer *initializer_;
1412 CYExpression *iterable_;
1413 CYStatement *code_;
1414
1415 CYForOf(CYForInInitializer *initializer, CYExpression *iterable, CYStatement *code) :
1416 initializer_(initializer),
1417 iterable_(iterable),
1418 code_(code)
1419 {
1420 }
1421
1422 CYCompact(Long)
1423
1424 virtual CYStatement *Replace(CYContext &context);
1425 virtual void Output(CYOutput &out, CYFlags flags) const;
1426 };
1427
1428 struct CYObject :
1429 CYLiteral
1430 {
1431 CYProperty *properties_;
1432
1433 CYObject(CYProperty *properties = NULL) :
1434 properties_(properties)
1435 {
1436 }
1437
1438 CYTarget *Replace(CYContext &context, CYTarget *seed);
1439
1440 virtual CYTarget *Replace(CYContext &context);
1441 void Output(CYOutput &out, CYFlags flags) const;
1442 };
1443
1444 struct CYMember :
1445 CYTarget
1446 {
1447 CYExpression *object_;
1448 CYExpression *property_;
1449
1450 CYMember(CYExpression *object, CYExpression *property) :
1451 object_(object),
1452 property_(property)
1453 {
1454 }
1455
1456 void SetLeft(CYExpression *object) {
1457 object_ = object;
1458 }
1459 };
1460
1461 struct CYDirectMember :
1462 CYMember
1463 {
1464 CYDirectMember(CYExpression *object, CYExpression *property) :
1465 CYMember(object, property)
1466 {
1467 }
1468
1469 CYPrecedence(1)
1470
1471 virtual CYTarget *Replace(CYContext &context);
1472 virtual void Output(CYOutput &out, CYFlags flags) const;
1473 };
1474
1475 struct CYIndirectMember :
1476 CYMember
1477 {
1478 CYIndirectMember(CYExpression *object, CYExpression *property) :
1479 CYMember(object, property)
1480 {
1481 }
1482
1483 CYPrecedence(1)
1484
1485 virtual CYTarget *Replace(CYContext &context);
1486 virtual void Output(CYOutput &out, CYFlags flags) const;
1487 };
1488
1489 struct CYResolveMember :
1490 CYMember
1491 {
1492 CYResolveMember(CYExpression *object, CYExpression *property) :
1493 CYMember(object, property)
1494 {
1495 }
1496
1497 CYPrecedence(1)
1498
1499 virtual CYTarget *Replace(CYContext &context);
1500 virtual void Output(CYOutput &out, CYFlags flags) const;
1501 };
1502
1503 struct CYSubscriptMember :
1504 CYMember
1505 {
1506 CYSubscriptMember(CYExpression *object, CYExpression *property) :
1507 CYMember(object, property)
1508 {
1509 }
1510
1511 CYPrecedence(1)
1512
1513 virtual CYTarget *Replace(CYContext &context);
1514 virtual void Output(CYOutput &out, CYFlags flags) const;
1515 };
1516
1517 namespace cy {
1518 namespace Syntax {
1519
1520 struct New :
1521 CYTarget
1522 {
1523 CYExpression *constructor_;
1524 CYArgument *arguments_;
1525
1526 New(CYExpression *constructor, CYArgument *arguments = NULL) :
1527 constructor_(constructor),
1528 arguments_(arguments)
1529 {
1530 }
1531
1532 virtual int Precedence() const {
1533 return arguments_ == NULL ? 2 : 1;
1534 }
1535
1536 virtual bool IsNew() const {
1537 return true;
1538 }
1539
1540 virtual CYTarget *Replace(CYContext &context);
1541 virtual void Output(CYOutput &out, CYFlags flags) const;
1542
1543 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
1544 };
1545
1546 } }
1547
1548 struct CYApply :
1549 CYTarget
1550 {
1551 CYArgument *arguments_;
1552
1553 CYApply(CYArgument *arguments = NULL) :
1554 arguments_(arguments)
1555 {
1556 }
1557
1558 CYPrecedence(1)
1559
1560 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
1561 };
1562
1563 struct CYCall :
1564 CYApply
1565 {
1566 CYExpression *function_;
1567
1568 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
1569 CYApply(arguments),
1570 function_(function)
1571 {
1572 }
1573
1574 virtual void Output(CYOutput &out, CYFlags flags) const;
1575 virtual CYTarget *Replace(CYContext &context);
1576 };
1577
1578 struct CYEval :
1579 CYApply
1580 {
1581 CYEval(CYArgument *arguments) :
1582 CYApply(arguments)
1583 {
1584 }
1585
1586 virtual void Output(CYOutput &out, CYFlags flags) const;
1587 virtual CYTarget *Replace(CYContext &context);
1588 };
1589
1590 struct CYRubyProc;
1591
1592 struct CYBraced :
1593 CYTarget
1594 {
1595 CYTarget *lhs_;
1596
1597 CYBraced(CYTarget *lhs = NULL) :
1598 lhs_(lhs)
1599 {
1600 }
1601
1602 CYPrecedence(1)
1603
1604 void SetLeft(CYTarget *lhs) {
1605 lhs_ = lhs;
1606 }
1607 };
1608
1609 struct CYRubyBlock :
1610 CYBraced
1611 {
1612 CYRubyProc *proc_;
1613
1614 CYRubyBlock(CYTarget *lhs, CYRubyProc *proc) :
1615 CYBraced(lhs),
1616 proc_(proc)
1617 {
1618 }
1619
1620 virtual CYTarget *Replace(CYContext &context);
1621 virtual void Output(CYOutput &out, CYFlags flags) const;
1622
1623 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
1624 };
1625
1626 struct CYExtend :
1627 CYBraced
1628 {
1629 CYObject object_;
1630
1631 CYExtend(CYTarget *lhs, CYProperty *properties = NULL) :
1632 CYBraced(lhs),
1633 object_(properties)
1634 {
1635 }
1636
1637 virtual CYTarget *Replace(CYContext &context);
1638 virtual void Output(CYOutput &out, CYFlags flags) const;
1639 };
1640
1641 struct CYIf :
1642 CYStatement
1643 {
1644 CYExpression *test_;
1645 CYStatement *true_;
1646 CYStatement *false_;
1647
1648 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
1649 test_(test),
1650 true_(_true),
1651 false_(_false)
1652 {
1653 }
1654
1655 CYCompact(Long)
1656
1657 virtual CYStatement *Replace(CYContext &context);
1658 virtual void Output(CYOutput &out, CYFlags flags) const;
1659
1660 virtual CYStatement *Return();
1661 };
1662
1663 struct CYDoWhile :
1664 CYStatement
1665 {
1666 CYExpression *test_;
1667 CYStatement *code_;
1668
1669 CYDoWhile(CYExpression *test, CYStatement *code) :
1670 test_(test),
1671 code_(code)
1672 {
1673 }
1674
1675 CYCompact(None)
1676
1677 virtual CYStatement *Replace(CYContext &context);
1678 virtual void Output(CYOutput &out, CYFlags flags) const;
1679 };
1680
1681 struct CYWhile :
1682 CYStatement
1683 {
1684 CYExpression *test_;
1685 CYStatement *code_;
1686
1687 CYWhile(CYExpression *test, CYStatement *code) :
1688 test_(test),
1689 code_(code)
1690 {
1691 }
1692
1693 CYCompact(Long)
1694
1695 virtual CYStatement *Replace(CYContext &context);
1696 virtual void Output(CYOutput &out, CYFlags flags) const;
1697 };
1698
1699 struct CYFunction {
1700 CYFunctionParameter *parameters_;
1701 CYStatement *code_;
1702
1703 CYNonLocal *nonlocal_;
1704 bool implicit_;
1705 CYThisScope this_;
1706 CYIdentifier *super_;
1707
1708 CYFunction(CYFunctionParameter *parameters, CYStatement *code) :
1709 parameters_(parameters),
1710 code_(code),
1711 nonlocal_(NULL),
1712 implicit_(false),
1713 super_(NULL)
1714 {
1715 }
1716
1717 void Replace(CYContext &context);
1718 void Output(CYOutput &out) const;
1719 };
1720
1721 struct CYFunctionExpression :
1722 CYFunction,
1723 CYTarget
1724 {
1725 CYIdentifier *name_;
1726
1727 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
1728 CYFunction(parameters, code),
1729 name_(name)
1730 {
1731 }
1732
1733 CYPrecedence(0)
1734
1735 CYTarget *Replace(CYContext &context) override;
1736 virtual void Output(CYOutput &out, CYFlags flags) const;
1737 };
1738
1739 struct CYFatArrow :
1740 CYFunction,
1741 CYExpression
1742 {
1743 CYFatArrow(CYFunctionParameter *parameters, CYStatement *code) :
1744 CYFunction(parameters, code)
1745 {
1746 }
1747
1748 CYPrecedence(0)
1749
1750 CYExpression *Replace(CYContext &context) override;
1751 virtual void Output(CYOutput &out, CYFlags flags) const;
1752 };
1753
1754 struct CYRubyProc :
1755 CYFunction,
1756 CYTarget
1757 {
1758 CYRubyProc(CYFunctionParameter *parameters, CYStatement *code) :
1759 CYFunction(parameters, code)
1760 {
1761 }
1762
1763 CYPrecedence(0)
1764
1765 CYTarget *Replace(CYContext &context) override;
1766 virtual void Output(CYOutput &out, CYFlags flags) const;
1767 };
1768
1769 struct CYFunctionStatement :
1770 CYFunction,
1771 CYStatement
1772 {
1773 CYIdentifier *name_;
1774
1775 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
1776 CYFunction(parameters, code),
1777 name_(name)
1778 {
1779 }
1780
1781 CYCompact(None)
1782
1783 CYStatement *Replace(CYContext &context) override;
1784 virtual void Output(CYOutput &out, CYFlags flags) const;
1785 };
1786
1787 struct CYPropertyMethod;
1788
1789 struct CYMethod :
1790 CYFunction,
1791 CYProperty
1792 {
1793 CYMethod(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) :
1794 CYFunction(parameters, code),
1795 CYProperty(name, next)
1796 {
1797 }
1798
1799 virtual CYFunctionExpression *Constructor();
1800
1801 using CYProperty::Replace;
1802 virtual void Replace(CYContext &context);
1803 };
1804
1805 struct CYPropertyGetter :
1806 CYMethod
1807 {
1808 CYPropertyGetter(CYPropertyName *name, CYStatement *code, CYProperty *next = NULL) :
1809 CYMethod(name, NULL, code, next)
1810 {
1811 }
1812
1813 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
1814 virtual void Output(CYOutput &out) const;
1815 };
1816
1817 struct CYPropertySetter :
1818 CYMethod
1819 {
1820 CYPropertySetter(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) :
1821 CYMethod(name, parameters, code, next)
1822 {
1823 }
1824
1825 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
1826 virtual void Output(CYOutput &out) const;
1827 };
1828
1829 struct CYPropertyMethod :
1830 CYMethod
1831 {
1832 CYPropertyMethod(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) :
1833 CYMethod(name, parameters, code, next)
1834 {
1835 }
1836
1837 bool Update() const override;
1838
1839 virtual CYFunctionExpression *Constructor();
1840
1841 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
1842 virtual void Output(CYOutput &out) const;
1843 };
1844
1845 struct CYClassTail :
1846 CYThing
1847 {
1848 CYExpression *extends_;
1849
1850 CYFunctionExpression *constructor_;
1851 CYList<CYProperty> instance_;
1852 CYList<CYProperty> static_;
1853
1854 CYClassTail(CYExpression *extends) :
1855 extends_(extends),
1856 constructor_(NULL)
1857 {
1858 }
1859
1860 void Output(CYOutput &out) const;
1861 };
1862
1863 struct CYClassExpression :
1864 CYTarget
1865 {
1866 CYIdentifier *name_;
1867 CYClassTail *tail_;
1868
1869 CYClassExpression(CYIdentifier *name, CYClassTail *tail) :
1870 name_(name),
1871 tail_(tail)
1872 {
1873 }
1874
1875 CYPrecedence(0)
1876
1877 CYTarget *Replace(CYContext &context) override;
1878 virtual void Output(CYOutput &out, CYFlags flags) const;
1879 };
1880
1881 struct CYClassStatement :
1882 CYStatement
1883 {
1884 CYIdentifier *name_;
1885 CYClassTail *tail_;
1886
1887 CYClassStatement(CYIdentifier *name, CYClassTail *tail) :
1888 name_(name),
1889 tail_(tail)
1890 {
1891 }
1892
1893 CYCompact(Long)
1894
1895 CYStatement *Replace(CYContext &context) override;
1896 virtual void Output(CYOutput &out, CYFlags flags) const;
1897 };
1898
1899 struct CYSuperCall :
1900 CYTarget
1901 {
1902 CYArgument *arguments_;
1903
1904 CYSuperCall(CYArgument *arguments) :
1905 arguments_(arguments)
1906 {
1907 }
1908
1909 CYPrecedence(2)
1910
1911 CYTarget *Replace(CYContext &context) override;
1912 virtual void Output(CYOutput &out, CYFlags flags) const;
1913 };
1914
1915 struct CYSuperAccess :
1916 CYTarget
1917 {
1918 CYExpression *property_;
1919
1920 CYSuperAccess(CYExpression *property) :
1921 property_(property)
1922 {
1923 }
1924
1925 CYPrecedence(1)
1926
1927 CYTarget *Replace(CYContext &context) override;
1928 virtual void Output(CYOutput &out, CYFlags flags) const;
1929 };
1930
1931 struct CYExpress :
1932 CYForInitializer
1933 {
1934 CYExpression *expression_;
1935
1936 CYExpress(CYExpression *expression) :
1937 expression_(expression)
1938 {
1939 if (expression_ == NULL)
1940 throw;
1941 }
1942
1943 CYCompact(None)
1944
1945 CYForInitializer *Replace(CYContext &context) override;
1946 virtual void Output(CYOutput &out, CYFlags flags) const;
1947
1948 virtual CYStatement *Return();
1949 };
1950
1951 struct CYContinue :
1952 CYStatement
1953 {
1954 CYIdentifier *label_;
1955
1956 CYContinue(CYIdentifier *label) :
1957 label_(label)
1958 {
1959 }
1960
1961 CYCompact(Short)
1962
1963 CYStatement *Replace(CYContext &context) override;
1964 virtual void Output(CYOutput &out, CYFlags flags) const;
1965 };
1966
1967 struct CYBreak :
1968 CYStatement
1969 {
1970 CYIdentifier *label_;
1971
1972 CYBreak(CYIdentifier *label) :
1973 label_(label)
1974 {
1975 }
1976
1977 CYCompact(Short)
1978
1979 CYStatement *Replace(CYContext &context) override;
1980 virtual void Output(CYOutput &out, CYFlags flags) const;
1981 };
1982
1983 struct CYReturn :
1984 CYStatement
1985 {
1986 CYExpression *value_;
1987
1988 CYReturn(CYExpression *value) :
1989 value_(value)
1990 {
1991 }
1992
1993 CYCompact(None)
1994
1995 CYStatement *Replace(CYContext &context) override;
1996 virtual void Output(CYOutput &out, CYFlags flags) const;
1997 };
1998
1999 struct CYYieldGenerator :
2000 CYExpression
2001 {
2002 CYExpression *value_;
2003
2004 CYYieldGenerator(CYExpression *value) :
2005 value_(value)
2006 {
2007 }
2008
2009 CYPrecedence(0)
2010
2011 CYExpression *Replace(CYContext &context) override;
2012 virtual void Output(CYOutput &out, CYFlags flags) const;
2013 };
2014
2015 struct CYYieldValue :
2016 CYExpression
2017 {
2018 CYExpression *value_;
2019
2020 CYYieldValue(CYExpression *value) :
2021 value_(value)
2022 {
2023 }
2024
2025 CYPrecedence(0)
2026
2027 virtual CYExpression *Replace(CYContext &context);
2028 virtual void Output(CYOutput &out, CYFlags flags) const;
2029 };
2030
2031 struct CYEmpty :
2032 CYForInitializer
2033 {
2034 CYCompact(Short)
2035
2036 virtual CYForInitializer *Replace(CYContext &context);
2037 virtual void Output(CYOutput &out, CYFlags flags) const;
2038 };
2039
2040 struct CYFinally :
2041 CYThing
2042 {
2043 CYStatement *code_;
2044
2045 CYFinally(CYStatement *code) :
2046 code_(code)
2047 {
2048 }
2049
2050 void Replace(CYContext &context);
2051 virtual void Output(CYOutput &out) const;
2052 };
2053
2054 struct CYTypeSpecifier :
2055 CYThing
2056 {
2057 virtual CYTarget *Replace(CYContext &context) = 0;
2058 };
2059
2060 struct CYTypeError :
2061 CYTypeSpecifier
2062 {
2063 CYTypeError() {
2064 }
2065
2066 virtual CYTarget *Replace(CYContext &context);
2067 virtual void Output(CYOutput &out) const;
2068 };
2069
2070 enum CYTypeSigning {
2071 CYTypeNeutral,
2072 CYTypeSigned,
2073 CYTypeUnsigned,
2074 };
2075
2076 struct CYTypeCharacter :
2077 CYTypeSpecifier
2078 {
2079 CYTypeSigning signing_;
2080
2081 CYTypeCharacter(CYTypeSigning signing) :
2082 signing_(signing)
2083 {
2084 }
2085
2086 virtual CYTarget *Replace(CYContext &context);
2087 virtual void Output(CYOutput &out) const;
2088 };
2089
2090 struct CYTypeInt128 :
2091 CYTypeSpecifier
2092 {
2093 CYTypeSigning signing_;
2094
2095 CYTypeInt128(CYTypeSigning signing) :
2096 signing_(signing)
2097 {
2098 }
2099
2100 virtual CYTarget *Replace(CYContext &context);
2101 virtual void Output(CYOutput &out) const;
2102 };
2103
2104 struct CYTypeIntegral :
2105 CYTypeSpecifier
2106 {
2107 CYTypeSigning signing_;
2108 int length_;
2109
2110 CYTypeIntegral(CYTypeSigning signing, int length = 1) :
2111 signing_(signing),
2112 length_(length)
2113 {
2114 }
2115
2116 CYTypeIntegral *Long() {
2117 if (length_ != 1 && length_ != 2)
2118 return NULL;
2119 ++length_;
2120 return this;
2121 }
2122
2123 CYTypeIntegral *Short() {
2124 if (length_ != 1)
2125 return NULL;
2126 --length_;
2127 return this;
2128 }
2129
2130 CYTypeIntegral *Signed() {
2131 if (signing_ != CYTypeNeutral)
2132 return NULL;
2133 signing_ = CYTypeSigned;
2134 return this;
2135 }
2136
2137 CYTypeIntegral *Unsigned() {
2138 if (signing_ != CYTypeNeutral)
2139 return NULL;
2140 signing_ = CYTypeUnsigned;
2141 return this;
2142 }
2143
2144 virtual CYTarget *Replace(CYContext &context);
2145 virtual void Output(CYOutput &out) const;
2146 };
2147
2148 struct CYTypeVoid :
2149 CYTypeSpecifier
2150 {
2151 CYTypeVoid() {
2152 }
2153
2154 virtual CYTarget *Replace(CYContext &context);
2155 virtual void Output(CYOutput &out) const;
2156 };
2157
2158 enum CYTypeReferenceKind {
2159 CYTypeReferenceStruct,
2160 CYTypeReferenceEnum,
2161 };
2162
2163 struct CYTypeReference :
2164 CYTypeSpecifier
2165 {
2166 CYTypeReferenceKind kind_;
2167 CYIdentifier *name_;
2168
2169 CYTypeReference(CYTypeReferenceKind kind, CYIdentifier *name) :
2170 kind_(kind),
2171 name_(name)
2172 {
2173 }
2174
2175 virtual CYTarget *Replace(CYContext &context);
2176 virtual void Output(CYOutput &out) const;
2177 };
2178
2179 struct CYTypeVariable :
2180 CYTypeSpecifier
2181 {
2182 CYIdentifier *name_;
2183
2184 CYTypeVariable(CYIdentifier *name) :
2185 name_(name)
2186 {
2187 }
2188
2189 CYTypeVariable(const char *name) :
2190 name_(new($pool) CYIdentifier(name))
2191 {
2192 }
2193
2194 virtual CYTarget *Replace(CYContext &context);
2195 virtual void Output(CYOutput &out) const;
2196 };
2197
2198 struct CYTypeFunctionWith;
2199
2200 struct CYTypeModifier :
2201 CYNext<CYTypeModifier>
2202 {
2203 CYTypeModifier(CYTypeModifier *next) :
2204 CYNext<CYTypeModifier>(next)
2205 {
2206 }
2207
2208 virtual int Precedence() const = 0;
2209
2210 virtual CYTarget *Replace_(CYContext &context, CYTarget *type) = 0;
2211 CYTarget *Replace(CYContext &context, CYTarget *type);
2212
2213 virtual void Output(CYOutput &out, CYPropertyName *name) const = 0;
2214 void Output(CYOutput &out, int precedence, CYPropertyName *name, bool space) const;
2215
2216 virtual CYTypeFunctionWith *Function() { return NULL; }
2217 };
2218
2219 struct CYTypeArrayOf :
2220 CYTypeModifier
2221 {
2222 CYExpression *size_;
2223
2224 CYTypeArrayOf(CYExpression *size, CYTypeModifier *next = NULL) :
2225 CYTypeModifier(next),
2226 size_(size)
2227 {
2228 }
2229
2230 CYPrecedence(1)
2231
2232 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2233 void Output(CYOutput &out, CYPropertyName *name) const override;
2234 };
2235
2236 struct CYTypeConstant :
2237 CYTypeModifier
2238 {
2239 CYTypeConstant(CYTypeModifier *next = NULL) :
2240 CYTypeModifier(next)
2241 {
2242 }
2243
2244 CYPrecedence(0)
2245
2246 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2247 void Output(CYOutput &out, CYPropertyName *name) const override;
2248 };
2249
2250 struct CYTypePointerTo :
2251 CYTypeModifier
2252 {
2253 CYTypePointerTo(CYTypeModifier *next = NULL) :
2254 CYTypeModifier(next)
2255 {
2256 }
2257
2258 CYPrecedence(0)
2259
2260 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2261 void Output(CYOutput &out, CYPropertyName *name) const override;
2262 };
2263
2264 struct CYTypeVolatile :
2265 CYTypeModifier
2266 {
2267 CYTypeVolatile(CYTypeModifier *next = NULL) :
2268 CYTypeModifier(next)
2269 {
2270 }
2271
2272 CYPrecedence(0)
2273
2274 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2275 void Output(CYOutput &out, CYPropertyName *name) const override;
2276 };
2277
2278 struct CYType :
2279 CYThing
2280 {
2281 CYTypeSpecifier *specifier_;
2282 CYTypeModifier *modifier_;
2283
2284 CYType(CYTypeSpecifier *specifier = NULL, CYTypeModifier *modifier = NULL) :
2285 specifier_(specifier),
2286 modifier_(modifier)
2287 {
2288 }
2289
2290 inline CYType *Modify(CYTypeModifier *modifier) {
2291 CYSetLast(modifier_) = modifier;
2292 return this;
2293 }
2294
2295 void Output(CYOutput &out, CYPropertyName *name) const;
2296
2297 virtual CYTarget *Replace(CYContext &context);
2298 virtual void Output(CYOutput &out) const;
2299
2300 CYTypeFunctionWith *Function();
2301 };
2302
2303 struct CYTypedLocation :
2304 CYType
2305 {
2306 CYLocation location_;
2307
2308 CYTypedLocation(const CYLocation &location) :
2309 location_(location)
2310 {
2311 }
2312 };
2313
2314 struct CYTypedName :
2315 CYTypedLocation
2316 {
2317 CYPropertyName *name_;
2318
2319 CYTypedName(const CYLocation &location, CYPropertyName *name = NULL) :
2320 CYTypedLocation(location),
2321 name_(name)
2322 {
2323 }
2324 };
2325
2326 struct CYEncodedType :
2327 CYTarget
2328 {
2329 CYType *typed_;
2330
2331 CYEncodedType(CYType *typed) :
2332 typed_(typed)
2333 {
2334 }
2335
2336 CYPrecedence(1)
2337
2338 virtual CYTarget *Replace(CYContext &context);
2339 virtual void Output(CYOutput &out, CYFlags flags) const;
2340 };
2341
2342 struct CYTypedParameter :
2343 CYNext<CYTypedParameter>,
2344 CYThing
2345 {
2346 CYType *type_;
2347 CYIdentifier *name_;
2348
2349 CYTypedParameter(CYType *type, CYIdentifier *name, CYTypedParameter *next = NULL) :
2350 CYNext<CYTypedParameter>(next),
2351 type_(type),
2352 name_(name)
2353 {
2354 }
2355
2356 CYArgument *Argument(CYContext &context);
2357 CYFunctionParameter *Parameters(CYContext &context);
2358 CYExpression *TypeSignature(CYContext &context, CYExpression *prefix);
2359
2360 virtual void Output(CYOutput &out) const;
2361 };
2362
2363 struct CYTypedFormal {
2364 bool variadic_;
2365 CYTypedParameter *parameters_;
2366
2367 CYTypedFormal(bool variadic) :
2368 variadic_(variadic),
2369 parameters_(NULL)
2370 {
2371 }
2372 };
2373
2374 struct CYLambda :
2375 CYTarget
2376 {
2377 CYType *typed_;
2378 CYTypedParameter *parameters_;
2379 CYStatement *code_;
2380
2381 CYLambda(CYType *typed, CYTypedParameter *parameters, CYStatement *code) :
2382 typed_(typed),
2383 parameters_(parameters),
2384 code_(code)
2385 {
2386 }
2387
2388 CYPrecedence(1)
2389
2390 virtual CYTarget *Replace(CYContext &context);
2391 virtual void Output(CYOutput &out, CYFlags flags) const;
2392 };
2393
2394 struct CYModule :
2395 CYNext<CYModule>,
2396 CYThing
2397 {
2398 CYWord *part_;
2399
2400 CYModule(CYWord *part, CYModule *next = NULL) :
2401 CYNext<CYModule>(next),
2402 part_(part)
2403 {
2404 }
2405
2406 CYString *Replace(CYContext &context, const char *separator) const;
2407 void Output(CYOutput &out) const;
2408 };
2409
2410 struct CYImport :
2411 CYStatement
2412 {
2413 CYModule *module_;
2414
2415 CYImport(CYModule *module) :
2416 module_(module)
2417 {
2418 }
2419
2420 CYCompact(None)
2421
2422 virtual CYStatement *Replace(CYContext &context);
2423 virtual void Output(CYOutput &out, CYFlags flags) const;
2424 };
2425
2426 struct CYImportSpecifier :
2427 CYNext<CYImportSpecifier>
2428 {
2429 CYWord *name_;
2430 CYIdentifier *binding_;
2431
2432 CYImportSpecifier(CYWord *name, CYIdentifier *binding) :
2433 name_(name),
2434 binding_(binding)
2435 {
2436 }
2437
2438 CYStatement *Replace(CYContext &context, CYIdentifier *module);
2439 };
2440
2441 struct CYImportDeclaration :
2442 CYStatement
2443 {
2444 CYImportSpecifier *specifiers_;
2445 CYString *module_;
2446
2447 CYImportDeclaration(CYImportSpecifier *specifiers, CYString *module) :
2448 specifiers_(specifiers),
2449 module_(module)
2450 {
2451 }
2452
2453 CYCompact(None)
2454
2455 virtual CYStatement *Replace(CYContext &context);
2456 virtual void Output(CYOutput &out, CYFlags flags) const;
2457 };
2458
2459 struct CYExternalExpression :
2460 CYTarget
2461 {
2462 CYString *abi_;
2463 CYType *type_;
2464 CYPropertyName *name_;
2465
2466 CYExternalExpression(CYString *abi, CYType *type, CYPropertyName *name) :
2467 abi_(abi),
2468 type_(type),
2469 name_(name)
2470 {
2471 }
2472
2473 CYPrecedence(0)
2474
2475 virtual CYTarget *Replace(CYContext &context);
2476 virtual void Output(CYOutput &out, CYFlags flags) const;
2477 };
2478
2479 struct CYExternalDefinition :
2480 CYStatement
2481 {
2482 CYString *abi_;
2483 CYType *type_;
2484 CYIdentifier *name_;
2485
2486 CYExternalDefinition(CYString *abi, CYType *type, CYIdentifier *name) :
2487 abi_(abi),
2488 type_(type),
2489 name_(name)
2490 {
2491 }
2492
2493 CYCompact(None)
2494
2495 virtual CYStatement *Replace(CYContext &context);
2496 virtual void Output(CYOutput &out, CYFlags flags) const;
2497 };
2498
2499 struct CYTypeExpression :
2500 CYTarget
2501 {
2502 CYType *typed_;
2503
2504 CYTypeExpression(CYType *typed) :
2505 typed_(typed)
2506 {
2507 }
2508
2509 CYPrecedence(0)
2510
2511 virtual CYTarget *Replace(CYContext &context);
2512 virtual void Output(CYOutput &out, CYFlags flags) const;
2513 };
2514
2515 struct CYTypeDefinition :
2516 CYStatement
2517 {
2518 CYType *type_;
2519 CYIdentifier *name_;
2520
2521 CYTypeDefinition(CYType *type, CYIdentifier *name) :
2522 type_(type),
2523 name_(name)
2524 {
2525 }
2526
2527 CYCompact(None)
2528
2529 virtual CYStatement *Replace(CYContext &context);
2530 virtual void Output(CYOutput &out, CYFlags flags) const;
2531 };
2532
2533 struct CYTypeBlockWith :
2534 CYTypeModifier
2535 {
2536 CYTypedParameter *parameters_;
2537
2538 CYTypeBlockWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
2539 CYTypeModifier(next),
2540 parameters_(parameters)
2541 {
2542 }
2543
2544 CYPrecedence(0)
2545
2546 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2547 void Output(CYOutput &out, CYPropertyName *name) const override;
2548 };
2549
2550 struct CYTypeFunctionWith :
2551 CYTypeModifier
2552 {
2553 bool variadic_;
2554 CYTypedParameter *parameters_;
2555
2556 CYTypeFunctionWith(bool variadic, CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
2557 CYTypeModifier(next),
2558 variadic_(variadic),
2559 parameters_(parameters)
2560 {
2561 }
2562
2563 CYPrecedence(1)
2564
2565 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2566 void Output(CYOutput &out, CYPropertyName *name) const override;
2567
2568 virtual CYTypeFunctionWith *Function() { return this; }
2569 };
2570
2571 struct CYTypeStructField :
2572 CYNext<CYTypeStructField>
2573 {
2574 CYType *type_;
2575 CYPropertyName *name_;
2576
2577 CYTypeStructField(CYType *type, CYPropertyName *name, CYTypeStructField *next = NULL) :
2578 CYNext<CYTypeStructField>(next),
2579 type_(type),
2580 name_(name)
2581 {
2582 }
2583 };
2584
2585 struct CYStructTail :
2586 CYThing
2587 {
2588 CYTypeStructField *fields_;
2589
2590 CYStructTail(CYTypeStructField *fields) :
2591 fields_(fields)
2592 {
2593 }
2594
2595 CYTarget *Replace(CYContext &context);
2596 virtual void Output(CYOutput &out) const;
2597 };
2598
2599 struct CYTypeStruct :
2600 CYTypeSpecifier
2601 {
2602 CYIdentifier *name_;
2603 CYStructTail *tail_;
2604
2605 CYTypeStruct(CYIdentifier *name, CYStructTail *tail) :
2606 name_(name),
2607 tail_(tail)
2608 {
2609 }
2610
2611 virtual CYTarget *Replace(CYContext &context);
2612 virtual void Output(CYOutput &out) const;
2613 };
2614
2615 struct CYStructDefinition :
2616 CYStatement
2617 {
2618 CYIdentifier *name_;
2619 CYStructTail *tail_;
2620
2621 CYStructDefinition(CYIdentifier *name, CYStructTail *tail) :
2622 name_(name),
2623 tail_(tail)
2624 {
2625 }
2626
2627 CYCompact(None)
2628
2629 virtual CYStatement *Replace(CYContext &context);
2630 virtual void Output(CYOutput &out, CYFlags flags) const;
2631 };
2632
2633 struct CYEnumConstant :
2634 CYNext<CYEnumConstant>
2635 {
2636 CYIdentifier *name_;
2637 CYNumber *value_;
2638
2639 CYEnumConstant(CYIdentifier *name, CYNumber *value, CYEnumConstant *next = NULL) :
2640 CYNext<CYEnumConstant>(next),
2641 name_(name),
2642 value_(value)
2643 {
2644 }
2645 };
2646
2647 struct CYTypeEnum :
2648 CYTypeSpecifier
2649 {
2650 CYIdentifier *name_;
2651 CYTypeSpecifier *specifier_;
2652 CYEnumConstant *constants_;
2653
2654 CYTypeEnum(CYIdentifier *name, CYTypeSpecifier *specifier, CYEnumConstant *constants) :
2655 name_(name),
2656 specifier_(specifier),
2657 constants_(constants)
2658 {
2659 }
2660
2661 virtual CYTarget *Replace(CYContext &context);
2662 virtual void Output(CYOutput &out) const;
2663 };
2664
2665 namespace cy {
2666 namespace Syntax {
2667
2668 struct Catch :
2669 CYThing
2670 {
2671 CYIdentifier *name_;
2672 CYStatement *code_;
2673
2674 Catch(CYIdentifier *name, CYStatement *code) :
2675 name_(name),
2676 code_(code)
2677 {
2678 }
2679
2680 void Replace(CYContext &context);
2681 virtual void Output(CYOutput &out) const;
2682 };
2683
2684 struct Try :
2685 CYStatement
2686 {
2687 CYStatement *code_;
2688 Catch *catch_;
2689 CYFinally *finally_;
2690
2691 Try(CYStatement *code, Catch *_catch, CYFinally *finally) :
2692 code_(code),
2693 catch_(_catch),
2694 finally_(finally)
2695 {
2696 }
2697
2698 CYCompact(Short)
2699
2700 virtual CYStatement *Replace(CYContext &context);
2701 virtual void Output(CYOutput &out, CYFlags flags) const;
2702 };
2703
2704 struct Throw :
2705 CYStatement
2706 {
2707 CYExpression *value_;
2708
2709 Throw(CYExpression *value = NULL) :
2710 value_(value)
2711 {
2712 }
2713
2714 CYCompact(None)
2715
2716 virtual CYStatement *Replace(CYContext &context);
2717 virtual void Output(CYOutput &out, CYFlags flags) const;
2718 };
2719
2720 } }
2721
2722 struct CYWith :
2723 CYStatement
2724 {
2725 CYExpression *scope_;
2726 CYStatement *code_;
2727
2728 CYWith(CYExpression *scope, CYStatement *code) :
2729 scope_(scope),
2730 code_(code)
2731 {
2732 }
2733
2734 CYCompact(Long)
2735
2736 virtual CYStatement *Replace(CYContext &context);
2737 virtual void Output(CYOutput &out, CYFlags flags) const;
2738 };
2739
2740 struct CYSwitch :
2741 CYStatement
2742 {
2743 CYExpression *value_;
2744 CYClause *clauses_;
2745
2746 CYSwitch(CYExpression *value, CYClause *clauses) :
2747 value_(value),
2748 clauses_(clauses)
2749 {
2750 }
2751
2752 CYCompact(Long)
2753
2754 virtual CYStatement *Replace(CYContext &context);
2755 virtual void Output(CYOutput &out, CYFlags flags) const;
2756 };
2757
2758 struct CYDebugger :
2759 CYStatement
2760 {
2761 CYDebugger()
2762 {
2763 }
2764
2765 CYCompact(None)
2766
2767 virtual CYStatement *Replace(CYContext &context);
2768 virtual void Output(CYOutput &out, CYFlags flags) const;
2769 };
2770
2771 struct CYCondition :
2772 CYExpression
2773 {
2774 CYExpression *test_;
2775 CYExpression *true_;
2776 CYExpression *false_;
2777
2778 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
2779 test_(test),
2780 true_(_true),
2781 false_(_false)
2782 {
2783 }
2784
2785 CYPrecedence(15)
2786
2787 virtual CYExpression *Replace(CYContext &context);
2788 virtual void Output(CYOutput &out, CYFlags flags) const;
2789 };
2790
2791 struct CYAddressOf :
2792 CYPrefix
2793 {
2794 CYAddressOf(CYExpression *rhs) :
2795 CYPrefix(rhs)
2796 {
2797 }
2798
2799 virtual const char *Operator() const {
2800 return "&";
2801 }
2802
2803 CYAlphabetic(false)
2804
2805 virtual CYExpression *Replace(CYContext &context);
2806 };
2807
2808 struct CYIndirect :
2809 CYTarget
2810 {
2811 CYExpression *rhs_;
2812
2813 CYIndirect(CYExpression *rhs) :
2814 rhs_(rhs)
2815 {
2816 }
2817
2818 // XXX: this should be checked
2819 CYPrecedence(2)
2820
2821 virtual CYTarget *Replace(CYContext &context);
2822 virtual void Output(CYOutput &out, CYFlags flags) const;
2823 };
2824
2825 #define CYReplace \
2826 virtual CYExpression *Replace(CYContext &context);
2827
2828 #define CYPostfix_(op, name, args...) \
2829 struct CY ## name : \
2830 CYPostfix \
2831 { args \
2832 CY ## name(CYExpression *lhs) : \
2833 CYPostfix(lhs) \
2834 { \
2835 } \
2836 \
2837 virtual const char *Operator() const { \
2838 return op; \
2839 } \
2840 };
2841
2842 #define CYPrefix_(alphabetic, op, name, args...) \
2843 struct CY ## name : \
2844 CYPrefix \
2845 { args \
2846 CY ## name(CYExpression *rhs) : \
2847 CYPrefix(rhs) \
2848 { \
2849 } \
2850 \
2851 CYAlphabetic(alphabetic) \
2852 \
2853 virtual const char *Operator() const { \
2854 return op; \
2855 } \
2856 };
2857
2858 #define CYInfix_(alphabetic, precedence, op, name, args...) \
2859 struct CY ## name : \
2860 CYInfix \
2861 { args \
2862 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
2863 CYInfix(lhs, rhs) \
2864 { \
2865 } \
2866 \
2867 CYAlphabetic(alphabetic) \
2868 CYPrecedence(precedence) \
2869 \
2870 virtual const char *Operator() const { \
2871 return op; \
2872 } \
2873 };
2874
2875 #define CYAssignment_(op, name, args...) \
2876 struct CY ## name ## Assign : \
2877 CYAssignment \
2878 { args \
2879 CY ## name ## Assign(CYTarget *lhs, CYExpression *rhs) : \
2880 CYAssignment(lhs, rhs) \
2881 { \
2882 } \
2883 \
2884 virtual const char *Operator() const { \
2885 return op; \
2886 } \
2887 };
2888
2889 CYPostfix_("++", PostIncrement)
2890 CYPostfix_("--", PostDecrement)
2891
2892 CYPrefix_(true, "delete", Delete)
2893 CYPrefix_(true, "void", Void)
2894 CYPrefix_(true, "typeof", TypeOf)
2895 CYPrefix_(false, "++", PreIncrement)
2896 CYPrefix_(false, "--", PreDecrement)
2897 CYPrefix_(false, "+", Affirm)
2898 CYPrefix_(false, "-", Negate)
2899 CYPrefix_(false, "~", BitwiseNot)
2900 CYPrefix_(false, "!", LogicalNot)
2901
2902 CYInfix_(false, 5, "*", Multiply, CYReplace)
2903 CYInfix_(false, 5, "/", Divide)
2904 CYInfix_(false, 5, "%", Modulus)
2905 CYInfix_(false, 6, "+", Add, CYReplace)
2906 CYInfix_(false, 6, "-", Subtract)
2907 CYInfix_(false, 7, "<<", ShiftLeft)
2908 CYInfix_(false, 7, ">>", ShiftRightSigned)
2909 CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
2910 CYInfix_(false, 8, "<", Less)
2911 CYInfix_(false, 8, ">", Greater)
2912 CYInfix_(false, 8, "<=", LessOrEqual)
2913 CYInfix_(false, 8, ">=", GreaterOrEqual)
2914 CYInfix_(true, 8, "instanceof", InstanceOf)
2915 CYInfix_(true, 8, "in", In)
2916 CYInfix_(false, 9, "==", Equal)
2917 CYInfix_(false, 9, "!=", NotEqual)
2918 CYInfix_(false, 9, "===", Identical)
2919 CYInfix_(false, 9, "!==", NotIdentical)
2920 CYInfix_(false, 10, "&", BitwiseAnd)
2921 CYInfix_(false, 11, "^", BitwiseXOr)
2922 CYInfix_(false, 12, "|", BitwiseOr)
2923 CYInfix_(false, 13, "&&", LogicalAnd)
2924 CYInfix_(false, 14, "||", LogicalOr)
2925
2926 CYAssignment_("=", )
2927 CYAssignment_("*=", Multiply)
2928 CYAssignment_("/=", Divide)
2929 CYAssignment_("%=", Modulus)
2930 CYAssignment_("+=", Add)
2931 CYAssignment_("-=", Subtract)
2932 CYAssignment_("<<=", ShiftLeft)
2933 CYAssignment_(">>=", ShiftRightSigned)
2934 CYAssignment_(">>>=", ShiftRightUnsigned)
2935 CYAssignment_("&=", BitwiseAnd)
2936 CYAssignment_("^=", BitwiseXOr)
2937 CYAssignment_("|=", BitwiseOr)
2938
2939 #endif/*CYCRIPT_PARSER_HPP*/