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