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/>.
35 #include "location.hh"
38 #include "Pooling.hpp"
39 #include "Options.hpp"
47 virtual void Output(struct CYOutput &out) const = 0;
65 CYOutput(std::ostream &out, CYOptions &options) :
75 void Check(char value);
78 CYOutput &operator <<(char rhs);
79 CYOutput &operator <<(const char *rhs);
81 _finline CYOutput &operator <<(const CYThing *rhs) {
87 _finline CYOutput &operator <<(const CYThing &rhs) {
93 struct CYPropertyName {
94 virtual void PropertyName(CYOutput &out) const = 0;
96 virtual ~CYPropertyName() {
110 CYNoBrace = (1 << 0),
111 CYNoFunction = (1 << 1),
114 CYNoRightHand = (1 << 4),
115 CYNoDangle = (1 << 5),
116 CYNoInteger = (1 << 6),
117 CYNoBF = (CYNoBrace | CYNoFunction),
123 virtual ~CYStatement() {
126 void Single(CYOutput &out, CYFlags flags) const;
127 void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
129 virtual CYStatement *Collapse(CYContext &context);
130 virtual CYStatement *Replace(CYContext &context) = 0;
133 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
136 struct CYStatements {
146 operator CYStatement *() const {
150 CYStatements &operator ->*(CYStatement *next) {
152 if (first_ == NULL) {
155 } else for (;; last_ = last_->next_)
156 if (last_->next_ == NULL) {
166 virtual ~CYClassName() {
169 virtual CYExpression *ClassName(CYContext &context, bool object) = 0;
170 virtual void ClassName(CYOutput &out, bool object) const = 0;
180 CYWord(const char *word) :
185 void Set(const char *value) {
189 virtual const char *Word() const;
190 virtual void Output(CYOutput &out) const;
192 virtual CYExpression *ClassName(CYContext &context, bool object);
193 virtual void ClassName(CYOutput &out, bool object) const;
194 virtual void PropertyName(CYOutput &out) const;
197 _finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) {
199 return lhs << rhs.Word();
202 struct CYIdentifier :
203 CYNext<CYIdentifier>,
206 CYIdentifier *replace_;
210 CYIdentifier(const char *word) :
218 virtual const char *Word() const;
219 CYIdentifier *Replace(CYContext &context);
227 CYComment(const char *value) :
232 virtual CYStatement *Replace(CYContext &context);
233 virtual void Output(CYOutput &out, CYFlags flags) const;
240 CYStatement *statement_;
242 CYLabel(CYIdentifier *name, CYStatement *statement) :
244 statement_(statement)
248 virtual CYStatement *Replace(CYContext &context);
249 virtual void Output(CYOutput &out, CYFlags flags) const;
252 struct CYCStringLess :
253 std::binary_function<const char *, const char *, bool>
255 _finline bool operator ()(const char *lhs, const char *rhs) const {
256 return strcmp(lhs, rhs) < 0;
260 struct CYIdentifierValueLess :
261 std::binary_function<CYIdentifier *, CYIdentifier *, bool>
263 _finline bool operator ()(CYIdentifier *lhs, CYIdentifier *rhs) const {
264 return CYCStringLess()(lhs->Word(), rhs->Word());
268 enum CYIdentifierFlags {
269 CYIdentifierArgument,
270 CYIdentifierVariable,
276 typedef std::set<const char *, CYCStringLess> CYCStringSet;
277 typedef std::set<CYIdentifier *, CYIdentifierValueLess> CYIdentifierValueSet;
278 typedef std::map<CYIdentifier *, CYIdentifierFlags> CYIdentifierAddressFlagsMap;
280 struct CYIdentifierUsage {
281 CYIdentifier *identifier_;
285 typedef std::vector<CYIdentifierUsage> CYIdentifierUsageVector;
287 // XXX: strategy pattern, maybe subclass
298 CYStatement *&statements_;
302 CYIdentifierAddressFlagsMap internal_;
303 CYIdentifierValueSet identifiers_;
305 CYScope(CYScopeType type, CYContext &context, CYStatement *&statements);
309 void Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags);
310 virtual CYIdentifier *Lookup(CYContext &context, CYIdentifier *identifier);
311 void Merge(CYContext &context, CYIdentifier *identifier);
312 void Scope(CYContext &context, CYStatement *&statements);
318 CYStatement *statements_;
320 CYProgram(CYStatement *statements) :
321 statements_(statements)
325 virtual void Replace(CYContext &context);
326 virtual void Output(CYOutput &out) const;
335 CYIdentifierUsageVector rename_;
337 CYNonLocal *nonlocal_;
338 CYNonLocal *nextlocal_;
341 CYContext(CYOptions &options) :
350 virtual ~CYContext() {
353 template <typename Type_>
354 void ReplaceAll(Type_ *&values) {
355 Type_ **last(&values);
356 CYForEach (next, values) {
358 last = &(*last)->next_;
362 template <typename Type_>
363 void Replace(Type_ *&value) {
364 for (;;) if (value == NULL)
367 Type_ *replace(value->Replace(*this));
368 if (replace != value)
374 void NonLocal(CYStatement *&statements);
375 CYIdentifier *Unique();
379 CYIdentifier *identifier_;
386 CYIdentifier *Target(CYContext &context) {
387 if (identifier_ == NULL)
388 identifier_ = context.Unique();
397 CYStatement *statements_;
399 CYBlock(CYStatement *statements) :
400 statements_(statements)
404 operator CYStatement *() const {
408 void AddPrev(CYStatement *statement) {
409 CYSetLast(statement, statements_);
410 statements_ = statement;
413 virtual CYStatement *Replace(CYContext &context);
415 virtual void Output(CYOutput &out) const;
416 virtual void Output(CYOutput &out, CYFlags flags) const;
442 std::string filename_;
446 cy::location location_;
447 std::string message_;
450 typedef std::vector<Error> Errors;
458 CYExpression *context_;
460 Context(CYExpression *context) :
465 typedef std::vector<CYWord *> Words;
469 typedef std::vector<Context> Contexts;
472 CYExpression *context_;
484 void ScannerDestroy();
487 CYDriver(const std::string &filename = "");
490 Condition GetCondition();
491 void SetCondition(Condition condition);
493 void PushCondition(Condition condition);
496 void Warning(const cy::location &location, const char *message);
499 struct CYForInitialiser {
500 virtual ~CYForInitialiser() {
503 virtual void For(CYOutput &out) const = 0;
504 virtual CYExpression *Replace(CYContext &context) = 0;
507 struct CYForInInitialiser {
508 virtual ~CYForInInitialiser() {
511 virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
512 virtual const char *ForEachIn() const = 0;
513 virtual CYExpression *ForEachIn(CYContext &out) = 0;
514 virtual CYExpression *Replace(CYContext &context) = 0;
520 struct CYExpression :
521 CYNext<CYExpression>,
527 virtual unsigned Precedence() const = 0;
529 virtual bool RightHand() const {
533 virtual void For(CYOutput &out) const;
534 virtual void ForIn(CYOutput &out, CYFlags flags) const;
536 virtual const char *ForEachIn() const;
537 virtual CYExpression *ForEachIn(CYContext &out);
539 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
541 virtual void Output(CYOutput &out) const;
542 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
543 void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
545 virtual CYExpression *ClassName(CYContext &context, bool object);
546 virtual void ClassName(CYOutput &out, bool object) const;
548 virtual CYExpression *Replace(CYContext &context) = 0;
550 virtual CYExpression *Primitive(CYContext &context) {
554 virtual CYNumber *Number(CYContext &context) {
558 virtual CYString *String(CYContext &context) {
562 virtual const char *Word() const {
567 #define CYAlphabetic(value) \
568 virtual bool Alphabetic() const { \
572 #define CYPrecedence(value) \
573 static const unsigned Precedence_ = value; \
574 virtual unsigned Precedence() const { \
575 return Precedence_; \
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 CYSetLast(expression, expressions_);
595 expressions_ = expression;
600 virtual CYExpression *Replace(CYContext &context);
601 void Output(CYOutput &out, CYFlags flags) const;
604 struct CYFunctionParameter :
605 CYNext<CYFunctionParameter>,
610 CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) :
611 CYNext<CYFunctionParameter>(next),
616 virtual CYFunctionParameter *Replace(CYContext &context, CYBlock &code);
617 virtual void Output(CYOutput &out) const;
620 struct CYOptionalFunctionParameter :
623 CYExpression *initializer_;
625 CYOptionalFunctionParameter(CYIdentifier *name, CYExpression *initializer, CYFunctionParameter *next = NULL) :
626 CYFunctionParameter(name, next),
627 initializer_(initializer)
631 virtual CYFunctionParameter *Replace(CYContext &context, CYBlock &code);
632 virtual void Output(CYOutput &out) const;
635 struct CYComprehension :
636 CYNext<CYComprehension>,
639 virtual const char *Name() const = 0;
641 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
642 CYFunctionParameter *Parameters(CYContext &context) const;
643 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
644 virtual void Output(CYOutput &out) const = 0;
647 struct CYForInComprehension :
653 CYForInComprehension(CYIdentifier *name, CYExpression *set) :
659 virtual const char *Name() const {
660 return name_->Word();
663 virtual CYFunctionParameter *Parameter(CYContext &context) const;
664 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
665 virtual void Output(CYOutput &out) const;
668 struct CYForEachInComprehension :
674 CYForEachInComprehension(CYIdentifier *name, CYExpression *set) :
680 virtual const char *Name() const {
681 return name_->Word();
684 virtual CYFunctionParameter *Parameter(CYContext &context) const;
685 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
686 virtual void Output(CYOutput &out) const;
689 struct CYIfComprehension :
694 CYIfComprehension(CYExpression *test) :
699 virtual const char *Name() const {
703 virtual CYFunctionParameter *Parameter(CYContext &context) const;
704 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
705 virtual void Output(CYOutput &out) const;
708 struct CYArrayComprehension :
711 CYExpression *expression_;
712 CYComprehension *comprehensions_;
714 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
715 expression_(expression),
716 comprehensions_(comprehensions)
722 virtual CYExpression *Replace(CYContext &context);
723 virtual void Output(CYOutput &out, CYFlags flags) const;
736 virtual CYExpression *Replace(CYContext &context);
750 CYRange(uint64_t lo, uint64_t hi) :
755 bool operator [](uint8_t value) const {
756 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
759 void operator()(uint8_t value) {
762 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
766 extern CYRange DigitRange_;
767 extern CYRange WordStartRange_;
768 extern CYRange WordEndRange_;
783 CYString(const char *value) :
789 CYString(const char *value, size_t size) :
795 CYString(const CYWord *word) :
796 value_(word->Word()),
797 size_(strlen(value_))
801 const char *Value() const {
805 virtual const char *Word() const;
807 virtual CYNumber *Number(CYContext &context);
808 virtual CYString *String(CYContext &context);
810 CYString *Concat(CYContext &out, CYString *rhs) const;
811 virtual void Output(CYOutput &out, CYFlags flags) const;
812 virtual void PropertyName(CYOutput &out) const;
821 CYNumber(double value) :
826 double Value() const {
830 virtual CYNumber *Number(CYContext &context);
831 virtual CYString *String(CYContext &context);
833 virtual void Output(CYOutput &out, CYFlags flags) const;
834 virtual void PropertyName(CYOutput &out) const;
842 CYRegEx(const char *value) :
847 const char *Value() const {
851 virtual void Output(CYOutput &out, CYFlags flags) const;
863 virtual CYNumber *Number(CYContext &context);
864 virtual CYString *String(CYContext &context);
866 virtual void Output(CYOutput &out, CYFlags flags) const;
878 virtual CYExpression *Replace(CYContext &context);
879 virtual void Output(CYOutput &out, CYFlags flags) const;
885 virtual bool Value() const = 0;
886 virtual void Output(CYOutput &out, CYFlags flags) const;
898 virtual bool Value() const {
902 virtual CYNumber *Number(CYContext &context);
903 virtual CYString *String(CYContext &context);
915 virtual bool Value() const {
919 virtual CYNumber *Number(CYContext &context);
920 virtual CYString *String(CYContext &context);
928 CYVariable(CYIdentifier *name) :
933 CYVariable(const char *name) :
934 name_(new($pool) CYIdentifier(name))
941 virtual CYExpression *Replace(CYContext &context);
942 virtual void Output(CYOutput &out, CYFlags flags) const;
950 CYPrefix(CYExpression *rhs) :
955 virtual bool Alphabetic() const = 0;
956 virtual const char *Operator() const = 0;
960 virtual CYExpression *Replace(CYContext &context);
961 virtual void Output(CYOutput &out, CYFlags flags) const;
970 CYInfix(CYExpression *lhs, CYExpression *rhs) :
976 void SetLeft(CYExpression *lhs) {
980 virtual bool Alphabetic() const = 0;
981 virtual const char *Operator() const = 0;
983 virtual CYExpression *Replace(CYContext &context);
984 virtual void Output(CYOutput &out, CYFlags flags) const;
992 CYPostfix(CYExpression *lhs) :
997 virtual const char *Operator() const = 0;
1001 virtual CYExpression *Replace(CYContext &context);
1002 virtual void Output(CYOutput &out, CYFlags flags) const;
1005 struct CYAssignment :
1011 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
1017 void SetLeft(CYExpression *lhs) {
1021 virtual const char *Operator() const = 0;
1025 virtual CYExpression *Replace(CYContext &context);
1026 virtual void Output(CYOutput &out, CYFlags flags) const;
1034 CYExpression *value_;
1036 CYArgument(CYExpression *value, CYArgument *next = NULL) :
1037 CYNext<CYArgument>(next),
1043 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
1044 CYNext<CYArgument>(next),
1050 void Replace(CYContext &context);
1051 void Output(CYOutput &out) const;
1067 CYExpression *case_;
1068 CYStatement *statements_;
1070 CYClause(CYExpression *_case, CYStatement *statements) :
1072 statements_(statements)
1076 void Replace(CYContext &context);
1077 virtual void Output(CYOutput &out) const;
1084 CYExpression *value_;
1086 CYElement(CYExpression *value, CYElement *next) :
1087 CYNext<CYElement>(next),
1092 void Replace(CYContext &context);
1093 void Output(CYOutput &out) const;
1099 CYElement *elements_;
1101 CYArray(CYElement *elements = NULL) :
1106 virtual CYExpression *Replace(CYContext &context);
1107 virtual void Output(CYOutput &out, CYFlags flags) const;
1114 CYPropertyName *name_;
1115 CYExpression *value_;
1117 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1118 CYNext<CYProperty>(next),
1124 void Replace(CYContext &context);
1125 virtual void Output(CYOutput &out) const;
1128 struct CYDeclaration :
1131 CYIdentifier *identifier_;
1132 CYExpression *initialiser_;
1134 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
1135 identifier_(identifier),
1136 initialiser_(initialiser)
1140 virtual void ForIn(CYOutput &out, CYFlags flags) const;
1142 virtual const char *ForEachIn() const;
1143 virtual CYExpression *ForEachIn(CYContext &out);
1145 virtual CYExpression *Replace(CYContext &context);
1146 virtual CYAssignment *Assignment(CYContext &context);
1148 virtual void Output(CYOutput &out, CYFlags flags) const;
1151 struct CYDeclarations :
1152 CYNext<CYDeclarations>,
1156 CYDeclaration *declaration_;
1158 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
1159 CYNext<CYDeclarations>(next),
1160 declaration_(declaration)
1164 virtual void For(CYOutput &out) const;
1166 virtual CYCompound *Replace(CYContext &context);
1167 CYProperty *Property(CYContext &context);
1169 virtual void Output(CYOutput &out) const;
1170 virtual void Output(CYOutput &out, CYFlags flags) const;
1176 CYDeclarations *declarations_;
1178 CYVar(CYDeclarations *declarations) :
1179 declarations_(declarations)
1183 virtual CYStatement *Replace(CYContext &context);
1184 virtual void Output(CYOutput &out, CYFlags flags) const;
1190 CYDeclarations *declarations_;
1193 CYLet(CYDeclarations *declarations, CYStatement *statements) :
1194 declarations_(declarations),
1199 virtual CYStatement *Replace(CYContext &context);
1200 virtual void Output(CYOutput &out, CYFlags flags) const;
1206 CYForInitialiser *initialiser_;
1207 CYExpression *test_;
1208 CYExpression *increment_;
1211 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
1212 initialiser_(initialiser),
1214 increment_(increment),
1219 virtual CYStatement *Replace(CYContext &context);
1220 virtual void Output(CYOutput &out, CYFlags flags) const;
1226 CYForInInitialiser *initialiser_;
1230 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1231 initialiser_(initialiser),
1237 virtual CYStatement *Replace(CYContext &context);
1238 virtual void Output(CYOutput &out, CYFlags flags) const;
1241 struct CYForEachIn :
1244 CYForInInitialiser *initialiser_;
1248 CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1249 initialiser_(initialiser),
1255 virtual CYStatement *Replace(CYContext &context);
1256 virtual void Output(CYOutput &out, CYFlags flags) const;
1262 CYProperty *properties_;
1264 CYObject(CYProperty *properties = NULL) :
1265 properties_(properties)
1269 virtual CYExpression *Replace(CYContext &context);
1270 void Output(CYOutput &out, CYFlags flags) const;
1276 CYExpression *object_;
1277 CYExpression *property_;
1279 CYMember(CYExpression *object, CYExpression *property) :
1285 void SetLeft(CYExpression *object) {
1289 void Replace_(CYContext &context);
1292 struct CYDirectMember :
1295 CYDirectMember(CYExpression *object, CYExpression *property) :
1296 CYMember(object, property)
1303 virtual CYExpression *Replace(CYContext &context);
1304 virtual void Output(CYOutput &out, CYFlags flags) const;
1307 struct CYIndirectMember :
1310 CYIndirectMember(CYExpression *object, CYExpression *property) :
1311 CYMember(object, property)
1318 virtual CYExpression *Replace(CYContext &context);
1319 virtual void Output(CYOutput &out, CYFlags flags) const;
1328 CYExpression *constructor_;
1329 CYArgument *arguments_;
1331 New(CYExpression *constructor, CYArgument *arguments) :
1332 constructor_(constructor),
1333 arguments_(arguments)
1337 virtual unsigned Precedence() const {
1338 return arguments_ == NULL ? 2 : 1;
1343 virtual CYExpression *Replace(CYContext &context);
1344 virtual void Output(CYOutput &out, CYFlags flags) const;
1346 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
1354 CYExpression *function_;
1355 CYArgument *arguments_;
1357 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
1358 function_(function),
1359 arguments_(arguments)
1366 virtual CYExpression *Replace(CYContext &context);
1367 virtual void Output(CYOutput &out, CYFlags flags) const;
1369 virtual CYExpression *AddArgument(CYContext &context, CYExpression *value);
1374 struct CYRubyBlock :
1377 CYExpression *call_;
1380 CYRubyBlock(CYExpression *call, CYRubyProc *proc) :
1389 virtual CYExpression *Replace(CYContext &context);
1390 virtual void Output(CYOutput &out, CYFlags flags) const;
1396 CYExpression *test_;
1398 CYStatement *false_;
1400 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
1407 virtual CYStatement *Replace(CYContext &context);
1408 virtual void Output(CYOutput &out, CYFlags flags) const;
1414 CYExpression *test_;
1417 CYDoWhile(CYExpression *test, CYStatement *code) :
1423 virtual CYStatement *Replace(CYContext &context);
1424 virtual void Output(CYOutput &out, CYFlags flags) const;
1430 CYExpression *test_;
1433 CYWhile(CYExpression *test, CYStatement *code) :
1439 virtual CYStatement *Replace(CYContext &context);
1440 virtual void Output(CYOutput &out, CYFlags flags) const;
1443 // XXX: this should be split up into CYAnonymousFunction and CYNamedFunction (subclass)
1445 CYIdentifier *name_;
1446 CYFunctionParameter *parameters_;
1448 CYNonLocal *nonlocal_;
1450 CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1452 parameters_(parameters),
1458 virtual ~CYFunction() {
1461 void Inject(CYContext &context);
1462 virtual void Replace_(CYContext &context, bool outer);
1463 virtual void Output(CYOutput &out, CYFlags flags) const;
1466 // XXX: this should be split up into CYAnonymousFunctionExpression and CYNamedFunctionExpression
1467 struct CYFunctionExpression :
1471 CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1472 CYFunction(name, parameters, statements)
1479 virtual CYExpression *Replace(CYContext &context);
1480 virtual void Output(CYOutput &out, CYFlags flags) const;
1483 // XXX: this should derive from CYAnonymousFunctionExpression
1485 CYFunctionExpression
1487 CYRubyProc(CYFunctionParameter *parameters, CYStatement *statements) :
1488 CYFunctionExpression(NULL, parameters, statements)
1492 virtual CYExpression *Replace(CYContext &context);
1493 virtual void Output(CYOutput &out, CYFlags flags) const;
1496 // XXX: this should derive from CYNamedFunction
1497 struct CYFunctionStatement :
1501 CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
1502 CYFunction(name, parameters, statements)
1506 virtual CYStatement *Replace(CYContext &context);
1507 virtual void Output(CYOutput &out, CYFlags flags) const;
1513 CYExpression *expression_;
1515 CYExpress(CYExpression *expression) :
1516 expression_(expression)
1518 if (expression == NULL)
1522 virtual CYStatement *Collapse(CYContext &context);
1523 virtual CYStatement *Replace(CYContext &context);
1524 virtual void Output(CYOutput &out, CYFlags flags) const;
1530 CYIdentifier *label_;
1532 CYContinue(CYIdentifier *label) :
1537 virtual CYStatement *Replace(CYContext &context);
1538 virtual void Output(CYOutput &out, CYFlags flags) const;
1544 CYIdentifier *label_;
1546 CYBreak(CYIdentifier *label) :
1551 virtual CYStatement *Replace(CYContext &context);
1552 virtual void Output(CYOutput &out, CYFlags flags) const;
1558 CYExpression *value_;
1560 CYReturn(CYExpression *value) :
1565 virtual CYStatement *Replace(CYContext &context);
1566 virtual void Output(CYOutput &out, CYFlags flags) const;
1572 virtual CYStatement *Collapse(CYContext &context);
1573 virtual CYStatement *Replace(CYContext &context);
1574 virtual void Output(CYOutput &out, CYFlags flags) const;
1582 CYFinally(CYStatement *statements) :
1587 void Replace(CYContext &context);
1588 virtual void Output(CYOutput &out) const;
1597 CYIdentifier *name_;
1600 Catch(CYIdentifier *name, CYStatement *statements) :
1606 void Replace(CYContext &context);
1607 virtual void Output(CYOutput &out) const;
1615 CYFinally *finally_;
1617 Try(CYStatement *statements, Catch *_catch, CYFinally *finally) :
1624 virtual CYStatement *Replace(CYContext &context);
1625 virtual void Output(CYOutput &out, CYFlags flags) const;
1631 CYExpression *value_;
1633 Throw(CYExpression *value = NULL) :
1638 virtual CYStatement *Replace(CYContext &context);
1639 virtual void Output(CYOutput &out, CYFlags flags) const;
1647 CYExpression *scope_;
1650 CYWith(CYExpression *scope, CYStatement *code) :
1656 virtual CYStatement *Replace(CYContext &context);
1657 virtual void Output(CYOutput &out, CYFlags flags) const;
1663 CYExpression *value_;
1666 CYSwitch(CYExpression *value, CYClause *clauses) :
1672 virtual CYStatement *Replace(CYContext &context);
1673 virtual void Output(CYOutput &out, CYFlags flags) const;
1676 struct CYCondition :
1679 CYExpression *test_;
1680 CYExpression *true_;
1681 CYExpression *false_;
1683 CYCondition(CYExpression *test, CYExpression *_true, CYExpression *_false) :
1692 virtual CYExpression *Replace(CYContext &context);
1693 virtual void Output(CYOutput &out, CYFlags flags) const;
1696 struct CYAddressOf :
1699 CYAddressOf(CYExpression *rhs) :
1704 virtual const char *Operator() const {
1710 virtual CYExpression *Replace(CYContext &context);
1716 CYIndirect(CYExpression *rhs) :
1721 virtual const char *Operator() const {
1727 virtual CYExpression *Replace(CYContext &context);
1731 virtual CYExpression *Replace(CYContext &context);
1733 #define CYPostfix_(op, name, args...) \
1734 struct CY ## name : \
1737 CY ## name(CYExpression *lhs) : \
1742 virtual const char *Operator() const { \
1747 #define CYPrefix_(alphabetic, op, name, args...) \
1748 struct CY ## name : \
1751 CY ## name(CYExpression *rhs) : \
1756 CYAlphabetic(alphabetic) \
1758 virtual const char *Operator() const { \
1763 #define CYInfix_(alphabetic, precedence, op, name, args...) \
1764 struct CY ## name : \
1767 CY ## name(CYExpression *lhs, CYExpression *rhs) : \
1772 CYAlphabetic(alphabetic) \
1773 CYPrecedence(precedence) \
1775 virtual const char *Operator() const { \
1780 #define CYAssignment_(op, name, args...) \
1781 struct CY ## name ## Assign : \
1784 CY ## name ## Assign(CYExpression *lhs, CYExpression *rhs) : \
1785 CYAssignment(lhs, rhs) \
1789 virtual const char *Operator() const { \
1794 CYPostfix_("++", PostIncrement)
1795 CYPostfix_("--", PostDecrement)
1797 CYPrefix_(true, "delete", Delete)
1798 CYPrefix_(true, "void", Void)
1799 CYPrefix_(true, "typeof", TypeOf)
1800 CYPrefix_(false, "++", PreIncrement)
1801 CYPrefix_(false, "--", PreDecrement)
1802 CYPrefix_(false, "+", Affirm)
1803 CYPrefix_(false, "-", Negate)
1804 CYPrefix_(false, "~", BitwiseNot)
1805 CYPrefix_(false, "!", LogicalNot)
1807 CYInfix_(false, 5, "*", Multiply)
1808 CYInfix_(false, 5, "/", Divide)
1809 CYInfix_(false, 5, "%", Modulus)
1810 CYInfix_(false, 6, "+", Add, CYReplace)
1811 CYInfix_(false, 6, "-", Subtract)
1812 CYInfix_(false, 7, "<<", ShiftLeft)
1813 CYInfix_(false, 7, ">>", ShiftRightSigned)
1814 CYInfix_(false, 7, ">>>", ShiftRightUnsigned)
1815 CYInfix_(false, 8, "<", Less)
1816 CYInfix_(false, 8, ">", Greater)
1817 CYInfix_(false, 8, "<=", LessOrEqual)
1818 CYInfix_(false, 8, ">=", GreaterOrEqual)
1819 CYInfix_(true, 8, "instanceof", InstanceOf)
1820 CYInfix_(true, 8, "in", In)
1821 CYInfix_(false, 9, "==", Equal)
1822 CYInfix_(false, 9, "!=", NotEqual)
1823 CYInfix_(false, 9, "===", Identical)
1824 CYInfix_(false, 9, "!==", NotIdentical)
1825 CYInfix_(false, 10, "&", BitwiseAnd)
1826 CYInfix_(false, 11, "^", BitwiseXOr)
1827 CYInfix_(false, 12, "|", BitwiseOr)
1828 CYInfix_(false, 13, "&&", LogicalAnd)
1829 CYInfix_(false, 14, "||", LogicalOr)
1831 CYAssignment_("=", )
1832 CYAssignment_("*=", Multiply)
1833 CYAssignment_("/=", Divide)
1834 CYAssignment_("%=", Modulus)
1835 CYAssignment_("+=", Add)
1836 CYAssignment_("-=", Subtract)
1837 CYAssignment_("<<=", ShiftLeft)
1838 CYAssignment_(">>=", ShiftRightSigned)
1839 CYAssignment_(">>>=", ShiftRightUnsigned)
1840 CYAssignment_("&=", BitwiseAnd)
1841 CYAssignment_("^=", BitwiseXOr)
1842 CYAssignment_("|=", BitwiseOr)
1844 #endif/*CYPARSER_HPP*/