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