]>
Commit | Line | Data |
---|---|---|
4644480a | 1 | /* Cycript - Remote Execution Server and Disassembler |
b4aa79af JF |
2 | * Copyright (C) 2009 Jay Freeman (saurik) |
3 | */ | |
4 | ||
5 | /* Modified BSD License {{{ */ | |
6 | /* | |
7 | * Redistribution and use in source and binary | |
8 | * forms, with or without modification, are permitted | |
9 | * provided that the following conditions are met: | |
10 | * | |
11 | * 1. Redistributions of source code must retain the | |
12 | * above copyright notice, this list of conditions | |
13 | * and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the | |
15 | * above copyright notice, this list of conditions | |
16 | * and the following disclaimer in the documentation | |
17 | * and/or other materials provided with the | |
18 | * distribution. | |
19 | * 3. The name of the author may not be used to endorse | |
20 | * or promote products derived from this software | |
21 | * without specific prior written permission. | |
22 | * | |
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' | |
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
25 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
26 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE | |
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
30 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
32 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
33 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
34 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
35 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
36 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
37 | */ | |
38 | /* }}} */ | |
39 | ||
63b4c5a8 JF |
40 | #ifndef CYPARSER_HPP |
41 | #define CYPARSER_HPP | |
42 | ||
4de0686f JF |
43 | // XXX: wtf is this here?! |
44 | #define CYPA 16 | |
45 | ||
46 | #include <iostream> | |
47 | ||
5999c315 | 48 | #include <string> |
c3c20102 | 49 | #include <vector> |
cf7d4c69 | 50 | |
4de0686f JF |
51 | #include <cstdlib> |
52 | ||
5befe15e | 53 | #include "location.hh" |
5999c315 | 54 | #include "Pooling.hpp" |
924f67b2 | 55 | |
5999c315 JF |
56 | template <typename Type_> |
57 | struct CYNext { | |
58 | Type_ *next_; | |
63b4c5a8 | 59 | |
5999c315 JF |
60 | CYNext() : |
61 | next_(NULL) | |
62 | { | |
63 | } | |
cf7d4c69 | 64 | |
62014ea9 JF |
65 | CYNext(Type_ *next) : |
66 | next_(next) | |
67 | { | |
68 | } | |
69 | ||
5999c315 | 70 | void SetNext(Type_ *next) { |
cf7d4c69 JF |
71 | next_ = next; |
72 | } | |
73 | }; | |
74 | ||
5999c315 | 75 | struct CYThing { |
652ec1ba | 76 | virtual void Output(struct CYOutput &out) const = 0; |
5999c315 JF |
77 | }; |
78 | ||
652ec1ba JF |
79 | struct CYOutput { |
80 | std::ostream &out_; | |
11c1cc16 JF |
81 | bool pretty_; |
82 | unsigned indent_; | |
652ec1ba | 83 | |
96a7e5c2 JF |
84 | enum { |
85 | NoMode, | |
86 | NoLetter, | |
c0bc320e | 87 | NoPlus, |
96a7e5c2 JF |
88 | NoHyphen, |
89 | Terminated | |
90 | } mode_; | |
91 | ||
652ec1ba | 92 | CYOutput(std::ostream &out) : |
11c1cc16 JF |
93 | out_(out), |
94 | pretty_(false), | |
96a7e5c2 JF |
95 | indent_(0), |
96 | mode_(NoMode) | |
652ec1ba JF |
97 | { |
98 | } | |
99 | ||
96a7e5c2 | 100 | void Check(char value); |
1fdca2fa | 101 | void Terminate(); |
652ec1ba | 102 | |
96a7e5c2 JF |
103 | CYOutput &operator <<(char rhs); |
104 | CYOutput &operator <<(const char *rhs); | |
105 | ||
106 | _finline CYOutput &operator <<(const CYThing *rhs) { | |
107 | if (rhs != NULL) | |
108 | rhs->Output(*this); | |
652ec1ba JF |
109 | return *this; |
110 | } | |
111 | ||
112 | _finline CYOutput &operator <<(const CYThing &rhs) { | |
113 | rhs.Output(*this); | |
114 | return *this; | |
115 | } | |
116 | }; | |
5999c315 | 117 | |
e5bc40db | 118 | struct CYPropertyName { |
652ec1ba | 119 | virtual void PropertyName(CYOutput &out) const = 0; |
e5bc40db JF |
120 | }; |
121 | ||
3b52fd1a JF |
122 | struct CYExpression; |
123 | ||
124 | enum CYNeeded { | |
125 | CYNever = -1, | |
126 | CYSometimes = 0, | |
127 | CYAlways = 1, | |
128 | }; | |
129 | ||
130 | enum CYFlags { | |
131 | CYNoFlags = 0, | |
132 | CYNoBrace = (1 << 0), | |
133 | CYNoFunction = (1 << 1), | |
134 | CYNoIn = (1 << 2), | |
135 | CYNoCall = (1 << 3), | |
136 | CYNoRightHand = (1 << 4), | |
137 | CYNoDangle = (1 << 5), | |
138 | CYNoBF = (CYNoBrace | CYNoFunction), | |
139 | }; | |
140 | ||
141 | struct CYContext { | |
142 | apr_pool_t *pool_; | |
143 | ||
144 | CYContext(apr_pool_t *pool) : | |
145 | pool_(pool) | |
146 | { | |
147 | } | |
148 | ||
149 | template <typename Type_> | |
150 | void Replace(Type_ *&value) { | |
151 | if (value != NULL) | |
152 | while (Type_ *replace = value->Replace(*this)) | |
153 | value = replace; | |
154 | } | |
155 | }; | |
156 | ||
157 | struct CYStatement : | |
158 | CYNext<CYStatement> | |
159 | { | |
160 | void Single(CYOutput &out, CYFlags flags) const; | |
161 | void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const; | |
162 | ||
163 | CYStatement *ReplaceAll(CYContext &context); | |
164 | ||
165 | virtual CYStatement *Replace(CYContext &context) = 0; | |
166 | ||
167 | private: | |
168 | virtual void Output(CYOutput &out, CYFlags flags) const = 0; | |
169 | }; | |
170 | ||
171 | struct CYStatements { | |
172 | CYStatement *first_; | |
173 | CYStatement *last_; | |
174 | ||
175 | CYStatements() : | |
176 | first_(NULL), | |
177 | last_(NULL) | |
178 | { | |
179 | } | |
180 | ||
181 | operator CYStatement *() const { | |
182 | return first_; | |
183 | } | |
184 | ||
185 | CYStatements &operator ->*(CYStatement *next) { | |
186 | if (next != NULL) | |
187 | if (first_ == NULL) { | |
188 | first_ = next; | |
189 | last_ = next; | |
190 | } else for (;; last_ = last_->next_) | |
191 | if (last_->next_ == NULL) { | |
192 | last_->next_ = next; | |
193 | last_ = next; | |
194 | break; | |
195 | } | |
196 | return *this; | |
197 | } | |
198 | }; | |
199 | ||
e5bc40db | 200 | struct CYClassName { |
3b52fd1a | 201 | virtual CYExpression *ClassName(CYContext &context, bool object) = 0; |
652ec1ba | 202 | virtual void ClassName(CYOutput &out, bool object) const = 0; |
63b4c5a8 JF |
203 | }; |
204 | ||
cf7d4c69 | 205 | struct CYWord : |
e5bc40db JF |
206 | CYThing, |
207 | CYPropertyName, | |
208 | CYClassName | |
63b4c5a8 | 209 | { |
cf7d4c69 JF |
210 | const char *word_; |
211 | ||
212 | CYWord(const char *word) : | |
213 | word_(word) | |
214 | { | |
215 | } | |
216 | ||
5999c315 | 217 | const char *Value() const { |
cf7d4c69 JF |
218 | return word_; |
219 | } | |
220 | ||
652ec1ba | 221 | virtual void Output(CYOutput &out) const; |
e5bc40db | 222 | |
3b52fd1a | 223 | virtual CYExpression *ClassName(CYContext &context, bool object); |
652ec1ba JF |
224 | virtual void ClassName(CYOutput &out, bool object) const; |
225 | virtual void PropertyName(CYOutput &out) const; | |
63b4c5a8 JF |
226 | }; |
227 | ||
652ec1ba JF |
228 | _finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) { |
229 | return lhs << rhs.Value(); | |
230 | } | |
231 | ||
cf7d4c69 JF |
232 | struct CYIdentifier : |
233 | CYWord | |
63b4c5a8 | 234 | { |
5999c315 JF |
235 | CYIdentifier(const char *word) : |
236 | CYWord(word) | |
237 | { | |
cf7d4c69 | 238 | } |
63b4c5a8 JF |
239 | }; |
240 | ||
62014ea9 | 241 | struct CYLabel : |
3b52fd1a | 242 | CYStatement |
62014ea9 | 243 | { |
9e562cfc | 244 | CYIdentifier *name_; |
3b52fd1a | 245 | CYStatement *statement_; |
cf7d4c69 | 246 | |
3b52fd1a JF |
247 | CYLabel(CYIdentifier *name, CYStatement *statement) : |
248 | name_(name), | |
249 | statement_(statement) | |
cf7d4c69 JF |
250 | { |
251 | } | |
fb98ac0c | 252 | |
3b52fd1a JF |
253 | virtual CYStatement *Replace(CYContext &context); |
254 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
fb98ac0c JF |
255 | }; |
256 | ||
3b52fd1a JF |
257 | struct CYProgram : |
258 | CYThing | |
63b4c5a8 | 259 | { |
3b52fd1a | 260 | CYStatement *statements_; |
9e562cfc | 261 | |
3b52fd1a JF |
262 | CYProgram(CYStatement *statements) : |
263 | statements_(statements) | |
9e562cfc JF |
264 | { |
265 | } | |
cf7d4c69 | 266 | |
3b52fd1a | 267 | virtual void Replace(CYContext &context); |
fb98ac0c | 268 | |
3b52fd1a | 269 | virtual void Output(CYOutput &out) const; |
9e562cfc JF |
270 | }; |
271 | ||
272 | struct CYBlock : | |
3b52fd1a JF |
273 | CYStatement, |
274 | CYThing | |
9e562cfc JF |
275 | { |
276 | CYStatement *statements_; | |
277 | ||
278 | CYBlock(CYStatement *statements) : | |
279 | statements_(statements) | |
280 | { | |
cf7d4c69 | 281 | } |
9e562cfc | 282 | |
4644480a JF |
283 | operator CYStatement *() const { |
284 | return statements_; | |
285 | } | |
286 | ||
3b52fd1a JF |
287 | virtual CYStatement *Replace(CYContext &context); |
288 | ||
289 | virtual void Output(CYOutput &out) const; | |
fb98ac0c | 290 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
291 | }; |
292 | ||
db5e2840 JF |
293 | enum CYState { |
294 | CYClear, | |
295 | CYRestricted, | |
296 | CYNewLine | |
297 | }; | |
298 | ||
5999c315 JF |
299 | class CYDriver { |
300 | public: | |
301 | CYPool pool_; | |
e7ed5354 | 302 | |
db5e2840 | 303 | CYState state_; |
e7ed5354 JF |
304 | void *scanner_; |
305 | ||
306 | const char *data_; | |
307 | size_t size_; | |
48e3be8a | 308 | FILE *file_; |
e7ed5354 | 309 | |
b10bd496 JF |
310 | bool strict_; |
311 | ||
63cd45c9 | 312 | enum Condition { |
cb02f8ae JF |
313 | RegExpSlash, |
314 | RegExpSlashEqual, | |
315 | RegExpSlashRight, | |
63cd45c9 JF |
316 | }; |
317 | ||
5999c315 | 318 | std::string filename_; |
e7ed5354 | 319 | |
5befe15e | 320 | struct Error { |
b10bd496 | 321 | bool warning_; |
5befe15e JF |
322 | cy::location location_; |
323 | std::string message_; | |
324 | }; | |
325 | ||
326 | typedef std::vector<Error> Errors; | |
327 | ||
3b52fd1a | 328 | CYProgram *program_; |
5befe15e | 329 | Errors errors_; |
5999c315 JF |
330 | |
331 | private: | |
332 | void ScannerInit(); | |
333 | void ScannerDestroy(); | |
334 | ||
335 | public: | |
336 | CYDriver(const std::string &filename); | |
337 | ~CYDriver(); | |
63cd45c9 JF |
338 | |
339 | void SetCondition(Condition condition); | |
b10bd496 JF |
340 | |
341 | void Warning(const cy::location &location, const char *message); | |
5999c315 JF |
342 | }; |
343 | ||
cac61857 | 344 | struct CYForInitialiser { |
652ec1ba | 345 | virtual void For(CYOutput &out) const = 0; |
dea834b0 JF |
346 | }; |
347 | ||
cac61857 | 348 | struct CYForInInitialiser { |
652ec1ba | 349 | virtual void ForIn(CYOutput &out, CYFlags flags) const = 0; |
75b0a457 | 350 | virtual const char *ForEachIn() const = 0; |
3b52fd1a | 351 | virtual CYExpression *ForEachIn(CYContext &out) = 0; |
b09da87b JF |
352 | }; |
353 | ||
4644480a JF |
354 | struct CYNumber; |
355 | struct CYString; | |
356 | ||
cf7d4c69 | 357 | struct CYExpression : |
5999c315 | 358 | CYNext<CYExpression>, |
cf7d4c69 | 359 | CYForInitialiser, |
e5bc40db | 360 | CYForInInitialiser, |
96a7e5c2 JF |
361 | CYClassName, |
362 | CYThing | |
63b4c5a8 | 363 | { |
d35a3b07 | 364 | virtual unsigned Precedence() const = 0; |
75b0a457 | 365 | |
fb98ac0c JF |
366 | virtual bool RightHand() const { |
367 | return true; | |
368 | } | |
369 | ||
652ec1ba JF |
370 | virtual void For(CYOutput &out) const; |
371 | virtual void ForIn(CYOutput &out, CYFlags flags) const; | |
75b0a457 | 372 | |
cac61857 | 373 | virtual const char *ForEachIn() const; |
3b52fd1a | 374 | virtual CYExpression *ForEachIn(CYContext &out); |
75b0a457 | 375 | |
96a7e5c2 | 376 | virtual void Output(CYOutput &out) const; |
652ec1ba JF |
377 | virtual void Output(CYOutput &out, CYFlags flags) const = 0; |
378 | void Output(CYOutput &out, unsigned precedence, CYFlags flags) const; | |
dea834b0 | 379 | |
3b52fd1a | 380 | virtual CYExpression *ClassName(CYContext &context, bool object); |
652ec1ba | 381 | virtual void ClassName(CYOutput &out, bool object) const; |
e5bc40db | 382 | |
3b52fd1a JF |
383 | CYExpression *ReplaceAll(CYContext &context); |
384 | ||
385 | virtual CYExpression *Replace(CYContext &context) = 0; | |
386 | ||
4644480a JF |
387 | virtual CYExpression *Primitive(CYContext &context) { |
388 | return this; | |
389 | } | |
390 | ||
391 | virtual CYNumber *Number(CYContext &context) { | |
392 | return NULL; | |
393 | } | |
394 | ||
395 | virtual CYString *String(CYContext &context) { | |
396 | return NULL; | |
397 | } | |
398 | ||
dea834b0 JF |
399 | virtual const char *Word() const { |
400 | return NULL; | |
401 | } | |
63b4c5a8 JF |
402 | }; |
403 | ||
b09da87b JF |
404 | #define CYAlphabetic(value) \ |
405 | virtual bool Alphabetic() const { \ | |
406 | return value; \ | |
407 | } | |
408 | ||
d35a3b07 JF |
409 | #define CYPrecedence(value) \ |
410 | virtual unsigned Precedence() const { \ | |
411 | return value; \ | |
412 | } | |
413 | ||
fb98ac0c JF |
414 | #define CYRightHand(value) \ |
415 | virtual bool RightHand() const { \ | |
416 | return value; \ | |
417 | } | |
418 | ||
d35a3b07 JF |
419 | struct CYCompound : |
420 | CYExpression | |
421 | { | |
422 | CYExpression *expressions_; | |
423 | ||
424 | CYCompound(CYExpression *expressions) : | |
425 | expressions_(expressions) | |
426 | { | |
427 | } | |
428 | ||
429 | void AddPrev(CYExpression *expression) { | |
430 | CYExpression *last(expression); | |
431 | while (last->next_ != NULL) | |
432 | last = last->next_; | |
433 | last->SetNext(expressions_); | |
434 | expressions_ = expression; | |
435 | } | |
436 | ||
437 | CYPrecedence(17) | |
438 | ||
3b52fd1a | 439 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 440 | void Output(CYOutput &out, CYFlags flags) const; |
d35a3b07 | 441 | }; |
5999c315 | 442 | |
3b52fd1a JF |
443 | struct CYFunctionParameter : |
444 | CYNext<CYFunctionParameter>, | |
445 | CYThing | |
446 | { | |
447 | CYIdentifier *name_; | |
448 | ||
449 | CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) : | |
450 | CYNext<CYFunctionParameter>(next), | |
451 | name_(name) | |
452 | { | |
453 | } | |
454 | ||
455 | virtual void Output(CYOutput &out) const; | |
456 | }; | |
457 | ||
75b0a457 | 458 | struct CYComprehension : |
96a7e5c2 JF |
459 | CYNext<CYComprehension>, |
460 | CYThing | |
75b0a457 | 461 | { |
75b0a457 JF |
462 | virtual const char *Name() const = 0; |
463 | ||
3b52fd1a JF |
464 | virtual CYFunctionParameter *Parameter(CYContext &context) const = 0; |
465 | CYFunctionParameter *Parameters(CYContext &context) const; | |
466 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
4644480a | 467 | virtual void Output(CYOutput &out) const = 0; |
75b0a457 JF |
468 | }; |
469 | ||
470 | struct CYForInComprehension : | |
471 | CYComprehension | |
472 | { | |
473 | CYIdentifier *name_; | |
474 | CYExpression *set_; | |
475 | ||
476 | CYForInComprehension(CYIdentifier *name, CYExpression *set) : | |
477 | name_(name), | |
478 | set_(set) | |
479 | { | |
480 | } | |
481 | ||
482 | virtual const char *Name() const { | |
483 | return name_->Value(); | |
484 | } | |
485 | ||
3b52fd1a JF |
486 | virtual CYFunctionParameter *Parameter(CYContext &context) const; |
487 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
4644480a | 488 | virtual void Output(CYOutput &out) const; |
75b0a457 JF |
489 | }; |
490 | ||
491 | struct CYForEachInComprehension : | |
492 | CYComprehension | |
493 | { | |
494 | CYIdentifier *name_; | |
495 | CYExpression *set_; | |
496 | ||
497 | CYForEachInComprehension(CYIdentifier *name, CYExpression *set) : | |
498 | name_(name), | |
499 | set_(set) | |
500 | { | |
501 | } | |
502 | ||
503 | virtual const char *Name() const { | |
504 | return name_->Value(); | |
505 | } | |
506 | ||
3b52fd1a JF |
507 | virtual CYFunctionParameter *Parameter(CYContext &context) const; |
508 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
4644480a | 509 | virtual void Output(CYOutput &out) const; |
75b0a457 JF |
510 | }; |
511 | ||
512 | struct CYIfComprehension : | |
513 | CYComprehension | |
514 | { | |
515 | CYExpression *test_; | |
516 | ||
517 | CYIfComprehension(CYExpression *test) : | |
518 | test_(test) | |
519 | { | |
520 | } | |
521 | ||
522 | virtual const char *Name() const { | |
523 | return NULL; | |
524 | } | |
525 | ||
3b52fd1a JF |
526 | virtual CYFunctionParameter *Parameter(CYContext &context) const; |
527 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
4644480a | 528 | virtual void Output(CYOutput &out) const; |
75b0a457 JF |
529 | }; |
530 | ||
531 | struct CYArrayComprehension : | |
532 | CYExpression | |
533 | { | |
534 | CYExpression *expression_; | |
535 | CYComprehension *comprehensions_; | |
536 | ||
537 | CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) : | |
538 | expression_(expression), | |
539 | comprehensions_(comprehensions) | |
540 | { | |
541 | } | |
542 | ||
543 | CYPrecedence(0) | |
544 | ||
3b52fd1a | 545 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 546 | virtual void Output(CYOutput &out, CYFlags flags) const; |
75b0a457 JF |
547 | }; |
548 | ||
cf7d4c69 JF |
549 | struct CYLiteral : |
550 | CYExpression | |
63b4c5a8 | 551 | { |
d35a3b07 | 552 | CYPrecedence(0) |
fb98ac0c | 553 | CYRightHand(false) |
cf7d4c69 | 554 | }; |
63b4c5a8 | 555 | |
3b52fd1a JF |
556 | struct CYTrivial : |
557 | CYLiteral | |
558 | { | |
559 | virtual CYExpression *Replace(CYContext &context); | |
560 | }; | |
561 | ||
478d4ed0 JF |
562 | struct CYMagic : |
563 | CYExpression | |
564 | { | |
565 | CYPrecedence(0) | |
fb98ac0c | 566 | CYRightHand(false) |
478d4ed0 JF |
567 | }; |
568 | ||
dea834b0 JF |
569 | struct CYRange { |
570 | uint64_t lo_; | |
571 | uint64_t hi_; | |
572 | ||
573 | CYRange(uint64_t lo, uint64_t hi) : | |
574 | lo_(lo), hi_(hi) | |
575 | { | |
576 | } | |
577 | ||
578 | bool operator [](uint8_t value) const { | |
579 | return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1; | |
580 | } | |
581 | ||
582 | void operator()(uint8_t value) { | |
583 | if (value >> 7) | |
584 | return; | |
585 | (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f); | |
586 | } | |
587 | }; | |
588 | ||
283e7e33 | 589 | extern CYRange DigitRange_; |
dea834b0 JF |
590 | extern CYRange WordStartRange_; |
591 | extern CYRange WordEndRange_; | |
592 | ||
cf7d4c69 | 593 | struct CYString : |
3b52fd1a | 594 | CYTrivial, |
e5bc40db | 595 | CYPropertyName |
cf7d4c69 JF |
596 | { |
597 | const char *value_; | |
5999c315 | 598 | size_t size_; |
cf7d4c69 | 599 | |
3b52fd1a JF |
600 | CYString() : |
601 | value_(NULL), | |
602 | size_(0) | |
603 | { | |
604 | } | |
605 | ||
606 | CYString(const char *value) : | |
607 | value_(value), | |
608 | size_(strlen(value)) | |
609 | { | |
610 | } | |
611 | ||
5999c315 JF |
612 | CYString(const char *value, size_t size) : |
613 | value_(value), | |
614 | size_(size) | |
cf7d4c69 JF |
615 | { |
616 | } | |
617 | ||
3b52fd1a JF |
618 | CYString(const CYWord *word) : |
619 | value_(word->Value()), | |
5999c315 | 620 | size_(strlen(value_)) |
cf7d4c69 JF |
621 | { |
622 | } | |
623 | ||
5999c315 | 624 | const char *Value() const { |
cf7d4c69 JF |
625 | return value_; |
626 | } | |
627 | ||
11c1cc16 | 628 | virtual const char *Word() const; |
dea834b0 | 629 | |
4644480a JF |
630 | virtual CYNumber *Number(CYContext &context); |
631 | virtual CYString *String(CYContext &context); | |
632 | ||
633 | virtual CYString *Concat(CYContext &out, CYString *rhs) const; | |
652ec1ba JF |
634 | virtual void Output(CYOutput &out, CYFlags flags) const; |
635 | virtual void PropertyName(CYOutput &out) const; | |
63b4c5a8 JF |
636 | }; |
637 | ||
cf7d4c69 | 638 | struct CYNumber : |
3b52fd1a | 639 | CYTrivial, |
e5bc40db | 640 | CYPropertyName |
cf7d4c69 | 641 | { |
5999c315 JF |
642 | double value_; |
643 | ||
644 | CYNumber(double value) : | |
645 | value_(value) | |
646 | { | |
647 | } | |
648 | ||
649 | double Value() const { | |
650 | return value_; | |
cf7d4c69 JF |
651 | } |
652 | ||
4644480a JF |
653 | virtual CYNumber *Number(CYContext &context); |
654 | virtual CYString *String(CYContext &context); | |
655 | ||
652ec1ba JF |
656 | virtual void Output(CYOutput &out, CYFlags flags) const; |
657 | virtual void PropertyName(CYOutput &out) const; | |
cf7d4c69 JF |
658 | }; |
659 | ||
63cd45c9 | 660 | struct CYRegEx : |
3b52fd1a | 661 | CYTrivial |
63cd45c9 JF |
662 | { |
663 | const char *value_; | |
664 | ||
665 | CYRegEx(const char *value) : | |
666 | value_(value) | |
667 | { | |
668 | } | |
669 | ||
670 | const char *Value() const { | |
671 | return value_; | |
672 | } | |
673 | ||
674 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
675 | }; | |
676 | ||
cf7d4c69 JF |
677 | struct CYNull : |
678 | CYWord, | |
3b52fd1a | 679 | CYTrivial |
cf7d4c69 JF |
680 | { |
681 | CYNull() : | |
682 | CYWord("null") | |
683 | { | |
684 | } | |
5999c315 | 685 | |
4644480a JF |
686 | virtual CYNumber *Number(CYContext &context); |
687 | virtual CYString *String(CYContext &context); | |
688 | ||
652ec1ba | 689 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
690 | }; |
691 | ||
692 | struct CYThis : | |
693 | CYWord, | |
478d4ed0 | 694 | CYMagic |
cf7d4c69 JF |
695 | { |
696 | CYThis() : | |
697 | CYWord("this") | |
698 | { | |
699 | } | |
5999c315 | 700 | |
3b52fd1a | 701 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 702 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
703 | }; |
704 | ||
705 | struct CYBoolean : | |
3b52fd1a | 706 | CYTrivial |
cf7d4c69 | 707 | { |
5999c315 | 708 | virtual bool Value() const = 0; |
652ec1ba | 709 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
710 | }; |
711 | ||
712 | struct CYFalse : | |
713 | CYWord, | |
714 | CYBoolean | |
715 | { | |
716 | CYFalse() : | |
717 | CYWord("false") | |
718 | { | |
719 | } | |
5999c315 | 720 | |
11c1cc16 JF |
721 | virtual bool Value() const { |
722 | return false; | |
723 | } | |
4644480a JF |
724 | |
725 | virtual CYNumber *Number(CYContext &context); | |
726 | virtual CYString *String(CYContext &context); | |
cf7d4c69 JF |
727 | }; |
728 | ||
729 | struct CYTrue : | |
730 | CYWord, | |
731 | CYBoolean | |
732 | { | |
733 | CYTrue() : | |
734 | CYWord("true") | |
735 | { | |
736 | } | |
5999c315 | 737 | |
11c1cc16 JF |
738 | virtual bool Value() const { |
739 | return true; | |
740 | } | |
4644480a JF |
741 | |
742 | virtual CYNumber *Number(CYContext &context); | |
743 | virtual CYString *String(CYContext &context); | |
cf7d4c69 JF |
744 | }; |
745 | ||
746 | struct CYVariable : | |
747 | CYExpression | |
748 | { | |
749 | CYIdentifier *name_; | |
750 | ||
751 | CYVariable(CYIdentifier *name) : | |
752 | name_(name) | |
753 | { | |
754 | } | |
5999c315 | 755 | |
d35a3b07 | 756 | CYPrecedence(0) |
fb98ac0c | 757 | CYRightHand(false) |
d35a3b07 | 758 | |
3b52fd1a | 759 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 760 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
761 | }; |
762 | ||
763 | struct CYPrefix : | |
63b4c5a8 JF |
764 | CYExpression |
765 | { | |
766 | CYExpression *rhs_; | |
767 | ||
cf7d4c69 | 768 | CYPrefix(CYExpression *rhs) : |
63b4c5a8 JF |
769 | rhs_(rhs) |
770 | { | |
771 | } | |
5999c315 | 772 | |
b09da87b | 773 | virtual bool Alphabetic() const = 0; |
5999c315 JF |
774 | virtual const char *Operator() const = 0; |
775 | ||
3b52fd1a JF |
776 | CYPrecedence(4) |
777 | ||
778 | virtual CYExpression *Replace(CYContext &context); | |
652ec1ba | 779 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
780 | }; |
781 | ||
cf7d4c69 | 782 | struct CYInfix : |
63b4c5a8 JF |
783 | CYExpression |
784 | { | |
785 | CYExpression *lhs_; | |
786 | CYExpression *rhs_; | |
787 | ||
cf7d4c69 | 788 | CYInfix(CYExpression *lhs, CYExpression *rhs) : |
63b4c5a8 JF |
789 | lhs_(lhs), |
790 | rhs_(rhs) | |
791 | { | |
792 | } | |
5999c315 | 793 | |
0ff9f149 JF |
794 | void SetLeft(CYExpression *lhs) { |
795 | lhs_ = lhs; | |
796 | } | |
797 | ||
b09da87b | 798 | virtual bool Alphabetic() const = 0; |
5999c315 JF |
799 | virtual const char *Operator() const = 0; |
800 | ||
3b52fd1a | 801 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 802 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
803 | }; |
804 | ||
cf7d4c69 | 805 | struct CYPostfix : |
63b4c5a8 JF |
806 | CYExpression |
807 | { | |
808 | CYExpression *lhs_; | |
809 | ||
cf7d4c69 | 810 | CYPostfix(CYExpression *lhs) : |
63b4c5a8 JF |
811 | lhs_(lhs) |
812 | { | |
813 | } | |
5999c315 JF |
814 | |
815 | virtual const char *Operator() const = 0; | |
816 | ||
3b52fd1a JF |
817 | CYPrecedence(3) |
818 | ||
819 | virtual CYExpression *Replace(CYContext &context); | |
652ec1ba | 820 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
821 | }; |
822 | ||
cf7d4c69 | 823 | struct CYAssignment : |
d35a3b07 | 824 | CYExpression |
cf7d4c69 | 825 | { |
d35a3b07 JF |
826 | CYExpression *lhs_; |
827 | CYExpression *rhs_; | |
828 | ||
cf7d4c69 | 829 | CYAssignment(CYExpression *lhs, CYExpression *rhs) : |
d35a3b07 JF |
830 | lhs_(lhs), |
831 | rhs_(rhs) | |
cf7d4c69 JF |
832 | { |
833 | } | |
5999c315 | 834 | |
0ff9f149 JF |
835 | void SetLeft(CYExpression *lhs) { |
836 | lhs_ = lhs; | |
837 | } | |
838 | ||
5999c315 | 839 | virtual const char *Operator() const = 0; |
d35a3b07 | 840 | |
4de0686f JF |
841 | CYPrecedence(16) |
842 | ||
3b52fd1a | 843 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 844 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
845 | }; |
846 | ||
62014ea9 | 847 | struct CYArgument : |
96a7e5c2 JF |
848 | CYNext<CYArgument>, |
849 | CYThing | |
62014ea9 | 850 | { |
cf7d4c69 JF |
851 | CYWord *name_; |
852 | CYExpression *value_; | |
cf7d4c69 | 853 | |
3b52fd1a JF |
854 | CYArgument(CYExpression *value, CYArgument *next = NULL) : |
855 | CYNext<CYArgument>(next), | |
856 | name_(NULL), | |
857 | value_(value) | |
858 | { | |
859 | } | |
860 | ||
cf7d4c69 | 861 | CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) : |
62014ea9 | 862 | CYNext<CYArgument>(next), |
cf7d4c69 | 863 | name_(name), |
62014ea9 | 864 | value_(value) |
cf7d4c69 JF |
865 | { |
866 | } | |
5999c315 | 867 | |
3b52fd1a | 868 | void Replace(CYContext &context); |
652ec1ba | 869 | void Output(CYOutput &out) const; |
cf7d4c69 JF |
870 | }; |
871 | ||
872 | struct CYBlank : | |
873 | public CYWord | |
874 | { | |
875 | CYBlank() : | |
876 | CYWord("") | |
877 | { | |
878 | } | |
879 | }; | |
880 | ||
5999c315 JF |
881 | struct CYClause : |
882 | CYThing, | |
883 | CYNext<CYClause> | |
884 | { | |
cf7d4c69 | 885 | CYExpression *case_; |
3b52fd1a | 886 | CYStatement *statements_; |
cf7d4c69 | 887 | |
3b52fd1a | 888 | CYClause(CYExpression *_case, CYStatement *statements) : |
cf7d4c69 | 889 | case_(_case), |
3b52fd1a | 890 | statements_(statements) |
cf7d4c69 JF |
891 | { |
892 | } | |
893 | ||
fa389b0f | 894 | void Replace(CYContext &context); |
652ec1ba | 895 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
896 | }; |
897 | ||
62014ea9 | 898 | struct CYElement : |
96a7e5c2 JF |
899 | CYNext<CYElement>, |
900 | CYThing | |
62014ea9 | 901 | { |
cf7d4c69 | 902 | CYExpression *value_; |
cf7d4c69 JF |
903 | |
904 | CYElement(CYExpression *value, CYElement *next) : | |
62014ea9 JF |
905 | CYNext<CYElement>(next), |
906 | value_(value) | |
cf7d4c69 JF |
907 | { |
908 | } | |
5999c315 | 909 | |
3b52fd1a | 910 | void Replace(CYContext &context); |
652ec1ba | 911 | void Output(CYOutput &out) const; |
5befe15e JF |
912 | }; |
913 | ||
914 | struct CYArray : | |
915 | CYLiteral | |
916 | { | |
917 | CYElement *elements_; | |
918 | ||
3b52fd1a | 919 | CYArray(CYElement *elements = NULL) : |
5befe15e JF |
920 | elements_(elements) |
921 | { | |
922 | } | |
923 | ||
3b52fd1a | 924 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 925 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
926 | }; |
927 | ||
928 | struct CYDeclaration : | |
929 | CYForInInitialiser | |
930 | { | |
931 | CYIdentifier *identifier_; | |
932 | CYExpression *initialiser_; | |
933 | ||
934 | CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) : | |
935 | identifier_(identifier), | |
936 | initialiser_(initialiser) | |
937 | { | |
938 | } | |
5999c315 | 939 | |
652ec1ba | 940 | virtual void ForIn(CYOutput &out, CYFlags flags) const; |
75b0a457 | 941 | |
cac61857 | 942 | virtual const char *ForEachIn() const; |
3b52fd1a JF |
943 | virtual CYExpression *ForEachIn(CYContext &out); |
944 | ||
945 | void Replace(CYContext &context); | |
75b0a457 | 946 | |
652ec1ba | 947 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
948 | }; |
949 | ||
950 | struct CYDeclarations : | |
cac61857 | 951 | CYNext<CYDeclarations>, |
96a7e5c2 JF |
952 | CYForInitialiser, |
953 | CYThing | |
cf7d4c69 JF |
954 | { |
955 | CYDeclaration *declaration_; | |
cf7d4c69 | 956 | |
cacd1a88 | 957 | CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) : |
cac61857 JF |
958 | CYNext<CYDeclarations>(next), |
959 | declaration_(declaration) | |
960 | { | |
961 | } | |
962 | ||
652ec1ba | 963 | virtual void For(CYOutput &out) const; |
96a7e5c2 | 964 | |
3b52fd1a JF |
965 | void Replace(CYContext &context); |
966 | ||
96a7e5c2 | 967 | virtual void Output(CYOutput &out) const; |
652ec1ba | 968 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cac61857 JF |
969 | }; |
970 | ||
971 | struct CYVar : | |
972 | CYStatement | |
973 | { | |
974 | CYDeclarations *declarations_; | |
975 | ||
976 | CYVar(CYDeclarations *declarations) : | |
977 | declarations_(declarations) | |
978 | { | |
979 | } | |
980 | ||
3b52fd1a | 981 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 982 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cac61857 JF |
983 | }; |
984 | ||
985 | struct CYLet : | |
986 | CYStatement | |
987 | { | |
988 | CYDeclarations *declarations_; | |
3b52fd1a | 989 | CYBlock code_; |
cac61857 JF |
990 | |
991 | CYLet(CYDeclarations *declarations, CYStatement *statements) : | |
992 | declarations_(declarations), | |
3b52fd1a | 993 | code_(statements) |
cf7d4c69 JF |
994 | { |
995 | } | |
5999c315 | 996 | |
3b52fd1a | 997 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 998 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
999 | }; |
1000 | ||
cf7d4c69 JF |
1001 | struct CYFor : |
1002 | CYStatement | |
1003 | { | |
1004 | CYForInitialiser *initialiser_; | |
1005 | CYExpression *test_; | |
1006 | CYExpression *increment_; | |
1007 | CYStatement *code_; | |
1008 | ||
1009 | CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) : | |
1010 | initialiser_(initialiser), | |
1011 | test_(test), | |
1012 | increment_(increment), | |
1013 | code_(code) | |
1014 | { | |
1015 | } | |
5999c315 | 1016 | |
3b52fd1a | 1017 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1018 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1019 | }; |
1020 | ||
1021 | struct CYForIn : | |
1022 | CYStatement | |
1023 | { | |
1024 | CYForInInitialiser *initialiser_; | |
1025 | CYExpression *set_; | |
1026 | CYStatement *code_; | |
1027 | ||
1028 | CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) : | |
1029 | initialiser_(initialiser), | |
1030 | set_(set), | |
1031 | code_(code) | |
1032 | { | |
1033 | } | |
5999c315 | 1034 | |
3b52fd1a | 1035 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1036 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1037 | }; |
1038 | ||
75b0a457 JF |
1039 | struct CYForEachIn : |
1040 | CYStatement | |
1041 | { | |
1042 | CYForInInitialiser *initialiser_; | |
1043 | CYExpression *set_; | |
1044 | CYStatement *code_; | |
1045 | ||
1046 | CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) : | |
1047 | initialiser_(initialiser), | |
1048 | set_(set), | |
1049 | code_(code) | |
1050 | { | |
1051 | } | |
1052 | ||
3b52fd1a | 1053 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1054 | virtual void Output(CYOutput &out, CYFlags flags) const; |
75b0a457 JF |
1055 | }; |
1056 | ||
62014ea9 | 1057 | struct CYProperty : |
96a7e5c2 JF |
1058 | CYNext<CYProperty>, |
1059 | CYThing | |
62014ea9 | 1060 | { |
e5bc40db | 1061 | CYPropertyName *name_; |
cf7d4c69 | 1062 | CYExpression *value_; |
cf7d4c69 | 1063 | |
3b52fd1a | 1064 | CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) : |
62014ea9 | 1065 | CYNext<CYProperty>(next), |
cf7d4c69 | 1066 | name_(name), |
62014ea9 | 1067 | value_(value) |
cf7d4c69 JF |
1068 | { |
1069 | } | |
5999c315 | 1070 | |
3b52fd1a | 1071 | void Replace(CYContext &context); |
652ec1ba | 1072 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1073 | }; |
1074 | ||
693d501b JF |
1075 | struct CYObject : |
1076 | CYLiteral | |
1077 | { | |
3b52fd1a | 1078 | CYProperty *properties_; |
693d501b | 1079 | |
3b52fd1a JF |
1080 | CYObject(CYProperty *properties) : |
1081 | properties_(properties) | |
693d501b JF |
1082 | { |
1083 | } | |
1084 | ||
3b52fd1a | 1085 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1086 | void Output(CYOutput &out, CYFlags flags) const; |
693d501b JF |
1087 | }; |
1088 | ||
5999c315 JF |
1089 | struct CYCatch : |
1090 | CYThing | |
1091 | { | |
cf7d4c69 | 1092 | CYIdentifier *name_; |
3b52fd1a | 1093 | CYBlock code_; |
cf7d4c69 | 1094 | |
3b52fd1a | 1095 | CYCatch(CYIdentifier *name, CYStatement *statements) : |
cf7d4c69 | 1096 | name_(name), |
3b52fd1a | 1097 | code_(statements) |
cf7d4c69 JF |
1098 | { |
1099 | } | |
5999c315 | 1100 | |
3b52fd1a | 1101 | void Replace(CYContext &context); |
652ec1ba | 1102 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1103 | }; |
1104 | ||
cf7d4c69 JF |
1105 | struct CYMember : |
1106 | CYExpression | |
1107 | { | |
1108 | CYExpression *object_; | |
1109 | CYExpression *property_; | |
1110 | ||
1111 | CYMember(CYExpression *object, CYExpression *property) : | |
1112 | object_(object), | |
1113 | property_(property) | |
1114 | { | |
1115 | } | |
5999c315 | 1116 | |
9b5527f0 JF |
1117 | void SetLeft(CYExpression *object) { |
1118 | object_ = object; | |
1119 | } | |
3b52fd1a JF |
1120 | |
1121 | void Replace_(CYContext &context); | |
9b5527f0 JF |
1122 | }; |
1123 | ||
1124 | struct CYDirectMember : | |
1125 | CYMember | |
1126 | { | |
1127 | CYDirectMember(CYExpression *object, CYExpression *property) : | |
1128 | CYMember(object, property) | |
1129 | { | |
1130 | } | |
1131 | ||
1132 | CYPrecedence(1) | |
fb98ac0c | 1133 | CYRightHand(false) |
9b5527f0 | 1134 | |
3b52fd1a | 1135 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1136 | virtual void Output(CYOutput &out, CYFlags flags) const; |
9b5527f0 JF |
1137 | }; |
1138 | ||
1139 | struct CYIndirectMember : | |
1140 | CYMember | |
1141 | { | |
1142 | CYIndirectMember(CYExpression *object, CYExpression *property) : | |
1143 | CYMember(object, property) | |
1144 | { | |
1145 | } | |
1146 | ||
d35a3b07 | 1147 | CYPrecedence(1) |
fb98ac0c | 1148 | CYRightHand(false) |
d35a3b07 | 1149 | |
3b52fd1a | 1150 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1151 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1152 | }; |
1153 | ||
1154 | struct CYNew : | |
1155 | CYExpression | |
1156 | { | |
1157 | CYExpression *constructor_; | |
1158 | CYArgument *arguments_; | |
1159 | ||
1160 | CYNew(CYExpression *constructor, CYArgument *arguments) : | |
1161 | constructor_(constructor), | |
1162 | arguments_(arguments) | |
1163 | { | |
1164 | } | |
5999c315 | 1165 | |
fb98ac0c JF |
1166 | virtual unsigned Precedence() const { |
1167 | return arguments_ == NULL ? 2 : 1; | |
1168 | } | |
1169 | ||
1170 | CYRightHand(false) | |
d35a3b07 | 1171 | |
3b52fd1a | 1172 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1173 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1174 | }; |
1175 | ||
1176 | struct CYCall : | |
1177 | CYExpression | |
1178 | { | |
1179 | CYExpression *function_; | |
1180 | CYArgument *arguments_; | |
1181 | ||
3b52fd1a | 1182 | CYCall(CYExpression *function, CYArgument *arguments = NULL) : |
cf7d4c69 JF |
1183 | function_(function), |
1184 | arguments_(arguments) | |
1185 | { | |
1186 | } | |
5999c315 | 1187 | |
fb98ac0c JF |
1188 | CYPrecedence(1) |
1189 | CYRightHand(false) | |
d35a3b07 | 1190 | |
3b52fd1a | 1191 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1192 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1193 | }; |
1194 | ||
1195 | struct CYIf : | |
1196 | CYStatement | |
1197 | { | |
1198 | CYExpression *test_; | |
1199 | CYStatement *true_; | |
1200 | CYStatement *false_; | |
1201 | ||
3b52fd1a | 1202 | CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) : |
cf7d4c69 JF |
1203 | test_(test), |
1204 | true_(_true), | |
1205 | false_(_false) | |
1206 | { | |
1207 | } | |
5999c315 | 1208 | |
3b52fd1a | 1209 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1210 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1211 | }; |
1212 | ||
1213 | struct CYDoWhile : | |
1214 | CYStatement | |
1215 | { | |
1216 | CYExpression *test_; | |
1217 | CYStatement *code_; | |
1218 | ||
1219 | CYDoWhile(CYExpression *test, CYStatement *code) : | |
1220 | test_(test), | |
1221 | code_(code) | |
1222 | { | |
1223 | } | |
5999c315 | 1224 | |
3b52fd1a | 1225 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1226 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1227 | }; |
1228 | ||
1229 | struct CYWhile : | |
1230 | CYStatement | |
1231 | { | |
1232 | CYExpression *test_; | |
1233 | CYStatement *code_; | |
1234 | ||
1235 | CYWhile(CYExpression *test, CYStatement *code) : | |
1236 | test_(test), | |
1237 | code_(code) | |
1238 | { | |
1239 | } | |
5999c315 | 1240 | |
3b52fd1a | 1241 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1242 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1243 | }; |
1244 | ||
fb98ac0c | 1245 | struct CYFunction { |
cf7d4c69 | 1246 | CYIdentifier *name_; |
b09da87b | 1247 | CYFunctionParameter *parameters_; |
3b52fd1a | 1248 | CYBlock code_; |
cf7d4c69 | 1249 | |
3b52fd1a | 1250 | CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : |
cf7d4c69 JF |
1251 | name_(name), |
1252 | parameters_(parameters), | |
3b52fd1a | 1253 | code_(statements) |
cf7d4c69 JF |
1254 | { |
1255 | } | |
5999c315 | 1256 | |
3b52fd1a | 1257 | virtual void Replace_(CYContext &context); |
fb98ac0c JF |
1258 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1259 | }; | |
1260 | ||
1261 | struct CYFunctionExpression : | |
1262 | CYFunction, | |
1263 | CYExpression | |
1264 | { | |
3b52fd1a JF |
1265 | CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : |
1266 | CYFunction(name, parameters, statements) | |
fb98ac0c JF |
1267 | { |
1268 | } | |
1269 | ||
d35a3b07 | 1270 | CYPrecedence(0) |
fb98ac0c | 1271 | CYRightHand(false) |
d35a3b07 | 1272 | |
3b52fd1a | 1273 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1274 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1275 | }; |
1276 | ||
fb98ac0c JF |
1277 | struct CYFunctionStatement : |
1278 | CYFunction, | |
b10bd496 | 1279 | CYStatement |
cf7d4c69 | 1280 | { |
3b52fd1a JF |
1281 | CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : |
1282 | CYFunction(name, parameters, statements) | |
cf7d4c69 JF |
1283 | { |
1284 | } | |
5999c315 | 1285 | |
3b52fd1a | 1286 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1287 | virtual void Output(CYOutput &out, CYFlags flags) const; |
5999c315 JF |
1288 | }; |
1289 | ||
1290 | struct CYExpress : | |
1291 | CYStatement | |
1292 | { | |
1293 | CYExpression *expression_; | |
1294 | ||
1295 | CYExpress(CYExpression *expression) : | |
1296 | expression_(expression) | |
1297 | { | |
1298 | } | |
1299 | ||
3b52fd1a | 1300 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1301 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1302 | }; |
1303 | ||
1304 | struct CYContinue : | |
1305 | CYStatement | |
1306 | { | |
1307 | CYIdentifier *label_; | |
1308 | ||
1309 | CYContinue(CYIdentifier *label) : | |
1310 | label_(label) | |
1311 | { | |
1312 | } | |
5999c315 | 1313 | |
3b52fd1a | 1314 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1315 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1316 | }; |
1317 | ||
1318 | struct CYBreak : | |
1319 | CYStatement | |
1320 | { | |
1321 | CYIdentifier *label_; | |
1322 | ||
1323 | CYBreak(CYIdentifier *label) : | |
1324 | label_(label) | |
1325 | { | |
1326 | } | |
5999c315 | 1327 | |
3b52fd1a | 1328 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1329 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1330 | }; |
1331 | ||
1332 | struct CYReturn : | |
1333 | CYStatement | |
1334 | { | |
1335 | CYExpression *value_; | |
1336 | ||
1337 | CYReturn(CYExpression *value) : | |
1338 | value_(value) | |
1339 | { | |
1340 | } | |
5999c315 | 1341 | |
3b52fd1a | 1342 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1343 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1344 | }; |
1345 | ||
1346 | struct CYEmpty : | |
1347 | CYStatement | |
1348 | { | |
3b52fd1a | 1349 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1350 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1351 | }; |
1352 | ||
96a7e5c2 JF |
1353 | struct CYFinally : |
1354 | CYThing | |
1355 | { | |
3b52fd1a | 1356 | CYBlock code_; |
b10bd496 | 1357 | |
3b52fd1a JF |
1358 | CYFinally(CYStatement *statements) : |
1359 | code_(statements) | |
b10bd496 JF |
1360 | { |
1361 | } | |
1362 | ||
3b52fd1a | 1363 | void Replace(CYContext &context); |
b10bd496 JF |
1364 | virtual void Output(CYOutput &out) const; |
1365 | }; | |
1366 | ||
cf7d4c69 JF |
1367 | struct CYTry : |
1368 | CYStatement | |
1369 | { | |
3b52fd1a | 1370 | CYBlock code_; |
cf7d4c69 | 1371 | CYCatch *catch_; |
b10bd496 | 1372 | CYFinally *finally_; |
cf7d4c69 | 1373 | |
3b52fd1a JF |
1374 | CYTry(CYStatement *statements, CYCatch *_catch, CYFinally *finally) : |
1375 | code_(statements), | |
cf7d4c69 JF |
1376 | catch_(_catch), |
1377 | finally_(finally) | |
1378 | { | |
1379 | } | |
5999c315 | 1380 | |
3b52fd1a | 1381 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1382 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1383 | }; |
1384 | ||
1385 | struct CYThrow : | |
1386 | CYStatement | |
1387 | { | |
1388 | CYExpression *value_; | |
1389 | ||
1390 | CYThrow(CYExpression *value) : | |
1391 | value_(value) | |
1392 | { | |
1393 | } | |
5999c315 | 1394 | |
3b52fd1a | 1395 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1396 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1397 | }; |
1398 | ||
1399 | struct CYWith : | |
1400 | CYStatement | |
1401 | { | |
1402 | CYExpression *scope_; | |
1403 | CYStatement *code_; | |
1404 | ||
1405 | CYWith(CYExpression *scope, CYStatement *code) : | |
1406 | scope_(scope), | |
1407 | code_(code) | |
1408 | { | |
1409 | } | |
5999c315 | 1410 | |
3b52fd1a | 1411 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1412 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1413 | }; |
1414 | ||
1415 | struct CYSwitch : | |
1416 | CYStatement | |
1417 | { | |
1418 | CYExpression *value_; | |
1419 | CYClause *clauses_; | |
1420 | ||
1421 | CYSwitch(CYExpression *value, CYClause *clauses) : | |
1422 | value_(value), | |
1423 | clauses_(clauses) | |
1424 | { | |
1425 | } | |
5999c315 | 1426 | |
3b52fd1a | 1427 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1428 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1429 | }; |
1430 | ||
1431 | struct CYCondition : | |
1432 | CYExpression | |
1433 | { | |
1434 | CYExpression *test_; | |
1435 | CYExpression *true_; | |
1436 | CYExpression *false_; | |
1437 | ||
1438 | CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) : | |
91a416e4 | 1439 | test_(test), |
cf7d4c69 JF |
1440 | true_(_true), |
1441 | false_(_false) | |
1442 | { | |
1443 | } | |
5999c315 | 1444 | |
d35a3b07 JF |
1445 | CYPrecedence(15) |
1446 | ||
3b52fd1a | 1447 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1448 | virtual void Output(CYOutput &out, CYFlags flags) const; |
5999c315 JF |
1449 | }; |
1450 | ||
1451 | struct CYAddressOf : | |
1452 | CYPrefix | |
1453 | { | |
1454 | CYAddressOf(CYExpression *rhs) : | |
1455 | CYPrefix(rhs) | |
1456 | { | |
1457 | } | |
1458 | ||
1459 | virtual const char *Operator() const { | |
1460 | return "&"; | |
1461 | } | |
1462 | ||
b09da87b | 1463 | CYAlphabetic(false) |
d35a3b07 | 1464 | |
3b52fd1a | 1465 | virtual CYExpression *Replace(CYContext &context); |
5999c315 JF |
1466 | }; |
1467 | ||
1468 | struct CYIndirect : | |
1469 | CYPrefix | |
1470 | { | |
1471 | CYIndirect(CYExpression *rhs) : | |
1472 | CYPrefix(rhs) | |
1473 | { | |
1474 | } | |
1475 | ||
1476 | virtual const char *Operator() const { | |
1477 | return "*"; | |
1478 | } | |
1479 | ||
b09da87b | 1480 | CYAlphabetic(false) |
d35a3b07 | 1481 | |
3b52fd1a | 1482 | virtual CYExpression *Replace(CYContext &context); |
cf7d4c69 JF |
1483 | }; |
1484 | ||
4644480a JF |
1485 | #define CYReplace \ |
1486 | virtual CYExpression *Replace(CYContext &context); | |
1487 | ||
1488 | #define CYPostfix_(op, name, args...) \ | |
cf7d4c69 JF |
1489 | struct CY ## name : \ |
1490 | CYPostfix \ | |
4644480a | 1491 | { args \ |
cf7d4c69 JF |
1492 | CY ## name(CYExpression *lhs) : \ |
1493 | CYPostfix(lhs) \ | |
1494 | { \ | |
1495 | } \ | |
5999c315 JF |
1496 | \ |
1497 | virtual const char *Operator() const { \ | |
1498 | return op; \ | |
1499 | } \ | |
cf7d4c69 JF |
1500 | }; |
1501 | ||
4644480a | 1502 | #define CYPrefix_(alphabetic, op, name, args...) \ |
cf7d4c69 JF |
1503 | struct CY ## name : \ |
1504 | CYPrefix \ | |
4644480a | 1505 | { args \ |
cf7d4c69 JF |
1506 | CY ## name(CYExpression *rhs) : \ |
1507 | CYPrefix(rhs) \ | |
1508 | { \ | |
1509 | } \ | |
d35a3b07 | 1510 | \ |
b09da87b | 1511 | CYAlphabetic(alphabetic) \ |
5999c315 JF |
1512 | \ |
1513 | virtual const char *Operator() const { \ | |
1514 | return op; \ | |
1515 | } \ | |
cf7d4c69 JF |
1516 | }; |
1517 | ||
4644480a | 1518 | #define CYInfix_(alphabetic, precedence, op, name, args...) \ |
cf7d4c69 JF |
1519 | struct CY ## name : \ |
1520 | CYInfix \ | |
4644480a | 1521 | { args \ |
cf7d4c69 JF |
1522 | CY ## name(CYExpression *lhs, CYExpression *rhs) : \ |
1523 | CYInfix(lhs, rhs) \ | |
1524 | { \ | |
1525 | } \ | |
d35a3b07 | 1526 | \ |
b09da87b | 1527 | CYAlphabetic(alphabetic) \ |
d35a3b07 | 1528 | CYPrecedence(precedence) \ |
5999c315 JF |
1529 | \ |
1530 | virtual const char *Operator() const { \ | |
1531 | return op; \ | |
1532 | } \ | |
cf7d4c69 JF |
1533 | }; |
1534 | ||
4644480a | 1535 | #define CYAssignment_(op, name, args...) \ |
cf7d4c69 JF |
1536 | struct CY ## name ## Assign : \ |
1537 | CYAssignment \ | |
4644480a | 1538 | { args \ |
cf7d4c69 JF |
1539 | CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \ |
1540 | CYAssignment(lhs, rhs) \ | |
1541 | { \ | |
1542 | } \ | |
5999c315 JF |
1543 | \ |
1544 | virtual const char *Operator() const { \ | |
1545 | return op; \ | |
1546 | } \ | |
cf7d4c69 JF |
1547 | }; |
1548 | ||
1549 | CYPostfix_("++", PostIncrement) | |
1550 | CYPostfix_("--", PostDecrement) | |
1551 | ||
b09da87b JF |
1552 | CYPrefix_(true, "delete", Delete) |
1553 | CYPrefix_(true, "void", Void) | |
1554 | CYPrefix_(true, "typeof", TypeOf) | |
1555 | CYPrefix_(false, "++", PreIncrement) | |
1556 | CYPrefix_(false, "--", PreDecrement) | |
c0bc320e | 1557 | CYPrefix_(false, "+", Affirm) |
b09da87b JF |
1558 | CYPrefix_(false, "-", Negate) |
1559 | CYPrefix_(false, "~", BitwiseNot) | |
1560 | CYPrefix_(false, "!", LogicalNot) | |
1561 | ||
1562 | CYInfix_(false, 5, "*", Multiply) | |
1563 | CYInfix_(false, 5, "/", Divide) | |
1564 | CYInfix_(false, 5, "%", Modulus) | |
4644480a | 1565 | CYInfix_(false, 6, "+", Add, CYReplace) |
b09da87b JF |
1566 | CYInfix_(false, 6, "-", Subtract) |
1567 | CYInfix_(false, 7, "<<", ShiftLeft) | |
1568 | CYInfix_(false, 7, ">>", ShiftRightSigned) | |
1569 | CYInfix_(false, 7, ">>>", ShiftRightUnsigned) | |
1570 | CYInfix_(false, 8, "<", Less) | |
1571 | CYInfix_(false, 8, ">", Greater) | |
1572 | CYInfix_(false, 8, "<=", LessOrEqual) | |
1573 | CYInfix_(false, 8, ">=", GreaterOrEqual) | |
1574 | CYInfix_(true, 8, "instanceof", InstanceOf) | |
1575 | CYInfix_(true, 8, "in", In) | |
1576 | CYInfix_(false, 9, "==", Equal) | |
1577 | CYInfix_(false, 9, "!=", NotEqual) | |
1578 | CYInfix_(false, 9, "===", Identical) | |
1579 | CYInfix_(false, 9, "!==", NotIdentical) | |
1580 | CYInfix_(false, 10, "&", BitwiseAnd) | |
1581 | CYInfix_(false, 11, "^", BitwiseXOr) | |
1582 | CYInfix_(false, 12, "|", BitwiseOr) | |
1583 | CYInfix_(false, 13, "&&", LogicalAnd) | |
1584 | CYInfix_(false, 14, "||", LogicalOr) | |
cf7d4c69 JF |
1585 | |
1586 | CYAssignment_("=", ) | |
1587 | CYAssignment_("*=", Multiply) | |
1588 | CYAssignment_("/=", Divide) | |
1589 | CYAssignment_("%=", Modulus) | |
1590 | CYAssignment_("+=", Add) | |
1591 | CYAssignment_("-=", Subtract) | |
1592 | CYAssignment_("<<=", ShiftLeft) | |
1593 | CYAssignment_(">>=", ShiftRightSigned) | |
1594 | CYAssignment_(">>>=", ShiftRightUnsigned) | |
1595 | CYAssignment_("&=", BitwiseAnd) | |
1596 | CYAssignment_("^=", BitwiseXOr) | |
1597 | CYAssignment_("|=", BitwiseOr) | |
1598 | ||
63b4c5a8 | 1599 | #endif/*CYPARSER_HPP*/ |