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