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