1 /* Cycript - Inlining/Optimizing JavaScript Compiler
2 * Copyright (C) 2009 Jay Freeman (saurik)
5 /* Modified BSD License {{{ */
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
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
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.
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.
43 // XXX: wtf is this here?!
56 #include "location.hh"
57 #include "Pooling.hpp"
58 #include "Options.hpp"
62 template <typename Type_>
76 void SetNext(Type_ *next) {
85 virtual void Output(struct CYOutput &out) const = 0;
103 CYOutput(std::ostream &out, CYOptions &options) :
113 void Check(char value);
116 CYOutput &operator <<(char rhs);
117 CYOutput &operator <<(const char *rhs);
119 _finline CYOutput &operator <<(const CYThing *rhs) {
125 _finline CYOutput &operator <<(const CYThing &rhs) {
131 struct CYPropertyName {
132 virtual void PropertyName(CYOutput &out) const = 0;
134 virtual ~CYPropertyName() {
148 CYNoBrace = (1 << 0),
149 CYNoFunction = (1 << 1),
152 CYNoRightHand = (1 << 4),
153 CYNoDangle = (1 << 5),
154 CYNoInteger = (1 << 6),
155 CYNoBF = (CYNoBrace | CYNoFunction),
161 virtual ~CYStatement() {
164 void Single(CYOutput &out, CYFlags flags) const;
165 void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
167 CYStatement *ReplaceAll(CYContext &context);
168 virtual CYStatement *Collapse(CYContext &context);
170 virtual CYStatement *Replace(CYContext &context) = 0;
173 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
176 struct CYStatements {
186 operator CYStatement *() const {
190 CYStatements &operator ->*(CYStatement *next) {
192 if (first_ == NULL) {
195 } else for (;; last_ = last_->next_)
196 if (last_->next_ == NULL) {
206 virtual ~CYClassName() {
209 virtual CYExpression *ClassName(CYContext &context, bool object) = 0;
210 virtual void ClassName(CYOutput &out, bool object) const = 0;
220 CYWord(const char *word) :
225 void Set(const char *value) {
229 virtual const char *Word() const;
230 virtual void Output(CYOutput &out) const;
232 virtual CYExpression *ClassName(CYContext &context, bool object);
233 virtual void ClassName(CYOutput &out, bool object) const;
234 virtual void PropertyName(CYOutput &out) const;
237 _finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) {
239 return lhs << rhs.Word();
242 struct CYIdentifier :
243 CYNext<CYIdentifier>,
246 CYIdentifier *replace_;
250 CYIdentifier(const char *word) :
258 virtual const char *Word() const;
259 CYIdentifier *Replace(CYContext &context);
267 CYComment(const char *value) :
272 virtual CYStatement *Replace(CYContext &context);
273 virtual void Output(CYOutput &out, CYFlags flags) const;
280 CYStatement *statement_;
282 CYLabel(CYIdentifier *name, CYStatement *statement) :
284 statement_(statement)
288 virtual CYStatement *Replace(CYContext &context);
289 virtual void Output(CYOutput &out, CYFlags flags) const;
292 struct CYCStringLess :
293 std::binary_function<const char *, const char *, bool>
295 _finline bool operator ()(const char *lhs, const char *rhs) const {
296 return strcmp(lhs, rhs) < 0;
300 struct CYIdentifierValueLess :
301 std::binary_function<CYIdentifier *, CYIdentifier *, bool>
303 _finline bool operator ()(CYIdentifier *lhs, CYIdentifier *rhs) const {
304 return CYCStringLess()(lhs->Word(), rhs->Word());
308 enum CYIdentifierFlags {
309 CYIdentifierArgument,
310 CYIdentifierVariable,
315 typedef std::set<const char *, CYCStringLess> CYCStringSet;
316 typedef std::set<CYIdentifier *, CYIdentifierValueLess> CYIdentifierValueSet;
317 typedef std::map<CYIdentifier *, CYIdentifierFlags> CYIdentifierAddressFlagsMap;
319 struct CYIdentifierUsage {
320 CYIdentifier *identifier_;
324 typedef std::vector<CYIdentifierUsage> CYIdentifierUsageVector;
329 CYIdentifierAddressFlagsMap internal_;
330 CYIdentifierValueSet identifiers_;
340 void Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags);
341 virtual CYIdentifier *Lookup(CYContext &context, CYIdentifier *identifier);
342 void Merge(CYContext &context, CYIdentifier *identifier);
343 void Scope(CYContext &context, CYStatement *&statements);
349 CYStatement *statements_;
351 CYProgram(CYStatement *statements) :
352 statements_(statements)
356 virtual void Replace(CYContext &context);
357 virtual void Output(CYOutput &out) const;
364 CYIdentifierUsageVector rename_;
366 CYContext(apr_pool_t *pool, CYOptions &options) :
373 virtual ~CYContext() {
376 template <typename Type_>
377 void Replace(Type_ *&value) {
378 for (;;) if (value == NULL)
381 Type_ *replace(value->Replace(*this));
382 if (replace != value)
393 CYStatement *statements_;
395 CYBlock(CYStatement *statements) :
396 statements_(statements)
400 operator CYStatement *() const {
404 void AddPrev(CYStatement *statement) {
405 CYStatement *last(statement);
406 while (last->next_ != NULL)
408 last->SetNext(statements_);
409 statements_ = statement;
412 virtual CYStatement *Replace(CYContext &context);
414 virtual void Output(CYOutput &out) const;
415 virtual void Output(CYOutput &out, CYFlags flags) const;
443 std::string filename_;
447 cy::location location_;
448 std::string message_;
451 typedef std::vector<Error> Errors;
459 CYExpression *context_;
461 Context(CYExpression *context) :
466 typedef std::vector<CYWord *> Words;
470 typedef std::vector<Context> Contexts;
473 CYExpression *context_;
485 void ScannerDestroy();
488 CYDriver(apr_pool_t *pool = NULL, const std::string &filename = "");
491 Condition GetCondition();
492 void SetCondition(Condition condition);
494 void PushCondition(Condition condition);
497 void Warning(const cy::location &location, const char *message);
500 struct CYForInitialiser {
501 virtual ~CYForInitialiser() {
504 virtual void For(CYOutput &out) const = 0;
505 virtual CYExpression *Replace(CYContext &context) = 0;
508 struct CYForInInitialiser {
509 virtual ~CYForInInitialiser() {
512 virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
513 virtual const char *ForEachIn() const = 0;
514 virtual CYExpression *ForEachIn(CYContext &out) = 0;
515 virtual CYExpression *Replace(CYContext &context) = 0;
521 struct CYExpression :
522 CYNext<CYExpression>,
528 virtual unsigned Precedence() const = 0;
530 virtual bool RightHand() const {
534 virtual void For(CYOutput &out) const;
535 virtual void ForIn(CYOutput &out, CYFlags flags) const;
537 virtual const char *ForEachIn() const;
538 virtual CYExpression *ForEachIn(CYContext &out);
540 virtual void Output(CYOutput &out) const;
541 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
542 void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
544 virtual CYExpression *ClassName(CYContext &context, bool object);
545 virtual void ClassName(CYOutput &out, bool object) const;
547 CYExpression *ReplaceAll(CYContext &context);
549 virtual CYExpression *Replace(CYContext &context) = 0;
551 virtual CYExpression *Primitive(CYContext &context) {
555 virtual CYNumber *Number(CYContext &context) {
559 virtual CYString *String(CYContext &context) {
563 virtual const char *Word() const {
568 #define CYAlphabetic(value) \
569 virtual bool Alphabetic() const { \
573 #define CYPrecedence(value) \
574 virtual unsigned Precedence() const { \
578 #define CYRightHand(value) \
579 virtual bool RightHand() const { \
586 CYExpression *expressions_;
588 CYCompound(CYExpression *expressions = NULL) :
589 expressions_(expressions)
593 void AddPrev(CYExpression *expression) {
594 CYExpression *last(expression);
595 while (last->next_ != NULL)
597 last->SetNext(expressions_);
598 expressions_ = expression;
603 virtual CYExpression *Replace(CYContext &context);
604 void Output(CYOutput &out, CYFlags flags) const;
607 struct CYFunctionParameter :
608 CYNext<CYFunctionParameter>,
613 CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) :
614 CYNext<CYFunctionParameter>(next),
619 void Replace(CYContext &context);
620 virtual void Output(CYOutput &out) const;
623 struct CYComprehension :
624 CYNext<CYComprehension>,
627 virtual const char *Name() const = 0;
629 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
630 CYFunctionParameter *Parameters(CYContext &context) const;
631 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
632 virtual void Output(CYOutput &out) const = 0;
635 struct CYForInComprehension :
641 CYForInComprehension(CYIdentifier *name, CYExpression *set) :
647 virtual const char *Name() const {
648 return name_->Word();
651 virtual CYFunctionParameter *Parameter(CYContext &context) const;
652 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
653 virtual void Output(CYOutput &out) const;
656 struct CYForEachInComprehension :
662 CYForEachInComprehension(CYIdentifier *name, CYExpression *set) :
668 virtual const char *Name() const {
669 return name_->Word();
672 virtual CYFunctionParameter *Parameter(CYContext &context) const;
673 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
674 virtual void Output(CYOutput &out) const;
677 struct CYIfComprehension :
682 CYIfComprehension(CYExpression *test) :
687 virtual const char *Name() const {
691 virtual CYFunctionParameter *Parameter(CYContext &context) const;
692 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
693 virtual void Output(CYOutput &out) const;
696 struct CYArrayComprehension :
699 CYExpression *expression_;
700 CYComprehension *comprehensions_;
702 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
703 expression_(expression),
704 comprehensions_(comprehensions)
710 virtual CYExpression *Replace(CYContext &context);
711 virtual void Output(CYOutput &out, CYFlags flags) const;
724 virtual CYExpression *Replace(CYContext &context);
738 CYRange(uint64_t lo, uint64_t hi) :
743 bool operator [](uint8_t value) const {
744 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
747 void operator()(uint8_t value) {
750 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
754 extern CYRange DigitRange_;
755 extern CYRange WordStartRange_;
756 extern CYRange WordEndRange_;
771 CYString(const char *value) :
777 CYString(const char *value, size_t size) :
783 CYString(const CYWord *word) :
784 value_(word->Word()),
785 size_(strlen(value_))
789 const char *Value() const {
793 virtual const char *Word() const;
795 virtual CYNumber *Number(CYContext &context);
796 virtual CYString *String(CYContext &context);
798 CYString *Concat(CYContext &out, CYString *rhs) const;
799 virtual void Output(CYOutput &out, CYFlags flags) const;
800 virtual void PropertyName(CYOutput &out) const;
809 CYNumber(double value) :
814 double Value() const {
818 virtual CYNumber *Number(CYContext &context);
819 virtual CYString *String(CYContext &context);
821 virtual void Output(CYOutput &out, CYFlags flags) const;
822 virtual void PropertyName(CYOutput &out) const;
830 CYRegEx(const char *value) :
835 const char *Value() const {
839 virtual void Output(CYOutput &out, CYFlags flags) const;
851 virtual CYNumber *Number(CYContext &context);
852 virtual CYString *String(CYContext &context);
854 virtual void Output(CYOutput &out, CYFlags flags) const;
866 virtual CYExpression *Replace(CYContext &context);
867 virtual void Output(CYOutput &out, CYFlags flags) const;
873 virtual bool Value() const = 0;
874 virtual void Output(CYOutput &out, CYFlags flags) const;
886 virtual bool Value() const {
890 virtual CYNumber *Number(CYContext &context);
891 virtual CYString *String(CYContext &context);
903 virtual bool Value() const {
907 virtual CYNumber *Number(CYContext &context);
908 virtual CYString *String(CYContext &context);
916 CYVariable(CYIdentifier *name) :
924 virtual CYExpression *Replace(CYContext &context);
925 virtual void Output(CYOutput &out, CYFlags flags) const;
933 CYPrefix(CYExpression *rhs) :
938 virtual bool Alphabetic() const = 0;
939 virtual const char *Operator() const = 0;
943 virtual CYExpression *Replace(CYContext &context);
944 virtual void Output(CYOutput &out, CYFlags flags) const;
953 CYInfix(CYExpression *lhs, CYExpression *rhs) :
959 void SetLeft(CYExpression *lhs) {
963 virtual bool Alphabetic() const = 0;
964 virtual const char *Operator() const = 0;
966 virtual CYExpression *Replace(CYContext &context);
967 virtual void Output(CYOutput &out, CYFlags flags) const;
975 CYPostfix(CYExpression *lhs) :
980 virtual const char *Operator() const = 0;
984 virtual CYExpression *Replace(CYContext &context);
985 virtual void Output(CYOutput &out, CYFlags flags) const;
988 struct CYAssignment :
994 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
1000 void SetLeft(CYExpression *lhs) {
1004 virtual const char *Operator() const = 0;
1008 virtual CYExpression *Replace(CYContext &context);
1009 virtual void Output(CYOutput &out, CYFlags flags) const;
1017 CYExpression *value_;
1019 CYArgument(CYExpression *value, CYArgument *next = NULL) :
1020 CYNext<CYArgument>(next),
1026 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
1027 CYNext<CYArgument>(next),
1033 void Replace(CYContext &context);
1034 void Output(CYOutput &out) const;
1050 CYExpression *case_;
1051 CYStatement *statements_;
1053 CYClause(CYExpression *_case, CYStatement *statements) :
1055 statements_(statements)
1059 void Replace(CYContext &context);
1060 virtual void Output(CYOutput &out) const;
1067 CYExpression *value_;
1069 CYElement(CYExpression *value, CYElement *next) :
1070 CYNext<CYElement>(next),
1075 void Replace(CYContext &context);
1076 void Output(CYOutput &out) const;
1082 CYElement *elements_;
1084 CYArray(CYElement *elements = NULL) :
1089 virtual CYExpression *Replace(CYContext &context);
1090 virtual void Output(CYOutput &out, CYFlags flags) const;
1097 CYPropertyName *name_;
1098 CYExpression *value_;
1100 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1101 CYNext<CYProperty>(next),
1107 void Replace(CYContext &context);
1108 virtual void Output(CYOutput &out) const;
1111 struct CYDeclaration :
1114 CYIdentifier *identifier_;
1115 CYExpression *initialiser_;
1117 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
1118 identifier_(identifier),
1119 initialiser_(initialiser)
1123 virtual void ForIn(CYOutput &out, CYFlags flags) const;
1125 virtual const char *ForEachIn() const;
1126 virtual CYExpression *ForEachIn(CYContext &out);
1128 virtual CYExpression *Replace(CYContext &context);
1129 virtual CYAssignment *Assignment(CYContext &context);
1131 virtual void Output(CYOutput &out, CYFlags flags) const;
1134 struct CYDeclarations :
1135 CYNext<CYDeclarations>,
1139 CYDeclaration *declaration_;
1141 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
1142 CYNext<CYDeclarations>(next),
1143 declaration_(declaration)
1147 virtual void For(CYOutput &out) const;
1149 virtual CYCompound *Replace(CYContext &context);
1150 CYProperty *Property(CYContext &context);
1152 virtual void Output(CYOutput &out) const;
1153 virtual void Output(CYOutput &out, CYFlags flags) const;
1159 CYDeclarations *declarations_;
1161 CYVar(CYDeclarations *declarations) :
1162 declarations_(declarations)
1166 virtual CYStatement *Replace(CYContext &context);
1167 virtual void Output(CYOutput &out, CYFlags flags) const;
1173 CYDeclarations *declarations_;
1176 CYLet(CYDeclarations *declarations, CYStatement *statements) :
1177 declarations_(declarations),
1182 virtual CYStatement *Replace(CYContext &context);
1183 virtual void Output(CYOutput &out, CYFlags flags) const;
1189 CYForInitialiser *initialiser_;
1190 CYExpression *test_;
1191 CYExpression *increment_;
1194 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
1195 initialiser_(initialiser),
1197 increment_(increment),
1202 virtual CYStatement *Replace(CYContext &context);
1203 virtual void Output(CYOutput &out, CYFlags flags) const;
1209 CYForInInitialiser *initialiser_;
1213 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1214 initialiser_(initialiser),
1220 virtual CYStatement *Replace(CYContext &context);
1221 virtual void Output(CYOutput &out, CYFlags flags) const;
1224 struct CYForEachIn :
1227 CYForInInitialiser *initialiser_;
1231 CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1232 initialiser_(initialiser),
1238 virtual CYStatement *Replace(CYContext &context);
1239 virtual void Output(CYOutput &out, CYFlags flags) const;
1245 CYProperty *properties_;
1247 CYObject(CYProperty *properties) :
1248 properties_(properties)
1252 virtual CYExpression *Replace(CYContext &context);
1253 void Output(CYOutput &out, CYFlags flags) const;
1259 CYExpression *object_;
1260 CYExpression *property_;
1262 CYMember(CYExpression *object, CYExpression *property) :
1268 void SetLeft(CYExpression *object) {
1272 void Replace_(CYContext &context);
1275 struct CYDirectMember :
1278 CYDirectMember(CYExpression *object, CYExpression *property) :
1279 CYMember(object, property)
1286 virtual CYExpression *Replace(CYContext &context);
1287 virtual void Output(CYOutput &out, CYFlags flags) const;
1290 struct CYIndirectMember :
1293 CYIndirectMember(CYExpression *object, CYExpression *property) :
1294 CYMember(object, property)
1301 virtual CYExpression *Replace(CYContext &context);
1302 virtual void Output(CYOutput &out, CYFlags flags) const;
1308 CYExpression *constructor_;
1309 CYArgument *arguments_;
1311 CYNew(CYExpression *constructor, CYArgument *arguments) :
1312 constructor_(constructor),
1313 arguments_(arguments)
1317 virtual unsigned Precedence() const {
1318 return arguments_ == NULL ? 2 : 1;
1323 virtual CYExpression *Replace(CYContext &context);
1324 virtual void Output(CYOutput &out, CYFlags flags) const;
1330 CYExpression *function_;
1331 CYArgument *arguments_;
1333 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
1334 function_(function),
1335 arguments_(arguments)
1342 virtual CYExpression *Replace(CYContext &context);
1343 virtual void Output(CYOutput &out, CYFlags flags) const;
1349 CYExpression *test_;
1351 CYStatement *false_;
1353 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
1360 virtual CYStatement *Replace(CYContext &context);
1361 virtual void Output(CYOutput &out, CYFlags flags) const;
1367 CYExpression *test_;
1370 CYDoWhile(CYExpression *test, CYStatement *code) :
1376 virtual CYStatement *Replace(CYContext &context);
1377 virtual void Output(CYOutput &out, CYFlags flags) const;
1383 CYExpression *test_;
1386 CYWhile(CYExpression *test, CYStatement *code) :
1392 virtual CYStatement *Replace(CYContext &context);
1393 virtual void Output(CYOutput &out, CYFlags flags) const;
1397 CYIdentifier *name_;
1398 CYFunctionParameter *parameters_;
1401 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1403 parameters_(parameters),
1408 virtual ~CYFunction() {
1411 void Inject(CYContext &context);
1412 virtual void Replace_(CYContext &context, bool outer);
1413 virtual void Output(CYOutput &out, CYFlags flags) const;
1416 struct CYFunctionExpression :
1420 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1421 CYFunction(name, parameters, statements)
1428 virtual CYExpression *Replace(CYContext &context);
1429 virtual void Output(CYOutput &out, CYFlags flags) const;
1432 struct CYFunctionStatement :
1436 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1437 CYFunction(name, parameters, statements)
1441 virtual CYStatement *Replace(CYContext &context);
1442 virtual void Output(CYOutput &out, CYFlags flags) const;
1448 CYExpression *expression_;
1450 CYExpress(CYExpression *expression) :
1451 expression_(expression)
1453 if (expression == NULL)
1457 virtual CYStatement *Collapse(CYContext &context);
1458 virtual CYStatement *Replace(CYContext &context);
1459 virtual void Output(CYOutput &out, CYFlags flags) const;
1465 CYIdentifier *label_;
1467 CYContinue(CYIdentifier *label) :
1472 virtual CYStatement *Replace(CYContext &context);
1473 virtual void Output(CYOutput &out, CYFlags flags) const;
1479 CYIdentifier *label_;
1481 CYBreak(CYIdentifier *label) :
1486 virtual CYStatement *Replace(CYContext &context);
1487 virtual void Output(CYOutput &out, CYFlags flags) const;
1493 CYExpression *value_;
1495 CYReturn(CYExpression *value) :
1500 virtual CYStatement *Replace(CYContext &context);
1501 virtual void Output(CYOutput &out, CYFlags flags) const;
1507 virtual CYStatement *Collapse(CYContext &context);
1508 virtual CYStatement *Replace(CYContext &context);
1509 virtual void Output(CYOutput &out, CYFlags flags) const;
1517 CYFinally(CYStatement *statements) :
1522 void Replace(CYContext &context);
1523 virtual void Output(CYOutput &out) const;
1532 CYIdentifier *name_;
1535 Catch(CYIdentifier *name, CYStatement *statements) :
1541 void Replace(CYContext &context);
1542 virtual void Output(CYOutput &out) const;
1550 CYFinally *finally_;
1552 Try(CYStatement *statements, Catch *_catch, CYFinally *finally) :
1559 virtual CYStatement *Replace(CYContext &context);
1560 virtual void Output(CYOutput &out, CYFlags flags) const;
1566 CYExpression *value_;
1568 Throw(CYExpression *value) :
1573 virtual CYStatement *Replace(CYContext &context);
1574 virtual void Output(CYOutput &out, CYFlags flags) const;
1582 CYExpression *scope_;
1585 CYWith(CYExpression *scope, CYStatement *code) :
1591 virtual CYStatement *Replace(CYContext &context);
1592 virtual void Output(CYOutput &out, CYFlags flags) const;
1598 CYExpression *value_;
1601 CYSwitch(CYExpression *value, CYClause *clauses) :
1607 virtual CYStatement *Replace(CYContext &context);
1608 virtual void Output(CYOutput &out, CYFlags flags) const;
1611 struct CYCondition :
1614 CYExpression *test_;
1615 CYExpression *true_;
1616 CYExpression *false_;
1618 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
1627 virtual CYExpression *Replace(CYContext &context);
1628 virtual void Output(CYOutput &out, CYFlags flags) const;
1631 struct CYAddressOf :
1634 CYAddressOf(CYExpression *rhs) :
1639 virtual const char *Operator() const {
1645 virtual CYExpression *Replace(CYContext &context);
1651 CYIndirect(CYExpression *rhs) :
1656 virtual const char *Operator() const {
1662 virtual CYExpression *Replace(CYContext &context);
1666 virtual CYExpression *Replace(CYContext &context);
1668 #define CYPostfix_(op, name, args...) \
1669 struct CY ## name : \
1672 CY ## name(CYExpression *lhs) : \
1677 virtual const char *Operator() const { \
1682 #define CYPrefix_(alphabetic, op, name, args...) \
1683 struct CY ## name : \
1686 CY ## name(CYExpression *rhs) : \
1691 CYAlphabetic(alphabetic) \
1693 virtual const char *Operator() const { \
1698 #define CYInfix_(alphabetic, precedence, op, name, args...) \
1699 struct CY ## name : \
1702 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
1707 CYAlphabetic(alphabetic) \
1708 CYPrecedence(precedence) \
1710 virtual const char *Operator() const { \
1715 #define CYAssignment_(op, name, args...) \
1716 struct CY ## name ## Assign : \
1719 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
1720 CYAssignment(lhs, rhs) \
1724 virtual const char *Operator() const { \
1729 CYPostfix_("++", PostIncrement)
1730 CYPostfix_("--", PostDecrement)
1732 CYPrefix_(true, "delete", Delete)
1733 CYPrefix_(true, "void", Void)
1734 CYPrefix_(true, "typeof", TypeOf)
1735 CYPrefix_(false, "++", PreIncrement)
1736 CYPrefix_(false, "--", PreDecrement)
1737 CYPrefix_(false, "+", Affirm)
1738 CYPrefix_(false, "-", Negate)
1739 CYPrefix_(false, "~", BitwiseNot)
1740 CYPrefix_(false, "!", LogicalNot)
1742 CYInfix_(false, 5, "*", Multiply)
1743 CYInfix_(false, 5, "/", Divide)
1744 CYInfix_(false, 5, "%", Modulus)
1745 CYInfix_(false, 6, "+", Add, CYReplace)
1746 CYInfix_(false, 6, "-", Subtract)
1747 CYInfix_(false, 7, "<<", ShiftLeft)
1748 CYInfix_(false, 7, ">>", ShiftRightSigned)
1749 CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
1750 CYInfix_(false, 8, "<", Less)
1751 CYInfix_(false, 8, ">", Greater)
1752 CYInfix_(false, 8, "<=", LessOrEqual)
1753 CYInfix_(false, 8, ">=", GreaterOrEqual)
1754 CYInfix_(true, 8, "instanceof", InstanceOf)
1755 CYInfix_(true, 8, "in", In)
1756 CYInfix_(false, 9, "==", Equal)
1757 CYInfix_(false, 9, "!=", NotEqual)
1758 CYInfix_(false, 9, "===", Identical)
1759 CYInfix_(false, 9, "!==", NotIdentical)
1760 CYInfix_(false, 10, "&", BitwiseAnd)
1761 CYInfix_(false, 11, "^", BitwiseXOr)
1762 CYInfix_(false, 12, "|", BitwiseOr)
1763 CYInfix_(false, 13, "&&", LogicalAnd)
1764 CYInfix_(false, 14, "||", LogicalOr)
1766 CYAssignment_("=", )
1767 CYAssignment_("*=", Multiply)
1768 CYAssignment_("/=", Divide)
1769 CYAssignment_("%=", Modulus)
1770 CYAssignment_("+=", Add)
1771 CYAssignment_("-=", Subtract)
1772 CYAssignment_("<<=", ShiftLeft)
1773 CYAssignment_(">>=", ShiftRightSigned)
1774 CYAssignment_(">>>=", ShiftRightUnsigned)
1775 CYAssignment_("&=", BitwiseAnd)
1776 CYAssignment_("^=", BitwiseXOr)
1777 CYAssignment_("|=", BitwiseOr)
1779 #endif/*CYPARSER_HPP*/