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