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 :
244 CYIdentifier *replace_;
246 CYIdentifier(const char *word) :
252 virtual const char *Word() const;
253 CYIdentifier *Replace(CYContext &context);
261 CYComment(const char *value) :
266 virtual CYStatement *Replace(CYContext &context);
267 virtual void Output(CYOutput &out, CYFlags flags) const;
274 CYStatement *statement_;
276 CYLabel(CYIdentifier *name, CYStatement *statement) :
278 statement_(statement)
282 virtual CYStatement *Replace(CYContext &context);
283 virtual void Output(CYOutput &out, CYFlags flags) const;
287 std::binary_function<const char *, const char *, bool>
289 _finline bool operator ()(const char *lhs, const char *rhs) const {
290 return strcmp(lhs, rhs) < 0;
294 struct CYIdentifierValueLess :
295 std::binary_function<CYIdentifier *, CYIdentifier *, bool>
297 _finline bool operator ()(CYIdentifier *lhs, CYIdentifier *rhs) const {
298 return CStringLess()(lhs->Word(), rhs->Word());
302 enum CYIdentifierFlags {
303 CYIdentifierArgument,
304 CYIdentifierInternal,
308 typedef std::set<CYIdentifier *, CYIdentifierValueLess> CYIdentifierValueSet;
309 typedef std::set<CYIdentifier *> CYIdentifierAddressSet;
310 typedef std::map<CYIdentifier *, CYIdentifierFlags> CYIdentifierAddressFlagsMap;
314 CYIdentifierValueSet identifiers_;
315 CYIdentifierAddressFlagsMap internal_;
324 void Add(CYContext &context, CYIdentifierAddressSet &external);
325 void Scope(CYContext &context, CYStatement *&statements);
332 CYStatement *statements_;
334 CYProgram(CYStatement *statements) :
335 statements_(statements)
339 virtual void Replace(CYContext &context);
341 virtual void Output(CYOutput &out) const;
348 CYStatement *statements_;
351 CYBlock(CYStatement *statements, CYScope *scope = NULL) :
352 statements_(statements),
357 operator CYStatement *() const {
361 void AddPrev(CYStatement *statement) {
362 CYStatement *last(statement);
363 while (last->next_ != NULL)
365 last->SetNext(statements_);
366 statements_ = statement;
369 virtual CYStatement *Replace(CYContext &context);
371 virtual void Output(CYOutput &out) const;
372 virtual void Output(CYOutput &out, CYFlags flags) const;
400 std::string filename_;
404 cy::location location_;
405 std::string message_;
408 typedef std::vector<Error> Errors;
415 void ScannerDestroy();
418 CYDriver(const std::string &filename);
421 Condition GetCondition();
422 void SetCondition(Condition condition);
424 void PushCondition(Condition condition);
427 void Warning(const cy::location &location, const char *message);
430 struct CYForInitialiser {
431 virtual ~CYForInitialiser() {
434 virtual void For(CYOutput &out) const = 0;
435 virtual CYExpression *Replace(CYContext &context) = 0;
438 struct CYForInInitialiser {
439 virtual ~CYForInInitialiser() {
442 virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
443 virtual const char *ForEachIn() const = 0;
444 virtual CYExpression *ForEachIn(CYContext &out) = 0;
445 virtual CYExpression *Replace(CYContext &context) = 0;
451 struct CYExpression :
452 CYNext<CYExpression>,
458 virtual unsigned Precedence() const = 0;
460 virtual bool RightHand() const {
464 virtual void For(CYOutput &out) const;
465 virtual void ForIn(CYOutput &out, CYFlags flags) const;
467 virtual const char *ForEachIn() const;
468 virtual CYExpression *ForEachIn(CYContext &out);
470 virtual void Output(CYOutput &out) const;
471 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
472 void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
474 virtual CYExpression *ClassName(CYContext &context, bool object);
475 virtual void ClassName(CYOutput &out, bool object) const;
477 CYExpression *ReplaceAll(CYContext &context);
479 virtual CYExpression *Replace(CYContext &context) = 0;
481 virtual CYExpression *Primitive(CYContext &context) {
485 virtual CYNumber *Number(CYContext &context) {
489 virtual CYString *String(CYContext &context) {
493 virtual const char *Word() const {
498 #define CYAlphabetic(value) \
499 virtual bool Alphabetic() const { \
503 #define CYPrecedence(value) \
504 virtual unsigned Precedence() const { \
508 #define CYRightHand(value) \
509 virtual bool RightHand() const { \
516 CYExpression *expressions_;
518 CYCompound(CYExpression *expressions = NULL) :
519 expressions_(expressions)
523 void AddPrev(CYExpression *expression) {
524 CYExpression *last(expression);
525 while (last->next_ != NULL)
527 last->SetNext(expressions_);
528 expressions_ = expression;
533 virtual CYExpression *Replace(CYContext &context);
534 void Output(CYOutput &out, CYFlags flags) const;
537 struct CYFunctionParameter :
538 CYNext<CYFunctionParameter>,
543 CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) :
544 CYNext<CYFunctionParameter>(next),
549 void Replace(CYContext &context);
550 virtual void Output(CYOutput &out) const;
553 struct CYComprehension :
554 CYNext<CYComprehension>,
557 virtual const char *Name() const = 0;
559 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
560 CYFunctionParameter *Parameters(CYContext &context) const;
561 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
562 virtual void Output(CYOutput &out) const = 0;
565 struct CYForInComprehension :
571 CYForInComprehension(CYIdentifier *name, CYExpression *set) :
577 virtual const char *Name() const {
578 return name_->Word();
581 virtual CYFunctionParameter *Parameter(CYContext &context) const;
582 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
583 virtual void Output(CYOutput &out) const;
586 struct CYForEachInComprehension :
592 CYForEachInComprehension(CYIdentifier *name, CYExpression *set) :
598 virtual const char *Name() const {
599 return name_->Word();
602 virtual CYFunctionParameter *Parameter(CYContext &context) const;
603 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
604 virtual void Output(CYOutput &out) const;
607 struct CYIfComprehension :
612 CYIfComprehension(CYExpression *test) :
617 virtual const char *Name() const {
621 virtual CYFunctionParameter *Parameter(CYContext &context) const;
622 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
623 virtual void Output(CYOutput &out) const;
626 struct CYArrayComprehension :
629 CYExpression *expression_;
630 CYComprehension *comprehensions_;
632 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
633 expression_(expression),
634 comprehensions_(comprehensions)
640 virtual CYExpression *Replace(CYContext &context);
641 virtual void Output(CYOutput &out, CYFlags flags) const;
654 virtual CYExpression *Replace(CYContext &context);
668 CYRange(uint64_t lo, uint64_t hi) :
673 bool operator [](uint8_t value) const {
674 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
677 void operator()(uint8_t value) {
680 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
684 extern CYRange DigitRange_;
685 extern CYRange WordStartRange_;
686 extern CYRange WordEndRange_;
701 CYString(const char *value) :
707 CYString(const char *value, size_t size) :
713 CYString(const CYWord *word) :
714 value_(word->Word()),
715 size_(strlen(value_))
719 const char *Value() const {
723 virtual const char *Word() const;
725 virtual CYNumber *Number(CYContext &context);
726 virtual CYString *String(CYContext &context);
728 CYString *Concat(CYContext &out, CYString *rhs) const;
729 virtual void Output(CYOutput &out, CYFlags flags) const;
730 virtual void PropertyName(CYOutput &out) const;
739 CYNumber(double value) :
744 double Value() const {
748 virtual CYNumber *Number(CYContext &context);
749 virtual CYString *String(CYContext &context);
751 virtual void Output(CYOutput &out, CYFlags flags) const;
752 virtual void PropertyName(CYOutput &out) const;
760 CYRegEx(const char *value) :
765 const char *Value() const {
769 virtual void Output(CYOutput &out, CYFlags flags) const;
781 virtual CYNumber *Number(CYContext &context);
782 virtual CYString *String(CYContext &context);
784 virtual void Output(CYOutput &out, CYFlags flags) const;
796 virtual CYExpression *Replace(CYContext &context);
797 virtual void Output(CYOutput &out, CYFlags flags) const;
803 virtual bool Value() const = 0;
804 virtual void Output(CYOutput &out, CYFlags flags) const;
816 virtual bool Value() const {
820 virtual CYNumber *Number(CYContext &context);
821 virtual CYString *String(CYContext &context);
833 virtual bool Value() const {
837 virtual CYNumber *Number(CYContext &context);
838 virtual CYString *String(CYContext &context);
846 CYVariable(CYIdentifier *name) :
854 virtual CYExpression *Replace(CYContext &context);
855 virtual void Output(CYOutput &out, CYFlags flags) const;
863 CYPrefix(CYExpression *rhs) :
868 virtual bool Alphabetic() const = 0;
869 virtual const char *Operator() const = 0;
873 virtual CYExpression *Replace(CYContext &context);
874 virtual void Output(CYOutput &out, CYFlags flags) const;
883 CYInfix(CYExpression *lhs, CYExpression *rhs) :
889 void SetLeft(CYExpression *lhs) {
893 virtual bool Alphabetic() const = 0;
894 virtual const char *Operator() const = 0;
896 virtual CYExpression *Replace(CYContext &context);
897 virtual void Output(CYOutput &out, CYFlags flags) const;
905 CYPostfix(CYExpression *lhs) :
910 virtual const char *Operator() const = 0;
914 virtual CYExpression *Replace(CYContext &context);
915 virtual void Output(CYOutput &out, CYFlags flags) const;
918 struct CYAssignment :
924 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
930 void SetLeft(CYExpression *lhs) {
934 virtual const char *Operator() const = 0;
938 virtual CYExpression *Replace(CYContext &context);
939 virtual void Output(CYOutput &out, CYFlags flags) const;
947 CYExpression *value_;
949 CYArgument(CYExpression *value, CYArgument *next = NULL) :
950 CYNext<CYArgument>(next),
956 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
957 CYNext<CYArgument>(next),
963 void Replace(CYContext &context);
964 void Output(CYOutput &out) const;
981 CYStatement *statements_;
983 CYClause(CYExpression *_case, CYStatement *statements) :
985 statements_(statements)
989 void Replace(CYContext &context);
990 virtual void Output(CYOutput &out) const;
997 CYExpression *value_;
999 CYElement(CYExpression *value, CYElement *next) :
1000 CYNext<CYElement>(next),
1005 void Replace(CYContext &context);
1006 void Output(CYOutput &out) const;
1012 CYElement *elements_;
1014 CYArray(CYElement *elements = NULL) :
1019 virtual CYExpression *Replace(CYContext &context);
1020 virtual void Output(CYOutput &out, CYFlags flags) const;
1027 CYPropertyName *name_;
1028 CYExpression *value_;
1030 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1031 CYNext<CYProperty>(next),
1037 void Replace(CYContext &context);
1038 virtual void Output(CYOutput &out) const;
1041 struct CYDeclaration :
1044 CYIdentifier *identifier_;
1045 CYExpression *initialiser_;
1047 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
1048 identifier_(identifier),
1049 initialiser_(initialiser)
1053 virtual void ForIn(CYOutput &out, CYFlags flags) const;
1055 virtual const char *ForEachIn() const;
1056 virtual CYExpression *ForEachIn(CYContext &out);
1058 virtual CYExpression *Replace(CYContext &context);
1059 virtual CYAssignment *Assignment(CYContext &context);
1061 virtual void Output(CYOutput &out, CYFlags flags) const;
1064 struct CYDeclarations :
1065 CYNext<CYDeclarations>,
1069 CYDeclaration *declaration_;
1071 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
1072 CYNext<CYDeclarations>(next),
1073 declaration_(declaration)
1077 virtual void For(CYOutput &out) const;
1079 virtual CYCompound *Replace(CYContext &context);
1080 CYProperty *Property(CYContext &context);
1082 virtual void Output(CYOutput &out) const;
1083 virtual void Output(CYOutput &out, CYFlags flags) const;
1089 CYDeclarations *declarations_;
1091 CYVar(CYDeclarations *declarations) :
1092 declarations_(declarations)
1096 virtual CYStatement *Replace(CYContext &context);
1097 virtual void Output(CYOutput &out, CYFlags flags) const;
1103 CYDeclarations *declarations_;
1106 CYLet(CYDeclarations *declarations, CYStatement *statements) :
1107 declarations_(declarations),
1112 virtual CYStatement *Replace(CYContext &context);
1113 virtual void Output(CYOutput &out, CYFlags flags) const;
1119 CYForInitialiser *initialiser_;
1120 CYExpression *test_;
1121 CYExpression *increment_;
1124 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
1125 initialiser_(initialiser),
1127 increment_(increment),
1132 virtual CYStatement *Replace(CYContext &context);
1133 virtual void Output(CYOutput &out, CYFlags flags) const;
1139 CYForInInitialiser *initialiser_;
1143 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1144 initialiser_(initialiser),
1150 virtual CYStatement *Replace(CYContext &context);
1151 virtual void Output(CYOutput &out, CYFlags flags) const;
1154 struct CYForEachIn :
1157 CYForInInitialiser *initialiser_;
1161 CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1162 initialiser_(initialiser),
1168 virtual CYStatement *Replace(CYContext &context);
1169 virtual void Output(CYOutput &out, CYFlags flags) const;
1175 CYProperty *properties_;
1177 CYObject(CYProperty *properties) :
1178 properties_(properties)
1182 virtual CYExpression *Replace(CYContext &context);
1183 void Output(CYOutput &out, CYFlags flags) const;
1189 CYExpression *object_;
1190 CYExpression *property_;
1192 CYMember(CYExpression *object, CYExpression *property) :
1198 void SetLeft(CYExpression *object) {
1202 void Replace_(CYContext &context);
1205 struct CYDirectMember :
1208 CYDirectMember(CYExpression *object, CYExpression *property) :
1209 CYMember(object, property)
1216 virtual CYExpression *Replace(CYContext &context);
1217 virtual void Output(CYOutput &out, CYFlags flags) const;
1220 struct CYIndirectMember :
1223 CYIndirectMember(CYExpression *object, CYExpression *property) :
1224 CYMember(object, property)
1231 virtual CYExpression *Replace(CYContext &context);
1232 virtual void Output(CYOutput &out, CYFlags flags) const;
1238 CYExpression *constructor_;
1239 CYArgument *arguments_;
1241 CYNew(CYExpression *constructor, CYArgument *arguments) :
1242 constructor_(constructor),
1243 arguments_(arguments)
1247 virtual unsigned Precedence() const {
1248 return arguments_ == NULL ? 2 : 1;
1253 virtual CYExpression *Replace(CYContext &context);
1254 virtual void Output(CYOutput &out, CYFlags flags) const;
1260 CYExpression *function_;
1261 CYArgument *arguments_;
1263 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
1264 function_(function),
1265 arguments_(arguments)
1272 virtual CYExpression *Replace(CYContext &context);
1273 virtual void Output(CYOutput &out, CYFlags flags) const;
1279 CYExpression *test_;
1281 CYStatement *false_;
1283 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
1290 virtual CYStatement *Replace(CYContext &context);
1291 virtual void Output(CYOutput &out, CYFlags flags) const;
1297 CYExpression *test_;
1300 CYDoWhile(CYExpression *test, CYStatement *code) :
1306 virtual CYStatement *Replace(CYContext &context);
1307 virtual void Output(CYOutput &out, CYFlags flags) const;
1313 CYExpression *test_;
1316 CYWhile(CYExpression *test, CYStatement *code) :
1322 virtual CYStatement *Replace(CYContext &context);
1323 virtual void Output(CYOutput &out, CYFlags flags) const;
1329 CYIdentifier *name_;
1330 CYFunctionParameter *parameters_;
1333 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1335 parameters_(parameters),
1336 code_(statements, this)
1340 virtual ~CYFunction() {
1343 virtual void Replace_(CYContext &context);
1344 virtual void Output(CYOutput &out, CYFlags flags) const;
1347 struct CYFunctionExpression :
1351 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1352 CYFunction(name, parameters, statements)
1359 virtual CYExpression *Replace(CYContext &context);
1360 virtual void Output(CYOutput &out, CYFlags flags) const;
1363 struct CYFunctionStatement :
1367 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1368 CYFunction(name, parameters, statements)
1372 virtual CYStatement *Replace(CYContext &context);
1373 virtual void Output(CYOutput &out, CYFlags flags) const;
1379 CYExpression *expression_;
1381 CYExpress(CYExpression *expression) :
1382 expression_(expression)
1384 if (expression == NULL)
1388 virtual CYStatement *Collapse(CYContext &context);
1389 virtual CYStatement *Replace(CYContext &context);
1390 virtual void Output(CYOutput &out, CYFlags flags) const;
1396 CYIdentifier *label_;
1398 CYContinue(CYIdentifier *label) :
1403 virtual CYStatement *Replace(CYContext &context);
1404 virtual void Output(CYOutput &out, CYFlags flags) const;
1410 CYIdentifier *label_;
1412 CYBreak(CYIdentifier *label) :
1417 virtual CYStatement *Replace(CYContext &context);
1418 virtual void Output(CYOutput &out, CYFlags flags) const;
1424 CYExpression *value_;
1426 CYReturn(CYExpression *value) :
1431 virtual CYStatement *Replace(CYContext &context);
1432 virtual void Output(CYOutput &out, CYFlags flags) const;
1438 virtual CYStatement *Collapse(CYContext &context);
1439 virtual CYStatement *Replace(CYContext &context);
1440 virtual void Output(CYOutput &out, CYFlags flags) const;
1448 CYFinally(CYStatement *statements) :
1453 void Replace(CYContext &context);
1454 virtual void Output(CYOutput &out) const;
1463 CYIdentifier *name_;
1466 Catch(CYIdentifier *name, CYStatement *statements) :
1472 void Replace(CYContext &context);
1473 virtual void Output(CYOutput &out) const;
1481 CYFinally *finally_;
1483 Try(CYStatement *statements, Catch *_catch, CYFinally *finally) :
1490 virtual CYStatement *Replace(CYContext &context);
1491 virtual void Output(CYOutput &out, CYFlags flags) const;
1497 CYExpression *value_;
1499 Throw(CYExpression *value) :
1504 virtual CYStatement *Replace(CYContext &context);
1505 virtual void Output(CYOutput &out, CYFlags flags) const;
1513 CYExpression *scope_;
1516 CYWith(CYExpression *scope, CYStatement *code) :
1522 virtual CYStatement *Replace(CYContext &context);
1523 virtual void Output(CYOutput &out, CYFlags flags) const;
1529 CYExpression *value_;
1532 CYSwitch(CYExpression *value, CYClause *clauses) :
1538 virtual CYStatement *Replace(CYContext &context);
1539 virtual void Output(CYOutput &out, CYFlags flags) const;
1542 struct CYCondition :
1545 CYExpression *test_;
1546 CYExpression *true_;
1547 CYExpression *false_;
1549 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
1558 virtual CYExpression *Replace(CYContext &context);
1559 virtual void Output(CYOutput &out, CYFlags flags) const;
1562 struct CYAddressOf :
1565 CYAddressOf(CYExpression *rhs) :
1570 virtual const char *Operator() const {
1576 virtual CYExpression *Replace(CYContext &context);
1582 CYIndirect(CYExpression *rhs) :
1587 virtual const char *Operator() const {
1593 virtual CYExpression *Replace(CYContext &context);
1597 virtual CYExpression *Replace(CYContext &context);
1599 #define CYPostfix_(op, name, args...) \
1600 struct CY ## name : \
1603 CY ## name(CYExpression *lhs) : \
1608 virtual const char *Operator() const { \
1613 #define CYPrefix_(alphabetic, op, name, args...) \
1614 struct CY ## name : \
1617 CY ## name(CYExpression *rhs) : \
1622 CYAlphabetic(alphabetic) \
1624 virtual const char *Operator() const { \
1629 #define CYInfix_(alphabetic, precedence, op, name, args...) \
1630 struct CY ## name : \
1633 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
1638 CYAlphabetic(alphabetic) \
1639 CYPrecedence(precedence) \
1641 virtual const char *Operator() const { \
1646 #define CYAssignment_(op, name, args...) \
1647 struct CY ## name ## Assign : \
1650 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
1651 CYAssignment(lhs, rhs) \
1655 virtual const char *Operator() const { \
1660 CYPostfix_("++", PostIncrement)
1661 CYPostfix_("--", PostDecrement)
1663 CYPrefix_(true, "delete", Delete)
1664 CYPrefix_(true, "void", Void)
1665 CYPrefix_(true, "typeof", TypeOf)
1666 CYPrefix_(false, "++", PreIncrement)
1667 CYPrefix_(false, "--", PreDecrement)
1668 CYPrefix_(false, "+", Affirm)
1669 CYPrefix_(false, "-", Negate)
1670 CYPrefix_(false, "~", BitwiseNot)
1671 CYPrefix_(false, "!", LogicalNot)
1673 CYInfix_(false, 5, "*", Multiply)
1674 CYInfix_(false, 5, "/", Divide)
1675 CYInfix_(false, 5, "%", Modulus)
1676 CYInfix_(false, 6, "+", Add, CYReplace)
1677 CYInfix_(false, 6, "-", Subtract)
1678 CYInfix_(false, 7, "<<", ShiftLeft)
1679 CYInfix_(false, 7, ">>", ShiftRightSigned)
1680 CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
1681 CYInfix_(false, 8, "<", Less)
1682 CYInfix_(false, 8, ">", Greater)
1683 CYInfix_(false, 8, "<=", LessOrEqual)
1684 CYInfix_(false, 8, ">=", GreaterOrEqual)
1685 CYInfix_(true, 8, "instanceof", InstanceOf)
1686 CYInfix_(true, 8, "in", In)
1687 CYInfix_(false, 9, "==", Equal)
1688 CYInfix_(false, 9, "!=", NotEqual)
1689 CYInfix_(false, 9, "===", Identical)
1690 CYInfix_(false, 9, "!==", NotIdentical)
1691 CYInfix_(false, 10, "&", BitwiseAnd)
1692 CYInfix_(false, 11, "^", BitwiseXOr)
1693 CYInfix_(false, 12, "|", BitwiseOr)
1694 CYInfix_(false, 13, "&&", LogicalAnd)
1695 CYInfix_(false, 14, "||", LogicalOr)
1697 CYAssignment_("=", )
1698 CYAssignment_("*=", Multiply)
1699 CYAssignment_("/=", Divide)
1700 CYAssignment_("%=", Modulus)
1701 CYAssignment_("+=", Add)
1702 CYAssignment_("-=", Subtract)
1703 CYAssignment_("<<=", ShiftLeft)
1704 CYAssignment_(">>=", ShiftRightSigned)
1705 CYAssignment_(">>>=", ShiftRightUnsigned)
1706 CYAssignment_("&=", BitwiseAnd)
1707 CYAssignment_("^=", BitwiseXOr)
1708 CYAssignment_("|=", BitwiseOr)
1710 #endif/*CYPARSER_HPP*/