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