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