]> git.saurik.com Git - cycript.git/blame_incremental - Syntax.hpp
Improve support for char values (from JS strings).
[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 CYIndirectMember :
1485 CYMember
1486{
1487 CYIndirectMember(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 CYResolveMember :
1499 CYMember
1500{
1501 CYResolveMember(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 CYSubscriptMember :
1513 CYMember
1514{
1515 CYSubscriptMember(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
1526namespace cy {
1527namespace Syntax {
1528
1529struct New :
1530 CYTarget
1531{
1532 CYExpression *constructor_;
1533 CYArgument *arguments_;
1534
1535 New(CYExpression *constructor, CYArgument *arguments = NULL) :
1536 constructor_(constructor),
1537 arguments_(arguments)
1538 {
1539 }
1540
1541 virtual int Precedence() const {
1542 return arguments_ == NULL ? 2 : 1;
1543 }
1544
1545 virtual bool IsNew() const {
1546 return true;
1547 }
1548
1549 virtual CYTarget *Replace(CYContext &context);
1550 virtual void Output(CYOutput &out, CYFlags flags) const;
1551
1552 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
1553};
1554
1555} }
1556
1557struct CYApply :
1558 CYTarget
1559{
1560 CYArgument *arguments_;
1561
1562 CYApply(CYArgument *arguments = NULL) :
1563 arguments_(arguments)
1564 {
1565 }
1566
1567 CYPrecedence(1)
1568
1569 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
1570};
1571
1572struct CYCall :
1573 CYApply
1574{
1575 CYExpression *function_;
1576
1577 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
1578 CYApply(arguments),
1579 function_(function)
1580 {
1581 }
1582
1583 virtual void Output(CYOutput &out, CYFlags flags) const;
1584 virtual CYTarget *Replace(CYContext &context);
1585};
1586
1587struct CYEval :
1588 CYApply
1589{
1590 CYEval(CYArgument *arguments) :
1591 CYApply(arguments)
1592 {
1593 }
1594
1595 virtual void Output(CYOutput &out, CYFlags flags) const;
1596 virtual CYTarget *Replace(CYContext &context);
1597};
1598
1599struct CYRubyProc;
1600
1601struct CYBraced :
1602 CYTarget
1603{
1604 CYTarget *lhs_;
1605
1606 CYBraced(CYTarget *lhs = NULL) :
1607 lhs_(lhs)
1608 {
1609 }
1610
1611 CYPrecedence(1)
1612
1613 void SetLeft(CYTarget *lhs) {
1614 lhs_ = lhs;
1615 }
1616};
1617
1618struct CYRubyBlock :
1619 CYBraced
1620{
1621 CYRubyProc *proc_;
1622
1623 CYRubyBlock(CYTarget *lhs, CYRubyProc *proc) :
1624 CYBraced(lhs),
1625 proc_(proc)
1626 {
1627 }
1628
1629 virtual CYTarget *Replace(CYContext &context);
1630 virtual void Output(CYOutput &out, CYFlags flags) const;
1631
1632 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
1633};
1634
1635struct CYExtend :
1636 CYBraced
1637{
1638 CYObject object_;
1639
1640 CYExtend(CYTarget *lhs, CYProperty *properties = NULL) :
1641 CYBraced(lhs),
1642 object_(properties)
1643 {
1644 }
1645
1646 virtual CYTarget *Replace(CYContext &context);
1647 virtual void Output(CYOutput &out, CYFlags flags) const;
1648};
1649
1650struct CYIf :
1651 CYStatement
1652{
1653 CYExpression *test_;
1654 CYStatement *true_;
1655 CYStatement *false_;
1656
1657 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
1658 test_(test),
1659 true_(_true),
1660 false_(_false)
1661 {
1662 }
1663
1664 CYCompact(Long)
1665
1666 virtual CYStatement *Replace(CYContext &context);
1667 virtual void Output(CYOutput &out, CYFlags flags) const;
1668
1669 virtual CYStatement *Return();
1670};
1671
1672struct CYDoWhile :
1673 CYStatement
1674{
1675 CYExpression *test_;
1676 CYStatement *code_;
1677
1678 CYDoWhile(CYExpression *test, CYStatement *code) :
1679 test_(test),
1680 code_(code)
1681 {
1682 }
1683
1684 CYCompact(None)
1685
1686 virtual CYStatement *Replace(CYContext &context);
1687 virtual void Output(CYOutput &out, CYFlags flags) const;
1688};
1689
1690struct CYWhile :
1691 CYStatement
1692{
1693 CYExpression *test_;
1694 CYStatement *code_;
1695
1696 CYWhile(CYExpression *test, CYStatement *code) :
1697 test_(test),
1698 code_(code)
1699 {
1700 }
1701
1702 CYCompact(Long)
1703
1704 virtual CYStatement *Replace(CYContext &context);
1705 virtual void Output(CYOutput &out, CYFlags flags) const;
1706};
1707
1708struct CYFunction {
1709 CYFunctionParameter *parameters_;
1710 CYStatement *code_;
1711
1712 CYNonLocal *nonlocal_;
1713 bool implicit_;
1714 CYThisScope this_;
1715 CYIdentifier *super_;
1716
1717 CYFunction(CYFunctionParameter *parameters, CYStatement *code) :
1718 parameters_(parameters),
1719 code_(code),
1720 nonlocal_(NULL),
1721 implicit_(false),
1722 super_(NULL)
1723 {
1724 }
1725
1726 void Replace(CYContext &context);
1727 void Output(CYOutput &out) const;
1728};
1729
1730struct CYFunctionExpression :
1731 CYFunction,
1732 CYTarget
1733{
1734 CYIdentifier *name_;
1735
1736 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
1737 CYFunction(parameters, code),
1738 name_(name)
1739 {
1740 }
1741
1742 CYPrecedence(0)
1743
1744 CYTarget *Replace(CYContext &context) override;
1745 virtual void Output(CYOutput &out, CYFlags flags) const;
1746};
1747
1748struct CYFatArrow :
1749 CYFunction,
1750 CYExpression
1751{
1752 CYFatArrow(CYFunctionParameter *parameters, CYStatement *code) :
1753 CYFunction(parameters, code)
1754 {
1755 }
1756
1757 CYPrecedence(0)
1758
1759 CYExpression *Replace(CYContext &context) override;
1760 virtual void Output(CYOutput &out, CYFlags flags) const;
1761};
1762
1763struct CYRubyProc :
1764 CYFunction,
1765 CYTarget
1766{
1767 CYRubyProc(CYFunctionParameter *parameters, CYStatement *code) :
1768 CYFunction(parameters, code)
1769 {
1770 }
1771
1772 CYPrecedence(0)
1773
1774 CYTarget *Replace(CYContext &context) override;
1775 virtual void Output(CYOutput &out, CYFlags flags) const;
1776};
1777
1778struct CYFunctionStatement :
1779 CYFunction,
1780 CYStatement
1781{
1782 CYIdentifier *name_;
1783
1784 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
1785 CYFunction(parameters, code),
1786 name_(name)
1787 {
1788 }
1789
1790 CYCompact(None)
1791
1792 CYStatement *Replace(CYContext &context) override;
1793 virtual void Output(CYOutput &out, CYFlags flags) const;
1794};
1795
1796struct CYPropertyMethod;
1797
1798struct CYMethod :
1799 CYFunction,
1800 CYProperty
1801{
1802 CYMethod(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) :
1803 CYFunction(parameters, code),
1804 CYProperty(name, next)
1805 {
1806 }
1807
1808 virtual CYFunctionExpression *Constructor();
1809
1810 using CYProperty::Replace;
1811 virtual void Replace(CYContext &context);
1812};
1813
1814struct CYPropertyGetter :
1815 CYMethod
1816{
1817 CYPropertyGetter(CYPropertyName *name, CYStatement *code, CYProperty *next = NULL) :
1818 CYMethod(name, NULL, code, next)
1819 {
1820 }
1821
1822 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
1823 virtual void Output(CYOutput &out) const;
1824};
1825
1826struct CYPropertySetter :
1827 CYMethod
1828{
1829 CYPropertySetter(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) :
1830 CYMethod(name, parameters, code, next)
1831 {
1832 }
1833
1834 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
1835 virtual void Output(CYOutput &out) const;
1836};
1837
1838struct CYPropertyMethod :
1839 CYMethod
1840{
1841 CYPropertyMethod(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) :
1842 CYMethod(name, parameters, code, next)
1843 {
1844 }
1845
1846 bool Update() const override;
1847
1848 virtual CYFunctionExpression *Constructor();
1849
1850 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
1851 virtual void Output(CYOutput &out) const;
1852};
1853
1854struct CYClassTail :
1855 CYThing
1856{
1857 CYExpression *extends_;
1858
1859 CYFunctionExpression *constructor_;
1860 CYList<CYProperty> instance_;
1861 CYList<CYProperty> static_;
1862
1863 CYClassTail(CYExpression *extends) :
1864 extends_(extends),
1865 constructor_(NULL)
1866 {
1867 }
1868
1869 void Output(CYOutput &out) const;
1870};
1871
1872struct CYClassExpression :
1873 CYTarget
1874{
1875 CYIdentifier *name_;
1876 CYClassTail *tail_;
1877
1878 CYClassExpression(CYIdentifier *name, CYClassTail *tail) :
1879 name_(name),
1880 tail_(tail)
1881 {
1882 }
1883
1884 CYPrecedence(0)
1885
1886 CYTarget *Replace(CYContext &context) override;
1887 virtual void Output(CYOutput &out, CYFlags flags) const;
1888};
1889
1890struct CYClassStatement :
1891 CYStatement
1892{
1893 CYIdentifier *name_;
1894 CYClassTail *tail_;
1895
1896 CYClassStatement(CYIdentifier *name, CYClassTail *tail) :
1897 name_(name),
1898 tail_(tail)
1899 {
1900 }
1901
1902 CYCompact(Long)
1903
1904 CYStatement *Replace(CYContext &context) override;
1905 virtual void Output(CYOutput &out, CYFlags flags) const;
1906};
1907
1908struct CYSuperCall :
1909 CYTarget
1910{
1911 CYArgument *arguments_;
1912
1913 CYSuperCall(CYArgument *arguments) :
1914 arguments_(arguments)
1915 {
1916 }
1917
1918 CYPrecedence(2)
1919
1920 CYTarget *Replace(CYContext &context) override;
1921 virtual void Output(CYOutput &out, CYFlags flags) const;
1922};
1923
1924struct CYSuperAccess :
1925 CYTarget
1926{
1927 CYExpression *property_;
1928
1929 CYSuperAccess(CYExpression *property) :
1930 property_(property)
1931 {
1932 }
1933
1934 CYPrecedence(1)
1935
1936 CYTarget *Replace(CYContext &context) override;
1937 virtual void Output(CYOutput &out, CYFlags flags) const;
1938};
1939
1940struct CYExpress :
1941 CYForInitializer
1942{
1943 CYExpression *expression_;
1944
1945 CYExpress(CYExpression *expression) :
1946 expression_(expression)
1947 {
1948 if (expression_ == NULL)
1949 throw;
1950 }
1951
1952 CYCompact(None)
1953
1954 CYForInitializer *Replace(CYContext &context) override;
1955 virtual void Output(CYOutput &out, CYFlags flags) const;
1956
1957 virtual CYStatement *Return();
1958};
1959
1960struct CYContinue :
1961 CYStatement
1962{
1963 CYIdentifier *label_;
1964
1965 CYContinue(CYIdentifier *label) :
1966 label_(label)
1967 {
1968 }
1969
1970 CYCompact(Short)
1971
1972 CYStatement *Replace(CYContext &context) override;
1973 virtual void Output(CYOutput &out, CYFlags flags) const;
1974};
1975
1976struct CYBreak :
1977 CYStatement
1978{
1979 CYIdentifier *label_;
1980
1981 CYBreak(CYIdentifier *label) :
1982 label_(label)
1983 {
1984 }
1985
1986 CYCompact(Short)
1987
1988 CYStatement *Replace(CYContext &context) override;
1989 virtual void Output(CYOutput &out, CYFlags flags) const;
1990};
1991
1992struct CYReturn :
1993 CYStatement
1994{
1995 CYExpression *value_;
1996
1997 CYReturn(CYExpression *value) :
1998 value_(value)
1999 {
2000 }
2001
2002 CYCompact(None)
2003
2004 CYStatement *Replace(CYContext &context) override;
2005 virtual void Output(CYOutput &out, CYFlags flags) const;
2006};
2007
2008struct CYYieldGenerator :
2009 CYExpression
2010{
2011 CYExpression *value_;
2012
2013 CYYieldGenerator(CYExpression *value) :
2014 value_(value)
2015 {
2016 }
2017
2018 CYPrecedence(0)
2019
2020 CYExpression *Replace(CYContext &context) override;
2021 virtual void Output(CYOutput &out, CYFlags flags) const;
2022};
2023
2024struct CYYieldValue :
2025 CYExpression
2026{
2027 CYExpression *value_;
2028
2029 CYYieldValue(CYExpression *value) :
2030 value_(value)
2031 {
2032 }
2033
2034 CYPrecedence(0)
2035
2036 virtual CYExpression *Replace(CYContext &context);
2037 virtual void Output(CYOutput &out, CYFlags flags) const;
2038};
2039
2040struct CYEmpty :
2041 CYForInitializer
2042{
2043 CYCompact(Short)
2044
2045 virtual CYForInitializer *Replace(CYContext &context);
2046 virtual void Output(CYOutput &out, CYFlags flags) const;
2047};
2048
2049struct CYFinally :
2050 CYThing
2051{
2052 CYStatement *code_;
2053
2054 CYFinally(CYStatement *code) :
2055 code_(code)
2056 {
2057 }
2058
2059 void Replace(CYContext &context);
2060 virtual void Output(CYOutput &out) const;
2061};
2062
2063struct CYTypeSpecifier :
2064 CYThing
2065{
2066 virtual CYTarget *Replace(CYContext &context) = 0;
2067};
2068
2069struct CYTypeError :
2070 CYTypeSpecifier
2071{
2072 CYTypeError() {
2073 }
2074
2075 virtual CYTarget *Replace(CYContext &context);
2076 virtual void Output(CYOutput &out) const;
2077};
2078
2079enum CYTypeSigning {
2080 CYTypeNeutral,
2081 CYTypeSigned,
2082 CYTypeUnsigned,
2083};
2084
2085struct CYTypeCharacter :
2086 CYTypeSpecifier
2087{
2088 CYTypeSigning signing_;
2089
2090 CYTypeCharacter(CYTypeSigning signing) :
2091 signing_(signing)
2092 {
2093 }
2094
2095 virtual CYTarget *Replace(CYContext &context);
2096 virtual void Output(CYOutput &out) const;
2097};
2098
2099struct CYTypeInt128 :
2100 CYTypeSpecifier
2101{
2102 CYTypeSigning signing_;
2103
2104 CYTypeInt128(CYTypeSigning signing) :
2105 signing_(signing)
2106 {
2107 }
2108
2109 virtual CYTarget *Replace(CYContext &context);
2110 virtual void Output(CYOutput &out) const;
2111};
2112
2113struct CYTypeIntegral :
2114 CYTypeSpecifier
2115{
2116 CYTypeSigning signing_;
2117 int length_;
2118
2119 CYTypeIntegral(CYTypeSigning signing, int length = 1) :
2120 signing_(signing),
2121 length_(length)
2122 {
2123 }
2124
2125 CYTypeIntegral *Long() {
2126 if (length_ != 1 && length_ != 2)
2127 return NULL;
2128 ++length_;
2129 return this;
2130 }
2131
2132 CYTypeIntegral *Short() {
2133 if (length_ != 1)
2134 return NULL;
2135 --length_;
2136 return this;
2137 }
2138
2139 CYTypeIntegral *Signed() {
2140 if (signing_ != CYTypeNeutral)
2141 return NULL;
2142 signing_ = CYTypeSigned;
2143 return this;
2144 }
2145
2146 CYTypeIntegral *Unsigned() {
2147 if (signing_ != CYTypeNeutral)
2148 return NULL;
2149 signing_ = CYTypeUnsigned;
2150 return this;
2151 }
2152
2153 virtual CYTarget *Replace(CYContext &context);
2154 virtual void Output(CYOutput &out) const;
2155};
2156
2157struct CYTypeVoid :
2158 CYTypeSpecifier
2159{
2160 CYTypeVoid() {
2161 }
2162
2163 virtual CYTarget *Replace(CYContext &context);
2164 virtual void Output(CYOutput &out) const;
2165};
2166
2167enum CYTypeReferenceKind {
2168 CYTypeReferenceStruct,
2169 CYTypeReferenceEnum,
2170};
2171
2172struct CYTypeReference :
2173 CYTypeSpecifier
2174{
2175 CYTypeReferenceKind kind_;
2176 CYIdentifier *name_;
2177
2178 CYTypeReference(CYTypeReferenceKind kind, CYIdentifier *name) :
2179 kind_(kind),
2180 name_(name)
2181 {
2182 }
2183
2184 virtual CYTarget *Replace(CYContext &context);
2185 virtual void Output(CYOutput &out) const;
2186};
2187
2188struct CYTypeVariable :
2189 CYTypeSpecifier
2190{
2191 CYIdentifier *name_;
2192
2193 CYTypeVariable(CYIdentifier *name) :
2194 name_(name)
2195 {
2196 }
2197
2198 CYTypeVariable(const char *name) :
2199 name_(new($pool) CYIdentifier(name))
2200 {
2201 }
2202
2203 virtual CYTarget *Replace(CYContext &context);
2204 virtual void Output(CYOutput &out) const;
2205};
2206
2207struct CYTypeFunctionWith;
2208
2209struct CYTypeModifier :
2210 CYNext<CYTypeModifier>
2211{
2212 CYTypeModifier(CYTypeModifier *next) :
2213 CYNext<CYTypeModifier>(next)
2214 {
2215 }
2216
2217 virtual int Precedence() const = 0;
2218
2219 virtual CYTarget *Replace_(CYContext &context, CYTarget *type) = 0;
2220 CYTarget *Replace(CYContext &context, CYTarget *type);
2221
2222 virtual void Output(CYOutput &out, CYPropertyName *name) const = 0;
2223 void Output(CYOutput &out, int precedence, CYPropertyName *name, bool space) const;
2224
2225 virtual CYTypeFunctionWith *Function() { return NULL; }
2226};
2227
2228struct CYTypeArrayOf :
2229 CYTypeModifier
2230{
2231 CYExpression *size_;
2232
2233 CYTypeArrayOf(CYExpression *size, CYTypeModifier *next = NULL) :
2234 CYTypeModifier(next),
2235 size_(size)
2236 {
2237 }
2238
2239 CYPrecedence(1)
2240
2241 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2242 void Output(CYOutput &out, CYPropertyName *name) const override;
2243};
2244
2245struct CYTypeConstant :
2246 CYTypeModifier
2247{
2248 CYTypeConstant(CYTypeModifier *next = NULL) :
2249 CYTypeModifier(next)
2250 {
2251 }
2252
2253 CYPrecedence(0)
2254
2255 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2256 void Output(CYOutput &out, CYPropertyName *name) const override;
2257};
2258
2259struct CYTypePointerTo :
2260 CYTypeModifier
2261{
2262 CYTypePointerTo(CYTypeModifier *next = NULL) :
2263 CYTypeModifier(next)
2264 {
2265 }
2266
2267 CYPrecedence(0)
2268
2269 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2270 void Output(CYOutput &out, CYPropertyName *name) const override;
2271};
2272
2273struct CYTypeVolatile :
2274 CYTypeModifier
2275{
2276 CYTypeVolatile(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 CYType :
2288 CYThing
2289{
2290 CYTypeSpecifier *specifier_;
2291 CYTypeModifier *modifier_;
2292
2293 CYType(CYTypeSpecifier *specifier = NULL, CYTypeModifier *modifier = NULL) :
2294 specifier_(specifier),
2295 modifier_(modifier)
2296 {
2297 }
2298
2299 inline CYType *Modify(CYTypeModifier *modifier) {
2300 CYSetLast(modifier_) = modifier;
2301 return this;
2302 }
2303
2304 void Output(CYOutput &out, CYPropertyName *name) const;
2305
2306 virtual CYTarget *Replace(CYContext &context);
2307 virtual void Output(CYOutput &out) const;
2308
2309 CYTypeFunctionWith *Function();
2310};
2311
2312struct CYTypedLocation :
2313 CYType
2314{
2315 CYLocation location_;
2316
2317 CYTypedLocation(const CYLocation &location) :
2318 location_(location)
2319 {
2320 }
2321};
2322
2323struct CYTypedName :
2324 CYTypedLocation
2325{
2326 CYPropertyName *name_;
2327
2328 CYTypedName(const CYLocation &location, CYPropertyName *name = NULL) :
2329 CYTypedLocation(location),
2330 name_(name)
2331 {
2332 }
2333};
2334
2335struct CYEncodedType :
2336 CYTarget
2337{
2338 CYType *typed_;
2339
2340 CYEncodedType(CYType *typed) :
2341 typed_(typed)
2342 {
2343 }
2344
2345 CYPrecedence(1)
2346
2347 virtual CYTarget *Replace(CYContext &context);
2348 virtual void Output(CYOutput &out, CYFlags flags) const;
2349};
2350
2351struct CYTypedParameter :
2352 CYNext<CYTypedParameter>,
2353 CYThing
2354{
2355 CYType *type_;
2356 CYIdentifier *name_;
2357
2358 CYTypedParameter(CYType *type, CYIdentifier *name, CYTypedParameter *next = NULL) :
2359 CYNext<CYTypedParameter>(next),
2360 type_(type),
2361 name_(name)
2362 {
2363 }
2364
2365 CYArgument *Argument(CYContext &context);
2366 CYFunctionParameter *Parameters(CYContext &context);
2367 CYExpression *TypeSignature(CYContext &context, CYExpression *prefix);
2368
2369 virtual void Output(CYOutput &out) const;
2370};
2371
2372struct CYTypedFormal {
2373 bool variadic_;
2374 CYTypedParameter *parameters_;
2375
2376 CYTypedFormal(bool variadic) :
2377 variadic_(variadic),
2378 parameters_(NULL)
2379 {
2380 }
2381};
2382
2383struct CYLambda :
2384 CYTarget
2385{
2386 CYType *typed_;
2387 CYTypedParameter *parameters_;
2388 CYStatement *code_;
2389
2390 CYLambda(CYType *typed, CYTypedParameter *parameters, CYStatement *code) :
2391 typed_(typed),
2392 parameters_(parameters),
2393 code_(code)
2394 {
2395 }
2396
2397 CYPrecedence(1)
2398
2399 virtual CYTarget *Replace(CYContext &context);
2400 virtual void Output(CYOutput &out, CYFlags flags) const;
2401};
2402
2403struct CYModule :
2404 CYNext<CYModule>,
2405 CYThing
2406{
2407 CYWord *part_;
2408
2409 CYModule(CYWord *part, CYModule *next = NULL) :
2410 CYNext<CYModule>(next),
2411 part_(part)
2412 {
2413 }
2414
2415 CYString *Replace(CYContext &context, const char *separator) const;
2416 void Output(CYOutput &out) const;
2417};
2418
2419struct CYImport :
2420 CYStatement
2421{
2422 CYModule *module_;
2423
2424 CYImport(CYModule *module) :
2425 module_(module)
2426 {
2427 }
2428
2429 CYCompact(None)
2430
2431 virtual CYStatement *Replace(CYContext &context);
2432 virtual void Output(CYOutput &out, CYFlags flags) const;
2433};
2434
2435struct CYImportSpecifier :
2436 CYNext<CYImportSpecifier>
2437{
2438 CYWord *name_;
2439 CYIdentifier *binding_;
2440
2441 CYImportSpecifier(CYWord *name, CYIdentifier *binding) :
2442 name_(name),
2443 binding_(binding)
2444 {
2445 }
2446
2447 CYStatement *Replace(CYContext &context, CYIdentifier *module);
2448};
2449
2450struct CYImportDeclaration :
2451 CYStatement
2452{
2453 CYImportSpecifier *specifiers_;
2454 CYString *module_;
2455
2456 CYImportDeclaration(CYImportSpecifier *specifiers, CYString *module) :
2457 specifiers_(specifiers),
2458 module_(module)
2459 {
2460 }
2461
2462 CYCompact(None)
2463
2464 virtual CYStatement *Replace(CYContext &context);
2465 virtual void Output(CYOutput &out, CYFlags flags) const;
2466};
2467
2468struct CYExternalExpression :
2469 CYTarget
2470{
2471 CYString *abi_;
2472 CYType *type_;
2473 CYPropertyName *name_;
2474
2475 CYExternalExpression(CYString *abi, CYType *type, CYPropertyName *name) :
2476 abi_(abi),
2477 type_(type),
2478 name_(name)
2479 {
2480 }
2481
2482 CYPrecedence(0)
2483
2484 virtual CYTarget *Replace(CYContext &context);
2485 virtual void Output(CYOutput &out, CYFlags flags) const;
2486};
2487
2488struct CYExternalDefinition :
2489 CYStatement
2490{
2491 CYString *abi_;
2492 CYType *type_;
2493 CYIdentifier *name_;
2494
2495 CYExternalDefinition(CYString *abi, CYType *type, CYIdentifier *name) :
2496 abi_(abi),
2497 type_(type),
2498 name_(name)
2499 {
2500 }
2501
2502 CYCompact(None)
2503
2504 virtual CYStatement *Replace(CYContext &context);
2505 virtual void Output(CYOutput &out, CYFlags flags) const;
2506};
2507
2508struct CYTypeExpression :
2509 CYTarget
2510{
2511 CYType *typed_;
2512
2513 CYTypeExpression(CYType *typed) :
2514 typed_(typed)
2515 {
2516 }
2517
2518 CYPrecedence(0)
2519
2520 virtual CYTarget *Replace(CYContext &context);
2521 virtual void Output(CYOutput &out, CYFlags flags) const;
2522};
2523
2524struct CYTypeDefinition :
2525 CYStatement
2526{
2527 CYType *type_;
2528 CYIdentifier *name_;
2529
2530 CYTypeDefinition(CYType *type, CYIdentifier *name) :
2531 type_(type),
2532 name_(name)
2533 {
2534 }
2535
2536 CYCompact(None)
2537
2538 virtual CYStatement *Replace(CYContext &context);
2539 virtual void Output(CYOutput &out, CYFlags flags) const;
2540};
2541
2542struct CYTypeBlockWith :
2543 CYTypeModifier
2544{
2545 CYTypedParameter *parameters_;
2546
2547 CYTypeBlockWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
2548 CYTypeModifier(next),
2549 parameters_(parameters)
2550 {
2551 }
2552
2553 CYPrecedence(0)
2554
2555 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2556 void Output(CYOutput &out, CYPropertyName *name) const override;
2557};
2558
2559struct CYTypeFunctionWith :
2560 CYTypeModifier
2561{
2562 bool variadic_;
2563 CYTypedParameter *parameters_;
2564
2565 CYTypeFunctionWith(bool variadic, CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
2566 CYTypeModifier(next),
2567 variadic_(variadic),
2568 parameters_(parameters)
2569 {
2570 }
2571
2572 CYPrecedence(1)
2573
2574 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
2575 void Output(CYOutput &out, CYPropertyName *name) const override;
2576
2577 virtual CYTypeFunctionWith *Function() { return this; }
2578};
2579
2580struct CYTypeStructField :
2581 CYNext<CYTypeStructField>
2582{
2583 CYType *type_;
2584 CYPropertyName *name_;
2585
2586 CYTypeStructField(CYType *type, CYPropertyName *name, CYTypeStructField *next = NULL) :
2587 CYNext<CYTypeStructField>(next),
2588 type_(type),
2589 name_(name)
2590 {
2591 }
2592};
2593
2594struct CYStructTail :
2595 CYThing
2596{
2597 CYTypeStructField *fields_;
2598
2599 CYStructTail(CYTypeStructField *fields) :
2600 fields_(fields)
2601 {
2602 }
2603
2604 CYTarget *Replace(CYContext &context);
2605 virtual void Output(CYOutput &out) const;
2606};
2607
2608struct CYTypeStruct :
2609 CYTypeSpecifier
2610{
2611 CYIdentifier *name_;
2612 CYStructTail *tail_;
2613
2614 CYTypeStruct(CYIdentifier *name, CYStructTail *tail) :
2615 name_(name),
2616 tail_(tail)
2617 {
2618 }
2619
2620 virtual CYTarget *Replace(CYContext &context);
2621 virtual void Output(CYOutput &out) const;
2622};
2623
2624struct CYStructDefinition :
2625 CYStatement
2626{
2627 CYIdentifier *name_;
2628 CYStructTail *tail_;
2629
2630 CYStructDefinition(CYIdentifier *name, CYStructTail *tail) :
2631 name_(name),
2632 tail_(tail)
2633 {
2634 }
2635
2636 CYCompact(None)
2637
2638 virtual CYStatement *Replace(CYContext &context);
2639 virtual void Output(CYOutput &out, CYFlags flags) const;
2640};
2641
2642struct CYEnumConstant :
2643 CYNext<CYEnumConstant>
2644{
2645 CYIdentifier *name_;
2646 CYNumber *value_;
2647
2648 CYEnumConstant(CYIdentifier *name, CYNumber *value, CYEnumConstant *next = NULL) :
2649 CYNext<CYEnumConstant>(next),
2650 name_(name),
2651 value_(value)
2652 {
2653 }
2654};
2655
2656struct CYTypeEnum :
2657 CYTypeSpecifier
2658{
2659 CYIdentifier *name_;
2660 CYTypeSpecifier *specifier_;
2661 CYEnumConstant *constants_;
2662
2663 CYTypeEnum(CYIdentifier *name, CYTypeSpecifier *specifier, CYEnumConstant *constants) :
2664 name_(name),
2665 specifier_(specifier),
2666 constants_(constants)
2667 {
2668 }
2669
2670 virtual CYTarget *Replace(CYContext &context);
2671 virtual void Output(CYOutput &out) const;
2672};
2673
2674namespace cy {
2675namespace Syntax {
2676
2677struct Catch :
2678 CYThing
2679{
2680 CYIdentifier *name_;
2681 CYStatement *code_;
2682
2683 Catch(CYIdentifier *name, CYStatement *code) :
2684 name_(name),
2685 code_(code)
2686 {
2687 }
2688
2689 void Replace(CYContext &context);
2690 virtual void Output(CYOutput &out) const;
2691};
2692
2693struct Try :
2694 CYStatement
2695{
2696 CYStatement *code_;
2697 Catch *catch_;
2698 CYFinally *finally_;
2699
2700 Try(CYStatement *code, Catch *_catch, CYFinally *finally) :
2701 code_(code),
2702 catch_(_catch),
2703 finally_(finally)
2704 {
2705 }
2706
2707 CYCompact(Short)
2708
2709 virtual CYStatement *Replace(CYContext &context);
2710 virtual void Output(CYOutput &out, CYFlags flags) const;
2711};
2712
2713struct Throw :
2714 CYStatement
2715{
2716 CYExpression *value_;
2717
2718 Throw(CYExpression *value = NULL) :
2719 value_(value)
2720 {
2721 }
2722
2723 CYCompact(None)
2724
2725 virtual CYStatement *Replace(CYContext &context);
2726 virtual void Output(CYOutput &out, CYFlags flags) const;
2727};
2728
2729} }
2730
2731struct CYWith :
2732 CYStatement
2733{
2734 CYExpression *scope_;
2735 CYStatement *code_;
2736
2737 CYWith(CYExpression *scope, CYStatement *code) :
2738 scope_(scope),
2739 code_(code)
2740 {
2741 }
2742
2743 CYCompact(Long)
2744
2745 virtual CYStatement *Replace(CYContext &context);
2746 virtual void Output(CYOutput &out, CYFlags flags) const;
2747};
2748
2749struct CYSwitch :
2750 CYStatement
2751{
2752 CYExpression *value_;
2753 CYClause *clauses_;
2754
2755 CYSwitch(CYExpression *value, CYClause *clauses) :
2756 value_(value),
2757 clauses_(clauses)
2758 {
2759 }
2760
2761 CYCompact(Long)
2762
2763 virtual CYStatement *Replace(CYContext &context);
2764 virtual void Output(CYOutput &out, CYFlags flags) const;
2765};
2766
2767struct CYDebugger :
2768 CYStatement
2769{
2770 CYDebugger()
2771 {
2772 }
2773
2774 CYCompact(None)
2775
2776 virtual CYStatement *Replace(CYContext &context);
2777 virtual void Output(CYOutput &out, CYFlags flags) const;
2778};
2779
2780struct CYCondition :
2781 CYExpression
2782{
2783 CYExpression *test_;
2784 CYExpression *true_;
2785 CYExpression *false_;
2786
2787 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
2788 test_(test),
2789 true_(_true),
2790 false_(_false)
2791 {
2792 }
2793
2794 CYPrecedence(15)
2795
2796 virtual CYExpression *Replace(CYContext &context);
2797 virtual void Output(CYOutput &out, CYFlags flags) const;
2798};
2799
2800struct CYAddressOf :
2801 CYPrefix
2802{
2803 CYAddressOf(CYExpression *rhs) :
2804 CYPrefix(rhs)
2805 {
2806 }
2807
2808 virtual const char *Operator() const {
2809 return "&";
2810 }
2811
2812 CYAlphabetic(false)
2813
2814 virtual CYExpression *Replace(CYContext &context);
2815};
2816
2817struct CYIndirect :
2818 CYTarget
2819{
2820 CYExpression *rhs_;
2821
2822 CYIndirect(CYExpression *rhs) :
2823 rhs_(rhs)
2824 {
2825 }
2826
2827 // XXX: this should be checked
2828 CYPrecedence(2)
2829
2830 virtual CYTarget *Replace(CYContext &context);
2831 virtual void Output(CYOutput &out, CYFlags flags) const;
2832};
2833
2834#define CYReplace \
2835 virtual CYExpression *Replace(CYContext &context);
2836
2837#define CYPostfix_(op, name, args...) \
2838 struct CY ## name : \
2839 CYPostfix \
2840 { args \
2841 CY ## name(CYExpression *lhs) : \
2842 CYPostfix(lhs) \
2843 { \
2844 } \
2845 \
2846 virtual const char *Operator() const { \
2847 return op; \
2848 } \
2849 };
2850
2851#define CYPrefix_(alphabetic, op, name, args...) \
2852 struct CY ## name : \
2853 CYPrefix \
2854 { args \
2855 CY ## name(CYExpression *rhs) : \
2856 CYPrefix(rhs) \
2857 { \
2858 } \
2859 \
2860 CYAlphabetic(alphabetic) \
2861 \
2862 virtual const char *Operator() const { \
2863 return op; \
2864 } \
2865 };
2866
2867#define CYInfix_(alphabetic, precedence, op, name, args...) \
2868 struct CY ## name : \
2869 CYInfix \
2870 { args \
2871 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
2872 CYInfix(lhs, rhs) \
2873 { \
2874 } \
2875 \
2876 CYAlphabetic(alphabetic) \
2877 CYPrecedence(precedence) \
2878 \
2879 virtual const char *Operator() const { \
2880 return op; \
2881 } \
2882 };
2883
2884#define CYAssignment_(op, name, args...) \
2885 struct CY ## name ## Assign : \
2886 CYAssignment \
2887 { args \
2888 CY ## name ## Assign(CYTarget *lhs, CYExpression *rhs) : \
2889 CYAssignment(lhs, rhs) \
2890 { \
2891 } \
2892 \
2893 virtual const char *Operator() const { \
2894 return op; \
2895 } \
2896 };
2897
2898CYPostfix_("++", PostIncrement)
2899CYPostfix_("--", PostDecrement)
2900
2901CYPrefix_(true, "delete", Delete)
2902CYPrefix_(true, "void", Void)
2903CYPrefix_(true, "typeof", TypeOf)
2904CYPrefix_(false, "++", PreIncrement)
2905CYPrefix_(false, "--", PreDecrement)
2906CYPrefix_(false, "+", Affirm)
2907CYPrefix_(false, "-", Negate)
2908CYPrefix_(false, "~", BitwiseNot)
2909CYPrefix_(false, "!", LogicalNot)
2910
2911CYInfix_(false, 5, "*", Multiply, CYReplace)
2912CYInfix_(false, 5, "/", Divide)
2913CYInfix_(false, 5, "%", Modulus)
2914CYInfix_(false, 6, "+", Add, CYReplace)
2915CYInfix_(false, 6, "-", Subtract)
2916CYInfix_(false, 7, "<<", ShiftLeft)
2917CYInfix_(false, 7, ">>", ShiftRightSigned)
2918CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
2919CYInfix_(false, 8, "<", Less)
2920CYInfix_(false, 8, ">", Greater)
2921CYInfix_(false, 8, "<=", LessOrEqual)
2922CYInfix_(false, 8, ">=", GreaterOrEqual)
2923CYInfix_(true, 8, "instanceof", InstanceOf)
2924CYInfix_(true, 8, "in", In)
2925CYInfix_(false, 9, "==", Equal)
2926CYInfix_(false, 9, "!=", NotEqual)
2927CYInfix_(false, 9, "===", Identical)
2928CYInfix_(false, 9, "!==", NotIdentical)
2929CYInfix_(false, 10, "&", BitwiseAnd)
2930CYInfix_(false, 11, "^", BitwiseXOr)
2931CYInfix_(false, 12, "|", BitwiseOr)
2932CYInfix_(false, 13, "&&", LogicalAnd)
2933CYInfix_(false, 14, "||", LogicalOr)
2934
2935CYAssignment_("=", )
2936CYAssignment_("*=", Multiply)
2937CYAssignment_("/=", Divide)
2938CYAssignment_("%=", Modulus)
2939CYAssignment_("+=", Add)
2940CYAssignment_("-=", Subtract)
2941CYAssignment_("<<=", ShiftLeft)
2942CYAssignment_(">>=", ShiftRightSigned)
2943CYAssignment_(">>>=", ShiftRightUnsigned)
2944CYAssignment_("&=", BitwiseAnd)
2945CYAssignment_("^=", BitwiseXOr)
2946CYAssignment_("|=", BitwiseOr)
2947
2948#endif/*CYCRIPT_PARSER_HPP*/