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