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