]>
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 { |
697d6fd2 | 313 | RegExpCondition, |
691e4717 JF |
314 | XMLContentCondition, |
315 | XMLTagCondition, | |
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 | 338 | |
691e4717 JF |
339 | Condition GetCondition(); |
340 | void SetCondition(Condition condition); | |
341 | ||
342 | void PushCondition(Condition condition); | |
343 | void PopCondition(); | |
b10bd496 JF |
344 | |
345 | void Warning(const cy::location &location, const char *message); | |
5999c315 JF |
346 | }; |
347 | ||
cac61857 | 348 | struct CYForInitialiser { |
652ec1ba | 349 | virtual void For(CYOutput &out) const = 0; |
dea834b0 JF |
350 | }; |
351 | ||
cac61857 | 352 | struct CYForInInitialiser { |
652ec1ba | 353 | virtual void ForIn(CYOutput &out, CYFlags flags) const = 0; |
75b0a457 | 354 | virtual const char *ForEachIn() const = 0; |
3b52fd1a | 355 | virtual CYExpression *ForEachIn(CYContext &out) = 0; |
b09da87b JF |
356 | }; |
357 | ||
4644480a JF |
358 | struct CYNumber; |
359 | struct CYString; | |
360 | ||
cf7d4c69 | 361 | struct CYExpression : |
5999c315 | 362 | CYNext<CYExpression>, |
cf7d4c69 | 363 | CYForInitialiser, |
e5bc40db | 364 | CYForInInitialiser, |
96a7e5c2 JF |
365 | CYClassName, |
366 | CYThing | |
63b4c5a8 | 367 | { |
d35a3b07 | 368 | virtual unsigned Precedence() const = 0; |
75b0a457 | 369 | |
fb98ac0c JF |
370 | virtual bool RightHand() const { |
371 | return true; | |
372 | } | |
373 | ||
652ec1ba JF |
374 | virtual void For(CYOutput &out) const; |
375 | virtual void ForIn(CYOutput &out, CYFlags flags) const; | |
75b0a457 | 376 | |
cac61857 | 377 | virtual const char *ForEachIn() const; |
3b52fd1a | 378 | virtual CYExpression *ForEachIn(CYContext &out); |
75b0a457 | 379 | |
96a7e5c2 | 380 | virtual void Output(CYOutput &out) const; |
652ec1ba JF |
381 | virtual void Output(CYOutput &out, CYFlags flags) const = 0; |
382 | void Output(CYOutput &out, unsigned precedence, CYFlags flags) const; | |
dea834b0 | 383 | |
3b52fd1a | 384 | virtual CYExpression *ClassName(CYContext &context, bool object); |
652ec1ba | 385 | virtual void ClassName(CYOutput &out, bool object) const; |
e5bc40db | 386 | |
3b52fd1a JF |
387 | CYExpression *ReplaceAll(CYContext &context); |
388 | ||
389 | virtual CYExpression *Replace(CYContext &context) = 0; | |
390 | ||
4644480a JF |
391 | virtual CYExpression *Primitive(CYContext &context) { |
392 | return this; | |
393 | } | |
394 | ||
395 | virtual CYNumber *Number(CYContext &context) { | |
396 | return NULL; | |
397 | } | |
398 | ||
399 | virtual CYString *String(CYContext &context) { | |
400 | return NULL; | |
401 | } | |
402 | ||
dea834b0 JF |
403 | virtual const char *Word() const { |
404 | return NULL; | |
405 | } | |
63b4c5a8 JF |
406 | }; |
407 | ||
b09da87b JF |
408 | #define CYAlphabetic(value) \ |
409 | virtual bool Alphabetic() const { \ | |
410 | return value; \ | |
411 | } | |
412 | ||
d35a3b07 JF |
413 | #define CYPrecedence(value) \ |
414 | virtual unsigned Precedence() const { \ | |
415 | return value; \ | |
416 | } | |
417 | ||
fb98ac0c JF |
418 | #define CYRightHand(value) \ |
419 | virtual bool RightHand() const { \ | |
420 | return value; \ | |
421 | } | |
422 | ||
d35a3b07 JF |
423 | struct CYCompound : |
424 | CYExpression | |
425 | { | |
426 | CYExpression *expressions_; | |
427 | ||
428 | CYCompound(CYExpression *expressions) : | |
429 | expressions_(expressions) | |
430 | { | |
431 | } | |
432 | ||
433 | void AddPrev(CYExpression *expression) { | |
434 | CYExpression *last(expression); | |
435 | while (last->next_ != NULL) | |
436 | last = last->next_; | |
437 | last->SetNext(expressions_); | |
438 | expressions_ = expression; | |
439 | } | |
440 | ||
441 | CYPrecedence(17) | |
442 | ||
3b52fd1a | 443 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 444 | void Output(CYOutput &out, CYFlags flags) const; |
d35a3b07 | 445 | }; |
5999c315 | 446 | |
3b52fd1a JF |
447 | struct CYFunctionParameter : |
448 | CYNext<CYFunctionParameter>, | |
449 | CYThing | |
450 | { | |
451 | CYIdentifier *name_; | |
452 | ||
453 | CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) : | |
454 | CYNext<CYFunctionParameter>(next), | |
455 | name_(name) | |
456 | { | |
457 | } | |
458 | ||
459 | virtual void Output(CYOutput &out) const; | |
460 | }; | |
461 | ||
75b0a457 | 462 | struct CYComprehension : |
96a7e5c2 JF |
463 | CYNext<CYComprehension>, |
464 | CYThing | |
75b0a457 | 465 | { |
75b0a457 JF |
466 | virtual const char *Name() const = 0; |
467 | ||
3b52fd1a JF |
468 | virtual CYFunctionParameter *Parameter(CYContext &context) const = 0; |
469 | CYFunctionParameter *Parameters(CYContext &context) const; | |
470 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
4644480a | 471 | virtual void Output(CYOutput &out) const = 0; |
75b0a457 JF |
472 | }; |
473 | ||
474 | struct CYForInComprehension : | |
475 | CYComprehension | |
476 | { | |
477 | CYIdentifier *name_; | |
478 | CYExpression *set_; | |
479 | ||
480 | CYForInComprehension(CYIdentifier *name, CYExpression *set) : | |
481 | name_(name), | |
482 | set_(set) | |
483 | { | |
484 | } | |
485 | ||
486 | virtual const char *Name() const { | |
487 | return name_->Value(); | |
488 | } | |
489 | ||
3b52fd1a JF |
490 | virtual CYFunctionParameter *Parameter(CYContext &context) const; |
491 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
4644480a | 492 | virtual void Output(CYOutput &out) const; |
75b0a457 JF |
493 | }; |
494 | ||
495 | struct CYForEachInComprehension : | |
496 | CYComprehension | |
497 | { | |
498 | CYIdentifier *name_; | |
499 | CYExpression *set_; | |
500 | ||
501 | CYForEachInComprehension(CYIdentifier *name, CYExpression *set) : | |
502 | name_(name), | |
503 | set_(set) | |
504 | { | |
505 | } | |
506 | ||
507 | virtual const char *Name() const { | |
508 | return name_->Value(); | |
509 | } | |
510 | ||
3b52fd1a JF |
511 | virtual CYFunctionParameter *Parameter(CYContext &context) const; |
512 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
4644480a | 513 | virtual void Output(CYOutput &out) const; |
75b0a457 JF |
514 | }; |
515 | ||
516 | struct CYIfComprehension : | |
517 | CYComprehension | |
518 | { | |
519 | CYExpression *test_; | |
520 | ||
521 | CYIfComprehension(CYExpression *test) : | |
522 | test_(test) | |
523 | { | |
524 | } | |
525 | ||
526 | virtual const char *Name() const { | |
527 | return NULL; | |
528 | } | |
529 | ||
3b52fd1a JF |
530 | virtual CYFunctionParameter *Parameter(CYContext &context) const; |
531 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
4644480a | 532 | virtual void Output(CYOutput &out) const; |
75b0a457 JF |
533 | }; |
534 | ||
535 | struct CYArrayComprehension : | |
536 | CYExpression | |
537 | { | |
538 | CYExpression *expression_; | |
539 | CYComprehension *comprehensions_; | |
540 | ||
541 | CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) : | |
542 | expression_(expression), | |
543 | comprehensions_(comprehensions) | |
544 | { | |
545 | } | |
546 | ||
547 | CYPrecedence(0) | |
548 | ||
3b52fd1a | 549 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 550 | virtual void Output(CYOutput &out, CYFlags flags) const; |
75b0a457 JF |
551 | }; |
552 | ||
cf7d4c69 JF |
553 | struct CYLiteral : |
554 | CYExpression | |
63b4c5a8 | 555 | { |
d35a3b07 | 556 | CYPrecedence(0) |
fb98ac0c | 557 | CYRightHand(false) |
cf7d4c69 | 558 | }; |
63b4c5a8 | 559 | |
3b52fd1a JF |
560 | struct CYTrivial : |
561 | CYLiteral | |
562 | { | |
563 | virtual CYExpression *Replace(CYContext &context); | |
564 | }; | |
565 | ||
478d4ed0 JF |
566 | struct CYMagic : |
567 | CYExpression | |
568 | { | |
569 | CYPrecedence(0) | |
fb98ac0c | 570 | CYRightHand(false) |
478d4ed0 JF |
571 | }; |
572 | ||
dea834b0 JF |
573 | struct CYRange { |
574 | uint64_t lo_; | |
575 | uint64_t hi_; | |
576 | ||
577 | CYRange(uint64_t lo, uint64_t hi) : | |
578 | lo_(lo), hi_(hi) | |
579 | { | |
580 | } | |
581 | ||
582 | bool operator [](uint8_t value) const { | |
583 | return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1; | |
584 | } | |
585 | ||
586 | void operator()(uint8_t value) { | |
587 | if (value >> 7) | |
588 | return; | |
589 | (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f); | |
590 | } | |
591 | }; | |
592 | ||
283e7e33 | 593 | extern CYRange DigitRange_; |
dea834b0 JF |
594 | extern CYRange WordStartRange_; |
595 | extern CYRange WordEndRange_; | |
596 | ||
cf7d4c69 | 597 | struct CYString : |
3b52fd1a | 598 | CYTrivial, |
e5bc40db | 599 | CYPropertyName |
cf7d4c69 JF |
600 | { |
601 | const char *value_; | |
5999c315 | 602 | size_t size_; |
cf7d4c69 | 603 | |
3b52fd1a JF |
604 | CYString() : |
605 | value_(NULL), | |
606 | size_(0) | |
607 | { | |
608 | } | |
609 | ||
610 | CYString(const char *value) : | |
611 | value_(value), | |
612 | size_(strlen(value)) | |
613 | { | |
614 | } | |
615 | ||
5999c315 JF |
616 | CYString(const char *value, size_t size) : |
617 | value_(value), | |
618 | size_(size) | |
cf7d4c69 JF |
619 | { |
620 | } | |
621 | ||
3b52fd1a JF |
622 | CYString(const CYWord *word) : |
623 | value_(word->Value()), | |
5999c315 | 624 | size_(strlen(value_)) |
cf7d4c69 JF |
625 | { |
626 | } | |
627 | ||
5999c315 | 628 | const char *Value() const { |
cf7d4c69 JF |
629 | return value_; |
630 | } | |
631 | ||
11c1cc16 | 632 | virtual const char *Word() const; |
dea834b0 | 633 | |
4644480a JF |
634 | virtual CYNumber *Number(CYContext &context); |
635 | virtual CYString *String(CYContext &context); | |
636 | ||
637 | virtual CYString *Concat(CYContext &out, CYString *rhs) const; | |
652ec1ba JF |
638 | virtual void Output(CYOutput &out, CYFlags flags) const; |
639 | virtual void PropertyName(CYOutput &out) const; | |
63b4c5a8 JF |
640 | }; |
641 | ||
cf7d4c69 | 642 | struct CYNumber : |
3b52fd1a | 643 | CYTrivial, |
e5bc40db | 644 | CYPropertyName |
cf7d4c69 | 645 | { |
5999c315 JF |
646 | double value_; |
647 | ||
648 | CYNumber(double value) : | |
649 | value_(value) | |
650 | { | |
651 | } | |
652 | ||
653 | double Value() const { | |
654 | return value_; | |
cf7d4c69 JF |
655 | } |
656 | ||
4644480a JF |
657 | virtual CYNumber *Number(CYContext &context); |
658 | virtual CYString *String(CYContext &context); | |
659 | ||
652ec1ba JF |
660 | virtual void Output(CYOutput &out, CYFlags flags) const; |
661 | virtual void PropertyName(CYOutput &out) const; | |
cf7d4c69 JF |
662 | }; |
663 | ||
63cd45c9 | 664 | struct CYRegEx : |
3b52fd1a | 665 | CYTrivial |
63cd45c9 JF |
666 | { |
667 | const char *value_; | |
668 | ||
669 | CYRegEx(const char *value) : | |
670 | value_(value) | |
671 | { | |
672 | } | |
673 | ||
674 | const char *Value() const { | |
675 | return value_; | |
676 | } | |
677 | ||
678 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
679 | }; | |
680 | ||
cf7d4c69 JF |
681 | struct CYNull : |
682 | CYWord, | |
3b52fd1a | 683 | CYTrivial |
cf7d4c69 JF |
684 | { |
685 | CYNull() : | |
686 | CYWord("null") | |
687 | { | |
688 | } | |
5999c315 | 689 | |
4644480a JF |
690 | virtual CYNumber *Number(CYContext &context); |
691 | virtual CYString *String(CYContext &context); | |
692 | ||
652ec1ba | 693 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
694 | }; |
695 | ||
696 | struct CYThis : | |
697 | CYWord, | |
478d4ed0 | 698 | CYMagic |
cf7d4c69 JF |
699 | { |
700 | CYThis() : | |
701 | CYWord("this") | |
702 | { | |
703 | } | |
5999c315 | 704 | |
3b52fd1a | 705 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 706 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
707 | }; |
708 | ||
709 | struct CYBoolean : | |
3b52fd1a | 710 | CYTrivial |
cf7d4c69 | 711 | { |
5999c315 | 712 | virtual bool Value() const = 0; |
652ec1ba | 713 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
714 | }; |
715 | ||
716 | struct CYFalse : | |
717 | CYWord, | |
718 | CYBoolean | |
719 | { | |
720 | CYFalse() : | |
721 | CYWord("false") | |
722 | { | |
723 | } | |
5999c315 | 724 | |
11c1cc16 JF |
725 | virtual bool Value() const { |
726 | return false; | |
727 | } | |
4644480a JF |
728 | |
729 | virtual CYNumber *Number(CYContext &context); | |
730 | virtual CYString *String(CYContext &context); | |
cf7d4c69 JF |
731 | }; |
732 | ||
733 | struct CYTrue : | |
734 | CYWord, | |
735 | CYBoolean | |
736 | { | |
737 | CYTrue() : | |
738 | CYWord("true") | |
739 | { | |
740 | } | |
5999c315 | 741 | |
11c1cc16 JF |
742 | virtual bool Value() const { |
743 | return true; | |
744 | } | |
4644480a JF |
745 | |
746 | virtual CYNumber *Number(CYContext &context); | |
747 | virtual CYString *String(CYContext &context); | |
cf7d4c69 JF |
748 | }; |
749 | ||
750 | struct CYVariable : | |
751 | CYExpression | |
752 | { | |
753 | CYIdentifier *name_; | |
754 | ||
755 | CYVariable(CYIdentifier *name) : | |
756 | name_(name) | |
757 | { | |
758 | } | |
5999c315 | 759 | |
d35a3b07 | 760 | CYPrecedence(0) |
fb98ac0c | 761 | CYRightHand(false) |
d35a3b07 | 762 | |
3b52fd1a | 763 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 764 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
765 | }; |
766 | ||
767 | struct CYPrefix : | |
63b4c5a8 JF |
768 | CYExpression |
769 | { | |
770 | CYExpression *rhs_; | |
771 | ||
cf7d4c69 | 772 | CYPrefix(CYExpression *rhs) : |
63b4c5a8 JF |
773 | rhs_(rhs) |
774 | { | |
775 | } | |
5999c315 | 776 | |
b09da87b | 777 | virtual bool Alphabetic() const = 0; |
5999c315 JF |
778 | virtual const char *Operator() const = 0; |
779 | ||
3b52fd1a JF |
780 | CYPrecedence(4) |
781 | ||
782 | virtual CYExpression *Replace(CYContext &context); | |
652ec1ba | 783 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
784 | }; |
785 | ||
cf7d4c69 | 786 | struct CYInfix : |
63b4c5a8 JF |
787 | CYExpression |
788 | { | |
789 | CYExpression *lhs_; | |
790 | CYExpression *rhs_; | |
791 | ||
cf7d4c69 | 792 | CYInfix(CYExpression *lhs, CYExpression *rhs) : |
63b4c5a8 JF |
793 | lhs_(lhs), |
794 | rhs_(rhs) | |
795 | { | |
796 | } | |
5999c315 | 797 | |
0ff9f149 JF |
798 | void SetLeft(CYExpression *lhs) { |
799 | lhs_ = lhs; | |
800 | } | |
801 | ||
b09da87b | 802 | virtual bool Alphabetic() const = 0; |
5999c315 JF |
803 | virtual const char *Operator() const = 0; |
804 | ||
3b52fd1a | 805 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 806 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
807 | }; |
808 | ||
cf7d4c69 | 809 | struct CYPostfix : |
63b4c5a8 JF |
810 | CYExpression |
811 | { | |
812 | CYExpression *lhs_; | |
813 | ||
cf7d4c69 | 814 | CYPostfix(CYExpression *lhs) : |
63b4c5a8 JF |
815 | lhs_(lhs) |
816 | { | |
817 | } | |
5999c315 JF |
818 | |
819 | virtual const char *Operator() const = 0; | |
820 | ||
3b52fd1a JF |
821 | CYPrecedence(3) |
822 | ||
823 | virtual CYExpression *Replace(CYContext &context); | |
652ec1ba | 824 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
825 | }; |
826 | ||
cf7d4c69 | 827 | struct CYAssignment : |
d35a3b07 | 828 | CYExpression |
cf7d4c69 | 829 | { |
d35a3b07 JF |
830 | CYExpression *lhs_; |
831 | CYExpression *rhs_; | |
832 | ||
cf7d4c69 | 833 | CYAssignment(CYExpression *lhs, CYExpression *rhs) : |
d35a3b07 JF |
834 | lhs_(lhs), |
835 | rhs_(rhs) | |
cf7d4c69 JF |
836 | { |
837 | } | |
5999c315 | 838 | |
0ff9f149 JF |
839 | void SetLeft(CYExpression *lhs) { |
840 | lhs_ = lhs; | |
841 | } | |
842 | ||
5999c315 | 843 | virtual const char *Operator() const = 0; |
d35a3b07 | 844 | |
4de0686f JF |
845 | CYPrecedence(16) |
846 | ||
3b52fd1a | 847 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 848 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
849 | }; |
850 | ||
62014ea9 | 851 | struct CYArgument : |
96a7e5c2 JF |
852 | CYNext<CYArgument>, |
853 | CYThing | |
62014ea9 | 854 | { |
cf7d4c69 JF |
855 | CYWord *name_; |
856 | CYExpression *value_; | |
cf7d4c69 | 857 | |
3b52fd1a JF |
858 | CYArgument(CYExpression *value, CYArgument *next = NULL) : |
859 | CYNext<CYArgument>(next), | |
860 | name_(NULL), | |
861 | value_(value) | |
862 | { | |
863 | } | |
864 | ||
cf7d4c69 | 865 | CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) : |
62014ea9 | 866 | CYNext<CYArgument>(next), |
cf7d4c69 | 867 | name_(name), |
62014ea9 | 868 | value_(value) |
cf7d4c69 JF |
869 | { |
870 | } | |
5999c315 | 871 | |
3b52fd1a | 872 | void Replace(CYContext &context); |
652ec1ba | 873 | void Output(CYOutput &out) const; |
cf7d4c69 JF |
874 | }; |
875 | ||
876 | struct CYBlank : | |
877 | public CYWord | |
878 | { | |
879 | CYBlank() : | |
880 | CYWord("") | |
881 | { | |
882 | } | |
883 | }; | |
884 | ||
5999c315 JF |
885 | struct CYClause : |
886 | CYThing, | |
887 | CYNext<CYClause> | |
888 | { | |
cf7d4c69 | 889 | CYExpression *case_; |
3b52fd1a | 890 | CYStatement *statements_; |
cf7d4c69 | 891 | |
3b52fd1a | 892 | CYClause(CYExpression *_case, CYStatement *statements) : |
cf7d4c69 | 893 | case_(_case), |
3b52fd1a | 894 | statements_(statements) |
cf7d4c69 JF |
895 | { |
896 | } | |
897 | ||
fa389b0f | 898 | void Replace(CYContext &context); |
652ec1ba | 899 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
900 | }; |
901 | ||
62014ea9 | 902 | struct CYElement : |
96a7e5c2 JF |
903 | CYNext<CYElement>, |
904 | CYThing | |
62014ea9 | 905 | { |
cf7d4c69 | 906 | CYExpression *value_; |
cf7d4c69 JF |
907 | |
908 | CYElement(CYExpression *value, CYElement *next) : | |
62014ea9 JF |
909 | CYNext<CYElement>(next), |
910 | value_(value) | |
cf7d4c69 JF |
911 | { |
912 | } | |
5999c315 | 913 | |
3b52fd1a | 914 | void Replace(CYContext &context); |
652ec1ba | 915 | void Output(CYOutput &out) const; |
5befe15e JF |
916 | }; |
917 | ||
918 | struct CYArray : | |
919 | CYLiteral | |
920 | { | |
921 | CYElement *elements_; | |
922 | ||
3b52fd1a | 923 | CYArray(CYElement *elements = NULL) : |
5befe15e JF |
924 | elements_(elements) |
925 | { | |
926 | } | |
927 | ||
3b52fd1a | 928 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 929 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
930 | }; |
931 | ||
932 | struct CYDeclaration : | |
933 | CYForInInitialiser | |
934 | { | |
935 | CYIdentifier *identifier_; | |
936 | CYExpression *initialiser_; | |
937 | ||
938 | CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser) : | |
939 | identifier_(identifier), | |
940 | initialiser_(initialiser) | |
941 | { | |
942 | } | |
5999c315 | 943 | |
652ec1ba | 944 | virtual void ForIn(CYOutput &out, CYFlags flags) const; |
75b0a457 | 945 | |
cac61857 | 946 | virtual const char *ForEachIn() const; |
3b52fd1a JF |
947 | virtual CYExpression *ForEachIn(CYContext &out); |
948 | ||
949 | void Replace(CYContext &context); | |
75b0a457 | 950 | |
652ec1ba | 951 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
952 | }; |
953 | ||
954 | struct CYDeclarations : | |
cac61857 | 955 | CYNext<CYDeclarations>, |
96a7e5c2 JF |
956 | CYForInitialiser, |
957 | CYThing | |
cf7d4c69 JF |
958 | { |
959 | CYDeclaration *declaration_; | |
cf7d4c69 | 960 | |
cacd1a88 | 961 | CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) : |
cac61857 JF |
962 | CYNext<CYDeclarations>(next), |
963 | declaration_(declaration) | |
964 | { | |
965 | } | |
966 | ||
652ec1ba | 967 | virtual void For(CYOutput &out) const; |
96a7e5c2 | 968 | |
3b52fd1a JF |
969 | void Replace(CYContext &context); |
970 | ||
96a7e5c2 | 971 | virtual void Output(CYOutput &out) const; |
652ec1ba | 972 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cac61857 JF |
973 | }; |
974 | ||
975 | struct CYVar : | |
976 | CYStatement | |
977 | { | |
978 | CYDeclarations *declarations_; | |
979 | ||
980 | CYVar(CYDeclarations *declarations) : | |
981 | declarations_(declarations) | |
982 | { | |
983 | } | |
984 | ||
3b52fd1a | 985 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 986 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cac61857 JF |
987 | }; |
988 | ||
989 | struct CYLet : | |
990 | CYStatement | |
991 | { | |
992 | CYDeclarations *declarations_; | |
3b52fd1a | 993 | CYBlock code_; |
cac61857 JF |
994 | |
995 | CYLet(CYDeclarations *declarations, CYStatement *statements) : | |
996 | declarations_(declarations), | |
3b52fd1a | 997 | code_(statements) |
cf7d4c69 JF |
998 | { |
999 | } | |
5999c315 | 1000 | |
3b52fd1a | 1001 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1002 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1003 | }; |
1004 | ||
cf7d4c69 JF |
1005 | struct CYFor : |
1006 | CYStatement | |
1007 | { | |
1008 | CYForInitialiser *initialiser_; | |
1009 | CYExpression *test_; | |
1010 | CYExpression *increment_; | |
1011 | CYStatement *code_; | |
1012 | ||
1013 | CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) : | |
1014 | initialiser_(initialiser), | |
1015 | test_(test), | |
1016 | increment_(increment), | |
1017 | code_(code) | |
1018 | { | |
1019 | } | |
5999c315 | 1020 | |
3b52fd1a | 1021 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1022 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1023 | }; |
1024 | ||
1025 | struct CYForIn : | |
1026 | CYStatement | |
1027 | { | |
1028 | CYForInInitialiser *initialiser_; | |
1029 | CYExpression *set_; | |
1030 | CYStatement *code_; | |
1031 | ||
1032 | CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) : | |
1033 | initialiser_(initialiser), | |
1034 | set_(set), | |
1035 | code_(code) | |
1036 | { | |
1037 | } | |
5999c315 | 1038 | |
3b52fd1a | 1039 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1040 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1041 | }; |
1042 | ||
75b0a457 JF |
1043 | struct CYForEachIn : |
1044 | CYStatement | |
1045 | { | |
1046 | CYForInInitialiser *initialiser_; | |
1047 | CYExpression *set_; | |
1048 | CYStatement *code_; | |
1049 | ||
1050 | CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) : | |
1051 | initialiser_(initialiser), | |
1052 | set_(set), | |
1053 | code_(code) | |
1054 | { | |
1055 | } | |
1056 | ||
3b52fd1a | 1057 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1058 | virtual void Output(CYOutput &out, CYFlags flags) const; |
75b0a457 JF |
1059 | }; |
1060 | ||
62014ea9 | 1061 | struct CYProperty : |
96a7e5c2 JF |
1062 | CYNext<CYProperty>, |
1063 | CYThing | |
62014ea9 | 1064 | { |
e5bc40db | 1065 | CYPropertyName *name_; |
cf7d4c69 | 1066 | CYExpression *value_; |
cf7d4c69 | 1067 | |
3b52fd1a | 1068 | CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) : |
62014ea9 | 1069 | CYNext<CYProperty>(next), |
cf7d4c69 | 1070 | name_(name), |
62014ea9 | 1071 | value_(value) |
cf7d4c69 JF |
1072 | { |
1073 | } | |
5999c315 | 1074 | |
3b52fd1a | 1075 | void Replace(CYContext &context); |
652ec1ba | 1076 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1077 | }; |
1078 | ||
693d501b JF |
1079 | struct CYObject : |
1080 | CYLiteral | |
1081 | { | |
3b52fd1a | 1082 | CYProperty *properties_; |
693d501b | 1083 | |
3b52fd1a JF |
1084 | CYObject(CYProperty *properties) : |
1085 | properties_(properties) | |
693d501b JF |
1086 | { |
1087 | } | |
1088 | ||
3b52fd1a | 1089 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1090 | void Output(CYOutput &out, CYFlags flags) const; |
693d501b JF |
1091 | }; |
1092 | ||
5999c315 JF |
1093 | struct CYCatch : |
1094 | CYThing | |
1095 | { | |
cf7d4c69 | 1096 | CYIdentifier *name_; |
3b52fd1a | 1097 | CYBlock code_; |
cf7d4c69 | 1098 | |
3b52fd1a | 1099 | CYCatch(CYIdentifier *name, CYStatement *statements) : |
cf7d4c69 | 1100 | name_(name), |
3b52fd1a | 1101 | code_(statements) |
cf7d4c69 JF |
1102 | { |
1103 | } | |
5999c315 | 1104 | |
3b52fd1a | 1105 | void Replace(CYContext &context); |
652ec1ba | 1106 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1107 | }; |
1108 | ||
cf7d4c69 JF |
1109 | struct CYMember : |
1110 | CYExpression | |
1111 | { | |
1112 | CYExpression *object_; | |
1113 | CYExpression *property_; | |
1114 | ||
1115 | CYMember(CYExpression *object, CYExpression *property) : | |
1116 | object_(object), | |
1117 | property_(property) | |
1118 | { | |
1119 | } | |
5999c315 | 1120 | |
9b5527f0 JF |
1121 | void SetLeft(CYExpression *object) { |
1122 | object_ = object; | |
1123 | } | |
3b52fd1a JF |
1124 | |
1125 | void Replace_(CYContext &context); | |
9b5527f0 JF |
1126 | }; |
1127 | ||
1128 | struct CYDirectMember : | |
1129 | CYMember | |
1130 | { | |
1131 | CYDirectMember(CYExpression *object, CYExpression *property) : | |
1132 | CYMember(object, property) | |
1133 | { | |
1134 | } | |
1135 | ||
1136 | CYPrecedence(1) | |
fb98ac0c | 1137 | CYRightHand(false) |
9b5527f0 | 1138 | |
3b52fd1a | 1139 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1140 | virtual void Output(CYOutput &out, CYFlags flags) const; |
9b5527f0 JF |
1141 | }; |
1142 | ||
1143 | struct CYIndirectMember : | |
1144 | CYMember | |
1145 | { | |
1146 | CYIndirectMember(CYExpression *object, CYExpression *property) : | |
1147 | CYMember(object, property) | |
1148 | { | |
1149 | } | |
1150 | ||
d35a3b07 | 1151 | CYPrecedence(1) |
fb98ac0c | 1152 | CYRightHand(false) |
d35a3b07 | 1153 | |
3b52fd1a | 1154 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1155 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1156 | }; |
1157 | ||
1158 | struct CYNew : | |
1159 | CYExpression | |
1160 | { | |
1161 | CYExpression *constructor_; | |
1162 | CYArgument *arguments_; | |
1163 | ||
1164 | CYNew(CYExpression *constructor, CYArgument *arguments) : | |
1165 | constructor_(constructor), | |
1166 | arguments_(arguments) | |
1167 | { | |
1168 | } | |
5999c315 | 1169 | |
fb98ac0c JF |
1170 | virtual unsigned Precedence() const { |
1171 | return arguments_ == NULL ? 2 : 1; | |
1172 | } | |
1173 | ||
1174 | CYRightHand(false) | |
d35a3b07 | 1175 | |
3b52fd1a | 1176 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1177 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1178 | }; |
1179 | ||
1180 | struct CYCall : | |
1181 | CYExpression | |
1182 | { | |
1183 | CYExpression *function_; | |
1184 | CYArgument *arguments_; | |
1185 | ||
3b52fd1a | 1186 | CYCall(CYExpression *function, CYArgument *arguments = NULL) : |
cf7d4c69 JF |
1187 | function_(function), |
1188 | arguments_(arguments) | |
1189 | { | |
1190 | } | |
5999c315 | 1191 | |
fb98ac0c JF |
1192 | CYPrecedence(1) |
1193 | CYRightHand(false) | |
d35a3b07 | 1194 | |
3b52fd1a | 1195 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1196 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1197 | }; |
1198 | ||
1199 | struct CYIf : | |
1200 | CYStatement | |
1201 | { | |
1202 | CYExpression *test_; | |
1203 | CYStatement *true_; | |
1204 | CYStatement *false_; | |
1205 | ||
3b52fd1a | 1206 | CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) : |
cf7d4c69 JF |
1207 | test_(test), |
1208 | true_(_true), | |
1209 | false_(_false) | |
1210 | { | |
1211 | } | |
5999c315 | 1212 | |
3b52fd1a | 1213 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1214 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1215 | }; |
1216 | ||
1217 | struct CYDoWhile : | |
1218 | CYStatement | |
1219 | { | |
1220 | CYExpression *test_; | |
1221 | CYStatement *code_; | |
1222 | ||
1223 | CYDoWhile(CYExpression *test, CYStatement *code) : | |
1224 | test_(test), | |
1225 | code_(code) | |
1226 | { | |
1227 | } | |
5999c315 | 1228 | |
3b52fd1a | 1229 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1230 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1231 | }; |
1232 | ||
1233 | struct CYWhile : | |
1234 | CYStatement | |
1235 | { | |
1236 | CYExpression *test_; | |
1237 | CYStatement *code_; | |
1238 | ||
1239 | CYWhile(CYExpression *test, CYStatement *code) : | |
1240 | test_(test), | |
1241 | code_(code) | |
1242 | { | |
1243 | } | |
5999c315 | 1244 | |
3b52fd1a | 1245 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1246 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1247 | }; |
1248 | ||
fb98ac0c | 1249 | struct CYFunction { |
cf7d4c69 | 1250 | CYIdentifier *name_; |
b09da87b | 1251 | CYFunctionParameter *parameters_; |
3b52fd1a | 1252 | CYBlock code_; |
cf7d4c69 | 1253 | |
3b52fd1a | 1254 | CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : |
cf7d4c69 JF |
1255 | name_(name), |
1256 | parameters_(parameters), | |
3b52fd1a | 1257 | code_(statements) |
cf7d4c69 JF |
1258 | { |
1259 | } | |
5999c315 | 1260 | |
3b52fd1a | 1261 | virtual void Replace_(CYContext &context); |
fb98ac0c JF |
1262 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1263 | }; | |
1264 | ||
1265 | struct CYFunctionExpression : | |
1266 | CYFunction, | |
1267 | CYExpression | |
1268 | { | |
3b52fd1a JF |
1269 | CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : |
1270 | CYFunction(name, parameters, statements) | |
fb98ac0c JF |
1271 | { |
1272 | } | |
1273 | ||
d35a3b07 | 1274 | CYPrecedence(0) |
fb98ac0c | 1275 | CYRightHand(false) |
d35a3b07 | 1276 | |
3b52fd1a | 1277 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1278 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1279 | }; |
1280 | ||
fb98ac0c JF |
1281 | struct CYFunctionStatement : |
1282 | CYFunction, | |
b10bd496 | 1283 | CYStatement |
cf7d4c69 | 1284 | { |
3b52fd1a JF |
1285 | CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : |
1286 | CYFunction(name, parameters, statements) | |
cf7d4c69 JF |
1287 | { |
1288 | } | |
5999c315 | 1289 | |
3b52fd1a | 1290 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1291 | virtual void Output(CYOutput &out, CYFlags flags) const; |
5999c315 JF |
1292 | }; |
1293 | ||
1294 | struct CYExpress : | |
1295 | CYStatement | |
1296 | { | |
1297 | CYExpression *expression_; | |
1298 | ||
1299 | CYExpress(CYExpression *expression) : | |
1300 | expression_(expression) | |
1301 | { | |
1302 | } | |
1303 | ||
3b52fd1a | 1304 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1305 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1306 | }; |
1307 | ||
1308 | struct CYContinue : | |
1309 | CYStatement | |
1310 | { | |
1311 | CYIdentifier *label_; | |
1312 | ||
1313 | CYContinue(CYIdentifier *label) : | |
1314 | label_(label) | |
1315 | { | |
1316 | } | |
5999c315 | 1317 | |
3b52fd1a | 1318 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1319 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1320 | }; |
1321 | ||
1322 | struct CYBreak : | |
1323 | CYStatement | |
1324 | { | |
1325 | CYIdentifier *label_; | |
1326 | ||
1327 | CYBreak(CYIdentifier *label) : | |
1328 | label_(label) | |
1329 | { | |
1330 | } | |
5999c315 | 1331 | |
3b52fd1a | 1332 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1333 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1334 | }; |
1335 | ||
1336 | struct CYReturn : | |
1337 | CYStatement | |
1338 | { | |
1339 | CYExpression *value_; | |
1340 | ||
1341 | CYReturn(CYExpression *value) : | |
1342 | value_(value) | |
1343 | { | |
1344 | } | |
5999c315 | 1345 | |
3b52fd1a | 1346 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1347 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1348 | }; |
1349 | ||
1350 | struct CYEmpty : | |
1351 | CYStatement | |
1352 | { | |
3b52fd1a | 1353 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1354 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1355 | }; |
1356 | ||
96a7e5c2 JF |
1357 | struct CYFinally : |
1358 | CYThing | |
1359 | { | |
3b52fd1a | 1360 | CYBlock code_; |
b10bd496 | 1361 | |
3b52fd1a JF |
1362 | CYFinally(CYStatement *statements) : |
1363 | code_(statements) | |
b10bd496 JF |
1364 | { |
1365 | } | |
1366 | ||
3b52fd1a | 1367 | void Replace(CYContext &context); |
b10bd496 JF |
1368 | virtual void Output(CYOutput &out) const; |
1369 | }; | |
1370 | ||
cf7d4c69 JF |
1371 | struct CYTry : |
1372 | CYStatement | |
1373 | { | |
3b52fd1a | 1374 | CYBlock code_; |
cf7d4c69 | 1375 | CYCatch *catch_; |
b10bd496 | 1376 | CYFinally *finally_; |
cf7d4c69 | 1377 | |
3b52fd1a JF |
1378 | CYTry(CYStatement *statements, CYCatch *_catch, CYFinally *finally) : |
1379 | code_(statements), | |
cf7d4c69 JF |
1380 | catch_(_catch), |
1381 | finally_(finally) | |
1382 | { | |
1383 | } | |
5999c315 | 1384 | |
3b52fd1a | 1385 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1386 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1387 | }; |
1388 | ||
1389 | struct CYThrow : | |
1390 | CYStatement | |
1391 | { | |
1392 | CYExpression *value_; | |
1393 | ||
1394 | CYThrow(CYExpression *value) : | |
1395 | value_(value) | |
1396 | { | |
1397 | } | |
5999c315 | 1398 | |
3b52fd1a | 1399 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1400 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1401 | }; |
1402 | ||
1403 | struct CYWith : | |
1404 | CYStatement | |
1405 | { | |
1406 | CYExpression *scope_; | |
1407 | CYStatement *code_; | |
1408 | ||
1409 | CYWith(CYExpression *scope, CYStatement *code) : | |
1410 | scope_(scope), | |
1411 | code_(code) | |
1412 | { | |
1413 | } | |
5999c315 | 1414 | |
3b52fd1a | 1415 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1416 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1417 | }; |
1418 | ||
1419 | struct CYSwitch : | |
1420 | CYStatement | |
1421 | { | |
1422 | CYExpression *value_; | |
1423 | CYClause *clauses_; | |
1424 | ||
1425 | CYSwitch(CYExpression *value, CYClause *clauses) : | |
1426 | value_(value), | |
1427 | clauses_(clauses) | |
1428 | { | |
1429 | } | |
5999c315 | 1430 | |
3b52fd1a | 1431 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1432 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1433 | }; |
1434 | ||
1435 | struct CYCondition : | |
1436 | CYExpression | |
1437 | { | |
1438 | CYExpression *test_; | |
1439 | CYExpression *true_; | |
1440 | CYExpression *false_; | |
1441 | ||
1442 | CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) : | |
91a416e4 | 1443 | test_(test), |
cf7d4c69 JF |
1444 | true_(_true), |
1445 | false_(_false) | |
1446 | { | |
1447 | } | |
5999c315 | 1448 | |
d35a3b07 JF |
1449 | CYPrecedence(15) |
1450 | ||
3b52fd1a | 1451 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1452 | virtual void Output(CYOutput &out, CYFlags flags) const; |
5999c315 JF |
1453 | }; |
1454 | ||
1455 | struct CYAddressOf : | |
1456 | CYPrefix | |
1457 | { | |
1458 | CYAddressOf(CYExpression *rhs) : | |
1459 | CYPrefix(rhs) | |
1460 | { | |
1461 | } | |
1462 | ||
1463 | virtual const char *Operator() const { | |
1464 | return "&"; | |
1465 | } | |
1466 | ||
b09da87b | 1467 | CYAlphabetic(false) |
d35a3b07 | 1468 | |
3b52fd1a | 1469 | virtual CYExpression *Replace(CYContext &context); |
5999c315 JF |
1470 | }; |
1471 | ||
1472 | struct CYIndirect : | |
1473 | CYPrefix | |
1474 | { | |
1475 | CYIndirect(CYExpression *rhs) : | |
1476 | CYPrefix(rhs) | |
1477 | { | |
1478 | } | |
1479 | ||
1480 | virtual const char *Operator() const { | |
691e4717 | 1481 | return "^"; |
5999c315 JF |
1482 | } |
1483 | ||
b09da87b | 1484 | CYAlphabetic(false) |
d35a3b07 | 1485 | |
3b52fd1a | 1486 | virtual CYExpression *Replace(CYContext &context); |
cf7d4c69 JF |
1487 | }; |
1488 | ||
4644480a JF |
1489 | #define CYReplace \ |
1490 | virtual CYExpression *Replace(CYContext &context); | |
1491 | ||
1492 | #define CYPostfix_(op, name, args...) \ | |
cf7d4c69 JF |
1493 | struct CY ## name : \ |
1494 | CYPostfix \ | |
4644480a | 1495 | { args \ |
cf7d4c69 JF |
1496 | CY ## name(CYExpression *lhs) : \ |
1497 | CYPostfix(lhs) \ | |
1498 | { \ | |
1499 | } \ | |
5999c315 JF |
1500 | \ |
1501 | virtual const char *Operator() const { \ | |
1502 | return op; \ | |
1503 | } \ | |
cf7d4c69 JF |
1504 | }; |
1505 | ||
4644480a | 1506 | #define CYPrefix_(alphabetic, op, name, args...) \ |
cf7d4c69 JF |
1507 | struct CY ## name : \ |
1508 | CYPrefix \ | |
4644480a | 1509 | { args \ |
cf7d4c69 JF |
1510 | CY ## name(CYExpression *rhs) : \ |
1511 | CYPrefix(rhs) \ | |
1512 | { \ | |
1513 | } \ | |
d35a3b07 | 1514 | \ |
b09da87b | 1515 | CYAlphabetic(alphabetic) \ |
5999c315 JF |
1516 | \ |
1517 | virtual const char *Operator() const { \ | |
1518 | return op; \ | |
1519 | } \ | |
cf7d4c69 JF |
1520 | }; |
1521 | ||
4644480a | 1522 | #define CYInfix_(alphabetic, precedence, op, name, args...) \ |
cf7d4c69 JF |
1523 | struct CY ## name : \ |
1524 | CYInfix \ | |
4644480a | 1525 | { args \ |
cf7d4c69 JF |
1526 | CY ## name(CYExpression *lhs, CYExpression *rhs) : \ |
1527 | CYInfix(lhs, rhs) \ | |
1528 | { \ | |
1529 | } \ | |
d35a3b07 | 1530 | \ |
b09da87b | 1531 | CYAlphabetic(alphabetic) \ |
d35a3b07 | 1532 | CYPrecedence(precedence) \ |
5999c315 JF |
1533 | \ |
1534 | virtual const char *Operator() const { \ | |
1535 | return op; \ | |
1536 | } \ | |
cf7d4c69 JF |
1537 | }; |
1538 | ||
4644480a | 1539 | #define CYAssignment_(op, name, args...) \ |
cf7d4c69 JF |
1540 | struct CY ## name ## Assign : \ |
1541 | CYAssignment \ | |
4644480a | 1542 | { args \ |
cf7d4c69 JF |
1543 | CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \ |
1544 | CYAssignment(lhs, rhs) \ | |
1545 | { \ | |
1546 | } \ | |
5999c315 JF |
1547 | \ |
1548 | virtual const char *Operator() const { \ | |
1549 | return op; \ | |
1550 | } \ | |
cf7d4c69 JF |
1551 | }; |
1552 | ||
1553 | CYPostfix_("++", PostIncrement) | |
1554 | CYPostfix_("--", PostDecrement) | |
1555 | ||
b09da87b JF |
1556 | CYPrefix_(true, "delete", Delete) |
1557 | CYPrefix_(true, "void", Void) | |
1558 | CYPrefix_(true, "typeof", TypeOf) | |
1559 | CYPrefix_(false, "++", PreIncrement) | |
1560 | CYPrefix_(false, "--", PreDecrement) | |
c0bc320e | 1561 | CYPrefix_(false, "+", Affirm) |
b09da87b JF |
1562 | CYPrefix_(false, "-", Negate) |
1563 | CYPrefix_(false, "~", BitwiseNot) | |
1564 | CYPrefix_(false, "!", LogicalNot) | |
1565 | ||
1566 | CYInfix_(false, 5, "*", Multiply) | |
1567 | CYInfix_(false, 5, "/", Divide) | |
1568 | CYInfix_(false, 5, "%", Modulus) | |
4644480a | 1569 | CYInfix_(false, 6, "+", Add, CYReplace) |
b09da87b JF |
1570 | CYInfix_(false, 6, "-", Subtract) |
1571 | CYInfix_(false, 7, "<<", ShiftLeft) | |
1572 | CYInfix_(false, 7, ">>", ShiftRightSigned) | |
1573 | CYInfix_(false, 7, ">>>", ShiftRightUnsigned) | |
1574 | CYInfix_(false, 8, "<", Less) | |
1575 | CYInfix_(false, 8, ">", Greater) | |
1576 | CYInfix_(false, 8, "<=", LessOrEqual) | |
1577 | CYInfix_(false, 8, ">=", GreaterOrEqual) | |
1578 | CYInfix_(true, 8, "instanceof", InstanceOf) | |
1579 | CYInfix_(true, 8, "in", In) | |
1580 | CYInfix_(false, 9, "==", Equal) | |
1581 | CYInfix_(false, 9, "!=", NotEqual) | |
1582 | CYInfix_(false, 9, "===", Identical) | |
1583 | CYInfix_(false, 9, "!==", NotIdentical) | |
1584 | CYInfix_(false, 10, "&", BitwiseAnd) | |
1585 | CYInfix_(false, 11, "^", BitwiseXOr) | |
1586 | CYInfix_(false, 12, "|", BitwiseOr) | |
1587 | CYInfix_(false, 13, "&&", LogicalAnd) | |
1588 | CYInfix_(false, 14, "||", LogicalOr) | |
cf7d4c69 JF |
1589 | |
1590 | CYAssignment_("=", ) | |
1591 | CYAssignment_("*=", Multiply) | |
1592 | CYAssignment_("/=", Divide) | |
1593 | CYAssignment_("%=", Modulus) | |
1594 | CYAssignment_("+=", Add) | |
1595 | CYAssignment_("-=", Subtract) | |
1596 | CYAssignment_("<<=", ShiftLeft) | |
1597 | CYAssignment_(">>=", ShiftRightSigned) | |
1598 | CYAssignment_(">>>=", ShiftRightUnsigned) | |
1599 | CYAssignment_("&=", BitwiseAnd) | |
1600 | CYAssignment_("^=", BitwiseXOr) | |
1601 | CYAssignment_("|=", BitwiseOr) | |
1602 | ||
63b4c5a8 | 1603 | #endif/*CYPARSER_HPP*/ |