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