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?!
55 #include "location.hh"
56 #include "Pooling.hpp"
57 #include "Options.hpp"
61 template <typename Type_>
75 void SetNext(Type_ *next) {
84 virtual void Output(struct CYOutput &out) const = 0;
102 CYOutput(std::ostream &out, CYOptions &options) :
112 void Check(char value);
115 CYOutput &operator <<(char rhs);
116 CYOutput &operator <<(const char *rhs);
118 _finline CYOutput &operator <<(const CYThing *rhs) {
124 _finline CYOutput &operator <<(const CYThing &rhs) {
130 struct CYPropertyName {
131 virtual void PropertyName(CYOutput &out) const = 0;
133 virtual ~CYPropertyName() {
147 CYNoBrace = (1 << 0),
148 CYNoFunction = (1 << 1),
151 CYNoRightHand = (1 << 4),
152 CYNoDangle = (1 << 5),
153 CYNoInteger = (1 << 6),
154 CYNoBF = (CYNoBrace | CYNoFunction),
160 virtual ~CYStatement() {
163 void Single(CYOutput &out, CYFlags flags) const;
164 void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
166 CYStatement *ReplaceAll(CYContext &context);
167 virtual CYStatement *Collapse(CYContext &context);
169 virtual CYStatement *Replace(CYContext &context) = 0;
172 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
175 struct CYStatements {
185 operator CYStatement *() const {
189 CYStatements &operator ->*(CYStatement *next) {
191 if (first_ == NULL) {
194 } else for (;; last_ = last_->next_)
195 if (last_->next_ == NULL) {
205 virtual ~CYClassName() {
208 virtual CYExpression *ClassName(CYContext &context, bool object) = 0;
209 virtual void ClassName(CYOutput &out, bool object) const = 0;
219 CYWord(const char *word) :
224 void Set(const char *value) {
228 virtual const char *Word() const;
229 virtual void Output(CYOutput &out) const;
231 virtual CYExpression *ClassName(CYContext &context, bool object);
232 virtual void ClassName(CYOutput &out, bool object) const;
233 virtual void PropertyName(CYOutput &out) const;
236 _finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) {
238 return lhs << rhs.Word();
241 struct CYIdentifier :
242 CYNext<CYIdentifier>,
245 CYIdentifier *replace_;
248 CYIdentifier(const char *word) :
255 virtual const char *Word() const;
256 CYIdentifier *Replace(CYContext &context);
264 CYComment(const char *value) :
269 virtual CYStatement *Replace(CYContext &context);
270 virtual void Output(CYOutput &out, CYFlags flags) const;
277 CYStatement *statement_;
279 CYLabel(CYIdentifier *name, CYStatement *statement) :
281 statement_(statement)
285 virtual CYStatement *Replace(CYContext &context);
286 virtual void Output(CYOutput &out, CYFlags flags) const;
289 struct CYCStringLess :
290 std::binary_function<const char *, const char *, bool>
292 _finline bool operator ()(const char *lhs, const char *rhs) const {
293 return strcmp(lhs, rhs) < 0;
297 struct CYIdentifierValueLess :
298 std::binary_function<CYIdentifier *, CYIdentifier *, bool>
300 _finline bool operator ()(CYIdentifier *lhs, CYIdentifier *rhs) const {
301 return CYCStringLess()(lhs->Word(), rhs->Word());
305 enum CYIdentifierFlags {
306 CYIdentifierArgument,
307 CYIdentifierVariable,
312 typedef std::set<const char *, CYCStringLess> CYCStringSet;
313 typedef std::set<CYIdentifier *, CYIdentifierValueLess> CYIdentifierValueSet;
314 typedef std::vector<CYIdentifier *> CYIdentifierAddressVector;
315 typedef std::map<CYIdentifier *, CYIdentifierFlags> CYIdentifierAddressFlagsMap;
319 CYIdentifierAddressFlagsMap internal_;
321 CYIdentifierValueSet identifiers_;
331 void Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags);
332 virtual CYIdentifier *Lookup(CYContext &context, CYIdentifier *identifier);
333 void Merge(CYContext &context, CYIdentifier *identifier);
334 void Scope(CYContext &context, CYStatement *&statements);
341 CYStatement *statements_;
342 CYIdentifierAddressVector rename_;
344 CYProgram(CYStatement *statements) :
345 statements_(statements)
349 virtual void Replace(CYContext &context);
350 virtual void Output(CYOutput &out) const;
361 CYContext(apr_pool_t *pool, CYOptions &options) :
369 virtual ~CYContext() {
372 template <typename Type_>
373 void Replace(Type_ *&value) {
374 for (;;) if (value == NULL)
377 Type_ *replace(value->Replace(*this));
378 if (replace != value)
389 CYStatement *statements_;
392 CYBlock(CYStatement *statements, CYScope *scope = NULL) :
393 statements_(statements),
398 operator CYStatement *() const {
402 void AddPrev(CYStatement *statement) {
403 CYStatement *last(statement);
404 while (last->next_ != NULL)
406 last->SetNext(statements_);
407 statements_ = statement;
410 virtual CYStatement *Replace(CYContext &context);
412 virtual void Output(CYOutput &out) const;
413 virtual void Output(CYOutput &out, CYFlags flags) const;
441 std::string filename_;
445 cy::location location_;
446 std::string message_;
449 typedef std::vector<Error> Errors;
456 void ScannerDestroy();
459 CYDriver(const std::string &filename);
462 Condition GetCondition();
463 void SetCondition(Condition condition);
465 void PushCondition(Condition condition);
468 void Warning(const cy::location &location, const char *message);
471 struct CYForInitialiser {
472 virtual ~CYForInitialiser() {
475 virtual void For(CYOutput &out) const = 0;
476 virtual CYExpression *Replace(CYContext &context) = 0;
479 struct CYForInInitialiser {
480 virtual ~CYForInInitialiser() {
483 virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
484 virtual const char *ForEachIn() const = 0;
485 virtual CYExpression *ForEachIn(CYContext &out) = 0;
486 virtual CYExpression *Replace(CYContext &context) = 0;
492 struct CYExpression :
493 CYNext<CYExpression>,
499 virtual unsigned Precedence() const = 0;
501 virtual bool RightHand() const {
505 virtual void For(CYOutput &out) const;
506 virtual void ForIn(CYOutput &out, CYFlags flags) const;
508 virtual const char *ForEachIn() const;
509 virtual CYExpression *ForEachIn(CYContext &out);
511 virtual void Output(CYOutput &out) const;
512 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
513 void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
515 virtual CYExpression *ClassName(CYContext &context, bool object);
516 virtual void ClassName(CYOutput &out, bool object) const;
518 CYExpression *ReplaceAll(CYContext &context);
520 virtual CYExpression *Replace(CYContext &context) = 0;
522 virtual CYExpression *Primitive(CYContext &context) {
526 virtual CYNumber *Number(CYContext &context) {
530 virtual CYString *String(CYContext &context) {
534 virtual const char *Word() const {
539 #define CYAlphabetic(value) \
540 virtual bool Alphabetic() const { \
544 #define CYPrecedence(value) \
545 virtual unsigned Precedence() const { \
549 #define CYRightHand(value) \
550 virtual bool RightHand() const { \
557 CYExpression *expressions_;
559 CYCompound(CYExpression *expressions = NULL) :
560 expressions_(expressions)
564 void AddPrev(CYExpression *expression) {
565 CYExpression *last(expression);
566 while (last->next_ != NULL)
568 last->SetNext(expressions_);
569 expressions_ = expression;
574 virtual CYExpression *Replace(CYContext &context);
575 void Output(CYOutput &out, CYFlags flags) const;
578 struct CYFunctionParameter :
579 CYNext<CYFunctionParameter>,
584 CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) :
585 CYNext<CYFunctionParameter>(next),
590 void Replace(CYContext &context);
591 virtual void Output(CYOutput &out) const;
594 struct CYComprehension :
595 CYNext<CYComprehension>,
598 virtual const char *Name() const = 0;
600 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
601 CYFunctionParameter *Parameters(CYContext &context) const;
602 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
603 virtual void Output(CYOutput &out) const = 0;
606 struct CYForInComprehension :
612 CYForInComprehension(CYIdentifier *name, CYExpression *set) :
618 virtual const char *Name() const {
619 return name_->Word();
622 virtual CYFunctionParameter *Parameter(CYContext &context) const;
623 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
624 virtual void Output(CYOutput &out) const;
627 struct CYForEachInComprehension :
633 CYForEachInComprehension(CYIdentifier *name, CYExpression *set) :
639 virtual const char *Name() const {
640 return name_->Word();
643 virtual CYFunctionParameter *Parameter(CYContext &context) const;
644 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
645 virtual void Output(CYOutput &out) const;
648 struct CYIfComprehension :
653 CYIfComprehension(CYExpression *test) :
658 virtual const char *Name() const {
662 virtual CYFunctionParameter *Parameter(CYContext &context) const;
663 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
664 virtual void Output(CYOutput &out) const;
667 struct CYArrayComprehension :
670 CYExpression *expression_;
671 CYComprehension *comprehensions_;
673 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
674 expression_(expression),
675 comprehensions_(comprehensions)
681 virtual CYExpression *Replace(CYContext &context);
682 virtual void Output(CYOutput &out, CYFlags flags) const;
695 virtual CYExpression *Replace(CYContext &context);
709 CYRange(uint64_t lo, uint64_t hi) :
714 bool operator [](uint8_t value) const {
715 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
718 void operator()(uint8_t value) {
721 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
725 extern CYRange DigitRange_;
726 extern CYRange WordStartRange_;
727 extern CYRange WordEndRange_;
742 CYString(const char *value) :
748 CYString(const char *value, size_t size) :
754 CYString(const CYWord *word) :
755 value_(word->Word()),
756 size_(strlen(value_))
760 const char *Value() const {
764 virtual const char *Word() const;
766 virtual CYNumber *Number(CYContext &context);
767 virtual CYString *String(CYContext &context);
769 CYString *Concat(CYContext &out, CYString *rhs) const;
770 virtual void Output(CYOutput &out, CYFlags flags) const;
771 virtual void PropertyName(CYOutput &out) const;
780 CYNumber(double value) :
785 double Value() const {
789 virtual CYNumber *Number(CYContext &context);
790 virtual CYString *String(CYContext &context);
792 virtual void Output(CYOutput &out, CYFlags flags) const;
793 virtual void PropertyName(CYOutput &out) const;
801 CYRegEx(const char *value) :
806 const char *Value() const {
810 virtual void Output(CYOutput &out, CYFlags flags) const;
822 virtual CYNumber *Number(CYContext &context);
823 virtual CYString *String(CYContext &context);
825 virtual void Output(CYOutput &out, CYFlags flags) const;
837 virtual CYExpression *Replace(CYContext &context);
838 virtual void Output(CYOutput &out, CYFlags flags) const;
844 virtual bool Value() const = 0;
845 virtual void Output(CYOutput &out, CYFlags flags) const;
857 virtual bool Value() const {
861 virtual CYNumber *Number(CYContext &context);
862 virtual CYString *String(CYContext &context);
874 virtual bool Value() const {
878 virtual CYNumber *Number(CYContext &context);
879 virtual CYString *String(CYContext &context);
887 CYVariable(CYIdentifier *name) :
895 virtual CYExpression *Replace(CYContext &context);
896 virtual void Output(CYOutput &out, CYFlags flags) const;
904 CYPrefix(CYExpression *rhs) :
909 virtual bool Alphabetic() const = 0;
910 virtual const char *Operator() const = 0;
914 virtual CYExpression *Replace(CYContext &context);
915 virtual void Output(CYOutput &out, CYFlags flags) const;
924 CYInfix(CYExpression *lhs, CYExpression *rhs) :
930 void SetLeft(CYExpression *lhs) {
934 virtual bool Alphabetic() const = 0;
935 virtual const char *Operator() const = 0;
937 virtual CYExpression *Replace(CYContext &context);
938 virtual void Output(CYOutput &out, CYFlags flags) const;
946 CYPostfix(CYExpression *lhs) :
951 virtual const char *Operator() const = 0;
955 virtual CYExpression *Replace(CYContext &context);
956 virtual void Output(CYOutput &out, CYFlags flags) const;
959 struct CYAssignment :
965 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
971 void SetLeft(CYExpression *lhs) {
975 virtual const char *Operator() const = 0;
979 virtual CYExpression *Replace(CYContext &context);
980 virtual void Output(CYOutput &out, CYFlags flags) const;
988 CYExpression *value_;
990 CYArgument(CYExpression *value, CYArgument *next = NULL) :
991 CYNext<CYArgument>(next),
997 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
998 CYNext<CYArgument>(next),
1004 void Replace(CYContext &context);
1005 void Output(CYOutput &out) const;
1021 CYExpression *case_;
1022 CYStatement *statements_;
1024 CYClause(CYExpression *_case, CYStatement *statements) :
1026 statements_(statements)
1030 void Replace(CYContext &context);
1031 virtual void Output(CYOutput &out) const;
1038 CYExpression *value_;
1040 CYElement(CYExpression *value, CYElement *next) :
1041 CYNext<CYElement>(next),
1046 void Replace(CYContext &context);
1047 void Output(CYOutput &out) const;
1053 CYElement *elements_;
1055 CYArray(CYElement *elements = NULL) :
1060 virtual CYExpression *Replace(CYContext &context);
1061 virtual void Output(CYOutput &out, CYFlags flags) const;
1068 CYPropertyName *name_;
1069 CYExpression *value_;
1071 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1072 CYNext<CYProperty>(next),
1078 void Replace(CYContext &context);
1079 virtual void Output(CYOutput &out) const;
1082 struct CYDeclaration :
1085 CYIdentifier *identifier_;
1086 CYExpression *initialiser_;
1088 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
1089 identifier_(identifier),
1090 initialiser_(initialiser)
1094 virtual void ForIn(CYOutput &out, CYFlags flags) const;
1096 virtual const char *ForEachIn() const;
1097 virtual CYExpression *ForEachIn(CYContext &out);
1099 virtual CYExpression *Replace(CYContext &context);
1100 virtual CYAssignment *Assignment(CYContext &context);
1102 virtual void Output(CYOutput &out, CYFlags flags) const;
1105 struct CYDeclarations :
1106 CYNext<CYDeclarations>,
1110 CYDeclaration *declaration_;
1112 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
1113 CYNext<CYDeclarations>(next),
1114 declaration_(declaration)
1118 virtual void For(CYOutput &out) const;
1120 virtual CYCompound *Replace(CYContext &context);
1121 CYProperty *Property(CYContext &context);
1123 virtual void Output(CYOutput &out) const;
1124 virtual void Output(CYOutput &out, CYFlags flags) const;
1130 CYDeclarations *declarations_;
1132 CYVar(CYDeclarations *declarations) :
1133 declarations_(declarations)
1137 virtual CYStatement *Replace(CYContext &context);
1138 virtual void Output(CYOutput &out, CYFlags flags) const;
1144 CYDeclarations *declarations_;
1147 CYLet(CYDeclarations *declarations, CYStatement *statements) :
1148 declarations_(declarations),
1153 virtual CYStatement *Replace(CYContext &context);
1154 virtual void Output(CYOutput &out, CYFlags flags) const;
1160 CYForInitialiser *initialiser_;
1161 CYExpression *test_;
1162 CYExpression *increment_;
1165 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
1166 initialiser_(initialiser),
1168 increment_(increment),
1173 virtual CYStatement *Replace(CYContext &context);
1174 virtual void Output(CYOutput &out, CYFlags flags) const;
1180 CYForInInitialiser *initialiser_;
1184 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1185 initialiser_(initialiser),
1191 virtual CYStatement *Replace(CYContext &context);
1192 virtual void Output(CYOutput &out, CYFlags flags) const;
1195 struct CYForEachIn :
1198 CYForInInitialiser *initialiser_;
1202 CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1203 initialiser_(initialiser),
1209 virtual CYStatement *Replace(CYContext &context);
1210 virtual void Output(CYOutput &out, CYFlags flags) const;
1216 CYProperty *properties_;
1218 CYObject(CYProperty *properties) :
1219 properties_(properties)
1223 virtual CYExpression *Replace(CYContext &context);
1224 void Output(CYOutput &out, CYFlags flags) const;
1230 CYExpression *object_;
1231 CYExpression *property_;
1233 CYMember(CYExpression *object, CYExpression *property) :
1239 void SetLeft(CYExpression *object) {
1243 void Replace_(CYContext &context);
1246 struct CYDirectMember :
1249 CYDirectMember(CYExpression *object, CYExpression *property) :
1250 CYMember(object, property)
1257 virtual CYExpression *Replace(CYContext &context);
1258 virtual void Output(CYOutput &out, CYFlags flags) const;
1261 struct CYIndirectMember :
1264 CYIndirectMember(CYExpression *object, CYExpression *property) :
1265 CYMember(object, property)
1272 virtual CYExpression *Replace(CYContext &context);
1273 virtual void Output(CYOutput &out, CYFlags flags) const;
1279 CYExpression *constructor_;
1280 CYArgument *arguments_;
1282 CYNew(CYExpression *constructor, CYArgument *arguments) :
1283 constructor_(constructor),
1284 arguments_(arguments)
1288 virtual unsigned Precedence() const {
1289 return arguments_ == NULL ? 2 : 1;
1294 virtual CYExpression *Replace(CYContext &context);
1295 virtual void Output(CYOutput &out, CYFlags flags) const;
1301 CYExpression *function_;
1302 CYArgument *arguments_;
1304 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
1305 function_(function),
1306 arguments_(arguments)
1313 virtual CYExpression *Replace(CYContext &context);
1314 virtual void Output(CYOutput &out, CYFlags flags) const;
1320 CYExpression *test_;
1322 CYStatement *false_;
1324 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
1331 virtual CYStatement *Replace(CYContext &context);
1332 virtual void Output(CYOutput &out, CYFlags flags) const;
1338 CYExpression *test_;
1341 CYDoWhile(CYExpression *test, CYStatement *code) :
1347 virtual CYStatement *Replace(CYContext &context);
1348 virtual void Output(CYOutput &out, CYFlags flags) const;
1354 CYExpression *test_;
1357 CYWhile(CYExpression *test, CYStatement *code) :
1363 virtual CYStatement *Replace(CYContext &context);
1364 virtual void Output(CYOutput &out, CYFlags flags) const;
1370 CYIdentifier *name_;
1371 CYFunctionParameter *parameters_;
1374 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1376 parameters_(parameters),
1377 code_(statements, this)
1381 virtual ~CYFunction() {
1384 void Inject(CYContext &context);
1385 virtual void Replace_(CYContext &context, bool outer);
1386 virtual void Output(CYOutput &out, CYFlags flags) const;
1389 struct CYFunctionExpression :
1393 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1394 CYFunction(name, parameters, statements)
1401 virtual CYExpression *Replace(CYContext &context);
1402 virtual void Output(CYOutput &out, CYFlags flags) const;
1405 struct CYFunctionStatement :
1409 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1410 CYFunction(name, parameters, statements)
1414 virtual CYStatement *Replace(CYContext &context);
1415 virtual void Output(CYOutput &out, CYFlags flags) const;
1421 CYExpression *expression_;
1423 CYExpress(CYExpression *expression) :
1424 expression_(expression)
1426 if (expression == NULL)
1430 virtual CYStatement *Collapse(CYContext &context);
1431 virtual CYStatement *Replace(CYContext &context);
1432 virtual void Output(CYOutput &out, CYFlags flags) const;
1438 CYIdentifier *label_;
1440 CYContinue(CYIdentifier *label) :
1445 virtual CYStatement *Replace(CYContext &context);
1446 virtual void Output(CYOutput &out, CYFlags flags) const;
1452 CYIdentifier *label_;
1454 CYBreak(CYIdentifier *label) :
1459 virtual CYStatement *Replace(CYContext &context);
1460 virtual void Output(CYOutput &out, CYFlags flags) const;
1466 CYExpression *value_;
1468 CYReturn(CYExpression *value) :
1473 virtual CYStatement *Replace(CYContext &context);
1474 virtual void Output(CYOutput &out, CYFlags flags) const;
1480 virtual CYStatement *Collapse(CYContext &context);
1481 virtual CYStatement *Replace(CYContext &context);
1482 virtual void Output(CYOutput &out, CYFlags flags) const;
1490 CYFinally(CYStatement *statements) :
1495 void Replace(CYContext &context);
1496 virtual void Output(CYOutput &out) const;
1505 CYIdentifier *name_;
1508 Catch(CYIdentifier *name, CYStatement *statements) :
1514 void Replace(CYContext &context);
1515 virtual void Output(CYOutput &out) const;
1523 CYFinally *finally_;
1525 Try(CYStatement *statements, Catch *_catch, CYFinally *finally) :
1532 virtual CYStatement *Replace(CYContext &context);
1533 virtual void Output(CYOutput &out, CYFlags flags) const;
1539 CYExpression *value_;
1541 Throw(CYExpression *value) :
1546 virtual CYStatement *Replace(CYContext &context);
1547 virtual void Output(CYOutput &out, CYFlags flags) const;
1555 CYExpression *scope_;
1558 CYWith(CYExpression *scope, CYStatement *code) :
1564 virtual CYStatement *Replace(CYContext &context);
1565 virtual void Output(CYOutput &out, CYFlags flags) const;
1571 CYExpression *value_;
1574 CYSwitch(CYExpression *value, CYClause *clauses) :
1580 virtual CYStatement *Replace(CYContext &context);
1581 virtual void Output(CYOutput &out, CYFlags flags) const;
1584 struct CYCondition :
1587 CYExpression *test_;
1588 CYExpression *true_;
1589 CYExpression *false_;
1591 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
1600 virtual CYExpression *Replace(CYContext &context);
1601 virtual void Output(CYOutput &out, CYFlags flags) const;
1604 struct CYAddressOf :
1607 CYAddressOf(CYExpression *rhs) :
1612 virtual const char *Operator() const {
1618 virtual CYExpression *Replace(CYContext &context);
1624 CYIndirect(CYExpression *rhs) :
1629 virtual const char *Operator() const {
1635 virtual CYExpression *Replace(CYContext &context);
1639 virtual CYExpression *Replace(CYContext &context);
1641 #define CYPostfix_(op, name, args...) \
1642 struct CY ## name : \
1645 CY ## name(CYExpression *lhs) : \
1650 virtual const char *Operator() const { \
1655 #define CYPrefix_(alphabetic, op, name, args...) \
1656 struct CY ## name : \
1659 CY ## name(CYExpression *rhs) : \
1664 CYAlphabetic(alphabetic) \
1666 virtual const char *Operator() const { \
1671 #define CYInfix_(alphabetic, precedence, op, name, args...) \
1672 struct CY ## name : \
1675 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
1680 CYAlphabetic(alphabetic) \
1681 CYPrecedence(precedence) \
1683 virtual const char *Operator() const { \
1688 #define CYAssignment_(op, name, args...) \
1689 struct CY ## name ## Assign : \
1692 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
1693 CYAssignment(lhs, rhs) \
1697 virtual const char *Operator() const { \
1702 CYPostfix_("++", PostIncrement)
1703 CYPostfix_("--", PostDecrement)
1705 CYPrefix_(true, "delete", Delete)
1706 CYPrefix_(true, "void", Void)
1707 CYPrefix_(true, "typeof", TypeOf)
1708 CYPrefix_(false, "++", PreIncrement)
1709 CYPrefix_(false, "--", PreDecrement)
1710 CYPrefix_(false, "+", Affirm)
1711 CYPrefix_(false, "-", Negate)
1712 CYPrefix_(false, "~", BitwiseNot)
1713 CYPrefix_(false, "!", LogicalNot)
1715 CYInfix_(false, 5, "*", Multiply)
1716 CYInfix_(false, 5, "/", Divide)
1717 CYInfix_(false, 5, "%", Modulus)
1718 CYInfix_(false, 6, "+", Add, CYReplace)
1719 CYInfix_(false, 6, "-", Subtract)
1720 CYInfix_(false, 7, "<<", ShiftLeft)
1721 CYInfix_(false, 7, ">>", ShiftRightSigned)
1722 CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
1723 CYInfix_(false, 8, "<", Less)
1724 CYInfix_(false, 8, ">", Greater)
1725 CYInfix_(false, 8, "<=", LessOrEqual)
1726 CYInfix_(false, 8, ">=", GreaterOrEqual)
1727 CYInfix_(true, 8, "instanceof", InstanceOf)
1728 CYInfix_(true, 8, "in", In)
1729 CYInfix_(false, 9, "==", Equal)
1730 CYInfix_(false, 9, "!=", NotEqual)
1731 CYInfix_(false, 9, "===", Identical)
1732 CYInfix_(false, 9, "!==", NotIdentical)
1733 CYInfix_(false, 10, "&", BitwiseAnd)
1734 CYInfix_(false, 11, "^", BitwiseXOr)
1735 CYInfix_(false, 12, "|", BitwiseOr)
1736 CYInfix_(false, 13, "&&", LogicalAnd)
1737 CYInfix_(false, 14, "||", LogicalOr)
1739 CYAssignment_("=", )
1740 CYAssignment_("*=", Multiply)
1741 CYAssignment_("/=", Divide)
1742 CYAssignment_("%=", Modulus)
1743 CYAssignment_("+=", Add)
1744 CYAssignment_("-=", Subtract)
1745 CYAssignment_("<<=", ShiftLeft)
1746 CYAssignment_(">>=", ShiftRightSigned)
1747 CYAssignment_(">>>=", ShiftRightUnsigned)
1748 CYAssignment_("&=", BitwiseAnd)
1749 CYAssignment_("^=", BitwiseXOr)
1750 CYAssignment_("|=", BitwiseOr)
1752 #endif/*CYPARSER_HPP*/