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