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