]> git.saurik.com Git - cycript.git/blame - Syntax.hpp
Use fauxsu (from DHowett) to fix .deb permissions.
[cycript.git] / Syntax.hpp
CommitLineData
b3378a02 1/* Cycript - Optimizing JavaScript Compiler/Runtime
c1d3e52e 2 * Copyright (C) 2009-2015 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>
029bc65b
JF
31#include <map>
32#include <set>
cf7d4c69 33
da2af935 34#include "List.hpp"
00b4cb83 35#include "Location.hpp"
029bc65b 36#include "Options.hpp"
20052ff7 37#include "Pooling.hpp"
029bc65b 38
01d0f64d 39struct CYContext;
924f67b2 40
5999c315 41struct CYThing {
652ec1ba 42 virtual void Output(struct CYOutput &out) const = 0;
5999c315
JF
43};
44
652ec1ba 45struct CYOutput {
efd689d8
JF
46 std::streambuf &out_;
47 CYPosition position_;
48
029bc65b 49 CYOptions &options_;
11c1cc16
JF
50 bool pretty_;
51 unsigned indent_;
efd689d8 52 unsigned recent_;
320ce753 53 bool right_;
652ec1ba 54
96a7e5c2
JF
55 enum {
56 NoMode,
57 NoLetter,
c0bc320e 58 NoPlus,
96a7e5c2
JF
59 NoHyphen,
60 Terminated
61 } mode_;
62
efd689d8 63 CYOutput(std::streambuf &out, CYOptions &options) :
11c1cc16 64 out_(out),
029bc65b 65 options_(options),
11c1cc16 66 pretty_(false),
96a7e5c2 67 indent_(0),
efd689d8 68 recent_(0),
320ce753 69 right_(false),
96a7e5c2 70 mode_(NoMode)
652ec1ba
JF
71 {
72 }
73
96a7e5c2 74 void Check(char value);
1fdca2fa 75 void Terminate();
652ec1ba 76
efd689d8
JF
77 _finline void operator ()(char value) {
78 _assert(out_.sputc(value) != EOF);
79 recent_ = indent_;
80 if (value == '\n')
81 position_.lines(1);
82 else
83 position_.columns(1);
84 }
85
86 _finline void operator ()(const char *data, std::streamsize size) {
87 _assert(out_.sputn(data, size) == size);
88 recent_ = indent_;
89 position_.columns(size);
90 }
91
92 _finline void operator ()(const char *data) {
93 return operator ()(data, strlen(data));
94 }
95
96a7e5c2
JF
96 CYOutput &operator <<(char rhs);
97 CYOutput &operator <<(const char *rhs);
98
99 _finline CYOutput &operator <<(const CYThing *rhs) {
100 if (rhs != NULL)
101 rhs->Output(*this);
652ec1ba
JF
102 return *this;
103 }
104
105 _finline CYOutput &operator <<(const CYThing &rhs) {
106 rhs.Output(*this);
107 return *this;
108 }
109};
5999c315 110
e5bc40db 111struct CYPropertyName {
652ec1ba 112 virtual void PropertyName(CYOutput &out) const = 0;
e5bc40db
JF
113};
114
3b52fd1a 115struct CYExpression;
ae65d594 116struct CYAssignment;
3b52fd1a
JF
117
118enum CYNeeded {
119 CYNever = -1,
120 CYSometimes = 0,
121 CYAlways = 1,
122};
123
124enum CYFlags {
125 CYNoFlags = 0,
126 CYNoBrace = (1 << 0),
127 CYNoFunction = (1 << 1),
128 CYNoIn = (1 << 2),
129 CYNoCall = (1 << 3),
130 CYNoRightHand = (1 << 4),
131 CYNoDangle = (1 << 5),
9561f209 132 CYNoInteger = (1 << 6),
3b52fd1a
JF
133 CYNoBF = (CYNoBrace | CYNoFunction),
134};
135
5a6d4d25
JF
136_finline CYFlags operator ~(CYFlags rhs) {
137 return static_cast<CYFlags>(~static_cast<unsigned>(rhs));
138}
139
140_finline CYFlags operator &(CYFlags lhs, CYFlags rhs) {
141 return static_cast<CYFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs));
142}
143
144_finline CYFlags operator |(CYFlags lhs, CYFlags rhs) {
145 return static_cast<CYFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs));
146}
147
148_finline CYFlags &operator |=(CYFlags &lhs, CYFlags rhs) {
149 return lhs = lhs | rhs;
150}
151
152_finline CYFlags CYLeft(CYFlags flags) {
153 return flags & ~(CYNoDangle | CYNoInteger);
154}
155
156_finline CYFlags CYRight(CYFlags flags) {
157 return flags & ~CYNoBF;
158}
159
160_finline CYFlags CYCenter(CYFlags flags) {
161 return CYLeft(CYRight(flags));
162}
163
efd689d8
JF
164enum CYCompactType {
165 CYCompactNone,
166 CYCompactLong,
167 CYCompactShort,
168};
169
170#define CYCompact(type) \
171 virtual CYCompactType Compact() const { \
172 return CYCompact ## type; \
173 }
174
3b52fd1a 175struct CYStatement :
b0385401
JF
176 CYNext<CYStatement>,
177 CYThing
3b52fd1a 178{
efd689d8 179 void Single(CYOutput &out, CYFlags flags, CYCompactType request) const;
3b52fd1a 180 void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
b0385401 181 virtual void Output(CYOutput &out) const;
3b52fd1a 182
3b52fd1a
JF
183 virtual CYStatement *Replace(CYContext &context) = 0;
184
efd689d8 185 virtual CYCompactType Compact() const = 0;
12e37ba3
JF
186 virtual CYStatement *Return();
187
3b52fd1a
JF
188 private:
189 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
190};
191
192struct CYStatements {
193 CYStatement *first_;
194 CYStatement *last_;
195
196 CYStatements() :
197 first_(NULL),
198 last_(NULL)
199 {
200 }
201
202 operator CYStatement *() const {
203 return first_;
204 }
205
206 CYStatements &operator ->*(CYStatement *next) {
207 if (next != NULL)
208 if (first_ == NULL) {
209 first_ = next;
210 last_ = next;
211 } else for (;; last_ = last_->next_)
212 if (last_->next_ == NULL) {
213 last_->next_ = next;
214 last_ = next;
215 break;
216 }
217 return *this;
218 }
219};
220
e5bc40db 221struct CYClassName {
3b52fd1a 222 virtual CYExpression *ClassName(CYContext &context, bool object) = 0;
652ec1ba 223 virtual void ClassName(CYOutput &out, bool object) const = 0;
63b4c5a8
JF
224};
225
cf7d4c69 226struct CYWord :
e5bc40db
JF
227 CYThing,
228 CYPropertyName,
229 CYClassName
63b4c5a8 230{
cf7d4c69
JF
231 const char *word_;
232
233 CYWord(const char *word) :
234 word_(word)
235 {
236 }
237
029bc65b
JF
238 void Set(const char *value) {
239 word_ = value;
cf7d4c69
JF
240 }
241
029bc65b 242 virtual const char *Word() const;
652ec1ba 243 virtual void Output(CYOutput &out) const;
e5bc40db 244
3b52fd1a 245 virtual CYExpression *ClassName(CYContext &context, bool object);
652ec1ba
JF
246 virtual void ClassName(CYOutput &out, bool object) const;
247 virtual void PropertyName(CYOutput &out) const;
63b4c5a8
JF
248};
249
652ec1ba 250_finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) {
029bc65b
JF
251 lhs << &rhs << '=';
252 return lhs << rhs.Word();
652ec1ba
JF
253}
254
cf7d4c69 255struct CYIdentifier :
14ec9e00 256 CYNext<CYIdentifier>,
cf7d4c69 257 CYWord
63b4c5a8 258{
029bc65b 259 CYIdentifier *replace_;
6a981250 260 size_t offset_;
e013809d 261 size_t usage_;
029bc65b 262
5999c315 263 CYIdentifier(const char *word) :
029bc65b 264 CYWord(word),
6a981250 265 replace_(NULL),
e013809d
JF
266 offset_(0),
267 usage_(0)
5999c315 268 {
cf7d4c69 269 }
029bc65b
JF
270
271 virtual const char *Word() const;
272 CYIdentifier *Replace(CYContext &context);
63b4c5a8
JF
273};
274
62014ea9 275struct CYLabel :
3b52fd1a 276 CYStatement
62014ea9 277{
9e562cfc 278 CYIdentifier *name_;
3b52fd1a 279 CYStatement *statement_;
cf7d4c69 280
3b52fd1a
JF
281 CYLabel(CYIdentifier *name, CYStatement *statement) :
282 name_(name),
283 statement_(statement)
cf7d4c69
JF
284 {
285 }
fb98ac0c 286
efd689d8
JF
287 CYCompact(Short)
288
3b52fd1a
JF
289 virtual CYStatement *Replace(CYContext &context);
290 virtual void Output(CYOutput &out, CYFlags flags) const;
fb98ac0c
JF
291};
292
14ec9e00 293struct CYCStringLess :
029bc65b
JF
294 std::binary_function<const char *, const char *, bool>
295{
296 _finline bool operator ()(const char *lhs, const char *rhs) const {
297 return strcmp(lhs, rhs) < 0;
298 }
299};
300
301struct CYIdentifierValueLess :
302 std::binary_function<CYIdentifier *, CYIdentifier *, bool>
303{
304 _finline bool operator ()(CYIdentifier *lhs, CYIdentifier *rhs) const {
14ec9e00 305 return CYCStringLess()(lhs->Word(), rhs->Word());
029bc65b
JF
306 }
307};
308
309enum CYIdentifierFlags {
310 CYIdentifierArgument,
14ec9e00
JF
311 CYIdentifierVariable,
312 CYIdentifierOther,
313 CYIdentifierMagic,
daf22a65 314 CYIdentifierCatch,
029bc65b
JF
315};
316
14ec9e00 317typedef std::set<const char *, CYCStringLess> CYCStringSet;
029bc65b 318typedef std::set<CYIdentifier *, CYIdentifierValueLess> CYIdentifierValueSet;
029bc65b
JF
319typedef std::map<CYIdentifier *, CYIdentifierFlags> CYIdentifierAddressFlagsMap;
320
e013809d
JF
321struct CYIdentifierUsage {
322 CYIdentifier *identifier_;
323 size_t usage_;
324};
325
326typedef std::vector<CYIdentifierUsage> CYIdentifierUsageVector;
327
029bc65b 328struct CYScope {
61fe0c53 329 bool transparent_;
029bc65b 330 CYScope *parent_;
a86e34d0 331
a846a8cd 332 CYIdentifierAddressFlagsMap internal_;
a86e34d0 333 CYIdentifierValueSet identifiers_;
029bc65b 334
50a3d79f 335 CYScope(bool transparent, CYContext &context);
0a356474 336
a86e34d0
JF
337 void Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags);
338 virtual CYIdentifier *Lookup(CYContext &context, CYIdentifier *identifier);
6a981250 339 void Merge(CYContext &context, CYIdentifier *identifier);
50a3d79f 340 void Close(CYContext &context, CYStatement *&statements);
029bc65b
JF
341};
342
a7d8b413 343struct CYScript :
3b52fd1a 344 CYThing
63b4c5a8 345{
b0385401 346 CYStatement *code_;
9e562cfc 347
a7d8b413 348 CYScript(CYStatement *code) :
b0385401 349 code_(code)
9e562cfc
JF
350 {
351 }
cf7d4c69 352
3b52fd1a 353 virtual void Replace(CYContext &context);
3b52fd1a 354 virtual void Output(CYOutput &out) const;
9e562cfc
JF
355};
356
ab2aa221 357struct CYNonLocal;
a0be43fc 358struct CYThisScope;
ab2aa221 359
2c81c6df 360struct CYContext {
6a981250 361 CYOptions &options_;
ab2aa221 362
6a981250 363 CYScope *scope_;
a0be43fc
JF
364 CYThisScope *this_;
365
a846a8cd 366 CYIdentifierUsageVector rename_;
6a981250 367
ab2aa221 368 CYNonLocal *nonlocal_;
06293152 369 CYNonLocal *nextlocal_;
ab2aa221
JF
370 unsigned unique_;
371
2eb8215d 372 CYContext(CYOptions &options) :
6a981250 373 options_(options),
ab2aa221 374 scope_(NULL),
a0be43fc 375 this_(NULL),
ab2aa221 376 nonlocal_(NULL),
06293152 377 nextlocal_(NULL),
ab2aa221 378 unique_(0)
6a981250
JF
379 {
380 }
381
b0385401
JF
382 void ReplaceAll(CYStatement *&statement) {
383 if (statement == NULL)
384 return;
385 CYStatement *next(statement->next_);
386
387 Replace(statement);
388 ReplaceAll(next);
389
390 if (statement == NULL)
391 statement = next;
392 else
393 statement->SetNext(next);
cde20a5a
JF
394 }
395
6a981250
JF
396 template <typename Type_>
397 void Replace(Type_ *&value) {
398 for (;;) if (value == NULL)
399 break;
400 else {
401 Type_ *replace(value->Replace(*this));
402 if (replace != value)
403 value = replace;
404 else break;
405 }
406 }
ab2aa221
JF
407
408 void NonLocal(CYStatement *&statements);
409 CYIdentifier *Unique();
410};
411
412struct CYNonLocal {
413 CYIdentifier *identifier_;
414
415 CYNonLocal() :
416 identifier_(NULL)
417 {
418 }
419
420 CYIdentifier *Target(CYContext &context) {
421 if (identifier_ == NULL)
422 identifier_ = context.Unique();
423 return identifier_;
424 }
6a981250
JF
425};
426
a0be43fc
JF
427struct CYThisScope :
428 CYNext<CYThisScope>
429{
430 CYIdentifier *identifier_;
431
432 CYThisScope() :
433 identifier_(NULL)
434 {
435 }
436
437 CYIdentifier *Identifier(CYContext &context) {
438 if (next_ != NULL)
439 return next_->Identifier(context);
440 if (identifier_ == NULL)
441 identifier_ = context.Unique();
442 return identifier_;
443 }
444};
445
9e562cfc 446struct CYBlock :
b0385401 447 CYStatement
9e562cfc 448{
b0385401 449 CYStatement *code_;
9e562cfc 450
b0385401
JF
451 CYBlock(CYStatement *code) :
452 code_(code)
9e562cfc 453 {
cf7d4c69 454 }
9e562cfc 455
efd689d8
JF
456 CYCompact(Short)
457
3b52fd1a
JF
458 virtual CYStatement *Replace(CYContext &context);
459
fb98ac0c 460 virtual void Output(CYOutput &out, CYFlags flags) const;
12e37ba3
JF
461
462 virtual CYStatement *Return();
cf7d4c69
JF
463};
464
a7d8b413 465struct CYForInitializer {
029bc65b 466 virtual CYExpression *Replace(CYContext &context) = 0;
15b88a33 467 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
dea834b0
JF
468};
469
a7d8b413 470struct CYForInInitializer {
652ec1ba 471 virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
ad3b38bb 472 virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value) = 0;
b158281e 473
029bc65b 474 virtual CYExpression *Replace(CYContext &context) = 0;
ae65d594 475 virtual CYAssignment *Assignment(CYContext &context) = 0;
c8a0500b
JF
476
477 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
b09da87b
JF
478};
479
0afc9ba3
JF
480struct CYFunctionParameter;
481
4644480a
JF
482struct CYNumber;
483struct CYString;
484
cf7d4c69 485struct CYExpression :
a7d8b413
JF
486 CYForInitializer,
487 CYForInInitializer,
96a7e5c2
JF
488 CYClassName,
489 CYThing
63b4c5a8 490{
9a39f705 491 virtual int Precedence() const = 0;
75b0a457 492
fb98ac0c
JF
493 virtual bool RightHand() const {
494 return true;
495 }
496
652ec1ba 497 virtual void ForIn(CYOutput &out, CYFlags flags) const;
ad3b38bb 498 virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value);
75b0a457 499
6c093cce
JF
500 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
501
96a7e5c2 502 virtual void Output(CYOutput &out) const;
652ec1ba 503 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
9a39f705 504 void Output(CYOutput &out, int precedence, CYFlags flags) const;
dea834b0 505
3b52fd1a 506 virtual CYExpression *ClassName(CYContext &context, bool object);
652ec1ba 507 virtual void ClassName(CYOutput &out, bool object) const;
e5bc40db 508
3b52fd1a 509 virtual CYExpression *Replace(CYContext &context) = 0;
ae65d594 510 virtual CYAssignment *Assignment(CYContext &context);
3b52fd1a 511
4644480a 512 virtual CYExpression *Primitive(CYContext &context) {
fd5cdf97 513 return NULL;
4644480a
JF
514 }
515
0afc9ba3 516 virtual CYFunctionParameter *Parameter() const;
0afc9ba3 517
4644480a
JF
518 virtual CYNumber *Number(CYContext &context) {
519 return NULL;
520 }
521
522 virtual CYString *String(CYContext &context) {
523 return NULL;
524 }
525
dea834b0
JF
526 virtual const char *Word() const {
527 return NULL;
528 }
63b4c5a8
JF
529};
530
b09da87b
JF
531#define CYAlphabetic(value) \
532 virtual bool Alphabetic() const { \
533 return value; \
534 }
535
d35a3b07 536#define CYPrecedence(value) \
9a39f705
JF
537 static const int Precedence_ = value; \
538 virtual int Precedence() const { \
8351aa30 539 return Precedence_; \
d35a3b07
JF
540 }
541
fb98ac0c
JF
542#define CYRightHand(value) \
543 virtual bool RightHand() const { \
544 return value; \
545 }
546
d35a3b07
JF
547struct CYCompound :
548 CYExpression
549{
fd5cdf97
JF
550 CYExpression *expression_;
551 CYExpression *next_;
d35a3b07 552
b0385401 553 CYCompound(CYExpression *expression, CYExpression *next) :
fd5cdf97
JF
554 expression_(expression),
555 next_(next)
d35a3b07 556 {
fd5cdf97 557 _assert(expression_ != NULL);
b0385401 558 _assert(next != NULL);
d35a3b07
JF
559 }
560
561 CYPrecedence(17)
562
3b52fd1a 563 virtual CYExpression *Replace(CYContext &context);
652ec1ba 564 void Output(CYOutput &out, CYFlags flags) const;
e06e5ee1 565
b0385401
JF
566 virtual CYFunctionParameter *Parameter() const;
567};
568
569struct CYParenthetical :
570 CYExpression
571{
572 CYExpression *expression_;
573
574 CYParenthetical(CYExpression *expression) :
575 expression_(expression)
576 {
577 }
578
579 CYPrecedence(0)
580
581 virtual CYExpression *Replace(CYContext &context);
582 void Output(CYOutput &out, CYFlags flags) const;
d35a3b07 583};
5999c315 584
c8a0500b
JF
585struct CYDeclaration;
586
3b52fd1a
JF
587struct CYFunctionParameter :
588 CYNext<CYFunctionParameter>,
589 CYThing
590{
a7d8b413 591 CYForInInitializer *initialiser_;
3b52fd1a 592
a7d8b413 593 CYFunctionParameter(CYForInInitializer *initialiser, CYFunctionParameter *next = NULL) :
3b52fd1a 594 CYNext<CYFunctionParameter>(next),
c8a0500b 595 initialiser_(initialiser)
4e11a430
JF
596 {
597 }
598
b0385401 599 void Replace(CYContext &context, CYStatement *&statements);
c8a0500b 600 void Output(CYOutput &out) const;
3b52fd1a
JF
601};
602
75b0a457 603struct CYComprehension :
96a7e5c2
JF
604 CYNext<CYComprehension>,
605 CYThing
75b0a457 606{
c2529502
JF
607 CYComprehension(CYComprehension *next = NULL) :
608 CYNext<CYComprehension>(next)
609 {
610 }
611
b3aa25d8
JF
612 CYComprehension *Modify(CYComprehension *next) {
613 next_ = next;
614 return this;
615 }
616
75b0a457
JF
617 virtual const char *Name() const = 0;
618
3b52fd1a
JF
619 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
620 CYFunctionParameter *Parameters(CYContext &context) const;
621 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 622 virtual void Output(CYOutput &out) const = 0;
75b0a457
JF
623};
624
625struct CYForInComprehension :
626 CYComprehension
627{
628 CYIdentifier *name_;
629 CYExpression *set_;
630
c2529502
JF
631 CYForInComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) :
632 CYComprehension(next),
75b0a457
JF
633 name_(name),
634 set_(set)
635 {
636 }
637
638 virtual const char *Name() const {
029bc65b 639 return name_->Word();
75b0a457
JF
640 }
641
3b52fd1a
JF
642 virtual CYFunctionParameter *Parameter(CYContext &context) const;
643 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 644 virtual void Output(CYOutput &out) const;
75b0a457
JF
645};
646
d5618df7 647struct CYForOfComprehension :
75b0a457
JF
648 CYComprehension
649{
650 CYIdentifier *name_;
651 CYExpression *set_;
652
c2529502
JF
653 CYForOfComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) :
654 CYComprehension(next),
75b0a457
JF
655 name_(name),
656 set_(set)
657 {
658 }
659
660 virtual const char *Name() const {
029bc65b 661 return name_->Word();
75b0a457
JF
662 }
663
3b52fd1a
JF
664 virtual CYFunctionParameter *Parameter(CYContext &context) const;
665 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 666 virtual void Output(CYOutput &out) const;
75b0a457
JF
667};
668
669struct CYIfComprehension :
670 CYComprehension
671{
672 CYExpression *test_;
673
b3aa25d8
JF
674 CYIfComprehension(CYExpression *test, CYComprehension *next = NULL) :
675 CYComprehension(next),
75b0a457
JF
676 test_(test)
677 {
678 }
679
680 virtual const char *Name() const {
681 return NULL;
682 }
683
3b52fd1a
JF
684 virtual CYFunctionParameter *Parameter(CYContext &context) const;
685 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
4644480a 686 virtual void Output(CYOutput &out) const;
75b0a457
JF
687};
688
689struct CYArrayComprehension :
690 CYExpression
691{
692 CYExpression *expression_;
693 CYComprehension *comprehensions_;
694
695 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
696 expression_(expression),
697 comprehensions_(comprehensions)
698 {
699 }
700
701 CYPrecedence(0)
702
3b52fd1a 703 virtual CYExpression *Replace(CYContext &context);
652ec1ba 704 virtual void Output(CYOutput &out, CYFlags flags) const;
75b0a457
JF
705};
706
cf7d4c69
JF
707struct CYLiteral :
708 CYExpression
63b4c5a8 709{
d35a3b07 710 CYPrecedence(0)
fb98ac0c 711 CYRightHand(false)
fd5cdf97
JF
712
713 virtual CYExpression *Primitive(CYContext &context) {
714 return this;
715 }
cf7d4c69 716};
63b4c5a8 717
3b52fd1a
JF
718struct CYTrivial :
719 CYLiteral
720{
721 virtual CYExpression *Replace(CYContext &context);
722};
723
478d4ed0
JF
724struct CYMagic :
725 CYExpression
726{
727 CYPrecedence(0)
fb98ac0c 728 CYRightHand(false)
478d4ed0
JF
729};
730
dea834b0
JF
731struct CYRange {
732 uint64_t lo_;
733 uint64_t hi_;
734
735 CYRange(uint64_t lo, uint64_t hi) :
736 lo_(lo), hi_(hi)
737 {
738 }
739
740 bool operator [](uint8_t value) const {
741 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
742 }
743
744 void operator()(uint8_t value) {
745 if (value >> 7)
746 return;
747 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
748 }
749};
750
283e7e33 751extern CYRange DigitRange_;
dea834b0
JF
752extern CYRange WordStartRange_;
753extern CYRange WordEndRange_;
754
cf7d4c69 755struct CYString :
3b52fd1a 756 CYTrivial,
e5bc40db 757 CYPropertyName
cf7d4c69
JF
758{
759 const char *value_;
5999c315 760 size_t size_;
cf7d4c69 761
3b52fd1a
JF
762 CYString() :
763 value_(NULL),
764 size_(0)
765 {
766 }
767
768 CYString(const char *value) :
769 value_(value),
770 size_(strlen(value))
771 {
772 }
773
5999c315
JF
774 CYString(const char *value, size_t size) :
775 value_(value),
776 size_(size)
cf7d4c69
JF
777 {
778 }
779
3b52fd1a 780 CYString(const CYWord *word) :
029bc65b 781 value_(word->Word()),
5999c315 782 size_(strlen(value_))
cf7d4c69
JF
783 {
784 }
785
5999c315 786 const char *Value() const {
cf7d4c69
JF
787 return value_;
788 }
789
11c1cc16 790 virtual const char *Word() const;
dea834b0 791
4644480a
JF
792 virtual CYNumber *Number(CYContext &context);
793 virtual CYString *String(CYContext &context);
794
5db9a7f5 795 CYString *Concat(CYContext &out, CYString *rhs) const;
652ec1ba
JF
796 virtual void Output(CYOutput &out, CYFlags flags) const;
797 virtual void PropertyName(CYOutput &out) const;
63b4c5a8
JF
798};
799
fc8fc33d 800struct CYElementValue;
b900e1a4
JF
801
802struct CYSpan :
803 CYNext<CYSpan>
804{
805 CYExpression *expression_;
806 CYString *string_;
807
808 CYSpan(CYExpression *expression, CYString *string, CYSpan *next) :
809 CYNext<CYSpan>(next),
810 expression_(expression),
811 string_(string)
812 {
813 }
814
fc8fc33d 815 CYElementValue *Replace(CYContext &context);
b900e1a4
JF
816};
817
818struct CYTemplate :
819 CYExpression
820{
821 CYString *string_;
822 CYSpan *spans_;
823
824 CYTemplate(CYString *string, CYSpan *spans) :
825 string_(string),
826 spans_(spans)
827 {
828 }
829
830 CYPrecedence(0)
831 CYRightHand(false)
832
833 virtual CYExpression *Replace(CYContext &context);
834 virtual void Output(CYOutput &out, CYFlags flags) const;
835};
836
cf7d4c69 837struct CYNumber :
3b52fd1a 838 CYTrivial,
e5bc40db 839 CYPropertyName
cf7d4c69 840{
5999c315
JF
841 double value_;
842
843 CYNumber(double value) :
844 value_(value)
845 {
846 }
847
848 double Value() const {
849 return value_;
cf7d4c69
JF
850 }
851
4644480a
JF
852 virtual CYNumber *Number(CYContext &context);
853 virtual CYString *String(CYContext &context);
854
652ec1ba
JF
855 virtual void Output(CYOutput &out, CYFlags flags) const;
856 virtual void PropertyName(CYOutput &out) const;
cf7d4c69
JF
857};
858
63cd45c9 859struct CYRegEx :
3b52fd1a 860 CYTrivial
63cd45c9
JF
861{
862 const char *value_;
c8a2a786 863 size_t size_;
63cd45c9 864
c8a2a786
JF
865 CYRegEx(const char *value, size_t size) :
866 value_(value),
867 size_(size)
63cd45c9
JF
868 {
869 }
870
871 const char *Value() const {
872 return value_;
873 }
874
875 virtual void Output(CYOutput &out, CYFlags flags) const;
876};
877
cf7d4c69 878struct CYNull :
3b52fd1a 879 CYTrivial
cf7d4c69 880{
4644480a
JF
881 virtual CYNumber *Number(CYContext &context);
882 virtual CYString *String(CYContext &context);
883
652ec1ba 884 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
885};
886
887struct CYThis :
478d4ed0 888 CYMagic
cf7d4c69 889{
3b52fd1a 890 virtual CYExpression *Replace(CYContext &context);
652ec1ba 891 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
892};
893
894struct CYBoolean :
3b52fd1a 895 CYTrivial
cf7d4c69 896{
5999c315 897 virtual bool Value() const = 0;
652ec1ba 898 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
899};
900
901struct CYFalse :
cf7d4c69
JF
902 CYBoolean
903{
11c1cc16
JF
904 virtual bool Value() const {
905 return false;
906 }
4644480a
JF
907
908 virtual CYNumber *Number(CYContext &context);
909 virtual CYString *String(CYContext &context);
cf7d4c69
JF
910};
911
912struct CYTrue :
cf7d4c69
JF
913 CYBoolean
914{
11c1cc16
JF
915 virtual bool Value() const {
916 return true;
917 }
4644480a
JF
918
919 virtual CYNumber *Number(CYContext &context);
920 virtual CYString *String(CYContext &context);
cf7d4c69
JF
921};
922
923struct CYVariable :
924 CYExpression
925{
926 CYIdentifier *name_;
927
928 CYVariable(CYIdentifier *name) :
929 name_(name)
930 {
931 }
5999c315 932
2eb8215d
JF
933 CYVariable(const char *name) :
934 name_(new($pool) CYIdentifier(name))
935 {
936 }
937
d35a3b07 938 CYPrecedence(0)
fb98ac0c 939 CYRightHand(false)
d35a3b07 940
3b52fd1a 941 virtual CYExpression *Replace(CYContext &context);
652ec1ba 942 virtual void Output(CYOutput &out, CYFlags flags) const;
0afc9ba3
JF
943
944 virtual CYFunctionParameter *Parameter() const;
cf7d4c69
JF
945};
946
947struct CYPrefix :
63b4c5a8
JF
948 CYExpression
949{
950 CYExpression *rhs_;
951
cf7d4c69 952 CYPrefix(CYExpression *rhs) :
63b4c5a8
JF
953 rhs_(rhs)
954 {
955 }
5999c315 956
b09da87b 957 virtual bool Alphabetic() const = 0;
5999c315
JF
958 virtual const char *Operator() const = 0;
959
3b52fd1a
JF
960 CYPrecedence(4)
961
962 virtual CYExpression *Replace(CYContext &context);
652ec1ba 963 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
964};
965
cf7d4c69 966struct CYInfix :
63b4c5a8
JF
967 CYExpression
968{
969 CYExpression *lhs_;
970 CYExpression *rhs_;
971
cf7d4c69 972 CYInfix(CYExpression *lhs, CYExpression *rhs) :
63b4c5a8
JF
973 lhs_(lhs),
974 rhs_(rhs)
975 {
976 }
5999c315 977
0ff9f149
JF
978 void SetLeft(CYExpression *lhs) {
979 lhs_ = lhs;
980 }
981
b09da87b 982 virtual bool Alphabetic() const = 0;
5999c315
JF
983 virtual const char *Operator() const = 0;
984
3b52fd1a 985 virtual CYExpression *Replace(CYContext &context);
652ec1ba 986 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
987};
988
cf7d4c69 989struct CYPostfix :
63b4c5a8
JF
990 CYExpression
991{
992 CYExpression *lhs_;
993
cf7d4c69 994 CYPostfix(CYExpression *lhs) :
63b4c5a8
JF
995 lhs_(lhs)
996 {
997 }
5999c315
JF
998
999 virtual const char *Operator() const = 0;
1000
3b52fd1a
JF
1001 CYPrecedence(3)
1002
1003 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1004 virtual void Output(CYOutput &out, CYFlags flags) const;
63b4c5a8
JF
1005};
1006
cf7d4c69 1007struct CYAssignment :
d35a3b07 1008 CYExpression
cf7d4c69 1009{
d35a3b07
JF
1010 CYExpression *lhs_;
1011 CYExpression *rhs_;
1012
cf7d4c69 1013 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
d35a3b07
JF
1014 lhs_(lhs),
1015 rhs_(rhs)
cf7d4c69
JF
1016 {
1017 }
5999c315 1018
0ff9f149
JF
1019 void SetLeft(CYExpression *lhs) {
1020 lhs_ = lhs;
1021 }
1022
5999c315 1023 virtual const char *Operator() const = 0;
d35a3b07 1024
4de0686f
JF
1025 CYPrecedence(16)
1026
3b52fd1a 1027 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1028 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1029};
1030
62014ea9 1031struct CYArgument :
96a7e5c2
JF
1032 CYNext<CYArgument>,
1033 CYThing
62014ea9 1034{
cf7d4c69
JF
1035 CYWord *name_;
1036 CYExpression *value_;
cf7d4c69 1037
3b52fd1a
JF
1038 CYArgument(CYExpression *value, CYArgument *next = NULL) :
1039 CYNext<CYArgument>(next),
1040 name_(NULL),
1041 value_(value)
1042 {
1043 }
1044
cf7d4c69 1045 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
62014ea9 1046 CYNext<CYArgument>(next),
cf7d4c69 1047 name_(name),
62014ea9 1048 value_(value)
cf7d4c69
JF
1049 {
1050 }
5999c315 1051
5192746c 1052 CYArgument *Replace(CYContext &context);
652ec1ba 1053 void Output(CYOutput &out) const;
cf7d4c69
JF
1054};
1055
5999c315
JF
1056struct CYClause :
1057 CYThing,
1058 CYNext<CYClause>
1059{
cf7d4c69 1060 CYExpression *case_;
b0385401 1061 CYStatement *code_;
cf7d4c69 1062
b0385401 1063 CYClause(CYExpression *_case, CYStatement *code) :
cf7d4c69 1064 case_(_case),
b0385401 1065 code_(code)
cf7d4c69
JF
1066 {
1067 }
1068
fa389b0f 1069 void Replace(CYContext &context);
652ec1ba 1070 virtual void Output(CYOutput &out) const;
cf7d4c69
JF
1071};
1072
62014ea9 1073struct CYElement :
96a7e5c2 1074 CYThing
fc8fc33d
JF
1075{
1076 virtual bool Elision() const = 0;
1077
1078 virtual void Replace(CYContext &context) = 0;
1079};
1080
1081struct CYElementValue :
1082 CYNext<CYElement>,
1083 CYElement
62014ea9 1084{
cf7d4c69 1085 CYExpression *value_;
cf7d4c69 1086
fc8fc33d 1087 CYElementValue(CYExpression *value, CYElement *next) :
62014ea9
JF
1088 CYNext<CYElement>(next),
1089 value_(value)
cf7d4c69
JF
1090 {
1091 }
5999c315 1092
fc8fc33d
JF
1093 virtual bool Elision() const {
1094 return value_ == NULL;
1095 }
1096
1097 virtual void Replace(CYContext &context);
1098 virtual void Output(CYOutput &out) const;
1099};
1100
1101struct CYElementSpread :
1102 CYElement
1103{
1104 CYExpression *value_;
1105
1106 CYElementSpread(CYExpression *value) :
1107 value_(value)
1108 {
1109 }
1110
1111 virtual bool Elision() const {
1112 return false;
1113 }
1114
1115 virtual void Replace(CYContext &context);
1116 virtual void Output(CYOutput &out) const;
5befe15e
JF
1117};
1118
1119struct CYArray :
1120 CYLiteral
1121{
1122 CYElement *elements_;
1123
3b52fd1a 1124 CYArray(CYElement *elements = NULL) :
5befe15e
JF
1125 elements_(elements)
1126 {
1127 }
1128
3b52fd1a 1129 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1130 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1131};
1132
550ee46a
JF
1133struct CYProperty :
1134 CYNext<CYProperty>,
1135 CYThing
1136{
1137 CYPropertyName *name_;
1138 CYExpression *value_;
1139
1140 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1141 CYNext<CYProperty>(next),
1142 name_(name),
1143 value_(value)
1144 {
1145 }
1146
1147 void Replace(CYContext &context);
1148 virtual void Output(CYOutput &out) const;
1149};
1150
cf7d4c69 1151struct CYDeclaration :
a7d8b413 1152 CYForInInitializer
cf7d4c69
JF
1153{
1154 CYIdentifier *identifier_;
1155 CYExpression *initialiser_;
1156
550ee46a 1157 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
cf7d4c69
JF
1158 identifier_(identifier),
1159 initialiser_(initialiser)
1160 {
1161 }
5999c315 1162
652ec1ba 1163 virtual void ForIn(CYOutput &out, CYFlags flags) const;
ad3b38bb 1164 virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value);
3b52fd1a 1165
029bc65b 1166 virtual CYExpression *Replace(CYContext &context);
15b88a33 1167
029bc65b 1168 virtual CYAssignment *Assignment(CYContext &context);
15b88a33 1169 CYVariable *Variable(CYContext &context);
75b0a457 1170
652ec1ba 1171 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1172};
1173
1174struct CYDeclarations :
cac61857 1175 CYNext<CYDeclarations>,
15b88a33 1176 CYThing
cf7d4c69
JF
1177{
1178 CYDeclaration *declaration_;
cf7d4c69 1179
cacd1a88 1180 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
cac61857
JF
1181 CYNext<CYDeclarations>(next),
1182 declaration_(declaration)
1183 {
1184 }
1185
15b88a33 1186 void Replace(CYContext &context);
96a7e5c2 1187
b0385401 1188 CYExpression *Expression(CYContext &context);
550ee46a 1189 CYProperty *Property(CYContext &context);
15b88a33
JF
1190 CYArgument *Argument(CYContext &context);
1191 CYFunctionParameter *Parameter(CYContext &context);
3b52fd1a 1192
96a7e5c2 1193 virtual void Output(CYOutput &out) const;
652ec1ba 1194 virtual void Output(CYOutput &out, CYFlags flags) const;
cac61857
JF
1195};
1196
15b88a33 1197struct CYForDeclarations :
a7d8b413 1198 CYForInitializer
15b88a33
JF
1199{
1200 CYDeclarations *declarations_;
1201
1202 CYForDeclarations(CYDeclarations *declarations) :
1203 declarations_(declarations)
1204 {
1205 }
1206
b0385401 1207 virtual CYExpression *Replace(CYContext &context);
15b88a33
JF
1208 virtual void Output(CYOutput &out, CYFlags flags) const;
1209};
1210
cac61857
JF
1211struct CYVar :
1212 CYStatement
1213{
1214 CYDeclarations *declarations_;
1215
1216 CYVar(CYDeclarations *declarations) :
1217 declarations_(declarations)
1218 {
1219 }
1220
efd689d8
JF
1221 CYCompact(None)
1222
3b52fd1a 1223 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1224 virtual void Output(CYOutput &out, CYFlags flags) const;
cac61857
JF
1225};
1226
c8a0500b 1227struct CYLetStatement :
cac61857
JF
1228 CYStatement
1229{
1230 CYDeclarations *declarations_;
15b88a33 1231 CYStatement *code_;
cac61857 1232
c8a0500b 1233 CYLetStatement(CYDeclarations *declarations, CYStatement *code) :
cac61857 1234 declarations_(declarations),
15b88a33 1235 code_(code)
cf7d4c69
JF
1236 {
1237 }
5999c315 1238
efd689d8
JF
1239 CYCompact(Long)
1240
3b52fd1a 1241 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1242 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1243};
1244
cf7d4c69
JF
1245struct CYFor :
1246 CYStatement
1247{
a7d8b413 1248 CYForInitializer *initialiser_;
cf7d4c69
JF
1249 CYExpression *test_;
1250 CYExpression *increment_;
1251 CYStatement *code_;
1252
a7d8b413 1253 CYFor(CYForInitializer *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
cf7d4c69
JF
1254 initialiser_(initialiser),
1255 test_(test),
1256 increment_(increment),
1257 code_(code)
1258 {
1259 }
5999c315 1260
efd689d8
JF
1261 CYCompact(Long)
1262
3b52fd1a 1263 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1264 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1265};
1266
1267struct CYForIn :
1268 CYStatement
1269{
a7d8b413 1270 CYForInInitializer *initialiser_;
cf7d4c69
JF
1271 CYExpression *set_;
1272 CYStatement *code_;
1273
a7d8b413 1274 CYForIn(CYForInInitializer *initialiser, CYExpression *set, CYStatement *code) :
cf7d4c69
JF
1275 initialiser_(initialiser),
1276 set_(set),
1277 code_(code)
1278 {
1279 }
5999c315 1280
efd689d8
JF
1281 CYCompact(Long)
1282
3b52fd1a 1283 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1284 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1285};
1286
d5618df7 1287struct CYForOf :
75b0a457
JF
1288 CYStatement
1289{
a7d8b413 1290 CYForInInitializer *initialiser_;
75b0a457
JF
1291 CYExpression *set_;
1292 CYStatement *code_;
1293
a7d8b413 1294 CYForOf(CYForInInitializer *initialiser, CYExpression *set, CYStatement *code) :
75b0a457
JF
1295 initialiser_(initialiser),
1296 set_(set),
1297 code_(code)
1298 {
1299 }
1300
efd689d8
JF
1301 CYCompact(Long)
1302
3b52fd1a 1303 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1304 virtual void Output(CYOutput &out, CYFlags flags) const;
75b0a457
JF
1305};
1306
693d501b
JF
1307struct CYObject :
1308 CYLiteral
1309{
3b52fd1a 1310 CYProperty *properties_;
693d501b 1311
ab2aa221 1312 CYObject(CYProperty *properties = NULL) :
3b52fd1a 1313 properties_(properties)
693d501b
JF
1314 {
1315 }
1316
3b52fd1a 1317 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1318 void Output(CYOutput &out, CYFlags flags) const;
693d501b
JF
1319};
1320
cf7d4c69
JF
1321struct CYMember :
1322 CYExpression
1323{
1324 CYExpression *object_;
1325 CYExpression *property_;
1326
1327 CYMember(CYExpression *object, CYExpression *property) :
1328 object_(object),
1329 property_(property)
1330 {
1331 }
5999c315 1332
9b5527f0
JF
1333 void SetLeft(CYExpression *object) {
1334 object_ = object;
1335 }
1336};
1337
1338struct CYDirectMember :
1339 CYMember
1340{
1341 CYDirectMember(CYExpression *object, CYExpression *property) :
1342 CYMember(object, property)
1343 {
1344 }
1345
1346 CYPrecedence(1)
fb98ac0c 1347 CYRightHand(false)
9b5527f0 1348
3b52fd1a 1349 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1350 virtual void Output(CYOutput &out, CYFlags flags) const;
9b5527f0
JF
1351};
1352
1353struct CYIndirectMember :
1354 CYMember
1355{
1356 CYIndirectMember(CYExpression *object, CYExpression *property) :
1357 CYMember(object, property)
1358 {
1359 }
1360
d35a3b07 1361 CYPrecedence(1)
fb98ac0c 1362 CYRightHand(false)
d35a3b07 1363
3b52fd1a 1364 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1365 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1366};
1367
2eb8215d
JF
1368namespace cy {
1369namespace Syntax {
1370
1371struct New :
cf7d4c69
JF
1372 CYExpression
1373{
1374 CYExpression *constructor_;
1375 CYArgument *arguments_;
1376
2eb8215d 1377 New(CYExpression *constructor, CYArgument *arguments) :
cf7d4c69
JF
1378 constructor_(constructor),
1379 arguments_(arguments)
1380 {
1381 }
5999c315 1382
9a39f705 1383 virtual int Precedence() const {
fb98ac0c
JF
1384 return arguments_ == NULL ? 2 : 1;
1385 }
1386
1387 CYRightHand(false)
d35a3b07 1388
3b52fd1a 1389 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1390 virtual void Output(CYOutput &out, CYFlags flags) const;
6c093cce
JF
1391
1392 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
cf7d4c69
JF
1393};
1394
2eb8215d
JF
1395} }
1396
cf7d4c69
JF
1397struct CYCall :
1398 CYExpression
1399{
1400 CYExpression *function_;
1401 CYArgument *arguments_;
1402
3b52fd1a 1403 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
cf7d4c69
JF
1404 function_(function),
1405 arguments_(arguments)
1406 {
1407 }
5999c315 1408
fb98ac0c
JF
1409 CYPrecedence(1)
1410 CYRightHand(false)
d35a3b07 1411
3b52fd1a 1412 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1413 virtual void Output(CYOutput &out, CYFlags flags) const;
6c093cce
JF
1414
1415 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
1416};
1417
1418struct CYRubyProc;
1419
1420struct CYRubyBlock :
1421 CYExpression
1422{
1423 CYExpression *call_;
1424 CYRubyProc *proc_;
1425
1426 CYRubyBlock(CYExpression *call, CYRubyProc *proc) :
1427 call_(call),
1428 proc_(proc)
1429 {
1430 }
1431
1432 CYPrecedence(1)
1433 CYRightHand(false)
1434
1435 virtual CYExpression *Replace(CYContext &context);
1436 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1437};
1438
1439struct CYIf :
1440 CYStatement
1441{
1442 CYExpression *test_;
1443 CYStatement *true_;
1444 CYStatement *false_;
1445
3b52fd1a 1446 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
cf7d4c69
JF
1447 test_(test),
1448 true_(_true),
1449 false_(_false)
1450 {
1451 }
5999c315 1452
efd689d8
JF
1453 CYCompact(Long)
1454
3b52fd1a 1455 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1456 virtual void Output(CYOutput &out, CYFlags flags) const;
12e37ba3
JF
1457
1458 virtual CYStatement *Return();
cf7d4c69
JF
1459};
1460
1461struct CYDoWhile :
1462 CYStatement
1463{
1464 CYExpression *test_;
1465 CYStatement *code_;
1466
1467 CYDoWhile(CYExpression *test, CYStatement *code) :
1468 test_(test),
1469 code_(code)
1470 {
1471 }
5999c315 1472
efd689d8
JF
1473 CYCompact(None)
1474
3b52fd1a 1475 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1476 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1477};
1478
1479struct CYWhile :
1480 CYStatement
1481{
1482 CYExpression *test_;
1483 CYStatement *code_;
1484
1485 CYWhile(CYExpression *test, CYStatement *code) :
1486 test_(test),
1487 code_(code)
1488 {
1489 }
5999c315 1490
efd689d8
JF
1491 CYCompact(Long)
1492
3b52fd1a 1493 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1494 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1495};
1496
6c093cce 1497// XXX: this should be split up into CYAnonymousFunction and CYNamedFunction (subclass)
a846a8cd 1498struct CYFunction {
cf7d4c69 1499 CYIdentifier *name_;
b09da87b 1500 CYFunctionParameter *parameters_;
b0385401 1501 CYStatement *code_;
a0be43fc 1502
ab2aa221 1503 CYNonLocal *nonlocal_;
12e37ba3 1504 bool implicit_;
a0be43fc 1505 CYThisScope this_;
cf7d4c69 1506
b0385401 1507 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
cf7d4c69
JF
1508 name_(name),
1509 parameters_(parameters),
b0385401 1510 code_(code),
12e37ba3
JF
1511 nonlocal_(NULL),
1512 implicit_(false)
cf7d4c69
JF
1513 {
1514 }
5999c315 1515
14ec9e00
JF
1516 void Inject(CYContext &context);
1517 virtual void Replace_(CYContext &context, bool outer);
fb98ac0c
JF
1518 virtual void Output(CYOutput &out, CYFlags flags) const;
1519};
1520
6c093cce 1521// XXX: this should be split up into CYAnonymousFunctionExpression and CYNamedFunctionExpression
fb98ac0c
JF
1522struct CYFunctionExpression :
1523 CYFunction,
1524 CYExpression
1525{
b0385401
JF
1526 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
1527 CYFunction(name, parameters, code)
fb98ac0c
JF
1528 {
1529 }
1530
a0be43fc
JF
1531 CYPrecedence(0)
1532 CYRightHand(false)
1533
1534 virtual CYExpression *Replace(CYContext &context);
1535 virtual void Output(CYOutput &out, CYFlags flags) const;
1536};
1537
1538// XXX: this should derive from CYAnonymousFunction
1539struct CYFatArrow :
1540 CYFunction,
1541 CYExpression
1542{
b0385401
JF
1543 CYFatArrow(CYFunctionParameter *parameters, CYStatement *code) :
1544 CYFunction(NULL, parameters, code)
a0be43fc
JF
1545 {
1546 }
1547
d35a3b07 1548 CYPrecedence(0)
fb98ac0c 1549 CYRightHand(false)
d35a3b07 1550
3b52fd1a 1551 virtual CYExpression *Replace(CYContext &context);
652ec1ba 1552 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1553};
1554
6c093cce
JF
1555// XXX: this should derive from CYAnonymousFunctionExpression
1556struct CYRubyProc :
1557 CYFunctionExpression
1558{
b0385401
JF
1559 CYRubyProc(CYFunctionParameter *parameters, CYStatement *code) :
1560 CYFunctionExpression(NULL, parameters, code)
6c093cce
JF
1561 {
1562 }
1563
1564 virtual CYExpression *Replace(CYContext &context);
1565 virtual void Output(CYOutput &out, CYFlags flags) const;
1566};
1567
1568// XXX: this should derive from CYNamedFunction
fb98ac0c
JF
1569struct CYFunctionStatement :
1570 CYFunction,
b10bd496 1571 CYStatement
cf7d4c69 1572{
b0385401
JF
1573 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
1574 CYFunction(name, parameters, code)
cf7d4c69
JF
1575 {
1576 }
5999c315 1577
efd689d8
JF
1578 CYCompact(None)
1579
3b52fd1a 1580 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1581 virtual void Output(CYOutput &out, CYFlags flags) const;
5999c315
JF
1582};
1583
1584struct CYExpress :
1585 CYStatement
1586{
1587 CYExpression *expression_;
1588
1589 CYExpress(CYExpression *expression) :
1590 expression_(expression)
1591 {
fd5cdf97 1592 if (expression_ == NULL)
029bc65b 1593 throw;
5999c315
JF
1594 }
1595
efd689d8
JF
1596 CYCompact(None)
1597
3b52fd1a 1598 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1599 virtual void Output(CYOutput &out, CYFlags flags) const;
12e37ba3
JF
1600
1601 virtual CYStatement *Return();
cf7d4c69
JF
1602};
1603
1604struct CYContinue :
1605 CYStatement
1606{
1607 CYIdentifier *label_;
1608
1609 CYContinue(CYIdentifier *label) :
1610 label_(label)
1611 {
1612 }
5999c315 1613
efd689d8
JF
1614 CYCompact(Short)
1615
3b52fd1a 1616 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1617 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1618};
1619
1620struct CYBreak :
1621 CYStatement
1622{
1623 CYIdentifier *label_;
1624
1625 CYBreak(CYIdentifier *label) :
1626 label_(label)
1627 {
1628 }
5999c315 1629
efd689d8
JF
1630 CYCompact(Short)
1631
3b52fd1a 1632 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1633 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1634};
1635
1636struct CYReturn :
1637 CYStatement
1638{
1639 CYExpression *value_;
1640
1641 CYReturn(CYExpression *value) :
1642 value_(value)
1643 {
1644 }
5999c315 1645
efd689d8
JF
1646 CYCompact(None)
1647
3b52fd1a 1648 virtual CYStatement *Replace(CYContext &context);
9d2b125d
JF
1649 virtual void Output(CYOutput &out, CYFlags flags) const;
1650};
1651
1652struct CYYieldGenerator :
1653 CYExpression
1654{
1655 CYExpression *value_;
1656
1657 CYYieldGenerator(CYExpression *value) :
1658 value_(value)
1659 {
1660 }
1661
1662 CYPrecedence(0)
1663
1664 virtual CYExpression *Replace(CYContext &context);
1665 virtual void Output(CYOutput &out, CYFlags flags) const;
1666};
1667
1668struct CYYieldValue :
1669 CYExpression
1670{
1671 CYExpression *value_;
1672
1673 CYYieldValue(CYExpression *value) :
1674 value_(value)
1675 {
1676 }
1677
1678 CYPrecedence(0)
1679
1680 virtual CYExpression *Replace(CYContext &context);
fb98ac0c 1681 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1682};
1683
1684struct CYEmpty :
1685 CYStatement
1686{
efd689d8
JF
1687 CYCompact(Short)
1688
3b52fd1a 1689 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 1690 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
1691};
1692
96a7e5c2
JF
1693struct CYFinally :
1694 CYThing
1695{
b0385401 1696 CYStatement *code_;
b10bd496 1697
b0385401
JF
1698 CYFinally(CYStatement *code) :
1699 code_(code)
b10bd496
JF
1700 {
1701 }
1702
3b52fd1a 1703 void Replace(CYContext &context);
b10bd496
JF
1704 virtual void Output(CYOutput &out) const;
1705};
1706
3fe283c5
JF
1707struct CYTypeSpecifier :
1708 CYThing
1709{
1710 virtual CYExpression *Replace(CYContext &context) = 0;
1711};
1712
03db6a67
JF
1713struct CYTypeError :
1714 CYTypeSpecifier
1715{
1716 CYTypeError() {
1717 }
1718
1719 virtual CYExpression *Replace(CYContext &context);
1720 virtual void Output(CYOutput &out) const;
1721};
1722
3fe283c5
JF
1723struct CYTypeVoid :
1724 CYTypeSpecifier
1725{
1726 CYTypeVoid() {
1727 }
1728
1729 virtual CYExpression *Replace(CYContext &context);
1730 virtual void Output(CYOutput &out) const;
1731};
1732
1733struct CYTypeVariable :
1734 CYTypeSpecifier
1735{
1736 CYIdentifier *name_;
1737
1738 CYTypeVariable(CYIdentifier *name) :
1739 name_(name)
1740 {
1741 }
1742
1743 CYTypeVariable(const char *name) :
1744 name_(new($pool) CYIdentifier(name))
1745 {
1746 }
1747
1748 virtual CYExpression *Replace(CYContext &context);
1749 virtual void Output(CYOutput &out) const;
1750};
1751
1752struct CYTypeUnsigned :
1753 CYTypeSpecifier
1754{
1755 CYTypeSpecifier *specifier_;
1756
1757 CYTypeUnsigned(CYTypeSpecifier *specifier) :
1758 specifier_(specifier)
1759 {
1760 }
1761
1762 virtual CYExpression *Replace(CYContext &context);
1763 virtual void Output(CYOutput &out) const;
1764};
1765
1766struct CYTypeSigned :
1767 CYTypeSpecifier
1768{
1769 CYTypeSpecifier *specifier_;
1770
1771 CYTypeSigned(CYTypeSpecifier *specifier) :
1772 specifier_(specifier)
1773 {
1774 }
1775
1776 virtual CYExpression *Replace(CYContext &context);
1777 virtual void Output(CYOutput &out) const;
1778};
1779
1780struct CYTypeLong :
1781 CYTypeSpecifier
1782{
1783 CYTypeSpecifier *specifier_;
1784
1785 CYTypeLong(CYTypeSpecifier *specifier) :
1786 specifier_(specifier)
1787 {
1788 }
1789
1790 virtual CYExpression *Replace(CYContext &context);
1791 virtual void Output(CYOutput &out) const;
1792};
1793
1794struct CYTypeShort :
1795 CYTypeSpecifier
1796{
1797 CYTypeSpecifier *specifier_;
1798
1799 CYTypeShort(CYTypeSpecifier *specifier) :
1800 specifier_(specifier)
1801 {
1802 }
1803
1804 virtual CYExpression *Replace(CYContext &context);
1805 virtual void Output(CYOutput &out) const;
1806};
1807
00b4cb83
JF
1808struct CYTypeFunctionWith;
1809
690cf1a8
JF
1810struct CYTypeModifier :
1811 CYNext<CYTypeModifier>
1812{
1813 CYTypeModifier(CYTypeModifier *next) :
1814 CYNext<CYTypeModifier>(next)
1815 {
1816 }
1817
9a39f705
JF
1818 virtual int Precedence() const = 0;
1819
1820 virtual CYExpression *Replace_(CYContext &context, CYExpression *type) = 0;
1821 CYExpression *Replace(CYContext &context, CYExpression *type);
1822
1823 virtual void Output(CYOutput &out, CYIdentifier *identifier) const = 0;
1824 void Output(CYOutput &out, int precedence, CYIdentifier *identifier) const;
00b4cb83
JF
1825
1826 virtual CYTypeFunctionWith *Function() { return NULL; }
690cf1a8
JF
1827};
1828
1829struct CYTypeArrayOf :
1830 CYTypeModifier
1831{
1832 CYExpression *size_;
1833
1834 CYTypeArrayOf(CYExpression *size, CYTypeModifier *next = NULL) :
1835 CYTypeModifier(next),
1836 size_(size)
1837 {
1838 }
1839
9a39f705 1840 CYPrecedence(1)
690cf1a8 1841
9a39f705
JF
1842 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1843 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
690cf1a8
JF
1844};
1845
1846struct CYTypeConstant :
1847 CYTypeModifier
1848{
1849 CYTypeConstant(CYTypeModifier *next = NULL) :
1850 CYTypeModifier(next)
1851 {
1852 }
1853
9a39f705 1854 CYPrecedence(0)
690cf1a8 1855
9a39f705
JF
1856 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1857 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
690cf1a8
JF
1858};
1859
1860struct CYTypePointerTo :
1861 CYTypeModifier
1862{
1863 CYTypePointerTo(CYTypeModifier *next = NULL) :
1864 CYTypeModifier(next)
1865 {
1866 }
1867
9a39f705 1868 CYPrecedence(0)
690cf1a8 1869
9a39f705
JF
1870 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1871 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
690cf1a8
JF
1872};
1873
9a39f705 1874struct CYTypeVolatile :
690cf1a8
JF
1875 CYTypeModifier
1876{
9a39f705
JF
1877 CYTypeVolatile(CYTypeModifier *next = NULL) :
1878 CYTypeModifier(next)
690cf1a8
JF
1879 {
1880 }
1881
9a39f705 1882 CYPrecedence(0)
690cf1a8 1883
9a39f705
JF
1884 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
1885 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
690cf1a8
JF
1886};
1887
1888struct CYTypedIdentifier :
60097023
JF
1889 CYNext<CYTypedIdentifier>,
1890 CYThing
690cf1a8 1891{
00b4cb83 1892 CYLocation location_;
690cf1a8 1893 CYIdentifier *identifier_;
3fe283c5 1894 CYTypeSpecifier *specifier_;
9a39f705 1895 CYTypeModifier *modifier_;
690cf1a8 1896
00b4cb83
JF
1897 CYTypedIdentifier(const CYLocation &location, CYIdentifier *identifier = NULL) :
1898 location_(location),
690cf1a8 1899 identifier_(identifier),
3fe283c5 1900 specifier_(NULL),
9a39f705 1901 modifier_(NULL)
690cf1a8
JF
1902 {
1903 }
60097023 1904
3fe283c5 1905 CYTypedIdentifier(CYTypeSpecifier *specifier, CYTypeModifier *modifier = NULL) :
9a39f705 1906 identifier_(NULL),
3fe283c5 1907 specifier_(specifier),
9a39f705
JF
1908 modifier_(modifier)
1909 {
1910 }
1911
1912 inline CYTypedIdentifier *Modify(CYTypeModifier *modifier) {
1913 CYSetLast(modifier_) = modifier;
1914 return this;
1915 }
1916
1917 virtual CYExpression *Replace(CYContext &context);
60097023 1918 virtual void Output(CYOutput &out) const;
00b4cb83
JF
1919
1920 CYTypeFunctionWith *Function();
690cf1a8
JF
1921};
1922
9a39f705
JF
1923struct CYEncodedType :
1924 CYExpression
1925{
1926 CYTypedIdentifier *typed_;
1927
1928 CYEncodedType(CYTypedIdentifier *typed) :
1929 typed_(typed)
1930 {
1931 }
1932
1933 CYPrecedence(1)
1934
1935 virtual CYExpression *Replace(CYContext &context);
1936 virtual void Output(CYOutput &out, CYFlags flags) const;
1937};
1938
690cf1a8 1939struct CYTypedParameter :
9a39f705
JF
1940 CYNext<CYTypedParameter>,
1941 CYThing
690cf1a8
JF
1942{
1943 CYTypedIdentifier *typed_;
1944
1945 CYTypedParameter(CYTypedIdentifier *typed, CYTypedParameter *next) :
1946 CYNext<CYTypedParameter>(next),
1947 typed_(typed)
1948 {
1949 }
1950
663c538f 1951 CYArgument *Argument(CYContext &context);
690cf1a8
JF
1952 CYFunctionParameter *Parameters(CYContext &context);
1953 CYExpression *TypeSignature(CYContext &context, CYExpression *prefix);
9a39f705
JF
1954
1955 virtual void Output(CYOutput &out) const;
690cf1a8
JF
1956};
1957
1958struct CYLambda :
1959 CYExpression
1960{
9a39f705 1961 CYTypedIdentifier *typed_;
690cf1a8 1962 CYTypedParameter *parameters_;
b0385401 1963 CYStatement *code_;
690cf1a8 1964
b0385401 1965 CYLambda(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *code) :
9a39f705 1966 typed_(typed),
690cf1a8 1967 parameters_(parameters),
b0385401 1968 code_(code)
690cf1a8
JF
1969 {
1970 }
1971
1972 CYPrecedence(1)
1973
1974 virtual CYExpression *Replace(CYContext &context);
1975 virtual void Output(CYOutput &out, CYFlags flags) const;
1976};
1977
7b750785
JF
1978struct CYModule :
1979 CYNext<CYModule>,
1980 CYThing
1981{
1982 CYWord *part_;
1983
1984 CYModule(CYWord *part, CYModule *next = NULL) :
1985 CYNext<CYModule>(next),
1986 part_(part)
1987 {
1988 }
1989
1990 CYString *Replace(CYContext &context, const char *separator) const;
1991 void Output(CYOutput &out) const;
1992};
1993
1994struct CYImport :
1995 CYStatement
1996{
1997 CYModule *module_;
1998
1999 CYImport(CYModule *module) :
2000 module_(module)
2001 {
2002 }
2003
efd689d8
JF
2004 CYCompact(None)
2005
7b750785
JF
2006 virtual CYStatement *Replace(CYContext &context);
2007 virtual void Output(CYOutput &out, CYFlags flags) const;
2008};
2009
c5587ed7
JF
2010struct CYExternal :
2011 CYStatement
2012{
2013 CYString *abi_;
2014 CYTypedIdentifier *typed_;
2015
2016 CYExternal(CYString *abi, CYTypedIdentifier *typed) :
2017 abi_(abi),
2018 typed_(typed)
2019 {
2020 }
2021
efd689d8
JF
2022 CYCompact(None)
2023
c5587ed7
JF
2024 virtual CYStatement *Replace(CYContext &context);
2025 virtual void Output(CYOutput &out, CYFlags flags) const;
2026};
2027
60097023
JF
2028struct CYTypeDefinition :
2029 CYStatement
2030{
2031 CYTypedIdentifier *typed_;
2032
2033 CYTypeDefinition(CYTypedIdentifier *typed) :
2034 typed_(typed)
2035 {
2036 }
2037
efd689d8
JF
2038 CYCompact(None)
2039
60097023
JF
2040 virtual CYStatement *Replace(CYContext &context);
2041 virtual void Output(CYOutput &out, CYFlags flags) const;
2042};
2043
3fe16be7
JF
2044struct CYTypeBlockWith :
2045 CYTypeModifier
2046{
2047 CYTypedParameter *parameters_;
2048
2049 CYTypeBlockWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
2050 CYTypeModifier(next),
2051 parameters_(parameters)
2052 {
2053 }
2054
2055 CYPrecedence(0)
2056
2057 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
2058 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
2059};
2060
663c538f
JF
2061struct CYTypeFunctionWith :
2062 CYTypeModifier
2063{
2064 CYTypedParameter *parameters_;
2065
2066 CYTypeFunctionWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) :
2067 CYTypeModifier(next),
2068 parameters_(parameters)
2069 {
2070 }
2071
9a39f705 2072 CYPrecedence(1)
663c538f 2073
9a39f705
JF
2074 virtual CYExpression *Replace_(CYContext &context, CYExpression *type);
2075 virtual void Output(CYOutput &out, CYIdentifier *identifier) const;
00b4cb83
JF
2076
2077 virtual CYTypeFunctionWith *Function() { return this; }
663c538f
JF
2078};
2079
37954781
JF
2080namespace cy {
2081namespace Syntax {
2082
2083struct Catch :
2084 CYThing
2085{
2086 CYIdentifier *name_;
b0385401 2087 CYStatement *code_;
37954781 2088
b0385401 2089 Catch(CYIdentifier *name, CYStatement *code) :
37954781 2090 name_(name),
b0385401 2091 code_(code)
37954781
JF
2092 {
2093 }
2094
2095 void Replace(CYContext &context);
2096 virtual void Output(CYOutput &out) const;
2097};
2098
2099struct Try :
cf7d4c69
JF
2100 CYStatement
2101{
b0385401 2102 CYStatement *code_;
37954781 2103 Catch *catch_;
b10bd496 2104 CYFinally *finally_;
cf7d4c69 2105
b0385401
JF
2106 Try(CYStatement *code, Catch *_catch, CYFinally *finally) :
2107 code_(code),
cf7d4c69
JF
2108 catch_(_catch),
2109 finally_(finally)
2110 {
2111 }
5999c315 2112
efd689d8
JF
2113 CYCompact(Short)
2114
3b52fd1a 2115 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 2116 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
2117};
2118
37954781 2119struct Throw :
cf7d4c69
JF
2120 CYStatement
2121{
2122 CYExpression *value_;
2123
ab2aa221 2124 Throw(CYExpression *value = NULL) :
cf7d4c69
JF
2125 value_(value)
2126 {
2127 }
5999c315 2128
efd689d8
JF
2129 CYCompact(None)
2130
3b52fd1a 2131 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 2132 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
2133};
2134
37954781
JF
2135} }
2136
cf7d4c69
JF
2137struct CYWith :
2138 CYStatement
2139{
2140 CYExpression *scope_;
2141 CYStatement *code_;
2142
2143 CYWith(CYExpression *scope, CYStatement *code) :
2144 scope_(scope),
2145 code_(code)
2146 {
2147 }
5999c315 2148
efd689d8
JF
2149 CYCompact(Long)
2150
3b52fd1a 2151 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 2152 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
2153};
2154
2155struct CYSwitch :
2156 CYStatement
2157{
2158 CYExpression *value_;
2159 CYClause *clauses_;
2160
2161 CYSwitch(CYExpression *value, CYClause *clauses) :
2162 value_(value),
2163 clauses_(clauses)
2164 {
2165 }
5999c315 2166
efd689d8
JF
2167 CYCompact(Long)
2168
3b52fd1a 2169 virtual CYStatement *Replace(CYContext &context);
c8a0500b
JF
2170 virtual void Output(CYOutput &out, CYFlags flags) const;
2171};
2172
2173struct CYDebugger :
2174 CYStatement
2175{
2176 CYDebugger()
2177 {
2178 }
2179
efd689d8
JF
2180 CYCompact(None)
2181
c8a0500b 2182 virtual CYStatement *Replace(CYContext &context);
fb98ac0c 2183 virtual void Output(CYOutput &out, CYFlags flags) const;
cf7d4c69
JF
2184};
2185
2186struct CYCondition :
2187 CYExpression
2188{
2189 CYExpression *test_;
2190 CYExpression *true_;
2191 CYExpression *false_;
2192
2193 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
91a416e4 2194 test_(test),
cf7d4c69
JF
2195 true_(_true),
2196 false_(_false)
2197 {
2198 }
5999c315 2199
d35a3b07
JF
2200 CYPrecedence(15)
2201
3b52fd1a 2202 virtual CYExpression *Replace(CYContext &context);
652ec1ba 2203 virtual void Output(CYOutput &out, CYFlags flags) const;
5999c315
JF
2204};
2205
2206struct CYAddressOf :
2207 CYPrefix
2208{
2209 CYAddressOf(CYExpression *rhs) :
2210 CYPrefix(rhs)
2211 {
2212 }
2213
2214 virtual const char *Operator() const {
2215 return "&";
2216 }
2217
b09da87b 2218 CYAlphabetic(false)
d35a3b07 2219
3b52fd1a 2220 virtual CYExpression *Replace(CYContext &context);
5999c315
JF
2221};
2222
2223struct CYIndirect :
2224 CYPrefix
2225{
2226 CYIndirect(CYExpression *rhs) :
2227 CYPrefix(rhs)
2228 {
2229 }
2230
2231 virtual const char *Operator() const {
561ac418 2232 return "*";
5999c315
JF
2233 }
2234
b09da87b 2235 CYAlphabetic(false)
d35a3b07 2236
3b52fd1a 2237 virtual CYExpression *Replace(CYContext &context);
cf7d4c69
JF
2238};
2239
4644480a
JF
2240#define CYReplace \
2241 virtual CYExpression *Replace(CYContext &context);
2242
2243#define CYPostfix_(op, name, args...) \
cf7d4c69
JF
2244 struct CY ## name : \
2245 CYPostfix \
4644480a 2246 { args \
cf7d4c69
JF
2247 CY ## name(CYExpression *lhs) : \
2248 CYPostfix(lhs) \
2249 { \
2250 } \
5999c315
JF
2251 \
2252 virtual const char *Operator() const { \
2253 return op; \
2254 } \
cf7d4c69
JF
2255 };
2256
4644480a 2257#define CYPrefix_(alphabetic, op, name, args...) \
cf7d4c69
JF
2258 struct CY ## name : \
2259 CYPrefix \
4644480a 2260 { args \
cf7d4c69
JF
2261 CY ## name(CYExpression *rhs) : \
2262 CYPrefix(rhs) \
2263 { \
2264 } \
d35a3b07 2265 \
b09da87b 2266 CYAlphabetic(alphabetic) \
5999c315
JF
2267 \
2268 virtual const char *Operator() const { \
2269 return op; \
2270 } \
cf7d4c69
JF
2271 };
2272
4644480a 2273#define CYInfix_(alphabetic, precedence, op, name, args...) \
cf7d4c69
JF
2274 struct CY ## name : \
2275 CYInfix \
4644480a 2276 { args \
cf7d4c69
JF
2277 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
2278 CYInfix(lhs, rhs) \
2279 { \
2280 } \
d35a3b07 2281 \
b09da87b 2282 CYAlphabetic(alphabetic) \
d35a3b07 2283 CYPrecedence(precedence) \
5999c315
JF
2284 \
2285 virtual const char *Operator() const { \
2286 return op; \
2287 } \
cf7d4c69
JF
2288 };
2289
4644480a 2290#define CYAssignment_(op, name, args...) \
cf7d4c69
JF
2291 struct CY ## name ## Assign : \
2292 CYAssignment \
4644480a 2293 { args \
cf7d4c69
JF
2294 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
2295 CYAssignment(lhs, rhs) \
2296 { \
2297 } \
5999c315
JF
2298 \
2299 virtual const char *Operator() const { \
2300 return op; \
2301 } \
cf7d4c69
JF
2302 };
2303
2304CYPostfix_("++", PostIncrement)
2305CYPostfix_("--", PostDecrement)
2306
b09da87b
JF
2307CYPrefix_(true, "delete", Delete)
2308CYPrefix_(true, "void", Void)
2309CYPrefix_(true, "typeof", TypeOf)
2310CYPrefix_(false, "++", PreIncrement)
2311CYPrefix_(false, "--", PreDecrement)
c0bc320e 2312CYPrefix_(false, "+", Affirm)
b09da87b
JF
2313CYPrefix_(false, "-", Negate)
2314CYPrefix_(false, "~", BitwiseNot)
2315CYPrefix_(false, "!", LogicalNot)
2316
62f398e4 2317CYInfix_(false, 5, "*", Multiply, CYReplace)
b09da87b
JF
2318CYInfix_(false, 5, "/", Divide)
2319CYInfix_(false, 5, "%", Modulus)
4644480a 2320CYInfix_(false, 6, "+", Add, CYReplace)
b09da87b
JF
2321CYInfix_(false, 6, "-", Subtract)
2322CYInfix_(false, 7, "<<", ShiftLeft)
2323CYInfix_(false, 7, ">>", ShiftRightSigned)
2324CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
2325CYInfix_(false, 8, "<", Less)
2326CYInfix_(false, 8, ">", Greater)
2327CYInfix_(false, 8, "<=", LessOrEqual)
2328CYInfix_(false, 8, ">=", GreaterOrEqual)
2329CYInfix_(true, 8, "instanceof", InstanceOf)
2330CYInfix_(true, 8, "in", In)
2331CYInfix_(false, 9, "==", Equal)
2332CYInfix_(false, 9, "!=", NotEqual)
2333CYInfix_(false, 9, "===", Identical)
2334CYInfix_(false, 9, "!==", NotIdentical)
2335CYInfix_(false, 10, "&", BitwiseAnd)
2336CYInfix_(false, 11, "^", BitwiseXOr)
2337CYInfix_(false, 12, "|", BitwiseOr)
2338CYInfix_(false, 13, "&&", LogicalAnd)
2339CYInfix_(false, 14, "||", LogicalOr)
cf7d4c69
JF
2340
2341CYAssignment_("=", )
2342CYAssignment_("*=", Multiply)
2343CYAssignment_("/=", Divide)
2344CYAssignment_("%=", Modulus)
2345CYAssignment_("+=", Add)
2346CYAssignment_("-=", Subtract)
2347CYAssignment_("<<=", ShiftLeft)
2348CYAssignment_(">>=", ShiftRightSigned)
2349CYAssignment_(">>>=", ShiftRightUnsigned)
2350CYAssignment_("&=", BitwiseAnd)
2351CYAssignment_("^=", BitwiseXOr)
2352CYAssignment_("|=", BitwiseOr)
2353
c5fa2867 2354#endif/*CYCRIPT_PARSER_HPP*/