]>
Commit | Line | Data |
---|---|---|
b3378a02 | 1 | /* Cycript - Optimizing JavaScript Compiler/Runtime |
c1d3e52e | 2 | * Copyright (C) 2009-2015 Jay Freeman (saurik) |
b4aa79af JF |
3 | */ |
4 | ||
f95d2598 | 5 | /* GNU Affero General Public License, Version 3 {{{ */ |
b4aa79af | 6 | /* |
f95d2598 JF |
7 | * This program is free software: you can redistribute it and/or modify |
8 | * it under the terms of the GNU Affero General Public License as published by | |
9 | * the Free Software Foundation, either version 3 of the License, or | |
10 | * (at your option) any later version. | |
11 | ||
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
c15969fd | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f95d2598 JF |
15 | * GNU Affero General Public License for more details. |
16 | ||
17 | * You should have received a copy of the GNU Affero General Public License | |
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
b3378a02 | 19 | **/ |
b4aa79af JF |
20 | /* }}} */ |
21 | ||
c5fa2867 JF |
22 | #ifndef CYCRIPT_PARSER_HPP |
23 | #define CYCRIPT_PARSER_HPP | |
63b4c5a8 | 24 | |
4de0686f JF |
25 | #include <iostream> |
26 | ||
5999c315 | 27 | #include <string> |
c3c20102 | 28 | #include <vector> |
029bc65b JF |
29 | #include <map> |
30 | #include <set> | |
cf7d4c69 | 31 | |
a4dbf05b | 32 | #include <cstdio> |
4de0686f JF |
33 | #include <cstdlib> |
34 | ||
da2af935 | 35 | #include "List.hpp" |
00b4cb83 | 36 | #include "Location.hpp" |
5999c315 | 37 | #include "Pooling.hpp" |
029bc65b JF |
38 | #include "Options.hpp" |
39 | ||
01d0f64d | 40 | struct CYContext; |
924f67b2 | 41 | |
5999c315 | 42 | struct CYThing { |
7c6c5b0a JF |
43 | virtual ~CYThing() { |
44 | } | |
45 | ||
652ec1ba | 46 | virtual void Output(struct CYOutput &out) const = 0; |
5999c315 JF |
47 | }; |
48 | ||
652ec1ba JF |
49 | struct CYOutput { |
50 | std::ostream &out_; | |
029bc65b | 51 | CYOptions &options_; |
11c1cc16 JF |
52 | bool pretty_; |
53 | unsigned indent_; | |
320ce753 | 54 | bool right_; |
652ec1ba | 55 | |
96a7e5c2 JF |
56 | enum { |
57 | NoMode, | |
58 | NoLetter, | |
c0bc320e | 59 | NoPlus, |
96a7e5c2 JF |
60 | NoHyphen, |
61 | Terminated | |
62 | } mode_; | |
63 | ||
029bc65b | 64 | CYOutput(std::ostream &out, CYOptions &options) : |
11c1cc16 | 65 | out_(out), |
029bc65b | 66 | options_(options), |
11c1cc16 | 67 | pretty_(false), |
96a7e5c2 | 68 | indent_(0), |
320ce753 | 69 | right_(false), |
96a7e5c2 | 70 | mode_(NoMode) |
652ec1ba JF |
71 | { |
72 | } | |
73 | ||
96a7e5c2 | 74 | void Check(char value); |
1fdca2fa | 75 | void Terminate(); |
652ec1ba | 76 | |
96a7e5c2 JF |
77 | CYOutput &operator <<(char rhs); |
78 | CYOutput &operator <<(const char *rhs); | |
79 | ||
80 | _finline CYOutput &operator <<(const CYThing *rhs) { | |
81 | if (rhs != NULL) | |
82 | rhs->Output(*this); | |
652ec1ba JF |
83 | return *this; |
84 | } | |
85 | ||
86 | _finline CYOutput &operator <<(const CYThing &rhs) { | |
87 | rhs.Output(*this); | |
88 | return *this; | |
89 | } | |
90 | }; | |
5999c315 | 91 | |
e5bc40db | 92 | struct CYPropertyName { |
652ec1ba | 93 | virtual void PropertyName(CYOutput &out) const = 0; |
7c6c5b0a JF |
94 | |
95 | virtual ~CYPropertyName() { | |
96 | } | |
e5bc40db JF |
97 | }; |
98 | ||
3b52fd1a | 99 | struct CYExpression; |
ae65d594 | 100 | struct CYAssignment; |
3b52fd1a JF |
101 | |
102 | enum CYNeeded { | |
103 | CYNever = -1, | |
104 | CYSometimes = 0, | |
105 | CYAlways = 1, | |
106 | }; | |
107 | ||
108 | enum CYFlags { | |
109 | CYNoFlags = 0, | |
110 | CYNoBrace = (1 << 0), | |
111 | CYNoFunction = (1 << 1), | |
112 | CYNoIn = (1 << 2), | |
113 | CYNoCall = (1 << 3), | |
114 | CYNoRightHand = (1 << 4), | |
115 | CYNoDangle = (1 << 5), | |
9561f209 | 116 | CYNoInteger = (1 << 6), |
3b52fd1a JF |
117 | CYNoBF = (CYNoBrace | CYNoFunction), |
118 | }; | |
119 | ||
5a6d4d25 JF |
120 | _finline CYFlags operator ~(CYFlags rhs) { |
121 | return static_cast<CYFlags>(~static_cast<unsigned>(rhs)); | |
122 | } | |
123 | ||
124 | _finline CYFlags operator &(CYFlags lhs, CYFlags rhs) { | |
125 | return static_cast<CYFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); | |
126 | } | |
127 | ||
128 | _finline CYFlags operator |(CYFlags lhs, CYFlags rhs) { | |
129 | return static_cast<CYFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); | |
130 | } | |
131 | ||
132 | _finline CYFlags &operator |=(CYFlags &lhs, CYFlags rhs) { | |
133 | return lhs = lhs | rhs; | |
134 | } | |
135 | ||
136 | _finline CYFlags CYLeft(CYFlags flags) { | |
137 | return flags & ~(CYNoDangle | CYNoInteger); | |
138 | } | |
139 | ||
140 | _finline CYFlags CYRight(CYFlags flags) { | |
141 | return flags & ~CYNoBF; | |
142 | } | |
143 | ||
144 | _finline CYFlags CYCenter(CYFlags flags) { | |
145 | return CYLeft(CYRight(flags)); | |
146 | } | |
147 | ||
3b52fd1a | 148 | struct CYStatement : |
b0385401 JF |
149 | CYNext<CYStatement>, |
150 | CYThing | |
3b52fd1a | 151 | { |
7c6c5b0a JF |
152 | virtual ~CYStatement() { |
153 | } | |
154 | ||
3b52fd1a JF |
155 | void Single(CYOutput &out, CYFlags flags) const; |
156 | void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const; | |
b0385401 | 157 | virtual void Output(CYOutput &out) const; |
3b52fd1a | 158 | |
3b52fd1a JF |
159 | virtual CYStatement *Replace(CYContext &context) = 0; |
160 | ||
161 | private: | |
162 | virtual void Output(CYOutput &out, CYFlags flags) const = 0; | |
163 | }; | |
164 | ||
165 | struct CYStatements { | |
166 | CYStatement *first_; | |
167 | CYStatement *last_; | |
168 | ||
169 | CYStatements() : | |
170 | first_(NULL), | |
171 | last_(NULL) | |
172 | { | |
173 | } | |
174 | ||
175 | operator CYStatement *() const { | |
176 | return first_; | |
177 | } | |
178 | ||
179 | CYStatements &operator ->*(CYStatement *next) { | |
180 | if (next != NULL) | |
181 | if (first_ == NULL) { | |
182 | first_ = next; | |
183 | last_ = next; | |
184 | } else for (;; last_ = last_->next_) | |
185 | if (last_->next_ == NULL) { | |
186 | last_->next_ = next; | |
187 | last_ = next; | |
188 | break; | |
189 | } | |
190 | return *this; | |
191 | } | |
192 | }; | |
193 | ||
e5bc40db | 194 | struct CYClassName { |
7c6c5b0a JF |
195 | virtual ~CYClassName() { |
196 | } | |
197 | ||
3b52fd1a | 198 | virtual CYExpression *ClassName(CYContext &context, bool object) = 0; |
652ec1ba | 199 | virtual void ClassName(CYOutput &out, bool object) const = 0; |
63b4c5a8 JF |
200 | }; |
201 | ||
cf7d4c69 | 202 | struct CYWord : |
e5bc40db JF |
203 | CYThing, |
204 | CYPropertyName, | |
205 | CYClassName | |
63b4c5a8 | 206 | { |
cf7d4c69 JF |
207 | const char *word_; |
208 | ||
209 | CYWord(const char *word) : | |
210 | word_(word) | |
211 | { | |
212 | } | |
213 | ||
029bc65b JF |
214 | void Set(const char *value) { |
215 | word_ = value; | |
cf7d4c69 JF |
216 | } |
217 | ||
029bc65b | 218 | virtual const char *Word() const; |
652ec1ba | 219 | virtual void Output(CYOutput &out) const; |
e5bc40db | 220 | |
3b52fd1a | 221 | virtual CYExpression *ClassName(CYContext &context, bool object); |
652ec1ba JF |
222 | virtual void ClassName(CYOutput &out, bool object) const; |
223 | virtual void PropertyName(CYOutput &out) const; | |
63b4c5a8 JF |
224 | }; |
225 | ||
652ec1ba | 226 | _finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) { |
029bc65b JF |
227 | lhs << &rhs << '='; |
228 | return lhs << rhs.Word(); | |
652ec1ba JF |
229 | } |
230 | ||
cf7d4c69 | 231 | struct CYIdentifier : |
14ec9e00 | 232 | CYNext<CYIdentifier>, |
cf7d4c69 | 233 | CYWord |
63b4c5a8 | 234 | { |
029bc65b | 235 | CYIdentifier *replace_; |
6a981250 | 236 | size_t offset_; |
e013809d | 237 | size_t usage_; |
029bc65b | 238 | |
5999c315 | 239 | CYIdentifier(const char *word) : |
029bc65b | 240 | CYWord(word), |
6a981250 | 241 | replace_(NULL), |
e013809d JF |
242 | offset_(0), |
243 | usage_(0) | |
5999c315 | 244 | { |
cf7d4c69 | 245 | } |
029bc65b JF |
246 | |
247 | virtual const char *Word() const; | |
248 | CYIdentifier *Replace(CYContext &context); | |
63b4c5a8 JF |
249 | }; |
250 | ||
320ce753 JF |
251 | struct CYComment : |
252 | CYStatement | |
253 | { | |
254 | const char *value_; | |
255 | ||
256 | CYComment(const char *value) : | |
257 | value_(value) | |
258 | { | |
259 | } | |
260 | ||
261 | virtual CYStatement *Replace(CYContext &context); | |
262 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
263 | }; | |
264 | ||
62014ea9 | 265 | struct CYLabel : |
3b52fd1a | 266 | CYStatement |
62014ea9 | 267 | { |
9e562cfc | 268 | CYIdentifier *name_; |
3b52fd1a | 269 | CYStatement *statement_; |
cf7d4c69 | 270 | |
3b52fd1a JF |
271 | CYLabel(CYIdentifier *name, CYStatement *statement) : |
272 | name_(name), | |
273 | statement_(statement) | |
cf7d4c69 JF |
274 | { |
275 | } | |
fb98ac0c | 276 | |
3b52fd1a JF |
277 | virtual CYStatement *Replace(CYContext &context); |
278 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
fb98ac0c JF |
279 | }; |
280 | ||
14ec9e00 | 281 | struct CYCStringLess : |
029bc65b JF |
282 | std::binary_function<const char *, const char *, bool> |
283 | { | |
284 | _finline bool operator ()(const char *lhs, const char *rhs) const { | |
285 | return strcmp(lhs, rhs) < 0; | |
286 | } | |
287 | }; | |
288 | ||
289 | struct CYIdentifierValueLess : | |
290 | std::binary_function<CYIdentifier *, CYIdentifier *, bool> | |
291 | { | |
292 | _finline bool operator ()(CYIdentifier *lhs, CYIdentifier *rhs) const { | |
14ec9e00 | 293 | return CYCStringLess()(lhs->Word(), rhs->Word()); |
029bc65b JF |
294 | } |
295 | }; | |
296 | ||
297 | enum CYIdentifierFlags { | |
298 | CYIdentifierArgument, | |
14ec9e00 JF |
299 | CYIdentifierVariable, |
300 | CYIdentifierOther, | |
301 | CYIdentifierMagic, | |
daf22a65 | 302 | CYIdentifierCatch, |
029bc65b JF |
303 | }; |
304 | ||
14ec9e00 | 305 | typedef std::set<const char *, CYCStringLess> CYCStringSet; |
029bc65b | 306 | typedef std::set<CYIdentifier *, CYIdentifierValueLess> CYIdentifierValueSet; |
029bc65b JF |
307 | typedef std::map<CYIdentifier *, CYIdentifierFlags> CYIdentifierAddressFlagsMap; |
308 | ||
e013809d JF |
309 | struct CYIdentifierUsage { |
310 | CYIdentifier *identifier_; | |
311 | size_t usage_; | |
312 | }; | |
313 | ||
314 | typedef std::vector<CYIdentifierUsage> CYIdentifierUsageVector; | |
315 | ||
029bc65b | 316 | struct CYScope { |
61fe0c53 | 317 | bool transparent_; |
029bc65b | 318 | CYScope *parent_; |
a86e34d0 | 319 | |
a846a8cd | 320 | CYIdentifierAddressFlagsMap internal_; |
a86e34d0 | 321 | CYIdentifierValueSet identifiers_; |
029bc65b | 322 | |
50a3d79f | 323 | CYScope(bool transparent, CYContext &context); |
0a356474 | 324 | |
a86e34d0 JF |
325 | void Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags); |
326 | virtual CYIdentifier *Lookup(CYContext &context, CYIdentifier *identifier); | |
6a981250 | 327 | void Merge(CYContext &context, CYIdentifier *identifier); |
50a3d79f | 328 | void Close(CYContext &context, CYStatement *&statements); |
029bc65b JF |
329 | }; |
330 | ||
3b52fd1a JF |
331 | struct CYProgram : |
332 | CYThing | |
63b4c5a8 | 333 | { |
b0385401 | 334 | CYStatement *code_; |
9e562cfc | 335 | |
b0385401 JF |
336 | CYProgram(CYStatement *code) : |
337 | code_(code) | |
9e562cfc JF |
338 | { |
339 | } | |
cf7d4c69 | 340 | |
3b52fd1a | 341 | virtual void Replace(CYContext &context); |
3b52fd1a | 342 | virtual void Output(CYOutput &out) const; |
9e562cfc JF |
343 | }; |
344 | ||
ab2aa221 | 345 | struct CYNonLocal; |
a0be43fc | 346 | struct CYThisScope; |
ab2aa221 | 347 | |
2c81c6df | 348 | struct CYContext { |
6a981250 | 349 | CYOptions &options_; |
ab2aa221 | 350 | |
6a981250 | 351 | CYScope *scope_; |
a0be43fc JF |
352 | CYThisScope *this_; |
353 | ||
a846a8cd | 354 | CYIdentifierUsageVector rename_; |
6a981250 | 355 | |
ab2aa221 | 356 | CYNonLocal *nonlocal_; |
06293152 | 357 | CYNonLocal *nextlocal_; |
ab2aa221 JF |
358 | unsigned unique_; |
359 | ||
2eb8215d | 360 | CYContext(CYOptions &options) : |
6a981250 | 361 | options_(options), |
ab2aa221 | 362 | scope_(NULL), |
a0be43fc | 363 | this_(NULL), |
ab2aa221 | 364 | nonlocal_(NULL), |
06293152 | 365 | nextlocal_(NULL), |
ab2aa221 | 366 | unique_(0) |
6a981250 JF |
367 | { |
368 | } | |
369 | ||
0a356474 JF |
370 | virtual ~CYContext() { |
371 | } | |
372 | ||
b0385401 JF |
373 | void ReplaceAll(CYStatement *&statement) { |
374 | if (statement == NULL) | |
375 | return; | |
376 | CYStatement *next(statement->next_); | |
377 | ||
378 | Replace(statement); | |
379 | ReplaceAll(next); | |
380 | ||
381 | if (statement == NULL) | |
382 | statement = next; | |
383 | else | |
384 | statement->SetNext(next); | |
cde20a5a JF |
385 | } |
386 | ||
6a981250 JF |
387 | template <typename Type_> |
388 | void Replace(Type_ *&value) { | |
389 | for (;;) if (value == NULL) | |
390 | break; | |
391 | else { | |
392 | Type_ *replace(value->Replace(*this)); | |
393 | if (replace != value) | |
394 | value = replace; | |
395 | else break; | |
396 | } | |
397 | } | |
ab2aa221 JF |
398 | |
399 | void NonLocal(CYStatement *&statements); | |
400 | CYIdentifier *Unique(); | |
401 | }; | |
402 | ||
403 | struct CYNonLocal { | |
404 | CYIdentifier *identifier_; | |
405 | ||
406 | CYNonLocal() : | |
407 | identifier_(NULL) | |
408 | { | |
409 | } | |
410 | ||
411 | CYIdentifier *Target(CYContext &context) { | |
412 | if (identifier_ == NULL) | |
413 | identifier_ = context.Unique(); | |
414 | return identifier_; | |
415 | } | |
6a981250 JF |
416 | }; |
417 | ||
a0be43fc JF |
418 | struct CYThisScope : |
419 | CYNext<CYThisScope> | |
420 | { | |
421 | CYIdentifier *identifier_; | |
422 | ||
423 | CYThisScope() : | |
424 | identifier_(NULL) | |
425 | { | |
426 | } | |
427 | ||
428 | CYIdentifier *Identifier(CYContext &context) { | |
429 | if (next_ != NULL) | |
430 | return next_->Identifier(context); | |
431 | if (identifier_ == NULL) | |
432 | identifier_ = context.Unique(); | |
433 | return identifier_; | |
434 | } | |
435 | }; | |
436 | ||
9e562cfc | 437 | struct CYBlock : |
b0385401 | 438 | CYStatement |
9e562cfc | 439 | { |
b0385401 | 440 | CYStatement *code_; |
9e562cfc | 441 | |
b0385401 JF |
442 | CYBlock(CYStatement *code) : |
443 | code_(code) | |
9e562cfc | 444 | { |
cf7d4c69 | 445 | } |
9e562cfc | 446 | |
3b52fd1a JF |
447 | virtual CYStatement *Replace(CYContext &context); |
448 | ||
fb98ac0c | 449 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
450 | }; |
451 | ||
cac61857 | 452 | struct CYForInitialiser { |
7c6c5b0a JF |
453 | virtual ~CYForInitialiser() { |
454 | } | |
455 | ||
029bc65b | 456 | virtual CYExpression *Replace(CYContext &context) = 0; |
15b88a33 | 457 | virtual void Output(CYOutput &out, CYFlags flags) const = 0; |
dea834b0 JF |
458 | }; |
459 | ||
cac61857 | 460 | struct CYForInInitialiser { |
7c6c5b0a JF |
461 | virtual ~CYForInInitialiser() { |
462 | } | |
463 | ||
652ec1ba | 464 | virtual void ForIn(CYOutput &out, CYFlags flags) const = 0; |
ad3b38bb | 465 | virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value) = 0; |
b158281e | 466 | |
029bc65b | 467 | virtual CYExpression *Replace(CYContext &context) = 0; |
ae65d594 | 468 | virtual CYAssignment *Assignment(CYContext &context) = 0; |
c8a0500b JF |
469 | |
470 | virtual void Output(CYOutput &out, CYFlags flags) const = 0; | |
b09da87b JF |
471 | }; |
472 | ||
0afc9ba3 JF |
473 | struct CYFunctionParameter; |
474 | ||
4644480a JF |
475 | struct CYNumber; |
476 | struct CYString; | |
477 | ||
cf7d4c69 | 478 | struct CYExpression : |
cf7d4c69 | 479 | CYForInitialiser, |
e5bc40db | 480 | CYForInInitialiser, |
96a7e5c2 JF |
481 | CYClassName, |
482 | CYThing | |
63b4c5a8 | 483 | { |
9a39f705 | 484 | virtual int Precedence() const = 0; |
75b0a457 | 485 | |
fb98ac0c JF |
486 | virtual bool RightHand() const { |
487 | return true; | |
488 | } | |
489 | ||
652ec1ba | 490 | virtual void ForIn(CYOutput &out, CYFlags flags) const; |
ad3b38bb | 491 | virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value); |
75b0a457 | 492 | |
6c093cce JF |
493 | virtual CYExpression *AddArgument(CYContext &context, CYExpression *value); |
494 | ||
96a7e5c2 | 495 | virtual void Output(CYOutput &out) const; |
652ec1ba | 496 | virtual void Output(CYOutput &out, CYFlags flags) const = 0; |
9a39f705 | 497 | void Output(CYOutput &out, int precedence, CYFlags flags) const; |
dea834b0 | 498 | |
3b52fd1a | 499 | virtual CYExpression *ClassName(CYContext &context, bool object); |
652ec1ba | 500 | virtual void ClassName(CYOutput &out, bool object) const; |
e5bc40db | 501 | |
3b52fd1a | 502 | virtual CYExpression *Replace(CYContext &context) = 0; |
ae65d594 | 503 | virtual CYAssignment *Assignment(CYContext &context); |
3b52fd1a | 504 | |
4644480a | 505 | virtual CYExpression *Primitive(CYContext &context) { |
fd5cdf97 | 506 | return NULL; |
4644480a JF |
507 | } |
508 | ||
0afc9ba3 | 509 | virtual CYFunctionParameter *Parameter() const; |
0afc9ba3 | 510 | |
4644480a JF |
511 | virtual CYNumber *Number(CYContext &context) { |
512 | return NULL; | |
513 | } | |
514 | ||
515 | virtual CYString *String(CYContext &context) { | |
516 | return NULL; | |
517 | } | |
518 | ||
dea834b0 JF |
519 | virtual const char *Word() const { |
520 | return NULL; | |
521 | } | |
63b4c5a8 JF |
522 | }; |
523 | ||
b09da87b JF |
524 | #define CYAlphabetic(value) \ |
525 | virtual bool Alphabetic() const { \ | |
526 | return value; \ | |
527 | } | |
528 | ||
d35a3b07 | 529 | #define CYPrecedence(value) \ |
9a39f705 JF |
530 | static const int Precedence_ = value; \ |
531 | virtual int Precedence() const { \ | |
8351aa30 | 532 | return Precedence_; \ |
d35a3b07 JF |
533 | } |
534 | ||
fb98ac0c JF |
535 | #define CYRightHand(value) \ |
536 | virtual bool RightHand() const { \ | |
537 | return value; \ | |
538 | } | |
539 | ||
d35a3b07 JF |
540 | struct CYCompound : |
541 | CYExpression | |
542 | { | |
fd5cdf97 JF |
543 | CYExpression *expression_; |
544 | CYExpression *next_; | |
d35a3b07 | 545 | |
b0385401 | 546 | CYCompound(CYExpression *expression, CYExpression *next) : |
fd5cdf97 JF |
547 | expression_(expression), |
548 | next_(next) | |
d35a3b07 | 549 | { |
fd5cdf97 | 550 | _assert(expression_ != NULL); |
b0385401 | 551 | _assert(next != NULL); |
d35a3b07 JF |
552 | } |
553 | ||
554 | CYPrecedence(17) | |
555 | ||
3b52fd1a | 556 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 557 | void Output(CYOutput &out, CYFlags flags) const; |
e06e5ee1 | 558 | |
b0385401 JF |
559 | virtual CYFunctionParameter *Parameter() const; |
560 | }; | |
561 | ||
562 | struct CYParenthetical : | |
563 | CYExpression | |
564 | { | |
565 | CYExpression *expression_; | |
566 | ||
567 | CYParenthetical(CYExpression *expression) : | |
568 | expression_(expression) | |
569 | { | |
570 | } | |
571 | ||
572 | CYPrecedence(0) | |
573 | ||
574 | virtual CYExpression *Replace(CYContext &context); | |
575 | void Output(CYOutput &out, CYFlags flags) const; | |
d35a3b07 | 576 | }; |
5999c315 | 577 | |
c8a0500b JF |
578 | struct CYDeclaration; |
579 | ||
3b52fd1a JF |
580 | struct CYFunctionParameter : |
581 | CYNext<CYFunctionParameter>, | |
582 | CYThing | |
583 | { | |
c8a0500b | 584 | CYForInInitialiser *initialiser_; |
3b52fd1a | 585 | |
c8a0500b | 586 | CYFunctionParameter(CYForInInitialiser *initialiser, CYFunctionParameter *next = NULL) : |
3b52fd1a | 587 | CYNext<CYFunctionParameter>(next), |
c8a0500b | 588 | initialiser_(initialiser) |
4e11a430 JF |
589 | { |
590 | } | |
591 | ||
b0385401 | 592 | void Replace(CYContext &context, CYStatement *&statements); |
c8a0500b | 593 | void Output(CYOutput &out) const; |
3b52fd1a JF |
594 | }; |
595 | ||
75b0a457 | 596 | struct CYComprehension : |
96a7e5c2 JF |
597 | CYNext<CYComprehension>, |
598 | CYThing | |
75b0a457 | 599 | { |
c2529502 JF |
600 | CYComprehension(CYComprehension *next = NULL) : |
601 | CYNext<CYComprehension>(next) | |
602 | { | |
603 | } | |
604 | ||
b3aa25d8 JF |
605 | CYComprehension *Modify(CYComprehension *next) { |
606 | next_ = next; | |
607 | return this; | |
608 | } | |
609 | ||
75b0a457 JF |
610 | virtual const char *Name() const = 0; |
611 | ||
3b52fd1a JF |
612 | virtual CYFunctionParameter *Parameter(CYContext &context) const = 0; |
613 | CYFunctionParameter *Parameters(CYContext &context) const; | |
614 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
4644480a | 615 | virtual void Output(CYOutput &out) const = 0; |
75b0a457 JF |
616 | }; |
617 | ||
618 | struct CYForInComprehension : | |
619 | CYComprehension | |
620 | { | |
621 | CYIdentifier *name_; | |
622 | CYExpression *set_; | |
623 | ||
c2529502 JF |
624 | CYForInComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) : |
625 | CYComprehension(next), | |
75b0a457 JF |
626 | name_(name), |
627 | set_(set) | |
628 | { | |
629 | } | |
630 | ||
631 | virtual const char *Name() const { | |
029bc65b | 632 | return name_->Word(); |
75b0a457 JF |
633 | } |
634 | ||
3b52fd1a JF |
635 | virtual CYFunctionParameter *Parameter(CYContext &context) const; |
636 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
4644480a | 637 | virtual void Output(CYOutput &out) const; |
75b0a457 JF |
638 | }; |
639 | ||
d5618df7 | 640 | struct CYForOfComprehension : |
75b0a457 JF |
641 | CYComprehension |
642 | { | |
643 | CYIdentifier *name_; | |
644 | CYExpression *set_; | |
645 | ||
c2529502 JF |
646 | CYForOfComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) : |
647 | CYComprehension(next), | |
75b0a457 JF |
648 | name_(name), |
649 | set_(set) | |
650 | { | |
651 | } | |
652 | ||
653 | virtual const char *Name() const { | |
029bc65b | 654 | return name_->Word(); |
75b0a457 JF |
655 | } |
656 | ||
3b52fd1a JF |
657 | virtual CYFunctionParameter *Parameter(CYContext &context) const; |
658 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
4644480a | 659 | virtual void Output(CYOutput &out) const; |
75b0a457 JF |
660 | }; |
661 | ||
662 | struct CYIfComprehension : | |
663 | CYComprehension | |
664 | { | |
665 | CYExpression *test_; | |
666 | ||
b3aa25d8 JF |
667 | CYIfComprehension(CYExpression *test, CYComprehension *next = NULL) : |
668 | CYComprehension(next), | |
75b0a457 JF |
669 | test_(test) |
670 | { | |
671 | } | |
672 | ||
673 | virtual const char *Name() const { | |
674 | return NULL; | |
675 | } | |
676 | ||
3b52fd1a JF |
677 | virtual CYFunctionParameter *Parameter(CYContext &context) const; |
678 | virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; | |
4644480a | 679 | virtual void Output(CYOutput &out) const; |
75b0a457 JF |
680 | }; |
681 | ||
682 | struct CYArrayComprehension : | |
683 | CYExpression | |
684 | { | |
685 | CYExpression *expression_; | |
686 | CYComprehension *comprehensions_; | |
687 | ||
688 | CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) : | |
689 | expression_(expression), | |
690 | comprehensions_(comprehensions) | |
691 | { | |
692 | } | |
693 | ||
694 | CYPrecedence(0) | |
695 | ||
3b52fd1a | 696 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 697 | virtual void Output(CYOutput &out, CYFlags flags) const; |
75b0a457 JF |
698 | }; |
699 | ||
cf7d4c69 JF |
700 | struct CYLiteral : |
701 | CYExpression | |
63b4c5a8 | 702 | { |
d35a3b07 | 703 | CYPrecedence(0) |
fb98ac0c | 704 | CYRightHand(false) |
fd5cdf97 JF |
705 | |
706 | virtual CYExpression *Primitive(CYContext &context) { | |
707 | return this; | |
708 | } | |
cf7d4c69 | 709 | }; |
63b4c5a8 | 710 | |
3b52fd1a JF |
711 | struct CYTrivial : |
712 | CYLiteral | |
713 | { | |
714 | virtual CYExpression *Replace(CYContext &context); | |
715 | }; | |
716 | ||
478d4ed0 JF |
717 | struct CYMagic : |
718 | CYExpression | |
719 | { | |
720 | CYPrecedence(0) | |
fb98ac0c | 721 | CYRightHand(false) |
478d4ed0 JF |
722 | }; |
723 | ||
dea834b0 JF |
724 | struct CYRange { |
725 | uint64_t lo_; | |
726 | uint64_t hi_; | |
727 | ||
728 | CYRange(uint64_t lo, uint64_t hi) : | |
729 | lo_(lo), hi_(hi) | |
730 | { | |
731 | } | |
732 | ||
733 | bool operator [](uint8_t value) const { | |
734 | return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1; | |
735 | } | |
736 | ||
737 | void operator()(uint8_t value) { | |
738 | if (value >> 7) | |
739 | return; | |
740 | (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f); | |
741 | } | |
742 | }; | |
743 | ||
283e7e33 | 744 | extern CYRange DigitRange_; |
dea834b0 JF |
745 | extern CYRange WordStartRange_; |
746 | extern CYRange WordEndRange_; | |
747 | ||
cf7d4c69 | 748 | struct CYString : |
3b52fd1a | 749 | CYTrivial, |
e5bc40db | 750 | CYPropertyName |
cf7d4c69 JF |
751 | { |
752 | const char *value_; | |
5999c315 | 753 | size_t size_; |
cf7d4c69 | 754 | |
3b52fd1a JF |
755 | CYString() : |
756 | value_(NULL), | |
757 | size_(0) | |
758 | { | |
759 | } | |
760 | ||
761 | CYString(const char *value) : | |
762 | value_(value), | |
763 | size_(strlen(value)) | |
764 | { | |
765 | } | |
766 | ||
5999c315 JF |
767 | CYString(const char *value, size_t size) : |
768 | value_(value), | |
769 | size_(size) | |
cf7d4c69 JF |
770 | { |
771 | } | |
772 | ||
3b52fd1a | 773 | CYString(const CYWord *word) : |
029bc65b | 774 | value_(word->Word()), |
5999c315 | 775 | size_(strlen(value_)) |
cf7d4c69 JF |
776 | { |
777 | } | |
778 | ||
5999c315 | 779 | const char *Value() const { |
cf7d4c69 JF |
780 | return value_; |
781 | } | |
782 | ||
11c1cc16 | 783 | virtual const char *Word() const; |
dea834b0 | 784 | |
4644480a JF |
785 | virtual CYNumber *Number(CYContext &context); |
786 | virtual CYString *String(CYContext &context); | |
787 | ||
5db9a7f5 | 788 | CYString *Concat(CYContext &out, CYString *rhs) const; |
652ec1ba JF |
789 | virtual void Output(CYOutput &out, CYFlags flags) const; |
790 | virtual void PropertyName(CYOutput &out) const; | |
63b4c5a8 JF |
791 | }; |
792 | ||
cf7d4c69 | 793 | struct CYNumber : |
3b52fd1a | 794 | CYTrivial, |
e5bc40db | 795 | CYPropertyName |
cf7d4c69 | 796 | { |
5999c315 JF |
797 | double value_; |
798 | ||
799 | CYNumber(double value) : | |
800 | value_(value) | |
801 | { | |
802 | } | |
803 | ||
804 | double Value() const { | |
805 | return value_; | |
cf7d4c69 JF |
806 | } |
807 | ||
4644480a JF |
808 | virtual CYNumber *Number(CYContext &context); |
809 | virtual CYString *String(CYContext &context); | |
810 | ||
652ec1ba JF |
811 | virtual void Output(CYOutput &out, CYFlags flags) const; |
812 | virtual void PropertyName(CYOutput &out) const; | |
cf7d4c69 JF |
813 | }; |
814 | ||
63cd45c9 | 815 | struct CYRegEx : |
3b52fd1a | 816 | CYTrivial |
63cd45c9 JF |
817 | { |
818 | const char *value_; | |
819 | ||
820 | CYRegEx(const char *value) : | |
821 | value_(value) | |
822 | { | |
823 | } | |
824 | ||
825 | const char *Value() const { | |
826 | return value_; | |
827 | } | |
828 | ||
829 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
830 | }; | |
831 | ||
cf7d4c69 JF |
832 | struct CYNull : |
833 | CYWord, | |
3b52fd1a | 834 | CYTrivial |
cf7d4c69 JF |
835 | { |
836 | CYNull() : | |
837 | CYWord("null") | |
838 | { | |
839 | } | |
5999c315 | 840 | |
4644480a JF |
841 | virtual CYNumber *Number(CYContext &context); |
842 | virtual CYString *String(CYContext &context); | |
843 | ||
652ec1ba | 844 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
845 | }; |
846 | ||
847 | struct CYThis : | |
848 | CYWord, | |
478d4ed0 | 849 | CYMagic |
cf7d4c69 JF |
850 | { |
851 | CYThis() : | |
852 | CYWord("this") | |
853 | { | |
854 | } | |
5999c315 | 855 | |
3b52fd1a | 856 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 857 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
858 | }; |
859 | ||
860 | struct CYBoolean : | |
3b52fd1a | 861 | CYTrivial |
cf7d4c69 | 862 | { |
5999c315 | 863 | virtual bool Value() const = 0; |
652ec1ba | 864 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
865 | }; |
866 | ||
867 | struct CYFalse : | |
868 | CYWord, | |
869 | CYBoolean | |
870 | { | |
871 | CYFalse() : | |
872 | CYWord("false") | |
873 | { | |
874 | } | |
5999c315 | 875 | |
11c1cc16 JF |
876 | virtual bool Value() const { |
877 | return false; | |
878 | } | |
4644480a JF |
879 | |
880 | virtual CYNumber *Number(CYContext &context); | |
881 | virtual CYString *String(CYContext &context); | |
cf7d4c69 JF |
882 | }; |
883 | ||
884 | struct CYTrue : | |
885 | CYWord, | |
886 | CYBoolean | |
887 | { | |
888 | CYTrue() : | |
889 | CYWord("true") | |
890 | { | |
891 | } | |
5999c315 | 892 | |
11c1cc16 JF |
893 | virtual bool Value() const { |
894 | return true; | |
895 | } | |
4644480a JF |
896 | |
897 | virtual CYNumber *Number(CYContext &context); | |
898 | virtual CYString *String(CYContext &context); | |
cf7d4c69 JF |
899 | }; |
900 | ||
901 | struct CYVariable : | |
902 | CYExpression | |
903 | { | |
904 | CYIdentifier *name_; | |
905 | ||
906 | CYVariable(CYIdentifier *name) : | |
907 | name_(name) | |
908 | { | |
909 | } | |
5999c315 | 910 | |
2eb8215d JF |
911 | CYVariable(const char *name) : |
912 | name_(new($pool) CYIdentifier(name)) | |
913 | { | |
914 | } | |
915 | ||
d35a3b07 | 916 | CYPrecedence(0) |
fb98ac0c | 917 | CYRightHand(false) |
d35a3b07 | 918 | |
3b52fd1a | 919 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 920 | virtual void Output(CYOutput &out, CYFlags flags) const; |
0afc9ba3 JF |
921 | |
922 | virtual CYFunctionParameter *Parameter() const; | |
cf7d4c69 JF |
923 | }; |
924 | ||
925 | struct CYPrefix : | |
63b4c5a8 JF |
926 | CYExpression |
927 | { | |
928 | CYExpression *rhs_; | |
929 | ||
cf7d4c69 | 930 | CYPrefix(CYExpression *rhs) : |
63b4c5a8 JF |
931 | rhs_(rhs) |
932 | { | |
933 | } | |
5999c315 | 934 | |
b09da87b | 935 | virtual bool Alphabetic() const = 0; |
5999c315 JF |
936 | virtual const char *Operator() const = 0; |
937 | ||
3b52fd1a JF |
938 | CYPrecedence(4) |
939 | ||
940 | virtual CYExpression *Replace(CYContext &context); | |
652ec1ba | 941 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
942 | }; |
943 | ||
cf7d4c69 | 944 | struct CYInfix : |
63b4c5a8 JF |
945 | CYExpression |
946 | { | |
947 | CYExpression *lhs_; | |
948 | CYExpression *rhs_; | |
949 | ||
cf7d4c69 | 950 | CYInfix(CYExpression *lhs, CYExpression *rhs) : |
63b4c5a8 JF |
951 | lhs_(lhs), |
952 | rhs_(rhs) | |
953 | { | |
954 | } | |
5999c315 | 955 | |
0ff9f149 JF |
956 | void SetLeft(CYExpression *lhs) { |
957 | lhs_ = lhs; | |
958 | } | |
959 | ||
b09da87b | 960 | virtual bool Alphabetic() const = 0; |
5999c315 JF |
961 | virtual const char *Operator() const = 0; |
962 | ||
3b52fd1a | 963 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 964 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
965 | }; |
966 | ||
cf7d4c69 | 967 | struct CYPostfix : |
63b4c5a8 JF |
968 | CYExpression |
969 | { | |
970 | CYExpression *lhs_; | |
971 | ||
cf7d4c69 | 972 | CYPostfix(CYExpression *lhs) : |
63b4c5a8 JF |
973 | lhs_(lhs) |
974 | { | |
975 | } | |
5999c315 JF |
976 | |
977 | virtual const char *Operator() const = 0; | |
978 | ||
3b52fd1a JF |
979 | CYPrecedence(3) |
980 | ||
981 | virtual CYExpression *Replace(CYContext &context); | |
652ec1ba | 982 | virtual void Output(CYOutput &out, CYFlags flags) const; |
63b4c5a8 JF |
983 | }; |
984 | ||
cf7d4c69 | 985 | struct CYAssignment : |
d35a3b07 | 986 | CYExpression |
cf7d4c69 | 987 | { |
d35a3b07 JF |
988 | CYExpression *lhs_; |
989 | CYExpression *rhs_; | |
990 | ||
cf7d4c69 | 991 | CYAssignment(CYExpression *lhs, CYExpression *rhs) : |
d35a3b07 JF |
992 | lhs_(lhs), |
993 | rhs_(rhs) | |
cf7d4c69 JF |
994 | { |
995 | } | |
5999c315 | 996 | |
0ff9f149 JF |
997 | void SetLeft(CYExpression *lhs) { |
998 | lhs_ = lhs; | |
999 | } | |
1000 | ||
5999c315 | 1001 | virtual const char *Operator() const = 0; |
d35a3b07 | 1002 | |
4de0686f JF |
1003 | CYPrecedence(16) |
1004 | ||
3b52fd1a | 1005 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1006 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1007 | }; |
1008 | ||
62014ea9 | 1009 | struct CYArgument : |
96a7e5c2 JF |
1010 | CYNext<CYArgument>, |
1011 | CYThing | |
62014ea9 | 1012 | { |
cf7d4c69 JF |
1013 | CYWord *name_; |
1014 | CYExpression *value_; | |
cf7d4c69 | 1015 | |
3b52fd1a JF |
1016 | CYArgument(CYExpression *value, CYArgument *next = NULL) : |
1017 | CYNext<CYArgument>(next), | |
1018 | name_(NULL), | |
1019 | value_(value) | |
1020 | { | |
1021 | } | |
1022 | ||
cf7d4c69 | 1023 | CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) : |
62014ea9 | 1024 | CYNext<CYArgument>(next), |
cf7d4c69 | 1025 | name_(name), |
62014ea9 | 1026 | value_(value) |
cf7d4c69 JF |
1027 | { |
1028 | } | |
5999c315 | 1029 | |
5192746c | 1030 | CYArgument *Replace(CYContext &context); |
652ec1ba | 1031 | void Output(CYOutput &out) const; |
cf7d4c69 JF |
1032 | }; |
1033 | ||
1034 | struct CYBlank : | |
1035 | public CYWord | |
1036 | { | |
1037 | CYBlank() : | |
1038 | CYWord("") | |
1039 | { | |
1040 | } | |
1041 | }; | |
1042 | ||
5999c315 JF |
1043 | struct CYClause : |
1044 | CYThing, | |
1045 | CYNext<CYClause> | |
1046 | { | |
cf7d4c69 | 1047 | CYExpression *case_; |
b0385401 | 1048 | CYStatement *code_; |
cf7d4c69 | 1049 | |
b0385401 | 1050 | CYClause(CYExpression *_case, CYStatement *code) : |
cf7d4c69 | 1051 | case_(_case), |
b0385401 | 1052 | code_(code) |
cf7d4c69 JF |
1053 | { |
1054 | } | |
1055 | ||
fa389b0f | 1056 | void Replace(CYContext &context); |
652ec1ba | 1057 | virtual void Output(CYOutput &out) const; |
cf7d4c69 JF |
1058 | }; |
1059 | ||
62014ea9 | 1060 | struct CYElement : |
96a7e5c2 JF |
1061 | CYNext<CYElement>, |
1062 | CYThing | |
62014ea9 | 1063 | { |
cf7d4c69 | 1064 | CYExpression *value_; |
cf7d4c69 JF |
1065 | |
1066 | CYElement(CYExpression *value, CYElement *next) : | |
62014ea9 JF |
1067 | CYNext<CYElement>(next), |
1068 | value_(value) | |
cf7d4c69 JF |
1069 | { |
1070 | } | |
5999c315 | 1071 | |
3b52fd1a | 1072 | void Replace(CYContext &context); |
652ec1ba | 1073 | void Output(CYOutput &out) const; |
5befe15e JF |
1074 | }; |
1075 | ||
1076 | struct CYArray : | |
1077 | CYLiteral | |
1078 | { | |
1079 | CYElement *elements_; | |
1080 | ||
3b52fd1a | 1081 | CYArray(CYElement *elements = NULL) : |
5befe15e JF |
1082 | elements_(elements) |
1083 | { | |
1084 | } | |
1085 | ||
3b52fd1a | 1086 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1087 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1088 | }; |
1089 | ||
550ee46a JF |
1090 | struct CYProperty : |
1091 | CYNext<CYProperty>, | |
1092 | CYThing | |
1093 | { | |
1094 | CYPropertyName *name_; | |
1095 | CYExpression *value_; | |
1096 | ||
1097 | CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) : | |
1098 | CYNext<CYProperty>(next), | |
1099 | name_(name), | |
1100 | value_(value) | |
1101 | { | |
1102 | } | |
1103 | ||
1104 | void Replace(CYContext &context); | |
1105 | virtual void Output(CYOutput &out) const; | |
1106 | }; | |
1107 | ||
cf7d4c69 JF |
1108 | struct CYDeclaration : |
1109 | CYForInInitialiser | |
1110 | { | |
1111 | CYIdentifier *identifier_; | |
1112 | CYExpression *initialiser_; | |
1113 | ||
550ee46a | 1114 | CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) : |
cf7d4c69 JF |
1115 | identifier_(identifier), |
1116 | initialiser_(initialiser) | |
1117 | { | |
1118 | } | |
5999c315 | 1119 | |
652ec1ba | 1120 | virtual void ForIn(CYOutput &out, CYFlags flags) const; |
ad3b38bb | 1121 | virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value); |
3b52fd1a | 1122 | |
029bc65b | 1123 | virtual CYExpression *Replace(CYContext &context); |
15b88a33 | 1124 | |
029bc65b | 1125 | virtual CYAssignment *Assignment(CYContext &context); |
15b88a33 | 1126 | CYVariable *Variable(CYContext &context); |
75b0a457 | 1127 | |
652ec1ba | 1128 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1129 | }; |
1130 | ||
1131 | struct CYDeclarations : | |
cac61857 | 1132 | CYNext<CYDeclarations>, |
15b88a33 | 1133 | CYThing |
cf7d4c69 JF |
1134 | { |
1135 | CYDeclaration *declaration_; | |
cf7d4c69 | 1136 | |
cacd1a88 | 1137 | CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) : |
cac61857 JF |
1138 | CYNext<CYDeclarations>(next), |
1139 | declaration_(declaration) | |
1140 | { | |
1141 | } | |
1142 | ||
15b88a33 | 1143 | void Replace(CYContext &context); |
96a7e5c2 | 1144 | |
b0385401 | 1145 | CYExpression *Expression(CYContext &context); |
550ee46a | 1146 | CYProperty *Property(CYContext &context); |
15b88a33 JF |
1147 | CYArgument *Argument(CYContext &context); |
1148 | CYFunctionParameter *Parameter(CYContext &context); | |
3b52fd1a | 1149 | |
96a7e5c2 | 1150 | virtual void Output(CYOutput &out) const; |
652ec1ba | 1151 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cac61857 JF |
1152 | }; |
1153 | ||
15b88a33 JF |
1154 | struct CYForDeclarations : |
1155 | CYForInitialiser | |
1156 | { | |
1157 | CYDeclarations *declarations_; | |
1158 | ||
1159 | CYForDeclarations(CYDeclarations *declarations) : | |
1160 | declarations_(declarations) | |
1161 | { | |
1162 | } | |
1163 | ||
b0385401 | 1164 | virtual CYExpression *Replace(CYContext &context); |
15b88a33 JF |
1165 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1166 | }; | |
1167 | ||
cac61857 JF |
1168 | struct CYVar : |
1169 | CYStatement | |
1170 | { | |
1171 | CYDeclarations *declarations_; | |
1172 | ||
1173 | CYVar(CYDeclarations *declarations) : | |
1174 | declarations_(declarations) | |
1175 | { | |
1176 | } | |
1177 | ||
3b52fd1a | 1178 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1179 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cac61857 JF |
1180 | }; |
1181 | ||
c8a0500b | 1182 | struct CYLetStatement : |
cac61857 JF |
1183 | CYStatement |
1184 | { | |
1185 | CYDeclarations *declarations_; | |
15b88a33 | 1186 | CYStatement *code_; |
cac61857 | 1187 | |
c8a0500b | 1188 | CYLetStatement(CYDeclarations *declarations, CYStatement *code) : |
cac61857 | 1189 | declarations_(declarations), |
15b88a33 | 1190 | code_(code) |
cf7d4c69 JF |
1191 | { |
1192 | } | |
5999c315 | 1193 | |
3b52fd1a | 1194 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1195 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1196 | }; |
1197 | ||
cf7d4c69 JF |
1198 | struct CYFor : |
1199 | CYStatement | |
1200 | { | |
1201 | CYForInitialiser *initialiser_; | |
1202 | CYExpression *test_; | |
1203 | CYExpression *increment_; | |
1204 | CYStatement *code_; | |
1205 | ||
1206 | CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) : | |
1207 | initialiser_(initialiser), | |
1208 | test_(test), | |
1209 | increment_(increment), | |
1210 | code_(code) | |
1211 | { | |
1212 | } | |
5999c315 | 1213 | |
3b52fd1a | 1214 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1215 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1216 | }; |
1217 | ||
1218 | struct CYForIn : | |
1219 | CYStatement | |
1220 | { | |
1221 | CYForInInitialiser *initialiser_; | |
1222 | CYExpression *set_; | |
1223 | CYStatement *code_; | |
1224 | ||
1225 | CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) : | |
1226 | initialiser_(initialiser), | |
1227 | set_(set), | |
1228 | code_(code) | |
1229 | { | |
1230 | } | |
5999c315 | 1231 | |
3b52fd1a | 1232 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1233 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1234 | }; |
1235 | ||
d5618df7 | 1236 | struct CYForOf : |
75b0a457 JF |
1237 | CYStatement |
1238 | { | |
1239 | CYForInInitialiser *initialiser_; | |
1240 | CYExpression *set_; | |
1241 | CYStatement *code_; | |
1242 | ||
d5618df7 | 1243 | CYForOf(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) : |
75b0a457 JF |
1244 | initialiser_(initialiser), |
1245 | set_(set), | |
1246 | code_(code) | |
1247 | { | |
1248 | } | |
1249 | ||
3b52fd1a | 1250 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1251 | virtual void Output(CYOutput &out, CYFlags flags) const; |
75b0a457 JF |
1252 | }; |
1253 | ||
693d501b JF |
1254 | struct CYObject : |
1255 | CYLiteral | |
1256 | { | |
3b52fd1a | 1257 | CYProperty *properties_; |
693d501b | 1258 | |
ab2aa221 | 1259 | CYObject(CYProperty *properties = NULL) : |
3b52fd1a | 1260 | properties_(properties) |
693d501b JF |
1261 | { |
1262 | } | |
1263 | ||
3b52fd1a | 1264 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1265 | void Output(CYOutput &out, CYFlags flags) const; |
693d501b JF |
1266 | }; |
1267 | ||
cf7d4c69 JF |
1268 | struct CYMember : |
1269 | CYExpression | |
1270 | { | |
1271 | CYExpression *object_; | |
1272 | CYExpression *property_; | |
1273 | ||
1274 | CYMember(CYExpression *object, CYExpression *property) : | |
1275 | object_(object), | |
1276 | property_(property) | |
1277 | { | |
1278 | } | |
5999c315 | 1279 | |
9b5527f0 JF |
1280 | void SetLeft(CYExpression *object) { |
1281 | object_ = object; | |
1282 | } | |
1283 | }; | |
1284 | ||
1285 | struct CYDirectMember : | |
1286 | CYMember | |
1287 | { | |
1288 | CYDirectMember(CYExpression *object, CYExpression *property) : | |
1289 | CYMember(object, property) | |
1290 | { | |
1291 | } | |
1292 | ||
1293 | CYPrecedence(1) | |
fb98ac0c | 1294 | CYRightHand(false) |
9b5527f0 | 1295 | |
3b52fd1a | 1296 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1297 | virtual void Output(CYOutput &out, CYFlags flags) const; |
9b5527f0 JF |
1298 | }; |
1299 | ||
1300 | struct CYIndirectMember : | |
1301 | CYMember | |
1302 | { | |
1303 | CYIndirectMember(CYExpression *object, CYExpression *property) : | |
1304 | CYMember(object, property) | |
1305 | { | |
1306 | } | |
1307 | ||
d35a3b07 | 1308 | CYPrecedence(1) |
fb98ac0c | 1309 | CYRightHand(false) |
d35a3b07 | 1310 | |
3b52fd1a | 1311 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1312 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1313 | }; |
1314 | ||
2eb8215d JF |
1315 | namespace cy { |
1316 | namespace Syntax { | |
1317 | ||
1318 | struct New : | |
cf7d4c69 JF |
1319 | CYExpression |
1320 | { | |
1321 | CYExpression *constructor_; | |
1322 | CYArgument *arguments_; | |
1323 | ||
2eb8215d | 1324 | New(CYExpression *constructor, CYArgument *arguments) : |
cf7d4c69 JF |
1325 | constructor_(constructor), |
1326 | arguments_(arguments) | |
1327 | { | |
1328 | } | |
5999c315 | 1329 | |
9a39f705 | 1330 | virtual int Precedence() const { |
fb98ac0c JF |
1331 | return arguments_ == NULL ? 2 : 1; |
1332 | } | |
1333 | ||
1334 | CYRightHand(false) | |
d35a3b07 | 1335 | |
3b52fd1a | 1336 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1337 | virtual void Output(CYOutput &out, CYFlags flags) const; |
6c093cce JF |
1338 | |
1339 | virtual CYExpression *AddArgument(CYContext &context, CYExpression *value); | |
cf7d4c69 JF |
1340 | }; |
1341 | ||
2eb8215d JF |
1342 | } } |
1343 | ||
cf7d4c69 JF |
1344 | struct CYCall : |
1345 | CYExpression | |
1346 | { | |
1347 | CYExpression *function_; | |
1348 | CYArgument *arguments_; | |
1349 | ||
3b52fd1a | 1350 | CYCall(CYExpression *function, CYArgument *arguments = NULL) : |
cf7d4c69 JF |
1351 | function_(function), |
1352 | arguments_(arguments) | |
1353 | { | |
1354 | } | |
5999c315 | 1355 | |
fb98ac0c JF |
1356 | CYPrecedence(1) |
1357 | CYRightHand(false) | |
d35a3b07 | 1358 | |
3b52fd1a | 1359 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1360 | virtual void Output(CYOutput &out, CYFlags flags) const; |
6c093cce JF |
1361 | |
1362 | virtual CYExpression *AddArgument(CYContext &context, CYExpression *value); | |
1363 | }; | |
1364 | ||
1365 | struct CYRubyProc; | |
1366 | ||
1367 | struct CYRubyBlock : | |
1368 | CYExpression | |
1369 | { | |
1370 | CYExpression *call_; | |
1371 | CYRubyProc *proc_; | |
1372 | ||
1373 | CYRubyBlock(CYExpression *call, CYRubyProc *proc) : | |
1374 | call_(call), | |
1375 | proc_(proc) | |
1376 | { | |
1377 | } | |
1378 | ||
1379 | CYPrecedence(1) | |
1380 | CYRightHand(false) | |
1381 | ||
1382 | virtual CYExpression *Replace(CYContext &context); | |
1383 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
cf7d4c69 JF |
1384 | }; |
1385 | ||
1386 | struct CYIf : | |
1387 | CYStatement | |
1388 | { | |
1389 | CYExpression *test_; | |
1390 | CYStatement *true_; | |
1391 | CYStatement *false_; | |
1392 | ||
3b52fd1a | 1393 | CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) : |
cf7d4c69 JF |
1394 | test_(test), |
1395 | true_(_true), | |
1396 | false_(_false) | |
1397 | { | |
1398 | } | |
5999c315 | 1399 | |
3b52fd1a | 1400 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1401 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1402 | }; |
1403 | ||
1404 | struct CYDoWhile : | |
1405 | CYStatement | |
1406 | { | |
1407 | CYExpression *test_; | |
1408 | CYStatement *code_; | |
1409 | ||
1410 | CYDoWhile(CYExpression *test, CYStatement *code) : | |
1411 | test_(test), | |
1412 | code_(code) | |
1413 | { | |
1414 | } | |
5999c315 | 1415 | |
3b52fd1a | 1416 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1417 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1418 | }; |
1419 | ||
1420 | struct CYWhile : | |
1421 | CYStatement | |
1422 | { | |
1423 | CYExpression *test_; | |
1424 | CYStatement *code_; | |
1425 | ||
1426 | CYWhile(CYExpression *test, CYStatement *code) : | |
1427 | test_(test), | |
1428 | code_(code) | |
1429 | { | |
1430 | } | |
5999c315 | 1431 | |
3b52fd1a | 1432 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1433 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1434 | }; |
1435 | ||
6c093cce | 1436 | // XXX: this should be split up into CYAnonymousFunction and CYNamedFunction (subclass) |
a846a8cd | 1437 | struct CYFunction { |
cf7d4c69 | 1438 | CYIdentifier *name_; |
b09da87b | 1439 | CYFunctionParameter *parameters_; |
b0385401 | 1440 | CYStatement *code_; |
a0be43fc | 1441 | |
ab2aa221 | 1442 | CYNonLocal *nonlocal_; |
a0be43fc | 1443 | CYThisScope this_; |
cf7d4c69 | 1444 | |
b0385401 | 1445 | CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) : |
cf7d4c69 JF |
1446 | name_(name), |
1447 | parameters_(parameters), | |
b0385401 | 1448 | code_(code), |
ab2aa221 | 1449 | nonlocal_(NULL) |
cf7d4c69 JF |
1450 | { |
1451 | } | |
5999c315 | 1452 | |
7c6c5b0a JF |
1453 | virtual ~CYFunction() { |
1454 | } | |
1455 | ||
14ec9e00 JF |
1456 | void Inject(CYContext &context); |
1457 | virtual void Replace_(CYContext &context, bool outer); | |
fb98ac0c JF |
1458 | virtual void Output(CYOutput &out, CYFlags flags) const; |
1459 | }; | |
1460 | ||
6c093cce | 1461 | // XXX: this should be split up into CYAnonymousFunctionExpression and CYNamedFunctionExpression |
fb98ac0c JF |
1462 | struct CYFunctionExpression : |
1463 | CYFunction, | |
1464 | CYExpression | |
1465 | { | |
b0385401 JF |
1466 | CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) : |
1467 | CYFunction(name, parameters, code) | |
fb98ac0c JF |
1468 | { |
1469 | } | |
1470 | ||
a0be43fc JF |
1471 | CYPrecedence(0) |
1472 | CYRightHand(false) | |
1473 | ||
1474 | virtual CYExpression *Replace(CYContext &context); | |
1475 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
1476 | }; | |
1477 | ||
1478 | // XXX: this should derive from CYAnonymousFunction | |
1479 | struct CYFatArrow : | |
1480 | CYFunction, | |
1481 | CYExpression | |
1482 | { | |
b0385401 JF |
1483 | CYFatArrow(CYFunctionParameter *parameters, CYStatement *code) : |
1484 | CYFunction(NULL, parameters, code) | |
a0be43fc JF |
1485 | { |
1486 | } | |
1487 | ||
d35a3b07 | 1488 | CYPrecedence(0) |
fb98ac0c | 1489 | CYRightHand(false) |
d35a3b07 | 1490 | |
3b52fd1a | 1491 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 1492 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1493 | }; |
1494 | ||
6c093cce JF |
1495 | // XXX: this should derive from CYAnonymousFunctionExpression |
1496 | struct CYRubyProc : | |
1497 | CYFunctionExpression | |
1498 | { | |
b0385401 JF |
1499 | CYRubyProc(CYFunctionParameter *parameters, CYStatement *code) : |
1500 | CYFunctionExpression(NULL, parameters, code) | |
6c093cce JF |
1501 | { |
1502 | } | |
1503 | ||
1504 | virtual CYExpression *Replace(CYContext &context); | |
1505 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
1506 | }; | |
1507 | ||
1508 | // XXX: this should derive from CYNamedFunction | |
fb98ac0c JF |
1509 | struct CYFunctionStatement : |
1510 | CYFunction, | |
b10bd496 | 1511 | CYStatement |
cf7d4c69 | 1512 | { |
b0385401 JF |
1513 | CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) : |
1514 | CYFunction(name, parameters, code) | |
cf7d4c69 JF |
1515 | { |
1516 | } | |
5999c315 | 1517 | |
3b52fd1a | 1518 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1519 | virtual void Output(CYOutput &out, CYFlags flags) const; |
5999c315 JF |
1520 | }; |
1521 | ||
1522 | struct CYExpress : | |
1523 | CYStatement | |
1524 | { | |
1525 | CYExpression *expression_; | |
1526 | ||
1527 | CYExpress(CYExpression *expression) : | |
1528 | expression_(expression) | |
1529 | { | |
fd5cdf97 | 1530 | if (expression_ == NULL) |
029bc65b | 1531 | throw; |
5999c315 JF |
1532 | } |
1533 | ||
3b52fd1a | 1534 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1535 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1536 | }; |
1537 | ||
1538 | struct CYContinue : | |
1539 | CYStatement | |
1540 | { | |
1541 | CYIdentifier *label_; | |
1542 | ||
1543 | CYContinue(CYIdentifier *label) : | |
1544 | label_(label) | |
1545 | { | |
1546 | } | |
5999c315 | 1547 | |
3b52fd1a | 1548 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1549 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1550 | }; |
1551 | ||
1552 | struct CYBreak : | |
1553 | CYStatement | |
1554 | { | |
1555 | CYIdentifier *label_; | |
1556 | ||
1557 | CYBreak(CYIdentifier *label) : | |
1558 | label_(label) | |
1559 | { | |
1560 | } | |
5999c315 | 1561 | |
3b52fd1a | 1562 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1563 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1564 | }; |
1565 | ||
1566 | struct CYReturn : | |
1567 | CYStatement | |
1568 | { | |
1569 | CYExpression *value_; | |
1570 | ||
1571 | CYReturn(CYExpression *value) : | |
1572 | value_(value) | |
1573 | { | |
1574 | } | |
5999c315 | 1575 | |
3b52fd1a | 1576 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1577 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1578 | }; |
1579 | ||
1580 | struct CYEmpty : | |
1581 | CYStatement | |
1582 | { | |
3b52fd1a | 1583 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 1584 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
1585 | }; |
1586 | ||
96a7e5c2 JF |
1587 | struct CYFinally : |
1588 | CYThing | |
1589 | { | |
b0385401 | 1590 | CYStatement *code_; |
b10bd496 | 1591 | |
b0385401 JF |
1592 | CYFinally(CYStatement *code) : |
1593 | code_(code) | |
b10bd496 JF |
1594 | { |
1595 | } | |
1596 | ||
3b52fd1a | 1597 | void Replace(CYContext &context); |
b10bd496 JF |
1598 | virtual void Output(CYOutput &out) const; |
1599 | }; | |
1600 | ||
3fe283c5 JF |
1601 | struct CYTypeSpecifier : |
1602 | CYThing | |
1603 | { | |
1604 | virtual CYExpression *Replace(CYContext &context) = 0; | |
1605 | }; | |
1606 | ||
03db6a67 JF |
1607 | struct CYTypeError : |
1608 | CYTypeSpecifier | |
1609 | { | |
1610 | CYTypeError() { | |
1611 | } | |
1612 | ||
1613 | virtual CYExpression *Replace(CYContext &context); | |
1614 | virtual void Output(CYOutput &out) const; | |
1615 | }; | |
1616 | ||
3fe283c5 JF |
1617 | struct CYTypeVoid : |
1618 | CYTypeSpecifier | |
1619 | { | |
1620 | CYTypeVoid() { | |
1621 | } | |
1622 | ||
1623 | virtual CYExpression *Replace(CYContext &context); | |
1624 | virtual void Output(CYOutput &out) const; | |
1625 | }; | |
1626 | ||
1627 | struct CYTypeVariable : | |
1628 | CYTypeSpecifier | |
1629 | { | |
1630 | CYIdentifier *name_; | |
1631 | ||
1632 | CYTypeVariable(CYIdentifier *name) : | |
1633 | name_(name) | |
1634 | { | |
1635 | } | |
1636 | ||
1637 | CYTypeVariable(const char *name) : | |
1638 | name_(new($pool) CYIdentifier(name)) | |
1639 | { | |
1640 | } | |
1641 | ||
1642 | virtual CYExpression *Replace(CYContext &context); | |
1643 | virtual void Output(CYOutput &out) const; | |
1644 | }; | |
1645 | ||
1646 | struct CYTypeUnsigned : | |
1647 | CYTypeSpecifier | |
1648 | { | |
1649 | CYTypeSpecifier *specifier_; | |
1650 | ||
1651 | CYTypeUnsigned(CYTypeSpecifier *specifier) : | |
1652 | specifier_(specifier) | |
1653 | { | |
1654 | } | |
1655 | ||
1656 | virtual CYExpression *Replace(CYContext &context); | |
1657 | virtual void Output(CYOutput &out) const; | |
1658 | }; | |
1659 | ||
1660 | struct CYTypeSigned : | |
1661 | CYTypeSpecifier | |
1662 | { | |
1663 | CYTypeSpecifier *specifier_; | |
1664 | ||
1665 | CYTypeSigned(CYTypeSpecifier *specifier) : | |
1666 | specifier_(specifier) | |
1667 | { | |
1668 | } | |
1669 | ||
1670 | virtual CYExpression *Replace(CYContext &context); | |
1671 | virtual void Output(CYOutput &out) const; | |
1672 | }; | |
1673 | ||
1674 | struct CYTypeLong : | |
1675 | CYTypeSpecifier | |
1676 | { | |
1677 | CYTypeSpecifier *specifier_; | |
1678 | ||
1679 | CYTypeLong(CYTypeSpecifier *specifier) : | |
1680 | specifier_(specifier) | |
1681 | { | |
1682 | } | |
1683 | ||
1684 | virtual CYExpression *Replace(CYContext &context); | |
1685 | virtual void Output(CYOutput &out) const; | |
1686 | }; | |
1687 | ||
1688 | struct CYTypeShort : | |
1689 | CYTypeSpecifier | |
1690 | { | |
1691 | CYTypeSpecifier *specifier_; | |
1692 | ||
1693 | CYTypeShort(CYTypeSpecifier *specifier) : | |
1694 | specifier_(specifier) | |
1695 | { | |
1696 | } | |
1697 | ||
1698 | virtual CYExpression *Replace(CYContext &context); | |
1699 | virtual void Output(CYOutput &out) const; | |
1700 | }; | |
1701 | ||
00b4cb83 JF |
1702 | struct CYTypeFunctionWith; |
1703 | ||
690cf1a8 JF |
1704 | struct CYTypeModifier : |
1705 | CYNext<CYTypeModifier> | |
1706 | { | |
1707 | CYTypeModifier(CYTypeModifier *next) : | |
1708 | CYNext<CYTypeModifier>(next) | |
1709 | { | |
1710 | } | |
1711 | ||
9a39f705 JF |
1712 | virtual int Precedence() const = 0; |
1713 | ||
1714 | virtual CYExpression *Replace_(CYContext &context, CYExpression *type) = 0; | |
1715 | CYExpression *Replace(CYContext &context, CYExpression *type); | |
1716 | ||
1717 | virtual void Output(CYOutput &out, CYIdentifier *identifier) const = 0; | |
1718 | void Output(CYOutput &out, int precedence, CYIdentifier *identifier) const; | |
00b4cb83 JF |
1719 | |
1720 | virtual CYTypeFunctionWith *Function() { return NULL; } | |
690cf1a8 JF |
1721 | }; |
1722 | ||
1723 | struct CYTypeArrayOf : | |
1724 | CYTypeModifier | |
1725 | { | |
1726 | CYExpression *size_; | |
1727 | ||
1728 | CYTypeArrayOf(CYExpression *size, CYTypeModifier *next = NULL) : | |
1729 | CYTypeModifier(next), | |
1730 | size_(size) | |
1731 | { | |
1732 | } | |
1733 | ||
9a39f705 | 1734 | CYPrecedence(1) |
690cf1a8 | 1735 | |
9a39f705 JF |
1736 | virtual CYExpression *Replace_(CYContext &context, CYExpression *type); |
1737 | virtual void Output(CYOutput &out, CYIdentifier *identifier) const; | |
690cf1a8 JF |
1738 | }; |
1739 | ||
1740 | struct CYTypeConstant : | |
1741 | CYTypeModifier | |
1742 | { | |
1743 | CYTypeConstant(CYTypeModifier *next = NULL) : | |
1744 | CYTypeModifier(next) | |
1745 | { | |
1746 | } | |
1747 | ||
9a39f705 | 1748 | CYPrecedence(0) |
690cf1a8 | 1749 | |
9a39f705 JF |
1750 | virtual CYExpression *Replace_(CYContext &context, CYExpression *type); |
1751 | virtual void Output(CYOutput &out, CYIdentifier *identifier) const; | |
690cf1a8 JF |
1752 | }; |
1753 | ||
1754 | struct CYTypePointerTo : | |
1755 | CYTypeModifier | |
1756 | { | |
1757 | CYTypePointerTo(CYTypeModifier *next = NULL) : | |
1758 | CYTypeModifier(next) | |
1759 | { | |
1760 | } | |
1761 | ||
9a39f705 | 1762 | CYPrecedence(0) |
690cf1a8 | 1763 | |
9a39f705 JF |
1764 | virtual CYExpression *Replace_(CYContext &context, CYExpression *type); |
1765 | virtual void Output(CYOutput &out, CYIdentifier *identifier) const; | |
690cf1a8 JF |
1766 | }; |
1767 | ||
9a39f705 | 1768 | struct CYTypeVolatile : |
690cf1a8 JF |
1769 | CYTypeModifier |
1770 | { | |
9a39f705 JF |
1771 | CYTypeVolatile(CYTypeModifier *next = NULL) : |
1772 | CYTypeModifier(next) | |
690cf1a8 JF |
1773 | { |
1774 | } | |
1775 | ||
9a39f705 | 1776 | CYPrecedence(0) |
690cf1a8 | 1777 | |
9a39f705 JF |
1778 | virtual CYExpression *Replace_(CYContext &context, CYExpression *type); |
1779 | virtual void Output(CYOutput &out, CYIdentifier *identifier) const; | |
690cf1a8 JF |
1780 | }; |
1781 | ||
1782 | struct CYTypedIdentifier : | |
60097023 JF |
1783 | CYNext<CYTypedIdentifier>, |
1784 | CYThing | |
690cf1a8 | 1785 | { |
00b4cb83 | 1786 | CYLocation location_; |
690cf1a8 | 1787 | CYIdentifier *identifier_; |
3fe283c5 | 1788 | CYTypeSpecifier *specifier_; |
9a39f705 | 1789 | CYTypeModifier *modifier_; |
690cf1a8 | 1790 | |
00b4cb83 JF |
1791 | CYTypedIdentifier(const CYLocation &location, CYIdentifier *identifier = NULL) : |
1792 | location_(location), | |
690cf1a8 | 1793 | identifier_(identifier), |
3fe283c5 | 1794 | specifier_(NULL), |
9a39f705 | 1795 | modifier_(NULL) |
690cf1a8 JF |
1796 | { |
1797 | } | |
60097023 | 1798 | |
3fe283c5 | 1799 | CYTypedIdentifier(CYTypeSpecifier *specifier, CYTypeModifier *modifier = NULL) : |
9a39f705 | 1800 | identifier_(NULL), |
3fe283c5 | 1801 | specifier_(specifier), |
9a39f705 JF |
1802 | modifier_(modifier) |
1803 | { | |
1804 | } | |
1805 | ||
1806 | inline CYTypedIdentifier *Modify(CYTypeModifier *modifier) { | |
1807 | CYSetLast(modifier_) = modifier; | |
1808 | return this; | |
1809 | } | |
1810 | ||
1811 | virtual CYExpression *Replace(CYContext &context); | |
60097023 | 1812 | virtual void Output(CYOutput &out) const; |
00b4cb83 JF |
1813 | |
1814 | CYTypeFunctionWith *Function(); | |
690cf1a8 JF |
1815 | }; |
1816 | ||
9a39f705 JF |
1817 | struct CYEncodedType : |
1818 | CYExpression | |
1819 | { | |
1820 | CYTypedIdentifier *typed_; | |
1821 | ||
1822 | CYEncodedType(CYTypedIdentifier *typed) : | |
1823 | typed_(typed) | |
1824 | { | |
1825 | } | |
1826 | ||
1827 | CYPrecedence(1) | |
1828 | ||
1829 | virtual CYExpression *Replace(CYContext &context); | |
1830 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
1831 | }; | |
1832 | ||
690cf1a8 | 1833 | struct CYTypedParameter : |
9a39f705 JF |
1834 | CYNext<CYTypedParameter>, |
1835 | CYThing | |
690cf1a8 JF |
1836 | { |
1837 | CYTypedIdentifier *typed_; | |
1838 | ||
1839 | CYTypedParameter(CYTypedIdentifier *typed, CYTypedParameter *next) : | |
1840 | CYNext<CYTypedParameter>(next), | |
1841 | typed_(typed) | |
1842 | { | |
1843 | } | |
1844 | ||
663c538f | 1845 | CYArgument *Argument(CYContext &context); |
690cf1a8 JF |
1846 | CYFunctionParameter *Parameters(CYContext &context); |
1847 | CYExpression *TypeSignature(CYContext &context, CYExpression *prefix); | |
9a39f705 JF |
1848 | |
1849 | virtual void Output(CYOutput &out) const; | |
690cf1a8 JF |
1850 | }; |
1851 | ||
1852 | struct CYLambda : | |
1853 | CYExpression | |
1854 | { | |
9a39f705 | 1855 | CYTypedIdentifier *typed_; |
690cf1a8 | 1856 | CYTypedParameter *parameters_; |
b0385401 | 1857 | CYStatement *code_; |
690cf1a8 | 1858 | |
b0385401 | 1859 | CYLambda(CYTypedIdentifier *typed, CYTypedParameter *parameters, CYStatement *code) : |
9a39f705 | 1860 | typed_(typed), |
690cf1a8 | 1861 | parameters_(parameters), |
b0385401 | 1862 | code_(code) |
690cf1a8 JF |
1863 | { |
1864 | } | |
1865 | ||
1866 | CYPrecedence(1) | |
1867 | ||
1868 | virtual CYExpression *Replace(CYContext &context); | |
1869 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
1870 | }; | |
1871 | ||
7b750785 JF |
1872 | struct CYModule : |
1873 | CYNext<CYModule>, | |
1874 | CYThing | |
1875 | { | |
1876 | CYWord *part_; | |
1877 | ||
1878 | CYModule(CYWord *part, CYModule *next = NULL) : | |
1879 | CYNext<CYModule>(next), | |
1880 | part_(part) | |
1881 | { | |
1882 | } | |
1883 | ||
1884 | CYString *Replace(CYContext &context, const char *separator) const; | |
1885 | void Output(CYOutput &out) const; | |
1886 | }; | |
1887 | ||
1888 | struct CYImport : | |
1889 | CYStatement | |
1890 | { | |
1891 | CYModule *module_; | |
1892 | ||
1893 | CYImport(CYModule *module) : | |
1894 | module_(module) | |
1895 | { | |
1896 | } | |
1897 | ||
1898 | virtual CYStatement *Replace(CYContext &context); | |
1899 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
1900 | }; | |
1901 | ||
c5587ed7 JF |
1902 | struct CYExternal : |
1903 | CYStatement | |
1904 | { | |
1905 | CYString *abi_; | |
1906 | CYTypedIdentifier *typed_; | |
1907 | ||
1908 | CYExternal(CYString *abi, CYTypedIdentifier *typed) : | |
1909 | abi_(abi), | |
1910 | typed_(typed) | |
1911 | { | |
1912 | } | |
1913 | ||
1914 | virtual CYStatement *Replace(CYContext &context); | |
1915 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
1916 | }; | |
1917 | ||
60097023 JF |
1918 | struct CYTypeDefinition : |
1919 | CYStatement | |
1920 | { | |
1921 | CYTypedIdentifier *typed_; | |
1922 | ||
1923 | CYTypeDefinition(CYTypedIdentifier *typed) : | |
1924 | typed_(typed) | |
1925 | { | |
1926 | } | |
1927 | ||
1928 | virtual CYStatement *Replace(CYContext &context); | |
1929 | virtual void Output(CYOutput &out, CYFlags flags) const; | |
1930 | }; | |
1931 | ||
3fe16be7 JF |
1932 | struct CYTypeBlockWith : |
1933 | CYTypeModifier | |
1934 | { | |
1935 | CYTypedParameter *parameters_; | |
1936 | ||
1937 | CYTypeBlockWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) : | |
1938 | CYTypeModifier(next), | |
1939 | parameters_(parameters) | |
1940 | { | |
1941 | } | |
1942 | ||
1943 | CYPrecedence(0) | |
1944 | ||
1945 | virtual CYExpression *Replace_(CYContext &context, CYExpression *type); | |
1946 | virtual void Output(CYOutput &out, CYIdentifier *identifier) const; | |
1947 | }; | |
1948 | ||
663c538f JF |
1949 | struct CYTypeFunctionWith : |
1950 | CYTypeModifier | |
1951 | { | |
1952 | CYTypedParameter *parameters_; | |
1953 | ||
1954 | CYTypeFunctionWith(CYTypedParameter *parameters, CYTypeModifier *next = NULL) : | |
1955 | CYTypeModifier(next), | |
1956 | parameters_(parameters) | |
1957 | { | |
1958 | } | |
1959 | ||
9a39f705 | 1960 | CYPrecedence(1) |
663c538f | 1961 | |
9a39f705 JF |
1962 | virtual CYExpression *Replace_(CYContext &context, CYExpression *type); |
1963 | virtual void Output(CYOutput &out, CYIdentifier *identifier) const; | |
00b4cb83 JF |
1964 | |
1965 | virtual CYTypeFunctionWith *Function() { return this; } | |
663c538f JF |
1966 | }; |
1967 | ||
37954781 JF |
1968 | namespace cy { |
1969 | namespace Syntax { | |
1970 | ||
1971 | struct Catch : | |
1972 | CYThing | |
1973 | { | |
1974 | CYIdentifier *name_; | |
b0385401 | 1975 | CYStatement *code_; |
37954781 | 1976 | |
b0385401 | 1977 | Catch(CYIdentifier *name, CYStatement *code) : |
37954781 | 1978 | name_(name), |
b0385401 | 1979 | code_(code) |
37954781 JF |
1980 | { |
1981 | } | |
1982 | ||
1983 | void Replace(CYContext &context); | |
1984 | virtual void Output(CYOutput &out) const; | |
1985 | }; | |
1986 | ||
1987 | struct Try : | |
cf7d4c69 JF |
1988 | CYStatement |
1989 | { | |
b0385401 | 1990 | CYStatement *code_; |
37954781 | 1991 | Catch *catch_; |
b10bd496 | 1992 | CYFinally *finally_; |
cf7d4c69 | 1993 | |
b0385401 JF |
1994 | Try(CYStatement *code, Catch *_catch, CYFinally *finally) : |
1995 | code_(code), | |
cf7d4c69 JF |
1996 | catch_(_catch), |
1997 | finally_(finally) | |
1998 | { | |
1999 | } | |
5999c315 | 2000 | |
3b52fd1a | 2001 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 2002 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
2003 | }; |
2004 | ||
37954781 | 2005 | struct Throw : |
cf7d4c69 JF |
2006 | CYStatement |
2007 | { | |
2008 | CYExpression *value_; | |
2009 | ||
ab2aa221 | 2010 | Throw(CYExpression *value = NULL) : |
cf7d4c69 JF |
2011 | value_(value) |
2012 | { | |
2013 | } | |
5999c315 | 2014 | |
3b52fd1a | 2015 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 2016 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
2017 | }; |
2018 | ||
37954781 JF |
2019 | } } |
2020 | ||
cf7d4c69 JF |
2021 | struct CYWith : |
2022 | CYStatement | |
2023 | { | |
2024 | CYExpression *scope_; | |
2025 | CYStatement *code_; | |
2026 | ||
2027 | CYWith(CYExpression *scope, CYStatement *code) : | |
2028 | scope_(scope), | |
2029 | code_(code) | |
2030 | { | |
2031 | } | |
5999c315 | 2032 | |
3b52fd1a | 2033 | virtual CYStatement *Replace(CYContext &context); |
fb98ac0c | 2034 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
2035 | }; |
2036 | ||
2037 | struct CYSwitch : | |
2038 | CYStatement | |
2039 | { | |
2040 | CYExpression *value_; | |
2041 | CYClause *clauses_; | |
2042 | ||
2043 | CYSwitch(CYExpression *value, CYClause *clauses) : | |
2044 | value_(value), | |
2045 | clauses_(clauses) | |
2046 | { | |
2047 | } | |
5999c315 | 2048 | |
3b52fd1a | 2049 | virtual CYStatement *Replace(CYContext &context); |
c8a0500b JF |
2050 | virtual void Output(CYOutput &out, CYFlags flags) const; |
2051 | }; | |
2052 | ||
2053 | struct CYDebugger : | |
2054 | CYStatement | |
2055 | { | |
2056 | CYDebugger() | |
2057 | { | |
2058 | } | |
2059 | ||
2060 | virtual CYStatement *Replace(CYContext &context); | |
fb98ac0c | 2061 | virtual void Output(CYOutput &out, CYFlags flags) const; |
cf7d4c69 JF |
2062 | }; |
2063 | ||
2064 | struct CYCondition : | |
2065 | CYExpression | |
2066 | { | |
2067 | CYExpression *test_; | |
2068 | CYExpression *true_; | |
2069 | CYExpression *false_; | |
2070 | ||
2071 | CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) : | |
91a416e4 | 2072 | test_(test), |
cf7d4c69 JF |
2073 | true_(_true), |
2074 | false_(_false) | |
2075 | { | |
2076 | } | |
5999c315 | 2077 | |
d35a3b07 JF |
2078 | CYPrecedence(15) |
2079 | ||
3b52fd1a | 2080 | virtual CYExpression *Replace(CYContext &context); |
652ec1ba | 2081 | virtual void Output(CYOutput &out, CYFlags flags) const; |
5999c315 JF |
2082 | }; |
2083 | ||
2084 | struct CYAddressOf : | |
2085 | CYPrefix | |
2086 | { | |
2087 | CYAddressOf(CYExpression *rhs) : | |
2088 | CYPrefix(rhs) | |
2089 | { | |
2090 | } | |
2091 | ||
2092 | virtual const char *Operator() const { | |
2093 | return "&"; | |
2094 | } | |
2095 | ||
b09da87b | 2096 | CYAlphabetic(false) |
d35a3b07 | 2097 | |
3b52fd1a | 2098 | virtual CYExpression *Replace(CYContext &context); |
5999c315 JF |
2099 | }; |
2100 | ||
2101 | struct CYIndirect : | |
2102 | CYPrefix | |
2103 | { | |
2104 | CYIndirect(CYExpression *rhs) : | |
2105 | CYPrefix(rhs) | |
2106 | { | |
2107 | } | |
2108 | ||
2109 | virtual const char *Operator() const { | |
561ac418 | 2110 | return "*"; |
5999c315 JF |
2111 | } |
2112 | ||
b09da87b | 2113 | CYAlphabetic(false) |
d35a3b07 | 2114 | |
3b52fd1a | 2115 | virtual CYExpression *Replace(CYContext &context); |
cf7d4c69 JF |
2116 | }; |
2117 | ||
4644480a JF |
2118 | #define CYReplace \ |
2119 | virtual CYExpression *Replace(CYContext &context); | |
2120 | ||
2121 | #define CYPostfix_(op, name, args...) \ | |
cf7d4c69 JF |
2122 | struct CY ## name : \ |
2123 | CYPostfix \ | |
4644480a | 2124 | { args \ |
cf7d4c69 JF |
2125 | CY ## name(CYExpression *lhs) : \ |
2126 | CYPostfix(lhs) \ | |
2127 | { \ | |
2128 | } \ | |
5999c315 JF |
2129 | \ |
2130 | virtual const char *Operator() const { \ | |
2131 | return op; \ | |
2132 | } \ | |
cf7d4c69 JF |
2133 | }; |
2134 | ||
4644480a | 2135 | #define CYPrefix_(alphabetic, op, name, args...) \ |
cf7d4c69 JF |
2136 | struct CY ## name : \ |
2137 | CYPrefix \ | |
4644480a | 2138 | { args \ |
cf7d4c69 JF |
2139 | CY ## name(CYExpression *rhs) : \ |
2140 | CYPrefix(rhs) \ | |
2141 | { \ | |
2142 | } \ | |
d35a3b07 | 2143 | \ |
b09da87b | 2144 | CYAlphabetic(alphabetic) \ |
5999c315 JF |
2145 | \ |
2146 | virtual const char *Operator() const { \ | |
2147 | return op; \ | |
2148 | } \ | |
cf7d4c69 JF |
2149 | }; |
2150 | ||
4644480a | 2151 | #define CYInfix_(alphabetic, precedence, op, name, args...) \ |
cf7d4c69 JF |
2152 | struct CY ## name : \ |
2153 | CYInfix \ | |
4644480a | 2154 | { args \ |
cf7d4c69 JF |
2155 | CY ## name(CYExpression *lhs, CYExpression *rhs) : \ |
2156 | CYInfix(lhs, rhs) \ | |
2157 | { \ | |
2158 | } \ | |
d35a3b07 | 2159 | \ |
b09da87b | 2160 | CYAlphabetic(alphabetic) \ |
d35a3b07 | 2161 | CYPrecedence(precedence) \ |
5999c315 JF |
2162 | \ |
2163 | virtual const char *Operator() const { \ | |
2164 | return op; \ | |
2165 | } \ | |
cf7d4c69 JF |
2166 | }; |
2167 | ||
4644480a | 2168 | #define CYAssignment_(op, name, args...) \ |
cf7d4c69 JF |
2169 | struct CY ## name ## Assign : \ |
2170 | CYAssignment \ | |
4644480a | 2171 | { args \ |
cf7d4c69 JF |
2172 | CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \ |
2173 | CYAssignment(lhs, rhs) \ | |
2174 | { \ | |
2175 | } \ | |
5999c315 JF |
2176 | \ |
2177 | virtual const char *Operator() const { \ | |
2178 | return op; \ | |
2179 | } \ | |
cf7d4c69 JF |
2180 | }; |
2181 | ||
2182 | CYPostfix_("++", PostIncrement) | |
2183 | CYPostfix_("--", PostDecrement) | |
2184 | ||
b09da87b JF |
2185 | CYPrefix_(true, "delete", Delete) |
2186 | CYPrefix_(true, "void", Void) | |
2187 | CYPrefix_(true, "typeof", TypeOf) | |
2188 | CYPrefix_(false, "++", PreIncrement) | |
2189 | CYPrefix_(false, "--", PreDecrement) | |
c0bc320e | 2190 | CYPrefix_(false, "+", Affirm) |
b09da87b JF |
2191 | CYPrefix_(false, "-", Negate) |
2192 | CYPrefix_(false, "~", BitwiseNot) | |
2193 | CYPrefix_(false, "!", LogicalNot) | |
2194 | ||
62f398e4 | 2195 | CYInfix_(false, 5, "*", Multiply, CYReplace) |
b09da87b JF |
2196 | CYInfix_(false, 5, "/", Divide) |
2197 | CYInfix_(false, 5, "%", Modulus) | |
4644480a | 2198 | CYInfix_(false, 6, "+", Add, CYReplace) |
b09da87b JF |
2199 | CYInfix_(false, 6, "-", Subtract) |
2200 | CYInfix_(false, 7, "<<", ShiftLeft) | |
2201 | CYInfix_(false, 7, ">>", ShiftRightSigned) | |
2202 | CYInfix_(false, 7, ">>>", ShiftRightUnsigned) | |
2203 | CYInfix_(false, 8, "<", Less) | |
2204 | CYInfix_(false, 8, ">", Greater) | |
2205 | CYInfix_(false, 8, "<=", LessOrEqual) | |
2206 | CYInfix_(false, 8, ">=", GreaterOrEqual) | |
2207 | CYInfix_(true, 8, "instanceof", InstanceOf) | |
2208 | CYInfix_(true, 8, "in", In) | |
2209 | CYInfix_(false, 9, "==", Equal) | |
2210 | CYInfix_(false, 9, "!=", NotEqual) | |
2211 | CYInfix_(false, 9, "===", Identical) | |
2212 | CYInfix_(false, 9, "!==", NotIdentical) | |
2213 | CYInfix_(false, 10, "&", BitwiseAnd) | |
2214 | CYInfix_(false, 11, "^", BitwiseXOr) | |
2215 | CYInfix_(false, 12, "|", BitwiseOr) | |
2216 | CYInfix_(false, 13, "&&", LogicalAnd) | |
2217 | CYInfix_(false, 14, "||", LogicalOr) | |
cf7d4c69 JF |
2218 | |
2219 | CYAssignment_("=", ) | |
2220 | CYAssignment_("*=", Multiply) | |
2221 | CYAssignment_("/=", Divide) | |
2222 | CYAssignment_("%=", Modulus) | |
2223 | CYAssignment_("+=", Add) | |
2224 | CYAssignment_("-=", Subtract) | |
2225 | CYAssignment_("<<=", ShiftLeft) | |
2226 | CYAssignment_(">>=", ShiftRightSigned) | |
2227 | CYAssignment_(">>>=", ShiftRightUnsigned) | |
2228 | CYAssignment_("&=", BitwiseAnd) | |
2229 | CYAssignment_("^=", BitwiseXOr) | |
2230 | CYAssignment_("|=", BitwiseOr) | |
2231 | ||
c5fa2867 | 2232 | #endif/*CYCRIPT_PARSER_HPP*/ |