]>
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 | ||
beb979b4 JF |
1484 | struct CYAttemptMember : |
1485 | CYMember | |
1486 | { | |
1487 | CYAttemptMember(CYExpression *object, CYExpression *property) : | |
1488 | CYMember(object, property) | |
1489 | { | |
1490 | } | |
1491 | ||
1492 | CYPrecedence(1) | |
1493 | ||
1494 | virtual CYTarget *Replace(CYContext &context); | |
1495 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
1496 | }; | |
1497 | ||
9b5527f0 JF |
1498 | struct CYIndirectMember : |
1499 | CYMember | |
1500 | { | |
1501 | CYIndirectMember(CYExpression *object, CYExpression *property) : | |
1502 | CYMember(object, property) | |
1503 | { | |
1504 | } | |
1505 | ||
d35a3b07 JF |
1506 | CYPrecedence(1) |
1507 | ||
7085e1ab | 1508 | virtual CYTarget *Replace(CYContext &context); |
652ec1ba | 1509 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1510 | }; |
1511 | ||
2fad14e5 JF |
1512 | struct CYResolveMember : |
1513 | CYMember | |
1514 | { | |
1515 | CYResolveMember(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 | ||
e56c2499 JF |
1526 | struct CYSubscriptMember : |
1527 | CYMember | |
1528 | { | |
1529 | CYSubscriptMember(CYExpression *object, CYExpression *property) : | |
1530 | CYMember(object, property) | |
1531 | { | |
1532 | } | |
1533 | ||
1534 | CYPrecedence(1) | |
1535 | ||
1536 | virtual CYTarget *Replace(CYContext &context); | |
1537 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
1538 | }; | |
1539 | ||
2eb8215d JF |
1540 | namespace cy { |
1541 | namespace Syntax { | |
1542 | ||
1543 | struct New : | |
7085e1ab | 1544 | CYTarget |
cf7d4c69 JF |
1545 | { |
1546 | CYExpression *constructor_; | |
1547 | CYArgument *arguments_; | |
1548 | ||
c5b15840 | 1549 | New(CYExpression *constructor, CYArgument *arguments = NULL) : |
cf7d4c69 JF |
1550 | constructor_(constructor), |
1551 | arguments_(arguments) | |
1552 | { | |
1553 | } | |
5999c315 | 1554 | |
9a39f705 | 1555 | virtual int Precedence() const { |
fb98ac0c JF |
1556 | return arguments_ == NULL ? 2 : 1; |
1557 | } | |
1558 | ||
4f3e597c JF |
1559 | virtual bool IsNew() const { |
1560 | return true; | |
1561 | } | |
d35a3b07 | 1562 | |
7085e1ab | 1563 | virtual CYTarget *Replace(CYContext &context); |
652ec1ba | 1564 | virtual void Output(CYOutput &out, CYFlags flags) const; |
6c093cce | 1565 | |
7085e1ab | 1566 | virtual CYTarget *AddArgument(CYContext &context, CYExpression *value); |
cf7d4c69 JF |
1567 | }; |
1568 | ||
2eb8215d JF |
1569 | } } |
1570 | ||
7085e1ab JF |
1571 | struct CYApply : |
1572 | CYTarget | |
cf7d4c69 | 1573 | { |
cf7d4c69 JF |
1574 | CYArgument *arguments_; |
1575 | ||
7085e1ab | 1576 | CYApply(CYArgument *arguments = NULL) : |
cf7d4c69 JF |
1577 | arguments_(arguments) |
1578 | { | |
1579 | } | |
5999c315 | 1580 | |
fb98ac0c | 1581 | CYPrecedence(1) |
d35a3b07 | 1582 | |
7085e1ab JF |
1583 | virtual CYTarget *AddArgument(CYContext &context, CYExpression *value); |
1584 | }; | |
1585 | ||
1586 | struct CYCall : | |
1587 | CYApply | |
1588 | { | |
1589 | CYExpression *function_; | |
1590 | ||
1591 | CYCall(CYExpression *function, CYArgument *arguments = NULL) : | |
1592 | CYApply(arguments), | |
1593 | function_(function) | |
1594 | { | |
1595 | } | |
1596 | ||
652ec1ba | 1597 | virtual void Output(CYOutput &out, CYFlags flags) const; |
7085e1ab JF |
1598 | virtual CYTarget *Replace(CYContext &context); |
1599 | }; | |
1600 | ||
1601 | struct CYEval : | |
1602 | CYApply | |
1603 | { | |
1604 | CYEval(CYArgument *arguments) : | |
1605 | CYApply(arguments) | |
1606 | { | |
1607 | } | |
6c093cce | 1608 | |
7085e1ab JF |
1609 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1610 | virtual CYTarget *Replace(CYContext &context); | |
6c093cce JF |
1611 | }; |
1612 | ||
1613 | struct CYRubyProc; | |
1614 | ||
4f3e597c | 1615 | struct CYBraced : |
7085e1ab | 1616 | CYTarget |
6c093cce | 1617 | { |
4f3e597c | 1618 | CYTarget *lhs_; |
6c093cce | 1619 | |
4f3e597c JF |
1620 | CYBraced(CYTarget *lhs = NULL) : |
1621 | lhs_(lhs) | |
6c093cce JF |
1622 | { |
1623 | } | |
1624 | ||
1625 | CYPrecedence(1) | |
6c093cce | 1626 | |
4f3e597c JF |
1627 | void SetLeft(CYTarget *lhs) { |
1628 | lhs_ = lhs; | |
1629 | } | |
1630 | }; | |
1631 | ||
1632 | struct CYRubyBlock : | |
1633 | CYBraced | |
1634 | { | |
1635 | CYRubyProc *proc_; | |
1636 | ||
1637 | CYRubyBlock(CYTarget *lhs, CYRubyProc *proc) : | |
1638 | CYBraced(lhs), | |
1639 | proc_(proc) | |
1640 | { | |
1641 | } | |
1642 | ||
7085e1ab | 1643 | virtual CYTarget *Replace(CYContext &context); |
6c093cce | 1644 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1abe53bf | 1645 | |
7085e1ab | 1646 | virtual CYTarget *AddArgument(CYContext &context, CYExpression *value); |
cf7d4c69 JF |
1647 | }; |
1648 | ||
4f3e597c JF |
1649 | struct CYExtend : |
1650 | CYBraced | |
1651 | { | |
1652 | CYObject object_; | |
1653 | ||
1654 | CYExtend(CYTarget *lhs, CYProperty *properties = NULL) : | |
1655 | CYBraced(lhs), | |
1656 | object_(properties) | |
1657 | { | |
1658 | } | |
1659 | ||
1660 | virtual CYTarget *Replace(CYContext &context); | |
1661 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
1662 | }; | |
1663 | ||
cf7d4c69 JF |
1664 | struct CYIf : |
1665 | CYStatement | |
1666 | { | |
1667 | CYExpression *test_; | |
1668 | CYStatement *true_; | |
1669 | CYStatement *false_; | |
1670 | ||
3b52fd1a | 1671 | CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) : |
cf7d4c69 JF |
1672 | test_(test), |
1673 | true_(_true), | |
1674 | false_(_false) | |
1675 | { | |
1676 | } | |
5999c315 | 1677 | |
efd689d8 JF |
1678 | CYCompact(Long) |
1679 | ||
3b52fd1a | 1680 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1681 | virtual void Output(CYOutput &out, CYFlags flags) const; |
12e37ba3 JF |
1682 | |
1683 | virtual CYStatement *Return(); | |
cf7d4c69 JF |
1684 | }; |
1685 | ||
1686 | struct CYDoWhile : | |
1687 | CYStatement | |
1688 | { | |
1689 | CYExpression *test_; | |
1690 | CYStatement *code_; | |
1691 | ||
1692 | CYDoWhile(CYExpression *test, CYStatement *code) : | |
1693 | test_(test), | |
1694 | code_(code) | |
1695 | { | |
1696 | } | |
5999c315 | 1697 | |
efd689d8 JF |
1698 | CYCompact(None) |
1699 | ||
3b52fd1a | 1700 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1701 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1702 | }; |
1703 | ||
1704 | struct CYWhile : | |
1705 | CYStatement | |
1706 | { | |
1707 | CYExpression *test_; | |
1708 | CYStatement *code_; | |
1709 | ||
1710 | CYWhile(CYExpression *test, CYStatement *code) : | |
1711 | test_(test), | |
1712 | code_(code) | |
1713 | { | |
1714 | } | |
5999c315 | 1715 | |
efd689d8 JF |
1716 | CYCompact(Long) |
1717 | ||
3b52fd1a | 1718 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1719 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1720 | }; |
1721 | ||
a846a8cd | 1722 | struct CYFunction { |
b09da87b | 1723 | CYFunctionParameter *parameters_; |
b0385401 | 1724 | CYStatement *code_; |
a0be43fc | 1725 | |
ab2aa221 | 1726 | CYNonLocal *nonlocal_; |
12e37ba3 | 1727 | bool implicit_; |
a0be43fc | 1728 | CYThisScope this_; |
c5b15840 | 1729 | CYIdentifier *super_; |
cf7d4c69 | 1730 | |
c5b15840 | 1731 | CYFunction(CYFunctionParameter *parameters, CYStatement *code) : |
cf7d4c69 | 1732 | parameters_(parameters), |
b0385401 | 1733 | code_(code), |
12e37ba3 | 1734 | nonlocal_(NULL), |
c5b15840 JF |
1735 | implicit_(false), |
1736 | super_(NULL) | |
cf7d4c69 JF |
1737 | { |
1738 | } | |
5999c315 | 1739 | |
c5b15840 JF |
1740 | void Replace(CYContext &context); |
1741 | void Output(CYOutput &out) const; | |
fb98ac0c JF |
1742 | }; |
1743 | ||
1744 | struct CYFunctionExpression : | |
1745 | CYFunction, | |
7085e1ab | 1746 | CYTarget |
fb98ac0c | 1747 | { |
c5b15840 JF |
1748 | CYIdentifier *name_; |
1749 | ||
b0385401 | 1750 | CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) : |
c5b15840 JF |
1751 | CYFunction(parameters, code), |
1752 | name_(name) | |
fb98ac0c JF |
1753 | { |
1754 | } | |
1755 | ||
a0be43fc | 1756 | CYPrecedence(0) |
a0be43fc | 1757 | |
7085e1ab | 1758 | CYTarget *Replace(CYContext &context) override; |
a0be43fc JF |
1759 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1760 | }; | |
1761 | ||
a0be43fc JF |
1762 | struct CYFatArrow : |
1763 | CYFunction, | |
1764 | CYExpression | |
1765 | { | |
b0385401 | 1766 | CYFatArrow(CYFunctionParameter *parameters, CYStatement *code) : |
c5b15840 | 1767 | CYFunction(parameters, code) |
a0be43fc JF |
1768 | { |
1769 | } | |
1770 | ||
d35a3b07 JF |
1771 | CYPrecedence(0) |
1772 | ||
7085e1ab | 1773 | CYExpression *Replace(CYContext &context) override; |
652ec1ba | 1774 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1775 | }; |
1776 | ||
6c093cce | 1777 | struct CYRubyProc : |
6ce0f978 | 1778 | CYFunction, |
7085e1ab | 1779 | CYTarget |
6c093cce | 1780 | { |
b0385401 | 1781 | CYRubyProc(CYFunctionParameter *parameters, CYStatement *code) : |
c5b15840 | 1782 | CYFunction(parameters, code) |
6c093cce JF |
1783 | { |
1784 | } | |
1785 | ||
c5b15840 | 1786 | CYPrecedence(0) |
c5b15840 | 1787 | |
7085e1ab | 1788 | CYTarget *Replace(CYContext &context) override; |
6c093cce JF |
1789 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1790 | }; | |
1791 | ||
fb98ac0c JF |
1792 | struct CYFunctionStatement : |
1793 | CYFunction, | |
b10bd496 | 1794 | CYStatement |
cf7d4c69 | 1795 | { |
c5b15840 JF |
1796 | CYIdentifier *name_; |
1797 | ||
b0385401 | 1798 | CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) : |
c5b15840 JF |
1799 | CYFunction(parameters, code), |
1800 | name_(name) | |
cf7d4c69 JF |
1801 | { |
1802 | } | |
5999c315 | 1803 | |
efd689d8 JF |
1804 | CYCompact(None) |
1805 | ||
7085e1ab | 1806 | CYStatement *Replace(CYContext &context) override; |
fb98ac0c | 1807 | virtual void Output(CYOutput &out, CYFlags flags) const; |
5999c315 JF |
1808 | }; |
1809 | ||
c5b15840 JF |
1810 | struct CYPropertyMethod; |
1811 | ||
1812 | struct CYMethod : | |
1813 | CYFunction, | |
1814 | CYProperty | |
1815 | { | |
1816 | CYMethod(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) : | |
1817 | CYFunction(parameters, code), | |
1818 | CYProperty(name, next) | |
1819 | { | |
1820 | } | |
1821 | ||
1822 | virtual CYFunctionExpression *Constructor(); | |
1823 | ||
1824 | using CYProperty::Replace; | |
1825 | virtual void Replace(CYContext &context); | |
1826 | }; | |
1827 | ||
1828 | struct CYPropertyGetter : | |
1829 | CYMethod | |
1830 | { | |
1831 | CYPropertyGetter(CYPropertyName *name, CYStatement *code, CYProperty *next = NULL) : | |
1832 | CYMethod(name, NULL, code, next) | |
1833 | { | |
1834 | } | |
1835 | ||
a196a97a | 1836 | virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect); |
c5b15840 JF |
1837 | virtual void Output(CYOutput &out) const; |
1838 | }; | |
1839 | ||
1840 | struct CYPropertySetter : | |
1841 | CYMethod | |
1842 | { | |
1843 | CYPropertySetter(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) : | |
1844 | CYMethod(name, parameters, code, next) | |
1845 | { | |
1846 | } | |
1847 | ||
a196a97a | 1848 | virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect); |
c5b15840 JF |
1849 | virtual void Output(CYOutput &out) const; |
1850 | }; | |
1851 | ||
1852 | struct CYPropertyMethod : | |
1853 | CYMethod | |
1854 | { | |
1855 | CYPropertyMethod(CYPropertyName *name, CYFunctionParameter *parameters, CYStatement *code, CYProperty *next = NULL) : | |
1856 | CYMethod(name, parameters, code, next) | |
1857 | { | |
1858 | } | |
1859 | ||
7b87d205 JF |
1860 | bool Update() const override; |
1861 | ||
c5b15840 JF |
1862 | virtual CYFunctionExpression *Constructor(); |
1863 | ||
a196a97a | 1864 | virtual void Replace(CYContext &context, CYBuilder &builder, CYExpression *self, CYExpression *name, bool protect); |
c5b15840 JF |
1865 | virtual void Output(CYOutput &out) const; |
1866 | }; | |
1867 | ||
1868 | struct CYClassTail : | |
1869 | CYThing | |
1870 | { | |
1871 | CYExpression *extends_; | |
1872 | ||
1873 | CYFunctionExpression *constructor_; | |
1874 | CYList<CYProperty> instance_; | |
1875 | CYList<CYProperty> static_; | |
1876 | ||
1877 | CYClassTail(CYExpression *extends) : | |
1878 | extends_(extends), | |
1879 | constructor_(NULL) | |
1880 | { | |
1881 | } | |
1882 | ||
1883 | void Output(CYOutput &out) const; | |
1884 | }; | |
1885 | ||
1886 | struct CYClassExpression : | |
7085e1ab | 1887 | CYTarget |
c5b15840 JF |
1888 | { |
1889 | CYIdentifier *name_; | |
1890 | CYClassTail *tail_; | |
1891 | ||
1892 | CYClassExpression(CYIdentifier *name, CYClassTail *tail) : | |
1893 | name_(name), | |
1894 | tail_(tail) | |
1895 | { | |
1896 | } | |
1897 | ||
1898 | CYPrecedence(0) | |
c5b15840 | 1899 | |
7085e1ab | 1900 | CYTarget *Replace(CYContext &context) override; |
c5b15840 JF |
1901 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1902 | }; | |
1903 | ||
1904 | struct CYClassStatement : | |
1905 | CYStatement | |
1906 | { | |
1907 | CYIdentifier *name_; | |
1908 | CYClassTail *tail_; | |
1909 | ||
1910 | CYClassStatement(CYIdentifier *name, CYClassTail *tail) : | |
1911 | name_(name), | |
1912 | tail_(tail) | |
1913 | { | |
1914 | } | |
1915 | ||
1916 | CYCompact(Long) | |
1917 | ||
7085e1ab | 1918 | CYStatement *Replace(CYContext &context) override; |
c5b15840 JF |
1919 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1920 | }; | |
1921 | ||
1922 | struct CYSuperCall : | |
7085e1ab | 1923 | CYTarget |
c5b15840 JF |
1924 | { |
1925 | CYArgument *arguments_; | |
1926 | ||
1927 | CYSuperCall(CYArgument *arguments) : | |
1928 | arguments_(arguments) | |
1929 | { | |
1930 | } | |
1931 | ||
1932 | CYPrecedence(2) | |
c5b15840 | 1933 | |
7085e1ab | 1934 | CYTarget *Replace(CYContext &context) override; |
c5b15840 JF |
1935 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1936 | }; | |
1937 | ||
1938 | struct CYSuperAccess : | |
7085e1ab | 1939 | CYTarget |
c5b15840 JF |
1940 | { |
1941 | CYExpression *property_; | |
1942 | ||
1943 | CYSuperAccess(CYExpression *property) : | |
1944 | property_(property) | |
1945 | { | |
1946 | } | |
1947 | ||
1948 | CYPrecedence(1) | |
c5b15840 | 1949 | |
7085e1ab | 1950 | CYTarget *Replace(CYContext &context) override; |
c5b15840 JF |
1951 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1952 | }; | |
1953 | ||
5999c315 | 1954 | struct CYExpress : |
bfd79fae | 1955 | CYForInitializer |
5999c315 JF |
1956 | { |
1957 | CYExpression *expression_; | |
1958 | ||
1959 | CYExpress(CYExpression *expression) : | |
1960 | expression_(expression) | |
1961 | { | |
fd5cdf97 | 1962 | if (expression_ == NULL) |
029bc65b | 1963 | throw; |
5999c315 JF |
1964 | } |
1965 | ||
efd689d8 JF |
1966 | CYCompact(None) |
1967 | ||
bfd79fae | 1968 | CYForInitializer *Replace(CYContext &context) override; |
fb98ac0c | 1969 | virtual void Output(CYOutput &out, CYFlags flags) const; |
12e37ba3 JF |
1970 | |
1971 | virtual CYStatement *Return(); | |
cf7d4c69 JF |
1972 | }; |
1973 | ||
1974 | struct CYContinue : | |
1975 | CYStatement | |
1976 | { | |
1977 | CYIdentifier *label_; | |
1978 | ||
1979 | CYContinue(CYIdentifier *label) : | |
1980 | label_(label) | |
1981 | { | |
1982 | } | |
5999c315 | 1983 | |
efd689d8 JF |
1984 | CYCompact(Short) |
1985 | ||
7085e1ab | 1986 | CYStatement *Replace(CYContext &context) override; |
fb98ac0c | 1987 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1988 | }; |
1989 | ||
1990 | struct CYBreak : | |
1991 | CYStatement | |
1992 | { | |
1993 | CYIdentifier *label_; | |
1994 | ||
1995 | CYBreak(CYIdentifier *label) : | |
1996 | label_(label) | |
1997 | { | |
1998 | } | |
5999c315 | 1999 | |
efd689d8 JF |
2000 | CYCompact(Short) |
2001 | ||
7085e1ab | 2002 | CYStatement *Replace(CYContext &context) override; |
fb98ac0c | 2003 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
2004 | }; |
2005 | ||
2006 | struct CYReturn : | |
2007 | CYStatement | |
2008 | { | |
2009 | CYExpression *value_; | |
2010 | ||
2011 | CYReturn(CYExpression *value) : | |
2012 | value_(value) | |
2013 | { | |
2014 | } | |
5999c315 | 2015 | |
efd689d8 JF |
2016 | CYCompact(None) |
2017 | ||
7085e1ab | 2018 | CYStatement *Replace(CYContext &context) override; |
9d2b125d JF |
2019 | virtual void Output(CYOutput &out, CYFlags flags) const; |
2020 | }; | |
2021 | ||
2022 | struct CYYieldGenerator : | |
2023 | CYExpression | |
2024 | { | |
2025 | CYExpression *value_; | |
2026 | ||
2027 | CYYieldGenerator(CYExpression *value) : | |
2028 | value_(value) | |
2029 | { | |
2030 | } | |
2031 | ||
2032 | CYPrecedence(0) | |
2033 | ||
7085e1ab | 2034 | CYExpression *Replace(CYContext &context) override; |
9d2b125d JF |
2035 | virtual void Output(CYOutput &out, CYFlags flags) const; |
2036 | }; | |
2037 | ||
2038 | struct CYYieldValue : | |
2039 | CYExpression | |
2040 | { | |
2041 | CYExpression *value_; | |
2042 | ||
2043 | CYYieldValue(CYExpression *value) : | |
2044 | value_(value) | |
2045 | { | |
2046 | } | |
2047 | ||
2048 | CYPrecedence(0) | |
2049 | ||
2050 | virtual CYExpression *Replace(CYContext &context); | |
fb98ac0c | 2051 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
2052 | }; |
2053 | ||
2054 | struct CYEmpty : | |
bfd79fae | 2055 | CYForInitializer |
cf7d4c69 | 2056 | { |
efd689d8 JF |
2057 | CYCompact(Short) |
2058 | ||
bfd79fae | 2059 | virtual CYForInitializer *Replace(CYContext &context); |
fb98ac0c | 2060 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
2061 | }; |
2062 | ||
96a7e5c2 JF |
2063 | struct CYFinally : |
2064 | CYThing | |
2065 | { | |
b0385401 | 2066 | CYStatement *code_; |
b10bd496 | 2067 | |
b0385401 JF |
2068 | CYFinally(CYStatement *code) : |
2069 | code_(code) | |
b10bd496 JF |
2070 | { |
2071 | } | |
2072 | ||
3b52fd1a | 2073 | void Replace(CYContext &context); |
b10bd496 JF |
2074 | virtual void Output(CYOutput &out) const; |
2075 | }; | |
2076 | ||
3fe283c5 JF |
2077 | struct CYTypeSpecifier : |
2078 | CYThing | |
2079 | { | |
7085e1ab | 2080 | virtual CYTarget *Replace(CYContext &context) = 0; |
3fe283c5 JF |
2081 | }; |
2082 | ||
03db6a67 JF |
2083 | struct CYTypeError : |
2084 | CYTypeSpecifier | |
2085 | { | |
2086 | CYTypeError() { | |
2087 | } | |
2088 | ||
7085e1ab | 2089 | virtual CYTarget *Replace(CYContext &context); |
03db6a67 JF |
2090 | virtual void Output(CYOutput &out) const; |
2091 | }; | |
2092 | ||
0559abf8 JF |
2093 | enum CYTypeSigning { |
2094 | CYTypeNeutral, | |
2095 | CYTypeSigned, | |
2096 | CYTypeUnsigned, | |
3fe283c5 JF |
2097 | }; |
2098 | ||
0559abf8 | 2099 | struct CYTypeCharacter : |
d8380373 JF |
2100 | CYTypeSpecifier |
2101 | { | |
0559abf8 | 2102 | CYTypeSigning signing_; |
d8380373 | 2103 | |
0559abf8 JF |
2104 | CYTypeCharacter(CYTypeSigning signing) : |
2105 | signing_(signing) | |
d8380373 JF |
2106 | { |
2107 | } | |
2108 | ||
2109 | virtual CYTarget *Replace(CYContext &context); | |
2110 | virtual void Output(CYOutput &out) const; | |
2111 | }; | |
2112 | ||
24ffc58c JF |
2113 | struct CYTypeInt128 : |
2114 | CYTypeSpecifier | |
2115 | { | |
2116 | CYTypeSigning signing_; | |
2117 | ||
2118 | CYTypeInt128(CYTypeSigning signing) : | |
2119 | signing_(signing) | |
2120 | { | |
2121 | } | |
2122 | ||
2123 | virtual CYTarget *Replace(CYContext &context); | |
2124 | virtual void Output(CYOutput &out) const; | |
2125 | }; | |
2126 | ||
0559abf8 | 2127 | struct CYTypeIntegral : |
3fe283c5 JF |
2128 | CYTypeSpecifier |
2129 | { | |
0559abf8 JF |
2130 | CYTypeSigning signing_; |
2131 | int length_; | |
3fe283c5 | 2132 | |
0559abf8 JF |
2133 | CYTypeIntegral(CYTypeSigning signing, int length = 1) : |
2134 | signing_(signing), | |
2135 | length_(length) | |
3fe283c5 JF |
2136 | { |
2137 | } | |
2138 | ||
0559abf8 JF |
2139 | CYTypeIntegral *Long() { |
2140 | if (length_ != 1 && length_ != 2) | |
2141 | return NULL; | |
2142 | ++length_; | |
2143 | return this; | |
3fe283c5 JF |
2144 | } |
2145 | ||
0559abf8 JF |
2146 | CYTypeIntegral *Short() { |
2147 | if (length_ != 1) | |
2148 | return NULL; | |
2149 | --length_; | |
2150 | return this; | |
2151 | } | |
3fe283c5 | 2152 | |
0559abf8 JF |
2153 | CYTypeIntegral *Signed() { |
2154 | if (signing_ != CYTypeNeutral) | |
2155 | return NULL; | |
2156 | signing_ = CYTypeSigned; | |
2157 | return this; | |
2158 | } | |
3fe283c5 | 2159 | |
0559abf8 JF |
2160 | CYTypeIntegral *Unsigned() { |
2161 | if (signing_ != CYTypeNeutral) | |
2162 | return NULL; | |
2163 | signing_ = CYTypeUnsigned; | |
2164 | return this; | |
3fe283c5 JF |
2165 | } |
2166 | ||
7085e1ab | 2167 | virtual CYTarget *Replace(CYContext &context); |
3fe283c5 JF |
2168 | virtual void Output(CYOutput &out) const; |
2169 | }; | |
2170 | ||
1e8d8047 JF |
2171 | struct CYTypeFloating : |
2172 | CYTypeSpecifier | |
2173 | { | |
2174 | int length_; | |
2175 | ||
2176 | CYTypeFloating(int length) : | |
2177 | length_(length) | |
2178 | { | |
2179 | } | |
2180 | ||
2181 | virtual CYTarget *Replace(CYContext &context); | |
2182 | virtual void Output(CYOutput &out) const; | |
2183 | }; | |
2184 | ||
0559abf8 | 2185 | struct CYTypeVoid : |
3fe283c5 JF |
2186 | CYTypeSpecifier |
2187 | { | |
0559abf8 | 2188 | CYTypeVoid() { |
3fe283c5 JF |
2189 | } |
2190 | ||
7085e1ab | 2191 | virtual CYTarget *Replace(CYContext &context); |
3fe283c5 JF |
2192 | virtual void Output(CYOutput &out) const; |
2193 | }; | |
2194 | ||
aaa29c28 JF |
2195 | enum CYTypeReferenceKind { |
2196 | CYTypeReferenceStruct, | |
2197 | CYTypeReferenceEnum, | |
2198 | }; | |
2199 | ||
0559abf8 | 2200 | struct CYTypeReference : |
3fe283c5 JF |
2201 | CYTypeSpecifier |
2202 | { | |
aaa29c28 | 2203 | CYTypeReferenceKind kind_; |
0559abf8 | 2204 | CYIdentifier *name_; |
3fe283c5 | 2205 | |
aaa29c28 JF |
2206 | CYTypeReference(CYTypeReferenceKind kind, CYIdentifier *name) : |
2207 | kind_(kind), | |
0559abf8 | 2208 | name_(name) |
3fe283c5 JF |
2209 | { |
2210 | } | |
2211 | ||
7085e1ab | 2212 | virtual CYTarget *Replace(CYContext &context); |
3fe283c5 JF |
2213 | virtual void Output(CYOutput &out) const; |
2214 | }; | |
2215 | ||
0559abf8 | 2216 | struct CYTypeVariable : |
3fe283c5 JF |
2217 | CYTypeSpecifier |
2218 | { | |
0559abf8 JF |
2219 | CYIdentifier *name_; |
2220 | ||
2221 | CYTypeVariable(CYIdentifier *name) : | |
2222 | name_(name) | |
2223 | { | |
2224 | } | |
3fe283c5 | 2225 | |
0559abf8 JF |
2226 | CYTypeVariable(const char *name) : |
2227 | name_(new($pool) CYIdentifier(name)) | |
3fe283c5 JF |
2228 | { |
2229 | } | |
2230 | ||
7085e1ab | 2231 | virtual CYTarget *Replace(CYContext &context); |
3fe283c5 JF |
2232 | virtual void Output(CYOutput &out) const; |
2233 | }; | |
2234 | ||
00b4cb83 JF |
2235 | struct CYTypeFunctionWith; |
2236 | ||
690cf1a8 JF |
2237 | struct CYTypeModifier : |
2238 | CYNext<CYTypeModifier> | |
2239 | { | |
2240 | CYTypeModifier(CYTypeModifier *next) : | |
2241 | CYNext<CYTypeModifier>(next) | |
2242 | { | |
2243 | } | |
2244 | ||
9a39f705 JF |
2245 | virtual int Precedence() const = 0; |
2246 | ||
7085e1ab JF |
2247 | virtual CYTarget *Replace_(CYContext &context, CYTarget *type) = 0; |
2248 | CYTarget *Replace(CYContext &context, CYTarget *type); | |
9a39f705 | 2249 | |
5b4dabb2 JF |
2250 | virtual void Output(CYOutput &out, CYPropertyName *name) const = 0; |
2251 | void Output(CYOutput &out, int precedence, CYPropertyName *name, bool space) const; | |
00b4cb83 JF |
2252 | |
2253 | virtual CYTypeFunctionWith *Function() { return NULL; } | |
690cf1a8 JF |
2254 | }; |
2255 | ||
2256 | struct CYTypeArrayOf : | |
2257 | CYTypeModifier | |
2258 | { | |
2259 | CYExpression *size_; | |
2260 | ||
2261 | CYTypeArrayOf(CYExpression *size, CYTypeModifier *next = NULL) : | |
2262 | CYTypeModifier(next), | |
2263 | size_(size) | |
2264 | { | |
2265 | } | |
2266 | ||
9a39f705 | 2267 | CYPrecedence(1) |
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 CYTypeConstant : | |
2274 | CYTypeModifier | |
2275 | { | |
2276 | CYTypeConstant(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 | ||
2287 | struct CYTypePointerTo : | |
2288 | CYTypeModifier | |
2289 | { | |
2290 | CYTypePointerTo(CYTypeModifier *next = NULL) : | |
2291 | CYTypeModifier(next) | |
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 | ||
9a39f705 | 2301 | struct CYTypeVolatile : |
690cf1a8 JF |
2302 | CYTypeModifier |
2303 | { | |
9a39f705 JF |
2304 | CYTypeVolatile(CYTypeModifier *next = NULL) : |
2305 | CYTypeModifier(next) | |
690cf1a8 JF |
2306 | { |
2307 | } | |
2308 | ||
9a39f705 | 2309 | CYPrecedence(0) |
690cf1a8 | 2310 | |
7085e1ab | 2311 | virtual CYTarget *Replace_(CYContext &context, CYTarget *type); |
5b4dabb2 | 2312 | void Output(CYOutput &out, CYPropertyName *name) const override; |
690cf1a8 JF |
2313 | }; |
2314 | ||
5b4dabb2 | 2315 | struct CYType : |
60097023 | 2316 | CYThing |
690cf1a8 | 2317 | { |
3fe283c5 | 2318 | CYTypeSpecifier *specifier_; |
9a39f705 | 2319 | CYTypeModifier *modifier_; |
690cf1a8 | 2320 | |
5b4dabb2 | 2321 | CYType(CYTypeSpecifier *specifier = NULL, CYTypeModifier *modifier = NULL) : |
3fe283c5 | 2322 | specifier_(specifier), |
9a39f705 JF |
2323 | modifier_(modifier) |
2324 | { | |
2325 | } | |
2326 | ||
5b4dabb2 | 2327 | inline CYType *Modify(CYTypeModifier *modifier) { |
9a39f705 JF |
2328 | CYSetLast(modifier_) = modifier; |
2329 | return this; | |
2330 | } | |
2331 | ||
5b4dabb2 JF |
2332 | void Output(CYOutput &out, CYPropertyName *name) const; |
2333 | ||
7085e1ab | 2334 | virtual CYTarget *Replace(CYContext &context); |
60097023 | 2335 | virtual void Output(CYOutput &out) const; |
00b4cb83 JF |
2336 | |
2337 | CYTypeFunctionWith *Function(); | |
690cf1a8 JF |
2338 | }; |
2339 | ||
5b4dabb2 JF |
2340 | struct CYTypedLocation : |
2341 | CYType | |
2342 | { | |
2343 | CYLocation location_; | |
2344 | ||
2345 | CYTypedLocation(const CYLocation &location) : | |
2346 | location_(location) | |
2347 | { | |
2348 | } | |
2349 | }; | |
2350 | ||
2351 | struct CYTypedName : | |
2352 | CYTypedLocation | |
2353 | { | |
2354 | CYPropertyName *name_; | |
2355 | ||
2356 | CYTypedName(const CYLocation &location, CYPropertyName *name = NULL) : | |
2357 | CYTypedLocation(location), | |
2358 | name_(name) | |
2359 | { | |
2360 | } | |
2361 | }; | |
2362 | ||
9a39f705 | 2363 | struct CYEncodedType : |
7085e1ab | 2364 | CYTarget |
9a39f705 | 2365 | { |
5b4dabb2 | 2366 | CYType *typed_; |
9a39f705 | 2367 | |
5b4dabb2 | 2368 | CYEncodedType(CYType *typed) : |
9a39f705 JF |
2369 | typed_(typed) |
2370 | { | |
2371 | } | |
2372 | ||
2373 | CYPrecedence(1) | |
2374 | ||
7085e1ab | 2375 | virtual CYTarget *Replace(CYContext &context); |
9a39f705 JF |
2376 | virtual void Output(CYOutput &out, CYFlags flags) const; |
2377 | }; | |
2378 | ||
690cf1a8 | 2379 | struct CYTypedParameter : |
9a39f705 JF |
2380 | CYNext<CYTypedParameter>, |
2381 | CYThing | |
690cf1a8 | 2382 | { |
5b4dabb2 JF |
2383 | CYType *type_; |
2384 | CYIdentifier *name_; | |
690cf1a8 | 2385 | |
5b4dabb2 | 2386 | CYTypedParameter(CYType *type, CYIdentifier *name, CYTypedParameter *next = NULL) : |
690cf1a8 | 2387 | CYNext<CYTypedParameter>(next), |
5b4dabb2 JF |
2388 | type_(type), |
2389 | name_(name) | |
690cf1a8 JF |
2390 | { |
2391 | } | |
2392 | ||
663c538f | 2393 | CYArgument *Argument(CYContext &context); |
690cf1a8 JF |
2394 | CYFunctionParameter *Parameters(CYContext &context); |
2395 | CYExpression *TypeSignature(CYContext &context, CYExpression *prefix); | |
9a39f705 JF |
2396 | |
2397 | virtual void Output(CYOutput &out) const; | |
690cf1a8 JF |
2398 | }; |
2399 | ||
574d4720 JF |
2400 | struct CYTypedFormal { |
2401 | bool variadic_; | |
2402 | CYTypedParameter *parameters_; | |
2403 | ||
2404 | CYTypedFormal(bool variadic) : | |
2405 | variadic_(variadic), | |
2406 | parameters_(NULL) | |
2407 | { | |
2408 | } | |
2409 | }; | |
2410 | ||
690cf1a8 | 2411 | struct CYLambda : |
7085e1ab | 2412 | CYTarget |
690cf1a8 | 2413 | { |
5b4dabb2 | 2414 | CYType *typed_; |
690cf1a8 | 2415 | CYTypedParameter *parameters_; |
b0385401 | 2416 | CYStatement *code_; |
690cf1a8 | 2417 | |
5b4dabb2 | 2418 | CYLambda(CYType *typed, CYTypedParameter *parameters, CYStatement *code) : |
9a39f705 | 2419 | typed_(typed), |
690cf1a8 | 2420 | parameters_(parameters), |
b0385401 | 2421 | code_(code) |
690cf1a8 JF |
2422 | { |
2423 | } | |
2424 | ||
2425 | CYPrecedence(1) | |
2426 | ||
7085e1ab | 2427 | virtual CYTarget *Replace(CYContext &context); |
690cf1a8 JF |
2428 | virtual void Output(CYOutput &out, CYFlags flags) const; |
2429 | }; | |
2430 | ||
7b750785 JF |
2431 | struct CYModule : |
2432 | CYNext<CYModule>, | |
2433 | CYThing | |
2434 | { | |
2435 | CYWord *part_; | |
2436 | ||
2437 | CYModule(CYWord *part, CYModule *next = NULL) : | |
2438 | CYNext<CYModule>(next), | |
2439 | part_(part) | |
2440 | { | |
2441 | } | |
2442 | ||
2443 | CYString *Replace(CYContext &context, const char *separator) const; | |
2444 | void Output(CYOutput &out) const; | |
2445 | }; | |
2446 | ||
2447 | struct CYImport : | |
2448 | CYStatement | |
2449 | { | |
2450 | CYModule *module_; | |
2451 | ||
2452 | CYImport(CYModule *module) : | |
2453 | module_(module) | |
2454 | { | |
2455 | } | |
2456 | ||
efd689d8 JF |
2457 | CYCompact(None) |
2458 | ||
7b750785 JF |
2459 | virtual CYStatement *Replace(CYContext &context); |
2460 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
2461 | }; | |
2462 | ||
90dd6ff1 JF |
2463 | struct CYImportSpecifier : |
2464 | CYNext<CYImportSpecifier> | |
2465 | { | |
2466 | CYWord *name_; | |
2467 | CYIdentifier *binding_; | |
2468 | ||
2469 | CYImportSpecifier(CYWord *name, CYIdentifier *binding) : | |
2470 | name_(name), | |
2471 | binding_(binding) | |
2472 | { | |
2473 | } | |
2474 | ||
2475 | CYStatement *Replace(CYContext &context, CYIdentifier *module); | |
2476 | }; | |
2477 | ||
2478 | struct CYImportDeclaration : | |
2479 | CYStatement | |
2480 | { | |
2481 | CYImportSpecifier *specifiers_; | |
2482 | CYString *module_; | |
2483 | ||
2484 | CYImportDeclaration(CYImportSpecifier *specifiers, CYString *module) : | |
2485 | specifiers_(specifiers), | |
2486 | module_(module) | |
2487 | { | |
2488 | } | |
2489 | ||
2490 | CYCompact(None) | |
2491 | ||
2492 | virtual CYStatement *Replace(CYContext &context); | |
2493 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
2494 | }; | |
2495 | ||
436a877b JF |
2496 | struct CYExternalExpression : |
2497 | CYTarget | |
2498 | { | |
2499 | CYString *abi_; | |
5b4dabb2 JF |
2500 | CYType *type_; |
2501 | CYPropertyName *name_; | |
436a877b | 2502 | |
5b4dabb2 | 2503 | CYExternalExpression(CYString *abi, CYType *type, CYPropertyName *name) : |
436a877b | 2504 | abi_(abi), |
5b4dabb2 JF |
2505 | type_(type), |
2506 | name_(name) | |
436a877b JF |
2507 | { |
2508 | } | |
2509 | ||
2510 | CYPrecedence(0) | |
2511 | ||
2512 | virtual CYTarget *Replace(CYContext &context); | |
2513 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
2514 | }; | |
2515 | ||
2516 | struct CYExternalDefinition : | |
c5587ed7 JF |
2517 | CYStatement |
2518 | { | |
2519 | CYString *abi_; | |
5b4dabb2 JF |
2520 | CYType *type_; |
2521 | CYIdentifier *name_; | |
c5587ed7 | 2522 | |
5b4dabb2 | 2523 | CYExternalDefinition(CYString *abi, CYType *type, CYIdentifier *name) : |
c5587ed7 | 2524 | abi_(abi), |
5b4dabb2 JF |
2525 | type_(type), |
2526 | name_(name) | |
c5587ed7 JF |
2527 | { |
2528 | } | |
2529 | ||
efd689d8 JF |
2530 | CYCompact(None) |
2531 | ||
c5587ed7 JF |
2532 | virtual CYStatement *Replace(CYContext &context); |
2533 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
64a505ff JF |
2534 | }; |
2535 | ||
2536 | struct CYTypeExpression : | |
2537 | CYTarget | |
2538 | { | |
5b4dabb2 | 2539 | CYType *typed_; |
64a505ff | 2540 | |
5b4dabb2 | 2541 | CYTypeExpression(CYType *typed) : |
64a505ff JF |
2542 | typed_(typed) |
2543 | { | |
2544 | } | |
2545 | ||
2546 | CYPrecedence(0) | |
2547 | ||
2548 | virtual CYTarget *Replace(CYContext &context); | |
2549 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
c5587ed7 JF |
2550 | }; |
2551 | ||
60097023 JF |
2552 | struct CYTypeDefinition : |
2553 | CYStatement | |
2554 | { | |
5b4dabb2 JF |
2555 | CYType *type_; |
2556 | CYIdentifier *name_; | |
60097023 | 2557 | |
5b4dabb2 JF |
2558 | CYTypeDefinition(CYType *type, CYIdentifier *name) : |
2559 | type_(type), | |
2560 | name_(name) | |
60097023 JF |
2561 | { |
2562 | } | |
2563 | ||
efd689d8 JF |
2564 | CYCompact(None) |
2565 | ||
60097023 JF |
2566 | virtual CYStatement *Replace(CYContext &context); |
2567 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
2568 | }; | |
2569 | ||
3fe16be7 JF |
2570 | struct CYTypeBlockWith : |
2571 | CYTypeModifier | |
2572 | { | |
2573 | CYTypedParameter *parameters_; | |
2574 | ||
2575 | CYTypeBlockWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) : | |
2576 | CYTypeModifier(next), | |
2577 | parameters_(parameters) | |
2578 | { | |
2579 | } | |
2580 | ||
2581 | CYPrecedence(0) | |
2582 | ||
7085e1ab | 2583 | virtual CYTarget *Replace_(CYContext &context, CYTarget *type); |
5b4dabb2 | 2584 | void Output(CYOutput &out, CYPropertyName *name) const override; |
3fe16be7 JF |
2585 | }; |
2586 | ||
663c538f JF |
2587 | struct CYTypeFunctionWith : |
2588 | CYTypeModifier | |
2589 | { | |
574d4720 | 2590 | bool variadic_; |
663c538f JF |
2591 | CYTypedParameter *parameters_; |
2592 | ||
574d4720 | 2593 | CYTypeFunctionWith(bool variadic, CYTypedParameter *parameters, CYTypeModifier *next = NULL) : |
663c538f | 2594 | CYTypeModifier(next), |
574d4720 | 2595 | variadic_(variadic), |
663c538f JF |
2596 | parameters_(parameters) |
2597 | { | |
2598 | } | |
2599 | ||
9a39f705 | 2600 | CYPrecedence(1) |
663c538f | 2601 | |
7085e1ab | 2602 | virtual CYTarget *Replace_(CYContext &context, CYTarget *type); |
5b4dabb2 | 2603 | void Output(CYOutput &out, CYPropertyName *name) const override; |
00b4cb83 JF |
2604 | |
2605 | virtual CYTypeFunctionWith *Function() { return this; } | |
663c538f JF |
2606 | }; |
2607 | ||
b3c38c5f JF |
2608 | struct CYTypeStructField : |
2609 | CYNext<CYTypeStructField> | |
2610 | { | |
5b4dabb2 JF |
2611 | CYType *type_; |
2612 | CYPropertyName *name_; | |
b3c38c5f | 2613 | |
5b4dabb2 | 2614 | CYTypeStructField(CYType *type, CYPropertyName *name, CYTypeStructField *next = NULL) : |
b3c38c5f | 2615 | CYNext<CYTypeStructField>(next), |
5b4dabb2 JF |
2616 | type_(type), |
2617 | name_(name) | |
b3c38c5f JF |
2618 | { |
2619 | } | |
2620 | }; | |
2621 | ||
d8380373 JF |
2622 | struct CYStructTail : |
2623 | CYThing | |
2624 | { | |
2625 | CYTypeStructField *fields_; | |
2626 | ||
2627 | CYStructTail(CYTypeStructField *fields) : | |
2628 | fields_(fields) | |
2629 | { | |
2630 | } | |
2631 | ||
2632 | CYTarget *Replace(CYContext &context); | |
2633 | virtual void Output(CYOutput &out) const; | |
2634 | }; | |
2635 | ||
b3c38c5f JF |
2636 | struct CYTypeStruct : |
2637 | CYTypeSpecifier | |
2638 | { | |
2639 | CYIdentifier *name_; | |
d8380373 | 2640 | CYStructTail *tail_; |
b3c38c5f | 2641 | |
d8380373 | 2642 | CYTypeStruct(CYIdentifier *name, CYStructTail *tail) : |
b3c38c5f | 2643 | name_(name), |
d8380373 | 2644 | tail_(tail) |
b3c38c5f JF |
2645 | { |
2646 | } | |
2647 | ||
2648 | virtual CYTarget *Replace(CYContext &context); | |
2649 | virtual void Output(CYOutput &out) const; | |
2650 | }; | |
2651 | ||
d8380373 JF |
2652 | struct CYStructDefinition : |
2653 | CYStatement | |
2654 | { | |
2655 | CYIdentifier *name_; | |
2656 | CYStructTail *tail_; | |
2657 | ||
2658 | CYStructDefinition(CYIdentifier *name, CYStructTail *tail) : | |
2659 | name_(name), | |
2660 | tail_(tail) | |
2661 | { | |
2662 | } | |
2663 | ||
2664 | CYCompact(None) | |
2665 | ||
2666 | virtual CYStatement *Replace(CYContext &context); | |
2667 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
2668 | }; | |
2669 | ||
aaa29c28 JF |
2670 | struct CYEnumConstant : |
2671 | CYNext<CYEnumConstant> | |
2672 | { | |
2673 | CYIdentifier *name_; | |
2674 | CYNumber *value_; | |
2675 | ||
2676 | CYEnumConstant(CYIdentifier *name, CYNumber *value, CYEnumConstant *next = NULL) : | |
2677 | CYNext<CYEnumConstant>(next), | |
2678 | name_(name), | |
2679 | value_(value) | |
2680 | { | |
2681 | } | |
2682 | }; | |
2683 | ||
2684 | struct CYTypeEnum : | |
2685 | CYTypeSpecifier | |
2686 | { | |
2687 | CYIdentifier *name_; | |
2688 | CYTypeSpecifier *specifier_; | |
2689 | CYEnumConstant *constants_; | |
2690 | ||
2691 | CYTypeEnum(CYIdentifier *name, CYTypeSpecifier *specifier, CYEnumConstant *constants) : | |
2692 | name_(name), | |
2693 | specifier_(specifier), | |
2694 | constants_(constants) | |
2695 | { | |
2696 | } | |
2697 | ||
2698 | virtual CYTarget *Replace(CYContext &context); | |
2699 | virtual void Output(CYOutput &out) const; | |
2700 | }; | |
2701 | ||
37954781 JF |
2702 | namespace cy { |
2703 | namespace Syntax { | |
2704 | ||
2705 | struct Catch : | |
2706 | CYThing | |
2707 | { | |
2708 | CYIdentifier *name_; | |
b0385401 | 2709 | CYStatement *code_; |
37954781 | 2710 | |
b0385401 | 2711 | Catch(CYIdentifier *name, CYStatement *code) : |
37954781 | 2712 | name_(name), |
b0385401 | 2713 | code_(code) |
37954781 JF |
2714 | { |
2715 | } | |
2716 | ||
2717 | void Replace(CYContext &context); | |
2718 | virtual void Output(CYOutput &out) const; | |
2719 | }; | |
2720 | ||
2721 | struct Try : | |
cf7d4c69 JF |
2722 | CYStatement |
2723 | { | |
b0385401 | 2724 | CYStatement *code_; |
37954781 | 2725 | Catch *catch_; |
b10bd496 | 2726 | CYFinally *finally_; |
cf7d4c69 | 2727 | |
b0385401 JF |
2728 | Try(CYStatement *code, Catch *_catch, CYFinally *finally) : |
2729 | code_(code), | |
cf7d4c69 JF |
2730 | catch_(_catch), |
2731 | finally_(finally) | |
2732 | { | |
2733 | } | |
5999c315 | 2734 | |
efd689d8 JF |
2735 | CYCompact(Short) |
2736 | ||
3b52fd1a | 2737 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 2738 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
2739 | }; |
2740 | ||
37954781 | 2741 | struct Throw : |
cf7d4c69 JF |
2742 | CYStatement |
2743 | { | |
2744 | CYExpression *value_; | |
2745 | ||
ab2aa221 | 2746 | Throw(CYExpression *value = NULL) : |
cf7d4c69 JF |
2747 | value_(value) |
2748 | { | |
2749 | } | |
5999c315 | 2750 | |
efd689d8 JF |
2751 | CYCompact(None) |
2752 | ||
3b52fd1a | 2753 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 2754 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
2755 | }; |
2756 | ||
37954781 JF |
2757 | } } |
2758 | ||
cf7d4c69 JF |
2759 | struct CYWith : |
2760 | CYStatement | |
2761 | { | |
2762 | CYExpression *scope_; | |
2763 | CYStatement *code_; | |
2764 | ||
2765 | CYWith(CYExpression *scope, CYStatement *code) : | |
2766 | scope_(scope), | |
2767 | code_(code) | |
2768 | { | |
2769 | } | |
5999c315 | 2770 | |
efd689d8 JF |
2771 | CYCompact(Long) |
2772 | ||
3b52fd1a | 2773 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 2774 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
2775 | }; |
2776 | ||
2777 | struct CYSwitch : | |
2778 | CYStatement | |
2779 | { | |
2780 | CYExpression *value_; | |
2781 | CYClause *clauses_; | |
2782 | ||
2783 | CYSwitch(CYExpression *value, CYClause *clauses) : | |
2784 | value_(value), | |
2785 | clauses_(clauses) | |
2786 | { | |
2787 | } | |
5999c315 | 2788 | |
efd689d8 JF |
2789 | CYCompact(Long) |
2790 | ||
3b52fd1a | 2791 | virtual CYStatement *Replace(CYContext &context); |
c8a0500b JF |
2792 | virtual void Output(CYOutput &out, CYFlags flags) const; |
2793 | }; | |
2794 | ||
2795 | struct CYDebugger : | |
2796 | CYStatement | |
2797 | { | |
2798 | CYDebugger() | |
2799 | { | |
2800 | } | |
2801 | ||
efd689d8 JF |
2802 | CYCompact(None) |
2803 | ||
c8a0500b | 2804 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 2805 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
2806 | }; |
2807 | ||
2808 | struct CYCondition : | |
2809 | CYExpression | |
2810 | { | |
2811 | CYExpression *test_; | |
2812 | CYExpression *true_; | |
2813 | CYExpression *false_; | |
2814 | ||
2815 | CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) : | |
91a416e4 | 2816 | test_(test), |
cf7d4c69 JF |
2817 | true_(_true), |
2818 | false_(_false) | |
2819 | { | |
2820 | } | |
5999c315 | 2821 | |
d35a3b07 JF |
2822 | CYPrecedence(15) |
2823 | ||
3b52fd1a | 2824 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 2825 | virtual void Output(CYOutput &out, CYFlags flags) const; |
5999c315 JF |
2826 | }; |
2827 | ||
2828 | struct CYAddressOf : | |
2829 | CYPrefix | |
2830 | { | |
2831 | CYAddressOf(CYExpression *rhs) : | |
2832 | CYPrefix(rhs) | |
2833 | { | |
2834 | } | |
2835 | ||
2836 | virtual const char *Operator() const { | |
2837 | return "&"; | |
2838 | } | |
2839 | ||
b09da87b | 2840 | CYAlphabetic(false) |
d35a3b07 | 2841 | |
3b52fd1a | 2842 | virtual CYExpression *Replace(CYContext &context); |
5999c315 JF |
2843 | }; |
2844 | ||
2845 | struct CYIndirect : | |
7085e1ab | 2846 | CYTarget |
5999c315 | 2847 | { |
7085e1ab JF |
2848 | CYExpression *rhs_; |
2849 | ||
5999c315 | 2850 | CYIndirect(CYExpression *rhs) : |
7085e1ab | 2851 | rhs_(rhs) |
5999c315 JF |
2852 | { |
2853 | } | |
2854 | ||
7085e1ab JF |
2855 | // XXX: this should be checked |
2856 | CYPrecedence(2) | |
d35a3b07 | 2857 | |
7085e1ab JF |
2858 | virtual CYTarget *Replace(CYContext &context); |
2859 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
cf7d4c69 JF |
2860 | }; |
2861 | ||
4644480a JF |
2862 | #define CYReplace \ |
2863 | virtual CYExpression *Replace(CYContext &context); | |
2864 | ||
2865 | #define CYPostfix_(op, name, args...) \ | |
cf7d4c69 JF |
2866 | struct CY ## name : \ |
2867 | CYPostfix \ | |
4644480a | 2868 | { args \ |
cf7d4c69 JF |
2869 | CY ## name(CYExpression *lhs) : \ |
2870 | CYPostfix(lhs) \ | |
2871 | { \ | |
2872 | } \ | |
5999c315 JF |
2873 | \ |
2874 | virtual const char *Operator() const { \ | |
2875 | return op; \ | |
2876 | } \ | |
cf7d4c69 JF |
2877 | }; |
2878 | ||
4644480a | 2879 | #define CYPrefix_(alphabetic, op, name, args...) \ |
cf7d4c69 JF |
2880 | struct CY ## name : \ |
2881 | CYPrefix \ | |
4644480a | 2882 | { args \ |
cf7d4c69 JF |
2883 | CY ## name(CYExpression *rhs) : \ |
2884 | CYPrefix(rhs) \ | |
2885 | { \ | |
2886 | } \ | |
d35a3b07 | 2887 | \ |
b09da87b | 2888 | CYAlphabetic(alphabetic) \ |
5999c315 JF |
2889 | \ |
2890 | virtual const char *Operator() const { \ | |
2891 | return op; \ | |
2892 | } \ | |
cf7d4c69 JF |
2893 | }; |
2894 | ||
4644480a | 2895 | #define CYInfix_(alphabetic, precedence, op, name, args...) \ |
cf7d4c69 JF |
2896 | struct CY ## name : \ |
2897 | CYInfix \ | |
4644480a | 2898 | { args \ |
cf7d4c69 JF |
2899 | CY ## name(CYExpression *lhs, CYExpression *rhs) : \ |
2900 | CYInfix(lhs, rhs) \ | |
2901 | { \ | |
2902 | } \ | |
d35a3b07 | 2903 | \ |
b09da87b | 2904 | CYAlphabetic(alphabetic) \ |
d35a3b07 | 2905 | CYPrecedence(precedence) \ |
5999c315 JF |
2906 | \ |
2907 | virtual const char *Operator() const { \ | |
2908 | return op; \ | |
2909 | } \ | |
cf7d4c69 JF |
2910 | }; |
2911 | ||
4644480a | 2912 | #define CYAssignment_(op, name, args...) \ |
cf7d4c69 JF |
2913 | struct CY ## name ## Assign : \ |
2914 | CYAssignment \ | |
4644480a | 2915 | { args \ |
7085e1ab | 2916 | CY ## name ## Assign(CYTarget *lhs, CYExpression *rhs) : \ |
cf7d4c69 JF |
2917 | CYAssignment(lhs, rhs) \ |
2918 | { \ | |
2919 | } \ | |
5999c315 JF |
2920 | \ |
2921 | virtual const char *Operator() const { \ | |
2922 | return op; \ | |
2923 | } \ | |
cf7d4c69 JF |
2924 | }; |
2925 | ||
2926 | CYPostfix_("++", PostIncrement) | |
2927 | CYPostfix_("--", PostDecrement) | |
2928 | ||
b09da87b JF |
2929 | CYPrefix_(true, "delete", Delete) |
2930 | CYPrefix_(true, "void", Void) | |
2931 | CYPrefix_(true, "typeof", TypeOf) | |
2932 | CYPrefix_(false, "++", PreIncrement) | |
2933 | CYPrefix_(false, "--", PreDecrement) | |
c0bc320e | 2934 | CYPrefix_(false, "+", Affirm) |
b09da87b JF |
2935 | CYPrefix_(false, "-", Negate) |
2936 | CYPrefix_(false, "~", BitwiseNot) | |
2937 | CYPrefix_(false, "!", LogicalNot) | |
2938 | ||
62f398e4 | 2939 | CYInfix_(false, 5, "*", Multiply, CYReplace) |
b09da87b JF |
2940 | CYInfix_(false, 5, "/", Divide) |
2941 | CYInfix_(false, 5, "%", Modulus) | |
4644480a | 2942 | CYInfix_(false, 6, "+", Add, CYReplace) |
b09da87b JF |
2943 | CYInfix_(false, 6, "-", Subtract) |
2944 | CYInfix_(false, 7, "<<", ShiftLeft) | |
2945 | CYInfix_(false, 7, ">>", ShiftRightSigned) | |
2946 | CYInfix_(false, 7, ">>>", ShiftRightUnsigned) | |
2947 | CYInfix_(false, 8, "<", Less) | |
2948 | CYInfix_(false, 8, ">", Greater) | |
2949 | CYInfix_(false, 8, "<=", LessOrEqual) | |
2950 | CYInfix_(false, 8, ">=", GreaterOrEqual) | |
2951 | CYInfix_(true, 8, "instanceof", InstanceOf) | |
2952 | CYInfix_(true, 8, "in", In) | |
2953 | CYInfix_(false, 9, "==", Equal) | |
2954 | CYInfix_(false, 9, "!=", NotEqual) | |
2955 | CYInfix_(false, 9, "===", Identical) | |
2956 | CYInfix_(false, 9, "!==", NotIdentical) | |
2957 | CYInfix_(false, 10, "&", BitwiseAnd) | |
2958 | CYInfix_(false, 11, "^", BitwiseXOr) | |
2959 | CYInfix_(false, 12, "|", BitwiseOr) | |
2960 | CYInfix_(false, 13, "&&", LogicalAnd) | |
2961 | CYInfix_(false, 14, "||", LogicalOr) | |
cf7d4c69 JF |
2962 | |
2963 | CYAssignment_("=", ) | |
2964 | CYAssignment_("*=", Multiply) | |
2965 | CYAssignment_("/=", Divide) | |
2966 | CYAssignment_("%=", Modulus) | |
2967 | CYAssignment_("+=", Add) | |
2968 | CYAssignment_("-=", Subtract) | |
2969 | CYAssignment_("<<=", ShiftLeft) | |
2970 | CYAssignment_(">>=", ShiftRightSigned) | |
2971 | CYAssignment_(">>>=", ShiftRightUnsigned) | |
2972 | CYAssignment_("&=", BitwiseAnd) | |
2973 | CYAssignment_("^=", BitwiseXOr) | |
2974 | CYAssignment_("|=", BitwiseOr) | |
2975 | ||
c5fa2867 | 2976 | #endif/*CYCRIPT_PARSER_HPP*/ |