1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2010 Jay Freeman (saurik)
5 /* GNU Lesser General Public License, Version 3 {{{ */
7 * Cycript is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
12 * Cycript is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with Cycript. If not, see <http://www.gnu.org/licenses/>.
25 // XXX: wtf is this here?!
38 #include "location.hh"
39 #include "Pooling.hpp"
40 #include "Options.hpp"
44 template <typename Type_>
58 void SetNext(Type_ *next) {
67 virtual void Output(struct CYOutput &out) const = 0;
85 CYOutput(std::ostream &out, CYOptions &options) :
95 void Check(char value);
98 CYOutput &operator <<(char rhs);
99 CYOutput &operator <<(const char *rhs);
101 _finline CYOutput &operator <<(const CYThing *rhs) {
107 _finline CYOutput &operator <<(const CYThing &rhs) {
113 struct CYPropertyName {
114 virtual void PropertyName(CYOutput &out) const = 0;
116 virtual ~CYPropertyName() {
130 CYNoBrace = (1 << 0),
131 CYNoFunction = (1 << 1),
134 CYNoRightHand = (1 << 4),
135 CYNoDangle = (1 << 5),
136 CYNoInteger = (1 << 6),
137 CYNoBF = (CYNoBrace | CYNoFunction),
143 virtual ~CYStatement() {
146 void Single(CYOutput &out, CYFlags flags) const;
147 void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
149 CYStatement *ReplaceAll(CYContext &context);
150 virtual CYStatement *Collapse(CYContext &context);
152 virtual CYStatement *Replace(CYContext &context) = 0;
155 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
158 struct CYStatements {
168 operator CYStatement *() const {
172 CYStatements &operator ->*(CYStatement *next) {
174 if (first_ == NULL) {
177 } else for (;; last_ = last_->next_)
178 if (last_->next_ == NULL) {
188 virtual ~CYClassName() {
191 virtual CYExpression *ClassName(CYContext &context, bool object) = 0;
192 virtual void ClassName(CYOutput &out, bool object) const = 0;
202 CYWord(const char *word) :
207 void Set(const char *value) {
211 virtual const char *Word() const;
212 virtual void Output(CYOutput &out) const;
214 virtual CYExpression *ClassName(CYContext &context, bool object);
215 virtual void ClassName(CYOutput &out, bool object) const;
216 virtual void PropertyName(CYOutput &out) const;
219 _finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) {
221 return lhs << rhs.Word();
224 struct CYIdentifier :
225 CYNext<CYIdentifier>,
228 CYIdentifier *replace_;
232 CYIdentifier(const char *word) :
240 virtual const char *Word() const;
241 CYIdentifier *Replace(CYContext &context);
249 CYComment(const char *value) :
254 virtual CYStatement *Replace(CYContext &context);
255 virtual void Output(CYOutput &out, CYFlags flags) const;
262 CYStatement *statement_;
264 CYLabel(CYIdentifier *name, CYStatement *statement) :
266 statement_(statement)
270 virtual CYStatement *Replace(CYContext &context);
271 virtual void Output(CYOutput &out, CYFlags flags) const;
274 struct CYCStringLess :
275 std::binary_function<const char *, const char *, bool>
277 _finline bool operator ()(const char *lhs, const char *rhs) const {
278 return strcmp(lhs, rhs) < 0;
282 struct CYIdentifierValueLess :
283 std::binary_function<CYIdentifier *, CYIdentifier *, bool>
285 _finline bool operator ()(CYIdentifier *lhs, CYIdentifier *rhs) const {
286 return CYCStringLess()(lhs->Word(), rhs->Word());
290 enum CYIdentifierFlags {
291 CYIdentifierArgument,
292 CYIdentifierVariable,
298 typedef std::set<const char *, CYCStringLess> CYCStringSet;
299 typedef std::set<CYIdentifier *, CYIdentifierValueLess> CYIdentifierValueSet;
300 typedef std::map<CYIdentifier *, CYIdentifierFlags> CYIdentifierAddressFlagsMap;
302 struct CYIdentifierUsage {
303 CYIdentifier *identifier_;
307 typedef std::vector<CYIdentifierUsage> CYIdentifierUsageVector;
309 // XXX: strategy pattern, maybe subclass
320 CYStatement *&statements_;
324 CYIdentifierAddressFlagsMap internal_;
325 CYIdentifierValueSet identifiers_;
327 CYScope(CYScopeType type, CYContext &context, CYStatement *&statements);
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);
340 CYStatement *statements_;
342 CYProgram(CYStatement *statements) :
343 statements_(statements)
347 virtual void Replace(CYContext &context);
348 virtual void Output(CYOutput &out) const;
357 CYIdentifierUsageVector rename_;
359 CYNonLocal *nonlocal_;
360 CYNonLocal *nextlocal_;
363 CYContext(CYOptions &options) :
372 virtual ~CYContext() {
375 template <typename Type_>
376 void Replace(Type_ *&value) {
377 for (;;) if (value == NULL)
380 Type_ *replace(value->Replace(*this));
381 if (replace != value)
387 void NonLocal(CYStatement *&statements);
388 CYIdentifier *Unique();
392 CYIdentifier *identifier_;
399 CYIdentifier *Target(CYContext &context) {
400 if (identifier_ == NULL)
401 identifier_ = context.Unique();
410 CYStatement *statements_;
412 CYBlock(CYStatement *statements) :
413 statements_(statements)
417 operator CYStatement *() const {
421 void AddPrev(CYStatement *statement) {
422 CYStatement *last(statement);
423 while (last->next_ != NULL)
425 last->SetNext(statements_);
426 statements_ = statement;
429 virtual CYStatement *Replace(CYContext &context);
431 virtual void Output(CYOutput &out) const;
432 virtual void Output(CYOutput &out, CYFlags flags) const;
458 std::string filename_;
462 cy::location location_;
463 std::string message_;
466 typedef std::vector<Error> Errors;
474 CYExpression *context_;
476 Context(CYExpression *context) :
481 typedef std::vector<CYWord *> Words;
485 typedef std::vector<Context> Contexts;
488 CYExpression *context_;
500 void ScannerDestroy();
503 CYDriver(const std::string &filename = "");
506 Condition GetCondition();
507 void SetCondition(Condition condition);
509 void PushCondition(Condition condition);
512 void Warning(const cy::location &location, const char *message);
515 struct CYForInitialiser {
516 virtual ~CYForInitialiser() {
519 virtual void For(CYOutput &out) const = 0;
520 virtual CYExpression *Replace(CYContext &context) = 0;
523 struct CYForInInitialiser {
524 virtual ~CYForInInitialiser() {
527 virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
528 virtual const char *ForEachIn() const = 0;
529 virtual CYExpression *ForEachIn(CYContext &out) = 0;
530 virtual CYExpression *Replace(CYContext &context) = 0;
536 struct CYExpression :
537 CYNext<CYExpression>,
543 virtual unsigned Precedence() const = 0;
545 virtual bool RightHand() const {
549 virtual void For(CYOutput &out) const;
550 virtual void ForIn(CYOutput &out, CYFlags flags) const;
552 virtual const char *ForEachIn() const;
553 virtual CYExpression *ForEachIn(CYContext &out);
555 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
557 virtual void Output(CYOutput &out) const;
558 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
559 void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
561 virtual CYExpression *ClassName(CYContext &context, bool object);
562 virtual void ClassName(CYOutput &out, bool object) const;
564 virtual CYExpression *Replace(CYContext &context) = 0;
566 virtual CYExpression *Primitive(CYContext &context) {
570 virtual CYNumber *Number(CYContext &context) {
574 virtual CYString *String(CYContext &context) {
578 virtual const char *Word() const {
583 #define CYAlphabetic(value) \
584 virtual bool Alphabetic() const { \
588 #define CYPrecedence(value) \
589 virtual unsigned Precedence() const { \
593 #define CYRightHand(value) \
594 virtual bool RightHand() const { \
601 CYExpression *expressions_;
603 CYCompound(CYExpression *expressions = NULL) :
604 expressions_(expressions)
608 void AddPrev(CYExpression *expression) {
609 CYExpression *last(expression);
610 while (last->next_ != NULL)
612 last->SetNext(expressions_);
613 expressions_ = expression;
618 virtual CYExpression *Replace(CYContext &context);
619 void Output(CYOutput &out, CYFlags flags) const;
622 struct CYFunctionParameter :
623 CYNext<CYFunctionParameter>,
628 CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) :
629 CYNext<CYFunctionParameter>(next),
634 virtual CYFunctionParameter *Replace(CYContext &context, CYBlock &code);
635 virtual void Output(CYOutput &out) const;
638 struct CYOptionalFunctionParameter :
641 CYExpression *initializer_;
643 CYOptionalFunctionParameter(CYIdentifier *name, CYExpression *initializer, CYFunctionParameter *next = NULL) :
644 CYFunctionParameter(name, next),
645 initializer_(initializer)
649 virtual CYFunctionParameter *Replace(CYContext &context, CYBlock &code);
650 virtual void Output(CYOutput &out) const;
653 struct CYComprehension :
654 CYNext<CYComprehension>,
657 virtual const char *Name() const = 0;
659 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
660 CYFunctionParameter *Parameters(CYContext &context) const;
661 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
662 virtual void Output(CYOutput &out) const = 0;
665 struct CYForInComprehension :
671 CYForInComprehension(CYIdentifier *name, CYExpression *set) :
677 virtual const char *Name() const {
678 return name_->Word();
681 virtual CYFunctionParameter *Parameter(CYContext &context) const;
682 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
683 virtual void Output(CYOutput &out) const;
686 struct CYForEachInComprehension :
692 CYForEachInComprehension(CYIdentifier *name, CYExpression *set) :
698 virtual const char *Name() const {
699 return name_->Word();
702 virtual CYFunctionParameter *Parameter(CYContext &context) const;
703 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
704 virtual void Output(CYOutput &out) const;
707 struct CYIfComprehension :
712 CYIfComprehension(CYExpression *test) :
717 virtual const char *Name() const {
721 virtual CYFunctionParameter *Parameter(CYContext &context) const;
722 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
723 virtual void Output(CYOutput &out) const;
726 struct CYArrayComprehension :
729 CYExpression *expression_;
730 CYComprehension *comprehensions_;
732 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
733 expression_(expression),
734 comprehensions_(comprehensions)
740 virtual CYExpression *Replace(CYContext &context);
741 virtual void Output(CYOutput &out, CYFlags flags) const;
754 virtual CYExpression *Replace(CYContext &context);
768 CYRange(uint64_t lo, uint64_t hi) :
773 bool operator [](uint8_t value) const {
774 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
777 void operator()(uint8_t value) {
780 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
784 extern CYRange DigitRange_;
785 extern CYRange WordStartRange_;
786 extern CYRange WordEndRange_;
801 CYString(const char *value) :
807 CYString(const char *value, size_t size) :
813 CYString(const CYWord *word) :
814 value_(word->Word()),
815 size_(strlen(value_))
819 const char *Value() const {
823 virtual const char *Word() const;
825 virtual CYNumber *Number(CYContext &context);
826 virtual CYString *String(CYContext &context);
828 CYString *Concat(CYContext &out, CYString *rhs) const;
829 virtual void Output(CYOutput &out, CYFlags flags) const;
830 virtual void PropertyName(CYOutput &out) const;
839 CYNumber(double value) :
844 double Value() const {
848 virtual CYNumber *Number(CYContext &context);
849 virtual CYString *String(CYContext &context);
851 virtual void Output(CYOutput &out, CYFlags flags) const;
852 virtual void PropertyName(CYOutput &out) const;
860 CYRegEx(const char *value) :
865 const char *Value() const {
869 virtual void Output(CYOutput &out, CYFlags flags) const;
881 virtual CYNumber *Number(CYContext &context);
882 virtual CYString *String(CYContext &context);
884 virtual void Output(CYOutput &out, CYFlags flags) const;
896 virtual CYExpression *Replace(CYContext &context);
897 virtual void Output(CYOutput &out, CYFlags flags) const;
903 virtual bool Value() const = 0;
904 virtual void Output(CYOutput &out, CYFlags flags) const;
916 virtual bool Value() const {
920 virtual CYNumber *Number(CYContext &context);
921 virtual CYString *String(CYContext &context);
933 virtual bool Value() const {
937 virtual CYNumber *Number(CYContext &context);
938 virtual CYString *String(CYContext &context);
946 CYVariable(CYIdentifier *name) :
951 CYVariable(const char *name) :
952 name_(new($pool) CYIdentifier(name))
959 virtual CYExpression *Replace(CYContext &context);
960 virtual void Output(CYOutput &out, CYFlags flags) const;
968 CYPrefix(CYExpression *rhs) :
973 virtual bool Alphabetic() const = 0;
974 virtual const char *Operator() const = 0;
978 virtual CYExpression *Replace(CYContext &context);
979 virtual void Output(CYOutput &out, CYFlags flags) const;
988 CYInfix(CYExpression *lhs, CYExpression *rhs) :
994 void SetLeft(CYExpression *lhs) {
998 virtual bool Alphabetic() const = 0;
999 virtual const char *Operator() const = 0;
1001 virtual CYExpression *Replace(CYContext &context);
1002 virtual void Output(CYOutput &out, CYFlags flags) const;
1010 CYPostfix(CYExpression *lhs) :
1015 virtual const char *Operator() const = 0;
1019 virtual CYExpression *Replace(CYContext &context);
1020 virtual void Output(CYOutput &out, CYFlags flags) const;
1023 struct CYAssignment :
1029 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
1035 void SetLeft(CYExpression *lhs) {
1039 virtual const char *Operator() const = 0;
1043 virtual CYExpression *Replace(CYContext &context);
1044 virtual void Output(CYOutput &out, CYFlags flags) const;
1052 CYExpression *value_;
1054 CYArgument(CYExpression *value, CYArgument *next = NULL) :
1055 CYNext<CYArgument>(next),
1061 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
1062 CYNext<CYArgument>(next),
1068 void Replace(CYContext &context);
1069 void Output(CYOutput &out) const;
1085 CYExpression *case_;
1086 CYStatement *statements_;
1088 CYClause(CYExpression *_case, CYStatement *statements) :
1090 statements_(statements)
1094 void Replace(CYContext &context);
1095 virtual void Output(CYOutput &out) const;
1102 CYExpression *value_;
1104 CYElement(CYExpression *value, CYElement *next) :
1105 CYNext<CYElement>(next),
1110 void Replace(CYContext &context);
1111 void Output(CYOutput &out) const;
1117 CYElement *elements_;
1119 CYArray(CYElement *elements = NULL) :
1124 virtual CYExpression *Replace(CYContext &context);
1125 virtual void Output(CYOutput &out, CYFlags flags) const;
1132 CYPropertyName *name_;
1133 CYExpression *value_;
1135 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1136 CYNext<CYProperty>(next),
1142 void Replace(CYContext &context);
1143 virtual void Output(CYOutput &out) const;
1146 struct CYDeclaration :
1149 CYIdentifier *identifier_;
1150 CYExpression *initialiser_;
1152 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
1153 identifier_(identifier),
1154 initialiser_(initialiser)
1158 virtual void ForIn(CYOutput &out, CYFlags flags) const;
1160 virtual const char *ForEachIn() const;
1161 virtual CYExpression *ForEachIn(CYContext &out);
1163 virtual CYExpression *Replace(CYContext &context);
1164 virtual CYAssignment *Assignment(CYContext &context);
1166 virtual void Output(CYOutput &out, CYFlags flags) const;
1169 struct CYDeclarations :
1170 CYNext<CYDeclarations>,
1174 CYDeclaration *declaration_;
1176 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
1177 CYNext<CYDeclarations>(next),
1178 declaration_(declaration)
1182 virtual void For(CYOutput &out) const;
1184 virtual CYCompound *Replace(CYContext &context);
1185 CYProperty *Property(CYContext &context);
1187 virtual void Output(CYOutput &out) const;
1188 virtual void Output(CYOutput &out, CYFlags flags) const;
1194 CYDeclarations *declarations_;
1196 CYVar(CYDeclarations *declarations) :
1197 declarations_(declarations)
1201 virtual CYStatement *Replace(CYContext &context);
1202 virtual void Output(CYOutput &out, CYFlags flags) const;
1208 CYDeclarations *declarations_;
1211 CYLet(CYDeclarations *declarations, CYStatement *statements) :
1212 declarations_(declarations),
1217 virtual CYStatement *Replace(CYContext &context);
1218 virtual void Output(CYOutput &out, CYFlags flags) const;
1224 CYForInitialiser *initialiser_;
1225 CYExpression *test_;
1226 CYExpression *increment_;
1229 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
1230 initialiser_(initialiser),
1232 increment_(increment),
1237 virtual CYStatement *Replace(CYContext &context);
1238 virtual void Output(CYOutput &out, CYFlags flags) const;
1244 CYForInInitialiser *initialiser_;
1248 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1249 initialiser_(initialiser),
1255 virtual CYStatement *Replace(CYContext &context);
1256 virtual void Output(CYOutput &out, CYFlags flags) const;
1259 struct CYForEachIn :
1262 CYForInInitialiser *initialiser_;
1266 CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1267 initialiser_(initialiser),
1273 virtual CYStatement *Replace(CYContext &context);
1274 virtual void Output(CYOutput &out, CYFlags flags) const;
1280 CYProperty *properties_;
1282 CYObject(CYProperty *properties = NULL) :
1283 properties_(properties)
1287 virtual CYExpression *Replace(CYContext &context);
1288 void Output(CYOutput &out, CYFlags flags) const;
1294 CYExpression *object_;
1295 CYExpression *property_;
1297 CYMember(CYExpression *object, CYExpression *property) :
1303 void SetLeft(CYExpression *object) {
1307 void Replace_(CYContext &context);
1310 struct CYDirectMember :
1313 CYDirectMember(CYExpression *object, CYExpression *property) :
1314 CYMember(object, property)
1321 virtual CYExpression *Replace(CYContext &context);
1322 virtual void Output(CYOutput &out, CYFlags flags) const;
1325 struct CYIndirectMember :
1328 CYIndirectMember(CYExpression *object, CYExpression *property) :
1329 CYMember(object, property)
1336 virtual CYExpression *Replace(CYContext &context);
1337 virtual void Output(CYOutput &out, CYFlags flags) const;
1346 CYExpression *constructor_;
1347 CYArgument *arguments_;
1349 New(CYExpression *constructor, CYArgument *arguments) :
1350 constructor_(constructor),
1351 arguments_(arguments)
1355 virtual unsigned Precedence() const {
1356 return arguments_ == NULL ? 2 : 1;
1361 virtual CYExpression *Replace(CYContext &context);
1362 virtual void Output(CYOutput &out, CYFlags flags) const;
1364 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
1372 CYExpression *function_;
1373 CYArgument *arguments_;
1375 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
1376 function_(function),
1377 arguments_(arguments)
1384 virtual CYExpression *Replace(CYContext &context);
1385 virtual void Output(CYOutput &out, CYFlags flags) const;
1387 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
1392 struct CYRubyBlock :
1395 CYExpression *call_;
1398 CYRubyBlock(CYExpression *call, CYRubyProc *proc) :
1407 virtual CYExpression *Replace(CYContext &context);
1408 virtual void Output(CYOutput &out, CYFlags flags) const;
1414 CYExpression *test_;
1416 CYStatement *false_;
1418 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
1425 virtual CYStatement *Replace(CYContext &context);
1426 virtual void Output(CYOutput &out, CYFlags flags) const;
1432 CYExpression *test_;
1435 CYDoWhile(CYExpression *test, CYStatement *code) :
1441 virtual CYStatement *Replace(CYContext &context);
1442 virtual void Output(CYOutput &out, CYFlags flags) const;
1448 CYExpression *test_;
1451 CYWhile(CYExpression *test, CYStatement *code) :
1457 virtual CYStatement *Replace(CYContext &context);
1458 virtual void Output(CYOutput &out, CYFlags flags) const;
1461 // XXX: this should be split up into CYAnonymousFunction and CYNamedFunction (subclass)
1463 CYIdentifier *name_;
1464 CYFunctionParameter *parameters_;
1466 CYNonLocal *nonlocal_;
1468 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1470 parameters_(parameters),
1476 virtual ~CYFunction() {
1479 void Inject(CYContext &context);
1480 virtual void Replace_(CYContext &context, bool outer);
1481 virtual void Output(CYOutput &out, CYFlags flags) const;
1484 // XXX: this should be split up into CYAnonymousFunctionExpression and CYNamedFunctionExpression
1485 struct CYFunctionExpression :
1489 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1490 CYFunction(name, parameters, statements)
1497 virtual CYExpression *Replace(CYContext &context);
1498 virtual void Output(CYOutput &out, CYFlags flags) const;
1501 // XXX: this should derive from CYAnonymousFunctionExpression
1503 CYFunctionExpression
1505 CYRubyProc(CYFunctionParameter *parameters, CYStatement *statements) :
1506 CYFunctionExpression(NULL, parameters, statements)
1510 virtual CYExpression *Replace(CYContext &context);
1511 virtual void Output(CYOutput &out, CYFlags flags) const;
1514 // XXX: this should derive from CYNamedFunction
1515 struct CYFunctionStatement :
1519 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1520 CYFunction(name, parameters, statements)
1524 virtual CYStatement *Replace(CYContext &context);
1525 virtual void Output(CYOutput &out, CYFlags flags) const;
1531 CYExpression *expression_;
1533 CYExpress(CYExpression *expression) :
1534 expression_(expression)
1536 if (expression == NULL)
1540 virtual CYStatement *Collapse(CYContext &context);
1541 virtual CYStatement *Replace(CYContext &context);
1542 virtual void Output(CYOutput &out, CYFlags flags) const;
1548 CYIdentifier *label_;
1550 CYContinue(CYIdentifier *label) :
1555 virtual CYStatement *Replace(CYContext &context);
1556 virtual void Output(CYOutput &out, CYFlags flags) const;
1562 CYIdentifier *label_;
1564 CYBreak(CYIdentifier *label) :
1569 virtual CYStatement *Replace(CYContext &context);
1570 virtual void Output(CYOutput &out, CYFlags flags) const;
1576 CYExpression *value_;
1578 CYReturn(CYExpression *value) :
1583 virtual CYStatement *Replace(CYContext &context);
1584 virtual void Output(CYOutput &out, CYFlags flags) const;
1590 virtual CYStatement *Collapse(CYContext &context);
1591 virtual CYStatement *Replace(CYContext &context);
1592 virtual void Output(CYOutput &out, CYFlags flags) const;
1600 CYFinally(CYStatement *statements) :
1605 void Replace(CYContext &context);
1606 virtual void Output(CYOutput &out) const;
1615 CYIdentifier *name_;
1618 Catch(CYIdentifier *name, CYStatement *statements) :
1624 void Replace(CYContext &context);
1625 virtual void Output(CYOutput &out) const;
1633 CYFinally *finally_;
1635 Try(CYStatement *statements, Catch *_catch, CYFinally *finally) :
1642 virtual CYStatement *Replace(CYContext &context);
1643 virtual void Output(CYOutput &out, CYFlags flags) const;
1649 CYExpression *value_;
1651 Throw(CYExpression *value = NULL) :
1656 virtual CYStatement *Replace(CYContext &context);
1657 virtual void Output(CYOutput &out, CYFlags flags) const;
1665 CYExpression *scope_;
1668 CYWith(CYExpression *scope, CYStatement *code) :
1674 virtual CYStatement *Replace(CYContext &context);
1675 virtual void Output(CYOutput &out, CYFlags flags) const;
1681 CYExpression *value_;
1684 CYSwitch(CYExpression *value, CYClause *clauses) :
1690 virtual CYStatement *Replace(CYContext &context);
1691 virtual void Output(CYOutput &out, CYFlags flags) const;
1694 struct CYCondition :
1697 CYExpression *test_;
1698 CYExpression *true_;
1699 CYExpression *false_;
1701 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
1710 virtual CYExpression *Replace(CYContext &context);
1711 virtual void Output(CYOutput &out, CYFlags flags) const;
1714 struct CYAddressOf :
1717 CYAddressOf(CYExpression *rhs) :
1722 virtual const char *Operator() const {
1728 virtual CYExpression *Replace(CYContext &context);
1734 CYIndirect(CYExpression *rhs) :
1739 virtual const char *Operator() const {
1745 virtual CYExpression *Replace(CYContext &context);
1749 virtual CYExpression *Replace(CYContext &context);
1751 #define CYPostfix_(op, name, args...) \
1752 struct CY ## name : \
1755 CY ## name(CYExpression *lhs) : \
1760 virtual const char *Operator() const { \
1765 #define CYPrefix_(alphabetic, op, name, args...) \
1766 struct CY ## name : \
1769 CY ## name(CYExpression *rhs) : \
1774 CYAlphabetic(alphabetic) \
1776 virtual const char *Operator() const { \
1781 #define CYInfix_(alphabetic, precedence, op, name, args...) \
1782 struct CY ## name : \
1785 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
1790 CYAlphabetic(alphabetic) \
1791 CYPrecedence(precedence) \
1793 virtual const char *Operator() const { \
1798 #define CYAssignment_(op, name, args...) \
1799 struct CY ## name ## Assign : \
1802 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
1803 CYAssignment(lhs, rhs) \
1807 virtual const char *Operator() const { \
1812 CYPostfix_("++", PostIncrement)
1813 CYPostfix_("--", PostDecrement)
1815 CYPrefix_(true, "delete", Delete)
1816 CYPrefix_(true, "void", Void)
1817 CYPrefix_(true, "typeof", TypeOf)
1818 CYPrefix_(false, "++", PreIncrement)
1819 CYPrefix_(false, "--", PreDecrement)
1820 CYPrefix_(false, "+", Affirm)
1821 CYPrefix_(false, "-", Negate)
1822 CYPrefix_(false, "~", BitwiseNot)
1823 CYPrefix_(false, "!", LogicalNot)
1825 CYInfix_(false, 5, "*", Multiply)
1826 CYInfix_(false, 5, "/", Divide)
1827 CYInfix_(false, 5, "%", Modulus)
1828 CYInfix_(false, 6, "+", Add, CYReplace)
1829 CYInfix_(false, 6, "-", Subtract)
1830 CYInfix_(false, 7, "<<", ShiftLeft)
1831 CYInfix_(false, 7, ">>", ShiftRightSigned)
1832 CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
1833 CYInfix_(false, 8, "<", Less)
1834 CYInfix_(false, 8, ">", Greater)
1835 CYInfix_(false, 8, "<=", LessOrEqual)
1836 CYInfix_(false, 8, ">=", GreaterOrEqual)
1837 CYInfix_(true, 8, "instanceof", InstanceOf)
1838 CYInfix_(true, 8, "in", In)
1839 CYInfix_(false, 9, "==", Equal)
1840 CYInfix_(false, 9, "!=", NotEqual)
1841 CYInfix_(false, 9, "===", Identical)
1842 CYInfix_(false, 9, "!==", NotIdentical)
1843 CYInfix_(false, 10, "&", BitwiseAnd)
1844 CYInfix_(false, 11, "^", BitwiseXOr)
1845 CYInfix_(false, 12, "|", BitwiseOr)
1846 CYInfix_(false, 13, "&&", LogicalAnd)
1847 CYInfix_(false, 14, "||", LogicalOr)
1849 CYAssignment_("=", )
1850 CYAssignment_("*=", Multiply)
1851 CYAssignment_("/=", Divide)
1852 CYAssignment_("%=", Modulus)
1853 CYAssignment_("+=", Add)
1854 CYAssignment_("-=", Subtract)
1855 CYAssignment_("<<=", ShiftLeft)
1856 CYAssignment_(">>=", ShiftRightSigned)
1857 CYAssignment_(">>>=", ShiftRightUnsigned)
1858 CYAssignment_("&=", BitwiseAnd)
1859 CYAssignment_("^=", BitwiseXOr)
1860 CYAssignment_("|=", BitwiseOr)
1862 #endif/*CYPARSER_HPP*/