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