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