]> git.saurik.com Git - cycript.git/blame - Syntax.hpp
Improve support for char values (from JS strings).
[cycript.git] / Syntax.hpp
CommitLineData
7341eedb
JF
1/* Cycript - The Truly Universal Scripting Language
2 * Copyright (C) 2009-2016 Jay Freeman (saurik)
b4aa79af
JF
3*/
4
f95d2598 5/* GNU Affero General Public License, Version 3 {{{ */
b4aa79af 6/*
f95d2598
JF
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
c15969fd 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f95d2598
JF
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/>.
b3378a02 19**/
b4aa79af
JF
20/* }}} */
21
20052ff7
JF
22#ifndef CYCRIPT_SYNTAX_HPP
23#define CYCRIPT_SYNTAX_HPP
24
25#include <cstdio>
26#include <cstdlib>
63b4c5a8 27
efd689d8 28#include <streambuf>
5999c315 29#include <string>
c3c20102 30#include <vector>
cf7d4c69 31
da2af935 32#include "List.hpp"
00b4cb83 33#include "Location.hpp"
029bc65b 34#include "Options.hpp"
20052ff7 35#include "Pooling.hpp"
2e43a0b0
JF
36#include "String.hpp"
37
38double CYCastDouble(const char *value, size_t size);
39double CYCastDouble(const char *value);
3935b9e5 40double CYCastDouble(CYUTF8String value);
2e43a0b0
JF
41
42void CYNumerify(std::ostringstream &str, double value);
37dadc21
JF
43
44enum CYStringifyMode {
45 CYStringifyModeLegacy,
46 CYStringifyModeCycript,
47 CYStringifyModeNative,
48};
49
50void CYStringify(std::ostringstream &str, const char *data, size_t size, CYStringifyMode mode);
029bc65b 51
3935b9e5
JF
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
01d0f64d 56struct CYContext;
924f67b2 57
5999c315 58struct CYThing {
652ec1ba 59 virtual void Output(struct CYOutput &out) const = 0;
5999c315
JF
60};
61
652ec1ba 62struct CYOutput {
efd689d8
JF
63 std::streambuf &out_;
64 CYPosition position_;
65
029bc65b 66 CYOptions &options_;
11c1cc16
JF
67 bool pretty_;
68 unsigned indent_;
efd689d8 69 unsigned recent_;
320ce753 70 bool right_;
652ec1ba 71
96a7e5c2
JF
72 enum {
73 NoMode,
74 NoLetter,
c0bc320e 75 NoPlus,
96a7e5c2
JF
76 NoHyphen,
77 Terminated
78 } mode_;
79
efd689d8 80 CYOutput(std::streambuf &out, CYOptions &options) :
11c1cc16 81 out_(out),
029bc65b 82 options_(options),
11c1cc16 83 pretty_(false),
96a7e5c2 84 indent_(0),
efd689d8 85 recent_(0),
320ce753 86 right_(false),
96a7e5c2 87 mode_(NoMode)
652ec1ba
JF
88 {
89 }
90
96a7e5c2 91 void Check(char value);
1fdca2fa 92 void Terminate();
652ec1ba 93
efd689d8
JF
94 _finline void operator ()(char value) {
95 _assert(out_.sputc(value) != EOF);
96 recent_ = indent_;
97 if (value == '\n')
51b2dc6b 98 position_.Lines(1);
efd689d8 99 else
51b2dc6b 100 position_.Columns(1);
efd689d8
JF
101 }
102
103 _finline void operator ()(const char *data, std::streamsize size) {
104 _assert(out_.sputn(data, size) == size);
105 recent_ = indent_;
51b2dc6b 106 position_.Columns(size);
efd689d8
JF
107 }
108
109 _finline void operator ()(const char *data) {
110 return operator ()(data, strlen(data));
111 }
112
96a7e5c2
JF
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);
652ec1ba
JF
119 return *this;
120 }
121
122 _finline CYOutput &operator <<(const CYThing &rhs) {
123 rhs.Output(*this);
124 return *this;
125 }
126};
5999c315 127
c5b15840
JF
128struct CYExpression;
129struct CYAssignment;
5b4dabb2 130struct CYIdentifier;
17764b01 131struct CYNumber;
c5b15840 132
e5bc40db 133struct CYPropertyName {
c5b15840
JF
134 virtual bool Computed() const {
135 return false;
136 }
137
138 virtual bool Constructor() const {
139 return false;
140 }
141
5b4dabb2
JF
142 virtual CYIdentifier *Identifier() {
143 return NULL;
144 }
145
17764b01
JF
146 virtual CYNumber *Number(CYContext &context) {
147 return NULL;
148 }
149
c5b15840 150 virtual CYExpression *PropertyName(CYContext &context) = 0;
652ec1ba 151 virtual void PropertyName(CYOutput &out) const = 0;
e5bc40db
JF
152};
153
3b52fd1a
JF
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),
c5b15840
JF
164 CYNoClass = (1 << 2),
165 CYNoIn = (1 << 3),
166 CYNoCall = (1 << 4),
167 CYNoRightHand = (1 << 5),
168 CYNoDangle = (1 << 6),
169 CYNoInteger = (1 << 7),
2fad14e5 170 CYNoColon = (1 << 8),
c5b15840 171 CYNoBFC = (CYNoBrace | CYNoFunction | CYNoClass),
3b52fd1a
JF
172};
173
5a6d4d25
JF
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) {
c5b15840 195 return flags & ~CYNoBFC;
5a6d4d25
JF
196}
197
198_finline CYFlags CYCenter(CYFlags flags) {
199 return CYLeft(CYRight(flags));
200}
201
efd689d8
JF
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
3b52fd1a 213struct CYStatement :
b0385401
JF
214 CYNext<CYStatement>,
215 CYThing
3b52fd1a 216{
efd689d8 217 void Single(CYOutput &out, CYFlags flags, CYCompactType request) const;
3b52fd1a 218 void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
b0385401 219 virtual void Output(CYOutput &out) const;
3b52fd1a 220
3b52fd1a
JF
221 virtual CYStatement *Replace(CYContext &context) = 0;
222
efd689d8 223 virtual CYCompactType Compact() const = 0;
12e37ba3
JF
224 virtual CYStatement *Return();
225
3b52fd1a
JF
226 private:
227 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
228};
229
c5b15840 230typedef CYList<CYStatement> CYStatements;
63b4c5a8 231
bfd79fae
JF
232struct CYForInitializer :
233 CYStatement
234{
235 virtual CYForInitializer *Replace(CYContext &context) = 0;
236 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
237};
238
cf7d4c69 239struct CYWord :
e5bc40db 240 CYThing,
c5b15840 241 CYPropertyName
63b4c5a8 242{
cf7d4c69
JF
243 const char *word_;
244
245 CYWord(const char *word) :
246 word_(word)
247 {
248 }
249
c5b15840
JF
250 virtual bool Constructor() const {
251 return strcmp(word_, "constructor") == 0;
252 }
253
029bc65b 254 virtual const char *Word() const;
652ec1ba 255 virtual void Output(CYOutput &out) const;
e5bc40db 256
c5b15840 257 virtual CYExpression *PropertyName(CYContext &context);
652ec1ba 258 virtual void PropertyName(CYOutput &out) const;
63b4c5a8
JF
259};
260
652ec1ba 261_finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) {
029bc65b
JF
262 lhs << &rhs << '=';
263 return lhs << rhs.Word();
652ec1ba
JF
264}
265
7085e1ab
JF
266enum CYIdentifierKind {
267 CYIdentifierArgument,
268 CYIdentifierCatch,
269 CYIdentifierGlobal,
270 CYIdentifierLexical,
271 CYIdentifierMagic,
272 CYIdentifierOther,
273 CYIdentifierVariable,
274};
275
cf7d4c69 276struct CYIdentifier :
14ec9e00 277 CYNext<CYIdentifier>,
cf7d4c69 278 CYWord
63b4c5a8 279{
7085e1ab 280 CYLocation location_;
6a981250 281 size_t offset_;
e013809d 282 size_t usage_;
029bc65b 283
5999c315 284 CYIdentifier(const char *word) :
029bc65b 285 CYWord(word),
e013809d
JF
286 offset_(0),
287 usage_(0)
5999c315 288 {
cf7d4c69 289 }
029bc65b 290
5b4dabb2
JF
291 CYIdentifier *Identifier() override {
292 return this;
293 }
294
029bc65b 295 virtual const char *Word() const;
7085e1ab 296 CYIdentifier *Replace(CYContext &context, CYIdentifierKind);
63b4c5a8
JF
297};
298
62014ea9 299struct CYLabel :
3b52fd1a 300 CYStatement
62014ea9 301{
9e562cfc 302 CYIdentifier *name_;
3b52fd1a 303 CYStatement *statement_;
cf7d4c69 304
3b52fd1a
JF
305 CYLabel(CYIdentifier *name, CYStatement *statement) :
306 name_(name),
307 statement_(statement)
cf7d4c69
JF
308 {
309 }
fb98ac0c 310
efd689d8
JF
311 CYCompact(Short)
312
3b52fd1a
JF
313 virtual CYStatement *Replace(CYContext &context);
314 virtual void Output(CYOutput &out, CYFlags flags) const;
fb98ac0c
JF
315};
316
14ec9e00 317struct CYCStringLess :
029bc65b
JF
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 {
14ec9e00 329 return CYCStringLess()(lhs->Word(), rhs->Word());
029bc65b
JF
330 }
331};
332
7085e1ab
JF
333struct CYIdentifierFlags :
334 CYNext<CYIdentifierFlags>
335{
e013809d 336 CYIdentifier *identifier_;
7085e1ab
JF
337 CYIdentifierKind kind_;
338 unsigned count_;
339 unsigned offset_;
e013809d 340
7085e1ab
JF
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};
e013809d 350
029bc65b 351struct CYScope {
61fe0c53 352 bool transparent_;
029bc65b 353 CYScope *parent_;
7085e1ab
JF
354 bool damaged_;
355 CYIdentifierFlags *shadow_;
a86e34d0 356
7085e1ab 357 CYIdentifierFlags *internal_;
029bc65b 358
50a3d79f 359 CYScope(bool transparent, CYContext &context);
0a356474 360
7085e1ab
JF
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
50a3d79f 367 void Close(CYContext &context, CYStatement *&statements);
7085e1ab
JF
368 void Close(CYContext &context);
369 void Damage();
029bc65b
JF
370};
371
a7d8b413 372struct CYScript :
3b52fd1a 373 CYThing
63b4c5a8 374{
b0385401 375 CYStatement *code_;
9e562cfc 376
a7d8b413 377 CYScript(CYStatement *code) :
b0385401 378 code_(code)
9e562cfc
JF
379 {
380 }
cf7d4c69 381
3b52fd1a 382 virtual void Replace(CYContext &context);
3b52fd1a 383 virtual void Output(CYOutput &out) const;
9e562cfc
JF
384};
385
ab2aa221 386struct CYNonLocal;
a0be43fc 387struct CYThisScope;
ab2aa221 388
2c81c6df 389struct CYContext {
6a981250 390 CYOptions &options_;
ab2aa221 391
6a981250 392 CYScope *scope_;
a0be43fc 393 CYThisScope *this_;
c5b15840 394 CYIdentifier *super_;
a0be43fc 395
ab2aa221 396 CYNonLocal *nonlocal_;
06293152 397 CYNonLocal *nextlocal_;
ab2aa221
JF
398 unsigned unique_;
399
7085e1ab
JF
400 std::vector<CYIdentifier *> replace_;
401
2eb8215d 402 CYContext(CYOptions &options) :
6a981250 403 options_(options),
ab2aa221 404 scope_(NULL),
a0be43fc 405 this_(NULL),
c5b15840 406 super_(NULL),
ab2aa221 407 nonlocal_(NULL),
06293152 408 nextlocal_(NULL),
ab2aa221 409 unique_(0)
6a981250
JF
410 {
411 }
412
b0385401
JF
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);
cde20a5a
JF
425 }
426
6a981250
JF
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 }
ab2aa221
JF
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 }
6a981250
JF
456};
457
a0be43fc
JF
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
9e562cfc 477struct CYBlock :
b0385401 478 CYStatement
9e562cfc 479{
b0385401 480 CYStatement *code_;
9e562cfc 481
b0385401
JF
482 CYBlock(CYStatement *code) :
483 code_(code)
9e562cfc 484 {
cf7d4c69 485 }
9e562cfc 486
efd689d8
JF
487 CYCompact(Short)
488
3b52fd1a
JF
489 virtual CYStatement *Replace(CYContext &context);
490
fb98ac0c 491 virtual void Output(CYOutput &out, CYFlags flags) const;
12e37ba3
JF
492
493 virtual CYStatement *Return();
cf7d4c69
JF
494};
495
7085e1ab
JF
496struct CYTarget;
497struct CYVar;
b158281e 498
7085e1ab
JF
499struct CYForInInitializer {
500 virtual CYStatement *Initialize(CYContext &context, CYExpression *value) = 0;
c8a0500b 501
7085e1ab 502 virtual CYTarget *Replace(CYContext &context) = 0;
c8a0500b 503 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
b09da87b
JF
504};
505
0afc9ba3
JF
506struct CYFunctionParameter;
507
4644480a
JF
508struct CYNumber;
509struct CYString;
510
cf7d4c69 511struct CYExpression :
96a7e5c2 512 CYThing
63b4c5a8 513{
9a39f705 514 virtual int Precedence() const = 0;
75b0a457 515
fb98ac0c
JF
516 virtual bool RightHand() const {
517 return true;
518 }
519
7085e1ab
JF
520 virtual bool Eval() const {
521 return false;
522 }
75b0a457 523
7085e1ab 524 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
6c093cce 525
96a7e5c2 526 virtual void Output(CYOutput &out) const;
652ec1ba 527 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
9a39f705 528 void Output(CYOutput &out, int precedence, CYFlags flags) const;
dea834b0 529
3b52fd1a
JF
530 virtual CYExpression *Replace(CYContext &context) = 0;
531
4644480a 532 virtual CYExpression *Primitive(CYContext &context) {
fd5cdf97 533 return NULL;
4644480a
JF
534 }
535
0afc9ba3 536 virtual CYFunctionParameter *Parameter() const;
0afc9ba3 537
4644480a
JF
538 virtual CYNumber *Number(CYContext &context) {
539 return NULL;
540 }
541
542 virtual CYString *String(CYContext &context) {
543 return NULL;
544 }
545
dea834b0
JF
546 virtual const char *Word() const {
547 return NULL;
548 }
63b4c5a8
JF
549};
550
7085e1ab
JF
551struct CYTarget :
552 CYExpression,
553 CYForInInitializer
554{
555 virtual bool RightHand() const {
556 return false;
557 }
558
4f3e597c
JF
559 virtual bool IsNew() const {
560 return false;
561 }
562
7085e1ab
JF
563 virtual CYStatement *Initialize(CYContext &context, CYExpression *value);
564
565 virtual CYTarget *Replace(CYContext &context) = 0;
566 using CYExpression::Output;
567};
568
b09da87b
JF
569#define CYAlphabetic(value) \
570 virtual bool Alphabetic() const { \
571 return value; \
572 }
573
d35a3b07 574#define CYPrecedence(value) \
9a39f705
JF
575 static const int Precedence_ = value; \
576 virtual int Precedence() const { \
8351aa30 577 return Precedence_; \
d35a3b07
JF
578 }
579
580struct CYCompound :
581 CYExpression
582{
fd5cdf97
JF
583 CYExpression *expression_;
584 CYExpression *next_;
d35a3b07 585
b0385401 586 CYCompound(CYExpression *expression, CYExpression *next) :
fd5cdf97
JF
587 expression_(expression),
588 next_(next)
d35a3b07 589 {
fd5cdf97 590 _assert(expression_ != NULL);
b0385401 591 _assert(next != NULL);
d35a3b07
JF
592 }
593
594 CYPrecedence(17)
595
3b52fd1a 596 virtual CYExpression *Replace(CYContext &context);
652ec1ba 597 void Output(CYOutput &out, CYFlags flags) const;
e06e5ee1 598
b0385401
JF
599 virtual CYFunctionParameter *Parameter() const;
600};
601
602struct CYParenthetical :
7085e1ab 603 CYTarget
b0385401
JF
604{
605 CYExpression *expression_;
606
607 CYParenthetical(CYExpression *expression) :
608 expression_(expression)
609 {
610 }
611
612 CYPrecedence(0)
613
7085e1ab 614 virtual CYTarget *Replace(CYContext &context);
b0385401 615 void Output(CYOutput &out, CYFlags flags) const;
d35a3b07 616};
5999c315 617
09fc3efb 618struct CYBinding;
c8a0500b 619
3b52fd1a
JF
620struct CYFunctionParameter :
621 CYNext<CYFunctionParameter>,
622 CYThing
623{
09fc3efb 624 CYBinding *binding_;
3b52fd1a 625
09fc3efb 626 CYFunctionParameter(CYBinding *binding, CYFunctionParameter *next = NULL) :
3b52fd1a 627 CYNext<CYFunctionParameter>(next),
09fc3efb 628 binding_(binding)
4e11a430
JF
629 {
630 }
631
b0385401 632 void Replace(CYContext &context, CYStatement *&statements);
c8a0500b 633 void Output(CYOutput &out) const;
3b52fd1a
JF
634};
635
75b0a457 636struct CYComprehension :
96a7e5c2
JF
637 CYNext<CYComprehension>,
638 CYThing
75b0a457 639{
c2529502
JF
640 CYComprehension(CYComprehension *next = NULL) :
641 CYNext<CYComprehension>(next)
642 {
643 }
644
3b52fd1a
JF
645 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
646 CYFunctionParameter *Parameters(CYContext &context) const;
647 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 648 virtual void Output(CYOutput &out) const = 0;
75b0a457
JF
649};
650
651struct CYForInComprehension :
652 CYComprehension
653{
09fc3efb
JF
654 CYBinding *binding_;
655 CYExpression *iterable_;
75b0a457 656
09fc3efb 657 CYForInComprehension(CYBinding *binding, CYExpression *iterable, CYComprehension *next = NULL) :
c2529502 658 CYComprehension(next),
09fc3efb
JF
659 binding_(binding),
660 iterable_(iterable)
75b0a457
JF
661 {
662 }
663
3b52fd1a
JF
664 virtual CYFunctionParameter *Parameter(CYContext &context) const;
665 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 666 virtual void Output(CYOutput &out) const;
75b0a457
JF
667};
668
d5618df7 669struct CYForOfComprehension :
75b0a457
JF
670 CYComprehension
671{
09fc3efb
JF
672 CYBinding *binding_;
673 CYExpression *iterable_;
75b0a457 674
09fc3efb 675 CYForOfComprehension(CYBinding *binding, CYExpression *iterable, CYComprehension *next = NULL) :
c2529502 676 CYComprehension(next),
09fc3efb
JF
677 binding_(binding),
678 iterable_(iterable)
75b0a457
JF
679 {
680 }
681
3b52fd1a
JF
682 virtual CYFunctionParameter *Parameter(CYContext &context) const;
683 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 684 virtual void Output(CYOutput &out) const;
75b0a457
JF
685};
686
687struct CYIfComprehension :
688 CYComprehension
689{
690 CYExpression *test_;
691
b3aa25d8
JF
692 CYIfComprehension(CYExpression *test, CYComprehension *next = NULL) :
693 CYComprehension(next),
75b0a457
JF
694 test_(test)
695 {
696 }
697
3b52fd1a
JF
698 virtual CYFunctionParameter *Parameter(CYContext &context) const;
699 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 700 virtual void Output(CYOutput &out) const;
75b0a457
JF
701};
702
703struct CYArrayComprehension :
7085e1ab 704 CYTarget
75b0a457
JF
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
7085e1ab 717 virtual CYTarget *Replace(CYContext &context);
652ec1ba 718 virtual void Output(CYOutput &out, CYFlags flags) const;
75b0a457
JF
719};
720
cf7d4c69 721struct CYLiteral :
7085e1ab 722 CYTarget
63b4c5a8 723{
7085e1ab
JF
724 CYLocation location_;
725
d35a3b07 726 CYPrecedence(0)
fd5cdf97
JF
727
728 virtual CYExpression *Primitive(CYContext &context) {
729 return this;
730 }
cf7d4c69 731};
63b4c5a8 732
3b52fd1a
JF
733struct CYTrivial :
734 CYLiteral
735{
7085e1ab 736 virtual CYTarget *Replace(CYContext &context);
3b52fd1a
JF
737};
738
478d4ed0 739struct CYMagic :
7085e1ab 740 CYTarget
478d4ed0
JF
741{
742 CYPrecedence(0)
743};
744
dea834b0
JF
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
283e7e33 765extern CYRange DigitRange_;
dea834b0
JF
766extern CYRange WordStartRange_;
767extern CYRange WordEndRange_;
768
cf7d4c69 769struct CYString :
3b52fd1a 770 CYTrivial,
e5bc40db 771 CYPropertyName
cf7d4c69
JF
772{
773 const char *value_;
5999c315 774 size_t size_;
cf7d4c69 775
3b52fd1a
JF
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
5999c315
JF
788 CYString(const char *value, size_t size) :
789 value_(value),
790 size_(size)
cf7d4c69
JF
791 {
792 }
793
3b52fd1a 794 CYString(const CYWord *word) :
029bc65b 795 value_(word->Word()),
5999c315 796 size_(strlen(value_))
cf7d4c69
JF
797 {
798 }
799
5999c315 800 const char *Value() const {
cf7d4c69
JF
801 return value_;
802 }
803
5b4dabb2 804 virtual CYIdentifier *Identifier() const;
11c1cc16 805 virtual const char *Word() const;
dea834b0 806
4644480a
JF
807 virtual CYNumber *Number(CYContext &context);
808 virtual CYString *String(CYContext &context);
809
5db9a7f5 810 CYString *Concat(CYContext &out, CYString *rhs) const;
652ec1ba 811 virtual void Output(CYOutput &out, CYFlags flags) const;
c5b15840
JF
812
813 virtual CYExpression *PropertyName(CYContext &context);
652ec1ba 814 virtual void PropertyName(CYOutput &out) const;
63b4c5a8
JF
815};
816
fc8fc33d 817struct CYElementValue;
b900e1a4
JF
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
fc8fc33d 832 CYElementValue *Replace(CYContext &context);
b900e1a4
JF
833};
834
835struct CYTemplate :
7085e1ab 836 CYTarget
b900e1a4
JF
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)
b900e1a4 848
37dadc21
JF
849 virtual CYString *String(CYContext &context);
850
7085e1ab 851 virtual CYTarget *Replace(CYContext &context);
b900e1a4
JF
852 virtual void Output(CYOutput &out, CYFlags flags) const;
853};
854
cf7d4c69 855struct CYNumber :
3b52fd1a 856 CYTrivial,
e5bc40db 857 CYPropertyName
cf7d4c69 858{
5999c315
JF
859 double value_;
860
861 CYNumber(double value) :
862 value_(value)
863 {
864 }
865
866 double Value() const {
867 return value_;
cf7d4c69
JF
868 }
869
4644480a
JF
870 virtual CYNumber *Number(CYContext &context);
871 virtual CYString *String(CYContext &context);
872
652ec1ba 873 virtual void Output(CYOutput &out, CYFlags flags) const;
c5b15840
JF
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);
652ec1ba 894 virtual void PropertyName(CYOutput &out) const;
cf7d4c69
JF
895};
896
63cd45c9 897struct CYRegEx :
3b52fd1a 898 CYTrivial
63cd45c9
JF
899{
900 const char *value_;
c8a2a786 901 size_t size_;
63cd45c9 902
c8a2a786
JF
903 CYRegEx(const char *value, size_t size) :
904 value_(value),
905 size_(size)
63cd45c9
JF
906 {
907 }
908
909 const char *Value() const {
910 return value_;
911 }
912
913 virtual void Output(CYOutput &out, CYFlags flags) const;
914};
915
cf7d4c69 916struct CYNull :
3b52fd1a 917 CYTrivial
cf7d4c69 918{
4644480a
JF
919 virtual CYNumber *Number(CYContext &context);
920 virtual CYString *String(CYContext &context);
921
652ec1ba 922 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
923};
924
925struct CYThis :
478d4ed0 926 CYMagic
cf7d4c69 927{
7085e1ab 928 virtual CYTarget *Replace(CYContext &context);
652ec1ba 929 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
930};
931
932struct CYBoolean :
3b52fd1a 933 CYTrivial
cf7d4c69 934{
42520424
JF
935 CYPrecedence(4)
936
937 virtual bool RightHand() const {
938 return true;
939 }
940
5999c315 941 virtual bool Value() const = 0;
652ec1ba 942 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
943};
944
945struct CYFalse :
cf7d4c69
JF
946 CYBoolean
947{
11c1cc16
JF
948 virtual bool Value() const {
949 return false;
950 }
4644480a
JF
951
952 virtual CYNumber *Number(CYContext &context);
953 virtual CYString *String(CYContext &context);
cf7d4c69
JF
954};
955
956struct CYTrue :
cf7d4c69
JF
957 CYBoolean
958{
11c1cc16
JF
959 virtual bool Value() const {
960 return true;
961 }
4644480a
JF
962
963 virtual CYNumber *Number(CYContext &context);
964 virtual CYString *String(CYContext &context);
cf7d4c69
JF
965};
966
967struct CYVariable :
7085e1ab 968 CYTarget
cf7d4c69
JF
969{
970 CYIdentifier *name_;
971
972 CYVariable(CYIdentifier *name) :
973 name_(name)
974 {
975 }
5999c315 976
2eb8215d
JF
977 CYVariable(const char *name) :
978 name_(new($pool) CYIdentifier(name))
979 {
980 }
981
d35a3b07
JF
982 CYPrecedence(0)
983
7085e1ab
JF
984 virtual bool Eval() const {
985 return strcmp(name_->Word(), "eval") == 0;
986 }
987
988 virtual CYTarget *Replace(CYContext &context);
652ec1ba 989 virtual void Output(CYOutput &out, CYFlags flags) const;
0afc9ba3
JF
990
991 virtual CYFunctionParameter *Parameter() const;
cf7d4c69
JF
992};
993
2fad14e5
JF
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
cf7d4c69 1010struct CYPrefix :
63b4c5a8
JF
1011 CYExpression
1012{
1013 CYExpression *rhs_;
1014
cf7d4c69 1015 CYPrefix(CYExpression *rhs) :
63b4c5a8
JF
1016 rhs_(rhs)
1017 {
1018 }
5999c315 1019
b09da87b 1020 virtual bool Alphabetic() const = 0;
5999c315
JF
1021 virtual const char *Operator() const = 0;
1022
3b52fd1a
JF
1023 CYPrecedence(4)
1024
1025 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1026 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
1027};
1028
cf7d4c69 1029struct CYInfix :
63b4c5a8
JF
1030 CYExpression
1031{
1032 CYExpression *lhs_;
1033 CYExpression *rhs_;
1034
cf7d4c69 1035 CYInfix(CYExpression *lhs, CYExpression *rhs) :
63b4c5a8
JF
1036 lhs_(lhs),
1037 rhs_(rhs)
1038 {
1039 }
5999c315 1040
0ff9f149
JF
1041 void SetLeft(CYExpression *lhs) {
1042 lhs_ = lhs;
1043 }
1044
b09da87b 1045 virtual bool Alphabetic() const = 0;
5999c315
JF
1046 virtual const char *Operator() const = 0;
1047
3b52fd1a 1048 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1049 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
1050};
1051
cf7d4c69 1052struct CYPostfix :
63b4c5a8
JF
1053 CYExpression
1054{
1055 CYExpression *lhs_;
1056
cf7d4c69 1057 CYPostfix(CYExpression *lhs) :
63b4c5a8
JF
1058 lhs_(lhs)
1059 {
1060 }
5999c315
JF
1061
1062 virtual const char *Operator() const = 0;
1063
3b52fd1a
JF
1064 CYPrecedence(3)
1065
1066 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1067 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
1068};
1069
cf7d4c69 1070struct CYAssignment :
d35a3b07 1071 CYExpression
cf7d4c69 1072{
7085e1ab 1073 CYTarget *lhs_;
d35a3b07
JF
1074 CYExpression *rhs_;
1075
7085e1ab 1076 CYAssignment(CYTarget *lhs, CYExpression *rhs) :
d35a3b07
JF
1077 lhs_(lhs),
1078 rhs_(rhs)
cf7d4c69
JF
1079 {
1080 }
5999c315 1081
8b77acf1
JF
1082 void SetRight(CYExpression *rhs) {
1083 rhs_ = rhs;
0ff9f149
JF
1084 }
1085
5999c315 1086 virtual const char *Operator() const = 0;
d35a3b07 1087
4de0686f
JF
1088 CYPrecedence(16)
1089
3b52fd1a 1090 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1091 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1092};
1093
62014ea9 1094struct CYArgument :
96a7e5c2
JF
1095 CYNext<CYArgument>,
1096 CYThing
62014ea9 1097{
cf7d4c69
JF
1098 CYWord *name_;
1099 CYExpression *value_;
cf7d4c69 1100
3b52fd1a
JF
1101 CYArgument(CYExpression *value, CYArgument *next = NULL) :
1102 CYNext<CYArgument>(next),
1103 name_(NULL),
1104 value_(value)
1105 {
1106 }
1107
cf7d4c69 1108 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
62014ea9 1109 CYNext<CYArgument>(next),
cf7d4c69 1110 name_(name),
62014ea9 1111 value_(value)
cf7d4c69
JF
1112 {
1113 }
5999c315 1114
5192746c 1115 CYArgument *Replace(CYContext &context);
652ec1ba 1116 void Output(CYOutput &out) const;
cf7d4c69
JF
1117};
1118
5999c315
JF
1119struct CYClause :
1120 CYThing,
1121 CYNext<CYClause>
1122{
09fc3efb 1123 CYExpression *value_;
b0385401 1124 CYStatement *code_;
cf7d4c69 1125
09fc3efb
JF
1126 CYClause(CYExpression *value, CYStatement *code) :
1127 value_(value),
b0385401 1128 code_(code)
cf7d4c69
JF
1129 {
1130 }
1131
fa389b0f 1132 void Replace(CYContext &context);
652ec1ba 1133 virtual void Output(CYOutput &out) const;
cf7d4c69
JF
1134};
1135
62014ea9 1136struct CYElement :
5a6c975a 1137 CYNext<CYElement>,
96a7e5c2 1138 CYThing
fc8fc33d 1139{
5a6c975a
JF
1140 CYElement(CYElement *next) :
1141 CYNext<CYElement>(next)
1142 {
1143 }
1144
fc8fc33d
JF
1145 virtual bool Elision() const = 0;
1146
1147 virtual void Replace(CYContext &context) = 0;
1148};
1149
1150struct CYElementValue :
fc8fc33d 1151 CYElement
62014ea9 1152{
cf7d4c69 1153 CYExpression *value_;
cf7d4c69 1154
b3c38c5f 1155 CYElementValue(CYExpression *value, CYElement *next = NULL) :
5a6c975a 1156 CYElement(next),
62014ea9 1157 value_(value)
cf7d4c69
JF
1158 {
1159 }
5999c315 1160
fc8fc33d
JF
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
5a6c975a
JF
1174 CYElementSpread(CYExpression *value, CYElement *next = NULL) :
1175 CYElement(next),
fc8fc33d
JF
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;
5befe15e
JF
1186};
1187
1188struct CYArray :
1189 CYLiteral
1190{
1191 CYElement *elements_;
1192
3b52fd1a 1193 CYArray(CYElement *elements = NULL) :
5befe15e
JF
1194 elements_(elements)
1195 {
1196 }
1197
7085e1ab 1198 virtual CYTarget *Replace(CYContext &context);
652ec1ba 1199 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1200};
1201
09fc3efb 1202struct CYBinding {
cf7d4c69 1203 CYIdentifier *identifier_;
09fc3efb 1204 CYExpression *initializer_;
cf7d4c69 1205
09fc3efb 1206 CYBinding(CYIdentifier *identifier, CYExpression *initializer = NULL) :
cf7d4c69 1207 identifier_(identifier),
09fc3efb 1208 initializer_(initializer)
cf7d4c69
JF
1209 {
1210 }
5999c315 1211
7085e1ab 1212 CYTarget *Target(CYContext &context);
3b52fd1a 1213
7085e1ab
JF
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_;
09fc3efb 1222 CYBinding *binding_;
7085e1ab 1223
09fc3efb 1224 CYForLexical(bool constant, CYBinding *binding) :
7085e1ab 1225 constant_(constant),
09fc3efb 1226 binding_(binding)
7085e1ab
JF
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};
15b88a33 1235
7085e1ab
JF
1236struct CYForVariable :
1237 CYForInInitializer
1238{
09fc3efb 1239 CYBinding *binding_;
75b0a457 1240
09fc3efb
JF
1241 CYForVariable(CYBinding *binding) :
1242 binding_(binding)
7085e1ab
JF
1243 {
1244 }
1245
1246 virtual CYStatement *Initialize(CYContext &context, CYExpression *value);
1247
1248 virtual CYTarget *Replace(CYContext &context);
652ec1ba 1249 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1250};
1251
09fc3efb
JF
1252struct CYBindings :
1253 CYNext<CYBindings>,
15b88a33 1254 CYThing
cf7d4c69 1255{
09fc3efb 1256 CYBinding *binding_;
cf7d4c69 1257
09fc3efb
JF
1258 CYBindings(CYBinding *binding, CYBindings *next = NULL) :
1259 CYNext<CYBindings>(next),
1260 binding_(binding)
cac61857
JF
1261 {
1262 }
1263
7085e1ab 1264 CYExpression *Replace(CYContext &context, CYIdentifierKind kind);
96a7e5c2 1265
15b88a33
JF
1266 CYArgument *Argument(CYContext &context);
1267 CYFunctionParameter *Parameter(CYContext &context);
3b52fd1a 1268
96a7e5c2 1269 virtual void Output(CYOutput &out) const;
652ec1ba 1270 virtual void Output(CYOutput &out, CYFlags flags) const;
cac61857
JF
1271};
1272
1273struct CYVar :
bfd79fae 1274 CYForInitializer
cac61857 1275{
09fc3efb 1276 CYBindings *bindings_;
cac61857 1277
09fc3efb
JF
1278 CYVar(CYBindings *bindings) :
1279 bindings_(bindings)
cac61857
JF
1280 {
1281 }
1282
efd689d8
JF
1283 CYCompact(None)
1284
bfd79fae 1285 virtual CYForInitializer *Replace(CYContext &context);
fb98ac0c 1286 virtual void Output(CYOutput &out, CYFlags flags) const;
cac61857
JF
1287};
1288
09fc3efb 1289struct CYLexical :
bfd79fae 1290 CYForInitializer
cac61857 1291{
7085e1ab 1292 bool constant_;
09fc3efb 1293 CYBindings *bindings_;
cac61857 1294
09fc3efb 1295 CYLexical(bool constant, CYBindings *bindings) :
7085e1ab 1296 constant_(constant),
09fc3efb 1297 bindings_(bindings)
cf7d4c69
JF
1298 {
1299 }
5999c315 1300
ca6a1b2b 1301 CYCompact(None)
efd689d8 1302
bfd79fae 1303 virtual CYForInitializer *Replace(CYContext &context);
fb98ac0c 1304 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1305};
1306
c5b15840 1307struct CYBuilder {
09fc3efb 1308 CYList<CYBindings> bindings_;
c5b15840
JF
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
7b87d205
JF
1328 virtual bool Update() const;
1329
c5b15840 1330 CYProperty *ReplaceAll(CYContext &context, CYBuilder &builder, CYExpression *self, bool update);
a196a97a 1331 void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, bool protect);
c5b15840 1332
a196a97a 1333 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect) = 0;
c5b15840
JF
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
a196a97a 1350 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
c5b15840
JF
1351 virtual void Replace(CYContext &context);
1352 virtual void Output(CYOutput &out) const;
1353};
1354
cf7d4c69
JF
1355struct CYFor :
1356 CYStatement
1357{
09fc3efb 1358 CYForInitializer *initializer_;
cf7d4c69
JF
1359 CYExpression *test_;
1360 CYExpression *increment_;
1361 CYStatement *code_;
1362
09fc3efb
JF
1363 CYFor(CYForInitializer *initializer, CYExpression *test, CYExpression *increment, CYStatement *code) :
1364 initializer_(initializer),
cf7d4c69
JF
1365 test_(test),
1366 increment_(increment),
1367 code_(code)
1368 {
1369 }
5999c315 1370
efd689d8
JF
1371 CYCompact(Long)
1372
3b52fd1a 1373 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1374 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1375};
1376
1377struct CYForIn :
1378 CYStatement
1379{
09fc3efb
JF
1380 CYForInInitializer *initializer_;
1381 CYExpression *iterable_;
cf7d4c69
JF
1382 CYStatement *code_;
1383
09fc3efb
JF
1384 CYForIn(CYForInInitializer *initializer, CYExpression *iterable, CYStatement *code) :
1385 initializer_(initializer),
1386 iterable_(iterable),
cf7d4c69
JF
1387 code_(code)
1388 {
1389 }
5999c315 1390
efd689d8
JF
1391 CYCompact(Long)
1392
3b52fd1a 1393 virtual CYStatement *Replace(CYContext &context);
23111dca
JF
1394 virtual void Output(CYOutput &out, CYFlags flags) const;
1395};
1396
1397struct CYForInitialized :
1398 CYStatement
1399{
09fc3efb
JF
1400 CYBinding *binding_;
1401 CYExpression *iterable_;
23111dca
JF
1402 CYStatement *code_;
1403
09fc3efb
JF
1404 CYForInitialized(CYBinding *binding, CYExpression *iterable, CYStatement *code) :
1405 binding_(binding),
1406 iterable_(iterable),
23111dca
JF
1407 code_(code)
1408 {
1409 }
1410
1411 CYCompact(Long)
1412
1413 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1414 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1415};
1416
d5618df7 1417struct CYForOf :
75b0a457
JF
1418 CYStatement
1419{
09fc3efb
JF
1420 CYForInInitializer *initializer_;
1421 CYExpression *iterable_;
75b0a457
JF
1422 CYStatement *code_;
1423
09fc3efb
JF
1424 CYForOf(CYForInInitializer *initializer, CYExpression *iterable, CYStatement *code) :
1425 initializer_(initializer),
1426 iterable_(iterable),
75b0a457
JF
1427 code_(code)
1428 {
1429 }
1430
efd689d8
JF
1431 CYCompact(Long)
1432
3b52fd1a 1433 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1434 virtual void Output(CYOutput &out, CYFlags flags) const;
75b0a457
JF
1435};
1436
693d501b
JF
1437struct CYObject :
1438 CYLiteral
1439{
3b52fd1a 1440 CYProperty *properties_;
693d501b 1441
ab2aa221 1442 CYObject(CYProperty *properties = NULL) :
3b52fd1a 1443 properties_(properties)
693d501b
JF
1444 {
1445 }
1446
4f3e597c
JF
1447 CYTarget *Replace(CYContext &context, CYTarget *seed);
1448
7085e1ab 1449 virtual CYTarget *Replace(CYContext &context);
652ec1ba 1450 void Output(CYOutput &out, CYFlags flags) const;
693d501b
JF
1451};
1452
cf7d4c69 1453struct CYMember :
7085e1ab 1454 CYTarget
cf7d4c69
JF
1455{
1456 CYExpression *object_;
1457 CYExpression *property_;
1458
1459 CYMember(CYExpression *object, CYExpression *property) :
1460 object_(object),
1461 property_(property)
1462 {
1463 }
5999c315 1464
9b5527f0
JF
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
7085e1ab 1480 virtual CYTarget *Replace(CYContext &context);
652ec1ba 1481 virtual void Output(CYOutput &out, CYFlags flags) const;
9b5527f0
JF
1482};
1483
1484struct CYIndirectMember :
1485 CYMember
1486{
1487 CYIndirectMember(CYExpression *object, CYExpression *property) :
1488 CYMember(object, property)
1489 {
1490 }
1491
d35a3b07
JF
1492 CYPrecedence(1)
1493
7085e1ab 1494 virtual CYTarget *Replace(CYContext &context);
652ec1ba 1495 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1496};
1497
2fad14e5
JF
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
e56c2499
JF
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
2eb8215d
JF
1526namespace cy {
1527namespace Syntax {
1528
1529struct New :
7085e1ab 1530 CYTarget
cf7d4c69
JF
1531{
1532 CYExpression *constructor_;
1533 CYArgument *arguments_;
1534
c5b15840 1535 New(CYExpression *constructor, CYArgument *arguments = NULL) :
cf7d4c69
JF
1536 constructor_(constructor),
1537 arguments_(arguments)
1538 {
1539 }
5999c315 1540
9a39f705 1541 virtual int Precedence() const {
fb98ac0c
JF
1542 return arguments_ == NULL ? 2 : 1;
1543 }
1544
4f3e597c
JF
1545 virtual bool IsNew() const {
1546 return true;
1547 }
d35a3b07 1548
7085e1ab 1549 virtual CYTarget *Replace(CYContext &context);
652ec1ba 1550 virtual void Output(CYOutput &out, CYFlags flags) const;
6c093cce 1551
7085e1ab 1552 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
cf7d4c69
JF
1553};
1554
2eb8215d
JF
1555} }
1556
7085e1ab
JF
1557struct CYApply :
1558 CYTarget
cf7d4c69 1559{
cf7d4c69
JF
1560 CYArgument *arguments_;
1561
7085e1ab 1562 CYApply(CYArgument *arguments = NULL) :
cf7d4c69
JF
1563 arguments_(arguments)
1564 {
1565 }
5999c315 1566
fb98ac0c 1567 CYPrecedence(1)
d35a3b07 1568
7085e1ab
JF
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
652ec1ba 1583 virtual void Output(CYOutput &out, CYFlags flags) const;
7085e1ab
JF
1584 virtual CYTarget *Replace(CYContext &context);
1585};
1586
1587struct CYEval :
1588 CYApply
1589{
1590 CYEval(CYArgument *arguments) :
1591 CYApply(arguments)
1592 {
1593 }
6c093cce 1594
7085e1ab
JF
1595 virtual void Output(CYOutput &out, CYFlags flags) const;
1596 virtual CYTarget *Replace(CYContext &context);
6c093cce
JF
1597};
1598
1599struct CYRubyProc;
1600
4f3e597c 1601struct CYBraced :
7085e1ab 1602 CYTarget
6c093cce 1603{
4f3e597c 1604 CYTarget *lhs_;
6c093cce 1605
4f3e597c
JF
1606 CYBraced(CYTarget *lhs = NULL) :
1607 lhs_(lhs)
6c093cce
JF
1608 {
1609 }
1610
1611 CYPrecedence(1)
6c093cce 1612
4f3e597c
JF
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
7085e1ab 1629 virtual CYTarget *Replace(CYContext &context);
6c093cce 1630 virtual void Output(CYOutput &out, CYFlags flags) const;
1abe53bf 1631
7085e1ab 1632 virtual CYTarget *AddArgument(CYContext &context, CYExpression *value);
cf7d4c69
JF
1633};
1634
4f3e597c
JF
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
cf7d4c69
JF
1650struct CYIf :
1651 CYStatement
1652{
1653 CYExpression *test_;
1654 CYStatement *true_;
1655 CYStatement *false_;
1656
3b52fd1a 1657 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
cf7d4c69
JF
1658 test_(test),
1659 true_(_true),
1660 false_(_false)
1661 {
1662 }
5999c315 1663
efd689d8
JF
1664 CYCompact(Long)
1665
3b52fd1a 1666 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1667 virtual void Output(CYOutput &out, CYFlags flags) const;
12e37ba3
JF
1668
1669 virtual CYStatement *Return();
cf7d4c69
JF
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 }
5999c315 1683
efd689d8
JF
1684 CYCompact(None)
1685
3b52fd1a 1686 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1687 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
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 }
5999c315 1701
efd689d8
JF
1702 CYCompact(Long)
1703
3b52fd1a 1704 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1705 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1706};
1707
a846a8cd 1708struct CYFunction {
b09da87b 1709 CYFunctionParameter *parameters_;
b0385401 1710 CYStatement *code_;
a0be43fc 1711
ab2aa221 1712 CYNonLocal *nonlocal_;
12e37ba3 1713 bool implicit_;
a0be43fc 1714 CYThisScope this_;
c5b15840 1715 CYIdentifier *super_;
cf7d4c69 1716
c5b15840 1717 CYFunction(CYFunctionParameter *parameters, CYStatement *code) :
cf7d4c69 1718 parameters_(parameters),
b0385401 1719 code_(code),
12e37ba3 1720 nonlocal_(NULL),
c5b15840
JF
1721 implicit_(false),
1722 super_(NULL)
cf7d4c69
JF
1723 {
1724 }
5999c315 1725
c5b15840
JF
1726 void Replace(CYContext &context);
1727 void Output(CYOutput &out) const;
fb98ac0c
JF
1728};
1729
1730struct CYFunctionExpression :
1731 CYFunction,
7085e1ab 1732 CYTarget
fb98ac0c 1733{
c5b15840
JF
1734 CYIdentifier *name_;
1735
b0385401 1736 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
c5b15840
JF
1737 CYFunction(parameters, code),
1738 name_(name)
fb98ac0c
JF
1739 {
1740 }
1741
a0be43fc 1742 CYPrecedence(0)
a0be43fc 1743
7085e1ab 1744 CYTarget *Replace(CYContext &context) override;
a0be43fc
JF
1745 virtual void Output(CYOutput &out, CYFlags flags) const;
1746};
1747
a0be43fc
JF
1748struct CYFatArrow :
1749 CYFunction,
1750 CYExpression
1751{
b0385401 1752 CYFatArrow(CYFunctionParameter *parameters, CYStatement *code) :
c5b15840 1753 CYFunction(parameters, code)
a0be43fc
JF
1754 {
1755 }
1756
d35a3b07
JF
1757 CYPrecedence(0)
1758
7085e1ab 1759 CYExpression *Replace(CYContext &context) override;
652ec1ba 1760 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1761};
1762
6c093cce 1763struct CYRubyProc :
6ce0f978 1764 CYFunction,
7085e1ab 1765 CYTarget
6c093cce 1766{
b0385401 1767 CYRubyProc(CYFunctionParameter *parameters, CYStatement *code) :
c5b15840 1768 CYFunction(parameters, code)
6c093cce
JF
1769 {
1770 }
1771
c5b15840 1772 CYPrecedence(0)
c5b15840 1773
7085e1ab 1774 CYTarget *Replace(CYContext &context) override;
6c093cce
JF
1775 virtual void Output(CYOutput &out, CYFlags flags) const;
1776};
1777
fb98ac0c
JF
1778struct CYFunctionStatement :
1779 CYFunction,
b10bd496 1780 CYStatement
cf7d4c69 1781{
c5b15840
JF
1782 CYIdentifier *name_;
1783
b0385401 1784 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
c5b15840
JF
1785 CYFunction(parameters, code),
1786 name_(name)
cf7d4c69
JF
1787 {
1788 }
5999c315 1789
efd689d8
JF
1790 CYCompact(None)
1791
7085e1ab 1792 CYStatement *Replace(CYContext &context) override;
fb98ac0c 1793 virtual void Output(CYOutput &out, CYFlags flags) const;
5999c315
JF
1794};
1795
c5b15840
JF
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
a196a97a 1822 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
c5b15840
JF
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
a196a97a 1834 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
c5b15840
JF
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
7b87d205
JF
1846 bool Update() const override;
1847
c5b15840
JF
1848 virtual CYFunctionExpression *Constructor();
1849
a196a97a 1850 virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect);
c5b15840
JF
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 :
7085e1ab 1873 CYTarget
c5b15840
JF
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)
c5b15840 1885
7085e1ab 1886 CYTarget *Replace(CYContext &context) override;
c5b15840
JF
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
7085e1ab 1904 CYStatement *Replace(CYContext &context) override;
c5b15840
JF
1905 virtual void Output(CYOutput &out, CYFlags flags) const;
1906};
1907
1908struct CYSuperCall :
7085e1ab 1909 CYTarget
c5b15840
JF
1910{
1911 CYArgument *arguments_;
1912
1913 CYSuperCall(CYArgument *arguments) :
1914 arguments_(arguments)
1915 {
1916 }
1917
1918 CYPrecedence(2)
c5b15840 1919
7085e1ab 1920 CYTarget *Replace(CYContext &context) override;
c5b15840
JF
1921 virtual void Output(CYOutput &out, CYFlags flags) const;
1922};
1923
1924struct CYSuperAccess :
7085e1ab 1925 CYTarget
c5b15840
JF
1926{
1927 CYExpression *property_;
1928
1929 CYSuperAccess(CYExpression *property) :
1930 property_(property)
1931 {
1932 }
1933
1934 CYPrecedence(1)
c5b15840 1935
7085e1ab 1936 CYTarget *Replace(CYContext &context) override;
c5b15840
JF
1937 virtual void Output(CYOutput &out, CYFlags flags) const;
1938};
1939
5999c315 1940struct CYExpress :
bfd79fae 1941 CYForInitializer
5999c315
JF
1942{
1943 CYExpression *expression_;
1944
1945 CYExpress(CYExpression *expression) :
1946 expression_(expression)
1947 {
fd5cdf97 1948 if (expression_ == NULL)
029bc65b 1949 throw;
5999c315
JF
1950 }
1951
efd689d8
JF
1952 CYCompact(None)
1953
bfd79fae 1954 CYForInitializer *Replace(CYContext &context) override;
fb98ac0c 1955 virtual void Output(CYOutput &out, CYFlags flags) const;
12e37ba3
JF
1956
1957 virtual CYStatement *Return();
cf7d4c69
JF
1958};
1959
1960struct CYContinue :
1961 CYStatement
1962{
1963 CYIdentifier *label_;
1964
1965 CYContinue(CYIdentifier *label) :
1966 label_(label)
1967 {
1968 }
5999c315 1969
efd689d8
JF
1970 CYCompact(Short)
1971
7085e1ab 1972 CYStatement *Replace(CYContext &context) override;
fb98ac0c 1973 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1974};
1975
1976struct CYBreak :
1977 CYStatement
1978{
1979 CYIdentifier *label_;
1980
1981 CYBreak(CYIdentifier *label) :
1982 label_(label)
1983 {
1984 }
5999c315 1985
efd689d8
JF
1986 CYCompact(Short)
1987
7085e1ab 1988 CYStatement *Replace(CYContext &context) override;
fb98ac0c 1989 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1990};
1991
1992struct CYReturn :
1993 CYStatement
1994{
1995 CYExpression *value_;
1996
1997 CYReturn(CYExpression *value) :
1998 value_(value)
1999 {
2000 }
5999c315 2001
efd689d8
JF
2002 CYCompact(None)
2003
7085e1ab 2004 CYStatement *Replace(CYContext &context) override;
9d2b125d
JF
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
7085e1ab 2020 CYExpression *Replace(CYContext &context) override;
9d2b125d
JF
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);
fb98ac0c 2037 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
2038};
2039
2040struct CYEmpty :
bfd79fae 2041 CYForInitializer
cf7d4c69 2042{
efd689d8
JF
2043 CYCompact(Short)
2044
bfd79fae 2045 virtual CYForInitializer *Replace(CYContext &context);
fb98ac0c 2046 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
2047};
2048
96a7e5c2
JF
2049struct CYFinally :
2050 CYThing
2051{
b0385401 2052 CYStatement *code_;
b10bd496 2053
b0385401
JF
2054 CYFinally(CYStatement *code) :
2055 code_(code)
b10bd496
JF
2056 {
2057 }
2058
3b52fd1a 2059 void Replace(CYContext &context);
b10bd496
JF
2060 virtual void Output(CYOutput &out) const;
2061};
2062
3fe283c5
JF
2063struct CYTypeSpecifier :
2064 CYThing
2065{
7085e1ab 2066 virtual CYTarget *Replace(CYContext &context) = 0;
3fe283c5
JF
2067};
2068
03db6a67
JF
2069struct CYTypeError :
2070 CYTypeSpecifier
2071{
2072 CYTypeError() {
2073 }
2074
7085e1ab 2075 virtual CYTarget *Replace(CYContext &context);
03db6a67
JF
2076 virtual void Output(CYOutput &out) const;
2077};
2078
0559abf8
JF
2079enum CYTypeSigning {
2080 CYTypeNeutral,
2081 CYTypeSigned,
2082 CYTypeUnsigned,
3fe283c5
JF
2083};
2084
0559abf8 2085struct CYTypeCharacter :
d8380373
JF
2086 CYTypeSpecifier
2087{
0559abf8 2088 CYTypeSigning signing_;
d8380373 2089
0559abf8
JF
2090 CYTypeCharacter(CYTypeSigning signing) :
2091 signing_(signing)
d8380373
JF
2092 {
2093 }
2094
2095 virtual CYTarget *Replace(CYContext &context);
2096 virtual void Output(CYOutput &out) const;
2097};
2098
24ffc58c
JF
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
0559abf8 2113struct CYTypeIntegral :
3fe283c5
JF
2114 CYTypeSpecifier
2115{
0559abf8
JF
2116 CYTypeSigning signing_;
2117 int length_;
3fe283c5 2118
0559abf8
JF
2119 CYTypeIntegral(CYTypeSigning signing, int length = 1) :
2120 signing_(signing),
2121 length_(length)
3fe283c5
JF
2122 {
2123 }
2124
0559abf8
JF
2125 CYTypeIntegral *Long() {
2126 if (length_ != 1 && length_ != 2)
2127 return NULL;
2128 ++length_;
2129 return this;
3fe283c5
JF
2130 }
2131
0559abf8
JF
2132 CYTypeIntegral *Short() {
2133 if (length_ != 1)
2134 return NULL;
2135 --length_;
2136 return this;
2137 }
3fe283c5 2138
0559abf8
JF
2139 CYTypeIntegral *Signed() {
2140 if (signing_ != CYTypeNeutral)
2141 return NULL;
2142 signing_ = CYTypeSigned;
2143 return this;
2144 }
3fe283c5 2145
0559abf8
JF
2146 CYTypeIntegral *Unsigned() {
2147 if (signing_ != CYTypeNeutral)
2148 return NULL;
2149 signing_ = CYTypeUnsigned;
2150 return this;
3fe283c5
JF
2151 }
2152
7085e1ab 2153 virtual CYTarget *Replace(CYContext &context);
3fe283c5
JF
2154 virtual void Output(CYOutput &out) const;
2155};
2156
0559abf8 2157struct CYTypeVoid :
3fe283c5
JF
2158 CYTypeSpecifier
2159{
0559abf8 2160 CYTypeVoid() {
3fe283c5
JF
2161 }
2162
7085e1ab 2163 virtual CYTarget *Replace(CYContext &context);
3fe283c5
JF
2164 virtual void Output(CYOutput &out) const;
2165};
2166
aaa29c28
JF
2167enum CYTypeReferenceKind {
2168 CYTypeReferenceStruct,
2169 CYTypeReferenceEnum,
2170};
2171
0559abf8 2172struct CYTypeReference :
3fe283c5
JF
2173 CYTypeSpecifier
2174{
aaa29c28 2175 CYTypeReferenceKind kind_;
0559abf8 2176 CYIdentifier *name_;
3fe283c5 2177
aaa29c28
JF
2178 CYTypeReference(CYTypeReferenceKind kind, CYIdentifier *name) :
2179 kind_(kind),
0559abf8 2180 name_(name)
3fe283c5
JF
2181 {
2182 }
2183
7085e1ab 2184 virtual CYTarget *Replace(CYContext &context);
3fe283c5
JF
2185 virtual void Output(CYOutput &out) const;
2186};
2187
0559abf8 2188struct CYTypeVariable :
3fe283c5
JF
2189 CYTypeSpecifier
2190{
0559abf8
JF
2191 CYIdentifier *name_;
2192
2193 CYTypeVariable(CYIdentifier *name) :
2194 name_(name)
2195 {
2196 }
3fe283c5 2197
0559abf8
JF
2198 CYTypeVariable(const char *name) :
2199 name_(new($pool) CYIdentifier(name))
3fe283c5
JF
2200 {
2201 }
2202
7085e1ab 2203 virtual CYTarget *Replace(CYContext &context);
3fe283c5
JF
2204 virtual void Output(CYOutput &out) const;
2205};
2206
00b4cb83
JF
2207struct CYTypeFunctionWith;
2208
690cf1a8
JF
2209struct CYTypeModifier :
2210 CYNext<CYTypeModifier>
2211{
2212 CYTypeModifier(CYTypeModifier *next) :
2213 CYNext<CYTypeModifier>(next)
2214 {
2215 }
2216
9a39f705
JF
2217 virtual int Precedence() const = 0;
2218
7085e1ab
JF
2219 virtual CYTarget *Replace_(CYContext &context, CYTarget *type) = 0;
2220 CYTarget *Replace(CYContext &context, CYTarget *type);
9a39f705 2221
5b4dabb2
JF
2222 virtual void Output(CYOutput &out, CYPropertyName *name) const = 0;
2223 void Output(CYOutput &out, int precedence, CYPropertyName *name, bool space) const;
00b4cb83
JF
2224
2225 virtual CYTypeFunctionWith *Function() { return NULL; }
690cf1a8
JF
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
9a39f705 2239 CYPrecedence(1)
690cf1a8 2240
7085e1ab 2241 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
5b4dabb2 2242 void Output(CYOutput &out, CYPropertyName *name) const override;
690cf1a8
JF
2243};
2244
2245struct CYTypeConstant :
2246 CYTypeModifier
2247{
2248 CYTypeConstant(CYTypeModifier *next = NULL) :
2249 CYTypeModifier(next)
2250 {
2251 }
2252
9a39f705 2253 CYPrecedence(0)
690cf1a8 2254
7085e1ab 2255 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
5b4dabb2 2256 void Output(CYOutput &out, CYPropertyName *name) const override;
690cf1a8
JF
2257};
2258
2259struct CYTypePointerTo :
2260 CYTypeModifier
2261{
2262 CYTypePointerTo(CYTypeModifier *next = NULL) :
2263 CYTypeModifier(next)
2264 {
2265 }
2266
9a39f705 2267 CYPrecedence(0)
690cf1a8 2268
7085e1ab 2269 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
5b4dabb2 2270 void Output(CYOutput &out, CYPropertyName *name) const override;
690cf1a8
JF
2271};
2272
9a39f705 2273struct CYTypeVolatile :
690cf1a8
JF
2274 CYTypeModifier
2275{
9a39f705
JF
2276 CYTypeVolatile(CYTypeModifier *next = NULL) :
2277 CYTypeModifier(next)
690cf1a8
JF
2278 {
2279 }
2280
9a39f705 2281 CYPrecedence(0)
690cf1a8 2282
7085e1ab 2283 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
5b4dabb2 2284 void Output(CYOutput &out, CYPropertyName *name) const override;
690cf1a8
JF
2285};
2286
5b4dabb2 2287struct CYType :
60097023 2288 CYThing
690cf1a8 2289{
3fe283c5 2290 CYTypeSpecifier *specifier_;
9a39f705 2291 CYTypeModifier *modifier_;
690cf1a8 2292
5b4dabb2 2293 CYType(CYTypeSpecifier *specifier = NULL, CYTypeModifier *modifier = NULL) :
3fe283c5 2294 specifier_(specifier),
9a39f705
JF
2295 modifier_(modifier)
2296 {
2297 }
2298
5b4dabb2 2299 inline CYType *Modify(CYTypeModifier *modifier) {
9a39f705
JF
2300 CYSetLast(modifier_) = modifier;
2301 return this;
2302 }
2303
5b4dabb2
JF
2304 void Output(CYOutput &out, CYPropertyName *name) const;
2305
7085e1ab 2306 virtual CYTarget *Replace(CYContext &context);
60097023 2307 virtual void Output(CYOutput &out) const;
00b4cb83
JF
2308
2309 CYTypeFunctionWith *Function();
690cf1a8
JF
2310};
2311
5b4dabb2
JF
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
9a39f705 2335struct CYEncodedType :
7085e1ab 2336 CYTarget
9a39f705 2337{
5b4dabb2 2338 CYType *typed_;
9a39f705 2339
5b4dabb2 2340 CYEncodedType(CYType *typed) :
9a39f705
JF
2341 typed_(typed)
2342 {
2343 }
2344
2345 CYPrecedence(1)
2346
7085e1ab 2347 virtual CYTarget *Replace(CYContext &context);
9a39f705
JF
2348 virtual void Output(CYOutput &out, CYFlags flags) const;
2349};
2350
690cf1a8 2351struct CYTypedParameter :
9a39f705
JF
2352 CYNext<CYTypedParameter>,
2353 CYThing
690cf1a8 2354{
5b4dabb2
JF
2355 CYType *type_;
2356 CYIdentifier *name_;
690cf1a8 2357
5b4dabb2 2358 CYTypedParameter(CYType *type, CYIdentifier *name, CYTypedParameter *next = NULL) :
690cf1a8 2359 CYNext<CYTypedParameter>(next),
5b4dabb2
JF
2360 type_(type),
2361 name_(name)
690cf1a8
JF
2362 {
2363 }
2364
663c538f 2365 CYArgument *Argument(CYContext &context);
690cf1a8
JF
2366 CYFunctionParameter *Parameters(CYContext &context);
2367 CYExpression *TypeSignature(CYContext &context, CYExpression *prefix);
9a39f705
JF
2368
2369 virtual void Output(CYOutput &out) const;
690cf1a8
JF
2370};
2371
574d4720
JF
2372struct CYTypedFormal {
2373 bool variadic_;
2374 CYTypedParameter *parameters_;
2375
2376 CYTypedFormal(bool variadic) :
2377 variadic_(variadic),
2378 parameters_(NULL)
2379 {
2380 }
2381};
2382
690cf1a8 2383struct CYLambda :
7085e1ab 2384 CYTarget
690cf1a8 2385{
5b4dabb2 2386 CYType *typed_;
690cf1a8 2387 CYTypedParameter *parameters_;
b0385401 2388 CYStatement *code_;
690cf1a8 2389
5b4dabb2 2390 CYLambda(CYType *typed, CYTypedParameter *parameters, CYStatement *code) :
9a39f705 2391 typed_(typed),
690cf1a8 2392 parameters_(parameters),
b0385401 2393 code_(code)
690cf1a8
JF
2394 {
2395 }
2396
2397 CYPrecedence(1)
2398
7085e1ab 2399 virtual CYTarget *Replace(CYContext &context);
690cf1a8
JF
2400 virtual void Output(CYOutput &out, CYFlags flags) const;
2401};
2402
7b750785
JF
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
efd689d8
JF
2429 CYCompact(None)
2430
7b750785
JF
2431 virtual CYStatement *Replace(CYContext &context);
2432 virtual void Output(CYOutput &out, CYFlags flags) const;
2433};
2434
90dd6ff1
JF
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
436a877b
JF
2468struct CYExternalExpression :
2469 CYTarget
2470{
2471 CYString *abi_;
5b4dabb2
JF
2472 CYType *type_;
2473 CYPropertyName *name_;
436a877b 2474
5b4dabb2 2475 CYExternalExpression(CYString *abi, CYType *type, CYPropertyName *name) :
436a877b 2476 abi_(abi),
5b4dabb2
JF
2477 type_(type),
2478 name_(name)
436a877b
JF
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 :
c5587ed7
JF
2489 CYStatement
2490{
2491 CYString *abi_;
5b4dabb2
JF
2492 CYType *type_;
2493 CYIdentifier *name_;
c5587ed7 2494
5b4dabb2 2495 CYExternalDefinition(CYString *abi, CYType *type, CYIdentifier *name) :
c5587ed7 2496 abi_(abi),
5b4dabb2
JF
2497 type_(type),
2498 name_(name)
c5587ed7
JF
2499 {
2500 }
2501
efd689d8
JF
2502 CYCompact(None)
2503
c5587ed7
JF
2504 virtual CYStatement *Replace(CYContext &context);
2505 virtual void Output(CYOutput &out, CYFlags flags) const;
64a505ff
JF
2506};
2507
2508struct CYTypeExpression :
2509 CYTarget
2510{
5b4dabb2 2511 CYType *typed_;
64a505ff 2512
5b4dabb2 2513 CYTypeExpression(CYType *typed) :
64a505ff
JF
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;
c5587ed7
JF
2522};
2523
60097023
JF
2524struct CYTypeDefinition :
2525 CYStatement
2526{
5b4dabb2
JF
2527 CYType *type_;
2528 CYIdentifier *name_;
60097023 2529
5b4dabb2
JF
2530 CYTypeDefinition(CYType *type, CYIdentifier *name) :
2531 type_(type),
2532 name_(name)
60097023
JF
2533 {
2534 }
2535
efd689d8
JF
2536 CYCompact(None)
2537
60097023
JF
2538 virtual CYStatement *Replace(CYContext &context);
2539 virtual void Output(CYOutput &out, CYFlags flags) const;
2540};
2541
3fe16be7
JF
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
7085e1ab 2555 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
5b4dabb2 2556 void Output(CYOutput &out, CYPropertyName *name) const override;
3fe16be7
JF
2557};
2558
663c538f
JF
2559struct CYTypeFunctionWith :
2560 CYTypeModifier
2561{
574d4720 2562 bool variadic_;
663c538f
JF
2563 CYTypedParameter *parameters_;
2564
574d4720 2565 CYTypeFunctionWith(bool variadic, CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
663c538f 2566 CYTypeModifier(next),
574d4720 2567 variadic_(variadic),
663c538f
JF
2568 parameters_(parameters)
2569 {
2570 }
2571
9a39f705 2572 CYPrecedence(1)
663c538f 2573
7085e1ab 2574 virtual CYTarget *Replace_(CYContext &context, CYTarget *type);
5b4dabb2 2575 void Output(CYOutput &out, CYPropertyName *name) const override;
00b4cb83
JF
2576
2577 virtual CYTypeFunctionWith *Function() { return this; }
663c538f
JF
2578};
2579
b3c38c5f
JF
2580struct CYTypeStructField :
2581 CYNext<CYTypeStructField>
2582{
5b4dabb2
JF
2583 CYType *type_;
2584 CYPropertyName *name_;
b3c38c5f 2585
5b4dabb2 2586 CYTypeStructField(CYType *type, CYPropertyName *name, CYTypeStructField *next = NULL) :
b3c38c5f 2587 CYNext<CYTypeStructField>(next),
5b4dabb2
JF
2588 type_(type),
2589 name_(name)
b3c38c5f
JF
2590 {
2591 }
2592};
2593
d8380373
JF
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
b3c38c5f
JF
2608struct CYTypeStruct :
2609 CYTypeSpecifier
2610{
2611 CYIdentifier *name_;
d8380373 2612 CYStructTail *tail_;
b3c38c5f 2613
d8380373 2614 CYTypeStruct(CYIdentifier *name, CYStructTail *tail) :
b3c38c5f 2615 name_(name),
d8380373 2616 tail_(tail)
b3c38c5f
JF
2617 {
2618 }
2619
2620 virtual CYTarget *Replace(CYContext &context);
2621 virtual void Output(CYOutput &out) const;
2622};
2623
d8380373
JF
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
aaa29c28
JF
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
37954781
JF
2674namespace cy {
2675namespace Syntax {
2676
2677struct Catch :
2678 CYThing
2679{
2680 CYIdentifier *name_;
b0385401 2681 CYStatement *code_;
37954781 2682
b0385401 2683 Catch(CYIdentifier *name, CYStatement *code) :
37954781 2684 name_(name),
b0385401 2685 code_(code)
37954781
JF
2686 {
2687 }
2688
2689 void Replace(CYContext &context);
2690 virtual void Output(CYOutput &out) const;
2691};
2692
2693struct Try :
cf7d4c69
JF
2694 CYStatement
2695{
b0385401 2696 CYStatement *code_;
37954781 2697 Catch *catch_;
b10bd496 2698 CYFinally *finally_;
cf7d4c69 2699
b0385401
JF
2700 Try(CYStatement *code, Catch *_catch, CYFinally *finally) :
2701 code_(code),
cf7d4c69
JF
2702 catch_(_catch),
2703 finally_(finally)
2704 {
2705 }
5999c315 2706
efd689d8
JF
2707 CYCompact(Short)
2708
3b52fd1a 2709 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 2710 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
2711};
2712
37954781 2713struct Throw :
cf7d4c69
JF
2714 CYStatement
2715{
2716 CYExpression *value_;
2717
ab2aa221 2718 Throw(CYExpression *value = NULL) :
cf7d4c69
JF
2719 value_(value)
2720 {
2721 }
5999c315 2722
efd689d8
JF
2723 CYCompact(None)
2724
3b52fd1a 2725 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 2726 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
2727};
2728
37954781
JF
2729} }
2730
cf7d4c69
JF
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 }
5999c315 2742
efd689d8
JF
2743 CYCompact(Long)
2744
3b52fd1a 2745 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 2746 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
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 }
5999c315 2760
efd689d8
JF
2761 CYCompact(Long)
2762
3b52fd1a 2763 virtual CYStatement *Replace(CYContext &context);
c8a0500b
JF
2764 virtual void Output(CYOutput &out, CYFlags flags) const;
2765};
2766
2767struct CYDebugger :
2768 CYStatement
2769{
2770 CYDebugger()
2771 {
2772 }
2773
efd689d8
JF
2774 CYCompact(None)
2775
c8a0500b 2776 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 2777 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
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) :
91a416e4 2788 test_(test),
cf7d4c69
JF
2789 true_(_true),
2790 false_(_false)
2791 {
2792 }
5999c315 2793
d35a3b07
JF
2794 CYPrecedence(15)
2795
3b52fd1a 2796 virtual CYExpression *Replace(CYContext &context);
652ec1ba 2797 virtual void Output(CYOutput &out, CYFlags flags) const;
5999c315
JF
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
b09da87b 2812 CYAlphabetic(false)
d35a3b07 2813
3b52fd1a 2814 virtual CYExpression *Replace(CYContext &context);
5999c315
JF
2815};
2816
2817struct CYIndirect :
7085e1ab 2818 CYTarget
5999c315 2819{
7085e1ab
JF
2820 CYExpression *rhs_;
2821
5999c315 2822 CYIndirect(CYExpression *rhs) :
7085e1ab 2823 rhs_(rhs)
5999c315
JF
2824 {
2825 }
2826
7085e1ab
JF
2827 // XXX: this should be checked
2828 CYPrecedence(2)
d35a3b07 2829
7085e1ab
JF
2830 virtual CYTarget *Replace(CYContext &context);
2831 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
2832};
2833
4644480a
JF
2834#define CYReplace \
2835 virtual CYExpression *Replace(CYContext &context);
2836
2837#define CYPostfix_(op, name, args...) \
cf7d4c69
JF
2838 struct CY ## name : \
2839 CYPostfix \
4644480a 2840 { args \
cf7d4c69
JF
2841 CY ## name(CYExpression *lhs) : \
2842 CYPostfix(lhs) \
2843 { \
2844 } \
5999c315
JF
2845 \
2846 virtual const char *Operator() const { \
2847 return op; \
2848 } \
cf7d4c69
JF
2849 };
2850
4644480a 2851#define CYPrefix_(alphabetic, op, name, args...) \
cf7d4c69
JF
2852 struct CY ## name : \
2853 CYPrefix \
4644480a 2854 { args \
cf7d4c69
JF
2855 CY ## name(CYExpression *rhs) : \
2856 CYPrefix(rhs) \
2857 { \
2858 } \
d35a3b07 2859 \
b09da87b 2860 CYAlphabetic(alphabetic) \
5999c315
JF
2861 \
2862 virtual const char *Operator() const { \
2863 return op; \
2864 } \
cf7d4c69
JF
2865 };
2866
4644480a 2867#define CYInfix_(alphabetic, precedence, op, name, args...) \
cf7d4c69
JF
2868 struct CY ## name : \
2869 CYInfix \
4644480a 2870 { args \
cf7d4c69
JF
2871 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
2872 CYInfix(lhs, rhs) \
2873 { \
2874 } \
d35a3b07 2875 \
b09da87b 2876 CYAlphabetic(alphabetic) \
d35a3b07 2877 CYPrecedence(precedence) \
5999c315
JF
2878 \
2879 virtual const char *Operator() const { \
2880 return op; \
2881 } \
cf7d4c69
JF
2882 };
2883
4644480a 2884#define CYAssignment_(op, name, args...) \
cf7d4c69
JF
2885 struct CY ## name ## Assign : \
2886 CYAssignment \
4644480a 2887 { args \
7085e1ab 2888 CY ## name ## Assign(CYTarget *lhs, CYExpression *rhs) : \
cf7d4c69
JF
2889 CYAssignment(lhs, rhs) \
2890 { \
2891 } \
5999c315
JF
2892 \
2893 virtual const char *Operator() const { \
2894 return op; \
2895 } \
cf7d4c69
JF
2896 };
2897
2898CYPostfix_("++", PostIncrement)
2899CYPostfix_("--", PostDecrement)
2900
b09da87b
JF
2901CYPrefix_(true, "delete", Delete)
2902CYPrefix_(true, "void", Void)
2903CYPrefix_(true, "typeof", TypeOf)
2904CYPrefix_(false, "++", PreIncrement)
2905CYPrefix_(false, "--", PreDecrement)
c0bc320e 2906CYPrefix_(false, "+", Affirm)
b09da87b
JF
2907CYPrefix_(false, "-", Negate)
2908CYPrefix_(false, "~", BitwiseNot)
2909CYPrefix_(false, "!", LogicalNot)
2910
62f398e4 2911CYInfix_(false, 5, "*", Multiply, CYReplace)
b09da87b
JF
2912CYInfix_(false, 5, "/", Divide)
2913CYInfix_(false, 5, "%", Modulus)
4644480a 2914CYInfix_(false, 6, "+", Add, CYReplace)
b09da87b
JF
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)
cf7d4c69
JF
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
c5fa2867 2948#endif/*CYCRIPT_PARSER_HPP*/