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