1 /* Cycript - Inlining/Optimizing JavaScript Compiler
2 * Copyright (C) 2009 Jay Freeman (saurik)
5 /* Modified BSD License {{{ */
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the
12 * above copyright notice, this list of conditions
13 * and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the
15 * above copyright notice, this list of conditions
16 * and the following disclaimer in the documentation
17 * and/or other materials provided with the
19 * 3. The name of the author may not be used to endorse
20 * or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
25 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 // XXX: wtf is this here?!
56 #include "location.hh"
57 #include "Pooling.hpp"
58 #include "Options.hpp"
62 template <typename Type_>
76 void SetNext(Type_ *next) {
85 virtual void Output(struct CYOutput &out) const = 0;
103 CYOutput(std::ostream &out, CYOptions &options) :
113 void Check(char value);
116 CYOutput &operator <<(char rhs);
117 CYOutput &operator <<(const char *rhs);
119 _finline CYOutput &operator <<(const CYThing *rhs) {
125 _finline CYOutput &operator <<(const CYThing &rhs) {
131 struct CYPropertyName {
132 virtual void PropertyName(CYOutput &out) const = 0;
134 virtual ~CYPropertyName() {
148 CYNoBrace = (1 << 0),
149 CYNoFunction = (1 << 1),
152 CYNoRightHand = (1 << 4),
153 CYNoDangle = (1 << 5),
154 CYNoInteger = (1 << 6),
155 CYNoBF = (CYNoBrace | CYNoFunction),
161 virtual ~CYStatement() {
164 void Single(CYOutput &out, CYFlags flags) const;
165 void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
167 CYStatement *ReplaceAll(CYContext &context);
168 virtual CYStatement *Collapse(CYContext &context);
170 virtual CYStatement *Replace(CYContext &context) = 0;
173 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
176 struct CYStatements {
186 operator CYStatement *() const {
190 CYStatements &operator ->*(CYStatement *next) {
192 if (first_ == NULL) {
195 } else for (;; last_ = last_->next_)
196 if (last_->next_ == NULL) {
206 virtual ~CYClassName() {
209 virtual CYExpression *ClassName(CYContext &context, bool object) = 0;
210 virtual void ClassName(CYOutput &out, bool object) const = 0;
220 CYWord(const char *word) :
225 void Set(const char *value) {
229 virtual const char *Word() const;
230 virtual void Output(CYOutput &out) const;
232 virtual CYExpression *ClassName(CYContext &context, bool object);
233 virtual void ClassName(CYOutput &out, bool object) const;
234 virtual void PropertyName(CYOutput &out) const;
237 _finline std::ostream &operator <<(std::ostream &lhs, const CYWord &rhs) {
239 return lhs << rhs.Word();
242 struct CYIdentifier :
243 CYNext<CYIdentifier>,
246 CYIdentifier *replace_;
250 CYIdentifier(const char *word) :
258 virtual const char *Word() const;
259 CYIdentifier *Replace(CYContext &context);
267 CYComment(const char *value) :
272 virtual CYStatement *Replace(CYContext &context);
273 virtual void Output(CYOutput &out, CYFlags flags) const;
280 CYStatement *statement_;
282 CYLabel(CYIdentifier *name, CYStatement *statement) :
284 statement_(statement)
288 virtual CYStatement *Replace(CYContext &context);
289 virtual void Output(CYOutput &out, CYFlags flags) const;
292 struct CYCStringLess :
293 std::binary_function<const char *, const char *, bool>
295 _finline bool operator ()(const char *lhs, const char *rhs) const {
296 return strcmp(lhs, rhs) < 0;
300 struct CYIdentifierValueLess :
301 std::binary_function<CYIdentifier *, CYIdentifier *, bool>
303 _finline bool operator ()(CYIdentifier *lhs, CYIdentifier *rhs) const {
304 return CYCStringLess()(lhs->Word(), rhs->Word());
308 enum CYIdentifierFlags {
309 CYIdentifierArgument,
310 CYIdentifierVariable,
315 typedef std::set<const char *, CYCStringLess> CYCStringSet;
316 typedef std::set<CYIdentifier *, CYIdentifierValueLess> CYIdentifierValueSet;
317 typedef std::map<CYIdentifier *, CYIdentifierFlags> CYIdentifierAddressFlagsMap;
319 struct CYIdentifierUsage {
320 CYIdentifier *identifier_;
324 typedef std::vector<CYIdentifierUsage> CYIdentifierUsageVector;
329 CYIdentifierAddressFlagsMap internal_;
330 CYIdentifierValueSet identifiers_;
340 void Declare(CYContext &context, CYIdentifier *identifier, CYIdentifierFlags flags);
341 virtual CYIdentifier *Lookup(CYContext &context, CYIdentifier *identifier);
342 void Merge(CYContext &context, CYIdentifier *identifier);
343 void Scope(CYContext &context, CYStatement *&statements);
349 CYStatement *statements_;
351 CYProgram(CYStatement *statements) :
352 statements_(statements)
356 virtual void Replace(CYContext &context);
357 virtual void Output(CYOutput &out) const;
364 CYIdentifierUsageVector rename_;
366 CYContext(apr_pool_t *pool, CYOptions &options) :
373 virtual ~CYContext() {
376 template <typename Type_>
377 void Replace(Type_ *&value) {
378 for (;;) if (value == NULL)
381 Type_ *replace(value->Replace(*this));
382 if (replace != value)
393 CYStatement *statements_;
395 CYBlock(CYStatement *statements) :
396 statements_(statements)
400 operator CYStatement *() const {
404 void AddPrev(CYStatement *statement) {
405 CYStatement *last(statement);
406 while (last->next_ != NULL)
408 last->SetNext(statements_);
409 statements_ = statement;
412 virtual CYStatement *Replace(CYContext &context);
414 virtual void Output(CYOutput &out) const;
415 virtual void Output(CYOutput &out, CYFlags flags) const;
443 std::string filename_;
447 cy::location location_;
448 std::string message_;
451 typedef std::vector<Error> Errors;
458 void ScannerDestroy();
461 CYDriver(const std::string &filename);
464 Condition GetCondition();
465 void SetCondition(Condition condition);
467 void PushCondition(Condition condition);
470 void Warning(const cy::location &location, const char *message);
473 struct CYForInitialiser {
474 virtual ~CYForInitialiser() {
477 virtual void For(CYOutput &out) const = 0;
478 virtual CYExpression *Replace(CYContext &context) = 0;
481 struct CYForInInitialiser {
482 virtual ~CYForInInitialiser() {
485 virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
486 virtual const char *ForEachIn() const = 0;
487 virtual CYExpression *ForEachIn(CYContext &out) = 0;
488 virtual CYExpression *Replace(CYContext &context) = 0;
494 struct CYExpression :
495 CYNext<CYExpression>,
501 virtual unsigned Precedence() const = 0;
503 virtual bool RightHand() const {
507 virtual void For(CYOutput &out) const;
508 virtual void ForIn(CYOutput &out, CYFlags flags) const;
510 virtual const char *ForEachIn() const;
511 virtual CYExpression *ForEachIn(CYContext &out);
513 virtual void Output(CYOutput &out) const;
514 virtual void Output(CYOutput &out, CYFlags flags) const = 0;
515 void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
517 virtual CYExpression *ClassName(CYContext &context, bool object);
518 virtual void ClassName(CYOutput &out, bool object) const;
520 CYExpression *ReplaceAll(CYContext &context);
522 virtual CYExpression *Replace(CYContext &context) = 0;
524 virtual CYExpression *Primitive(CYContext &context) {
528 virtual CYNumber *Number(CYContext &context) {
532 virtual CYString *String(CYContext &context) {
536 virtual const char *Word() const {
541 #define CYAlphabetic(value) \
542 virtual bool Alphabetic() const { \
546 #define CYPrecedence(value) \
547 virtual unsigned Precedence() const { \
551 #define CYRightHand(value) \
552 virtual bool RightHand() const { \
559 CYExpression *expressions_;
561 CYCompound(CYExpression *expressions = NULL) :
562 expressions_(expressions)
566 void AddPrev(CYExpression *expression) {
567 CYExpression *last(expression);
568 while (last->next_ != NULL)
570 last->SetNext(expressions_);
571 expressions_ = expression;
576 virtual CYExpression *Replace(CYContext &context);
577 void Output(CYOutput &out, CYFlags flags) const;
580 struct CYFunctionParameter :
581 CYNext<CYFunctionParameter>,
586 CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) :
587 CYNext<CYFunctionParameter>(next),
592 void Replace(CYContext &context);
593 virtual void Output(CYOutput &out) const;
596 struct CYComprehension :
597 CYNext<CYComprehension>,
600 virtual const char *Name() const = 0;
602 virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
603 CYFunctionParameter *Parameters(CYContext &context) const;
604 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
605 virtual void Output(CYOutput &out) const = 0;
608 struct CYForInComprehension :
614 CYForInComprehension(CYIdentifier *name, CYExpression *set) :
620 virtual const char *Name() const {
621 return name_->Word();
624 virtual CYFunctionParameter *Parameter(CYContext &context) const;
625 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
626 virtual void Output(CYOutput &out) const;
629 struct CYForEachInComprehension :
635 CYForEachInComprehension(CYIdentifier *name, CYExpression *set) :
641 virtual const char *Name() const {
642 return name_->Word();
645 virtual CYFunctionParameter *Parameter(CYContext &context) const;
646 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
647 virtual void Output(CYOutput &out) const;
650 struct CYIfComprehension :
655 CYIfComprehension(CYExpression *test) :
660 virtual const char *Name() const {
664 virtual CYFunctionParameter *Parameter(CYContext &context) const;
665 virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
666 virtual void Output(CYOutput &out) const;
669 struct CYArrayComprehension :
672 CYExpression *expression_;
673 CYComprehension *comprehensions_;
675 CYArrayComprehension(CYExpression *expression, CYComprehension *comprehensions) :
676 expression_(expression),
677 comprehensions_(comprehensions)
683 virtual CYExpression *Replace(CYContext &context);
684 virtual void Output(CYOutput &out, CYFlags flags) const;
697 virtual CYExpression *Replace(CYContext &context);
711 CYRange(uint64_t lo, uint64_t hi) :
716 bool operator [](uint8_t value) const {
717 return !(value >> 7) && (value >> 6 ? hi_ : lo_) >> (value & 0x3f) & 0x1;
720 void operator()(uint8_t value) {
723 (value >> 6 ? hi_ : lo_) |= uint64_t(0x1) << (value & 0x3f);
727 extern CYRange DigitRange_;
728 extern CYRange WordStartRange_;
729 extern CYRange WordEndRange_;
744 CYString(const char *value) :
750 CYString(const char *value, size_t size) :
756 CYString(const CYWord *word) :
757 value_(word->Word()),
758 size_(strlen(value_))
762 const char *Value() const {
766 virtual const char *Word() const;
768 virtual CYNumber *Number(CYContext &context);
769 virtual CYString *String(CYContext &context);
771 CYString *Concat(CYContext &out, CYString *rhs) const;
772 virtual void Output(CYOutput &out, CYFlags flags) const;
773 virtual void PropertyName(CYOutput &out) const;
782 CYNumber(double value) :
787 double Value() const {
791 virtual CYNumber *Number(CYContext &context);
792 virtual CYString *String(CYContext &context);
794 virtual void Output(CYOutput &out, CYFlags flags) const;
795 virtual void PropertyName(CYOutput &out) const;
803 CYRegEx(const char *value) :
808 const char *Value() const {
812 virtual void Output(CYOutput &out, CYFlags flags) const;
824 virtual CYNumber *Number(CYContext &context);
825 virtual CYString *String(CYContext &context);
827 virtual void Output(CYOutput &out, CYFlags flags) const;
839 virtual CYExpression *Replace(CYContext &context);
840 virtual void Output(CYOutput &out, CYFlags flags) const;
846 virtual bool Value() const = 0;
847 virtual void Output(CYOutput &out, CYFlags flags) const;
859 virtual bool Value() const {
863 virtual CYNumber *Number(CYContext &context);
864 virtual CYString *String(CYContext &context);
876 virtual bool Value() const {
880 virtual CYNumber *Number(CYContext &context);
881 virtual CYString *String(CYContext &context);
889 CYVariable(CYIdentifier *name) :
897 virtual CYExpression *Replace(CYContext &context);
898 virtual void Output(CYOutput &out, CYFlags flags) const;
906 CYPrefix(CYExpression *rhs) :
911 virtual bool Alphabetic() const = 0;
912 virtual const char *Operator() const = 0;
916 virtual CYExpression *Replace(CYContext &context);
917 virtual void Output(CYOutput &out, CYFlags flags) const;
926 CYInfix(CYExpression *lhs, CYExpression *rhs) :
932 void SetLeft(CYExpression *lhs) {
936 virtual bool Alphabetic() const = 0;
937 virtual const char *Operator() const = 0;
939 virtual CYExpression *Replace(CYContext &context);
940 virtual void Output(CYOutput &out, CYFlags flags) const;
948 CYPostfix(CYExpression *lhs) :
953 virtual const char *Operator() const = 0;
957 virtual CYExpression *Replace(CYContext &context);
958 virtual void Output(CYOutput &out, CYFlags flags) const;
961 struct CYAssignment :
967 CYAssignment(CYExpression *lhs, CYExpression *rhs) :
973 void SetLeft(CYExpression *lhs) {
977 virtual const char *Operator() const = 0;
981 virtual CYExpression *Replace(CYContext &context);
982 virtual void Output(CYOutput &out, CYFlags flags) const;
990 CYExpression *value_;
992 CYArgument(CYExpression *value, CYArgument *next = NULL) :
993 CYNext<CYArgument>(next),
999 CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
1000 CYNext<CYArgument>(next),
1006 void Replace(CYContext &context);
1007 void Output(CYOutput &out) const;
1023 CYExpression *case_;
1024 CYStatement *statements_;
1026 CYClause(CYExpression *_case, CYStatement *statements) :
1028 statements_(statements)
1032 void Replace(CYContext &context);
1033 virtual void Output(CYOutput &out) const;
1040 CYExpression *value_;
1042 CYElement(CYExpression *value, CYElement *next) :
1043 CYNext<CYElement>(next),
1048 void Replace(CYContext &context);
1049 void Output(CYOutput &out) const;
1055 CYElement *elements_;
1057 CYArray(CYElement *elements = NULL) :
1062 virtual CYExpression *Replace(CYContext &context);
1063 virtual void Output(CYOutput &out, CYFlags flags) const;
1070 CYPropertyName *name_;
1071 CYExpression *value_;
1073 CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
1074 CYNext<CYProperty>(next),
1080 void Replace(CYContext &context);
1081 virtual void Output(CYOutput &out) const;
1084 struct CYDeclaration :
1087 CYIdentifier *identifier_;
1088 CYExpression *initialiser_;
1090 CYDeclaration(CYIdentifier *identifier, CYExpression *initialiser = NULL) :
1091 identifier_(identifier),
1092 initialiser_(initialiser)
1096 virtual void ForIn(CYOutput &out, CYFlags flags) const;
1098 virtual const char *ForEachIn() const;
1099 virtual CYExpression *ForEachIn(CYContext &out);
1101 virtual CYExpression *Replace(CYContext &context);
1102 virtual CYAssignment *Assignment(CYContext &context);
1104 virtual void Output(CYOutput &out, CYFlags flags) const;
1107 struct CYDeclarations :
1108 CYNext<CYDeclarations>,
1112 CYDeclaration *declaration_;
1114 CYDeclarations(CYDeclaration *declaration, CYDeclarations *next = NULL) :
1115 CYNext<CYDeclarations>(next),
1116 declaration_(declaration)
1120 virtual void For(CYOutput &out) const;
1122 virtual CYCompound *Replace(CYContext &context);
1123 CYProperty *Property(CYContext &context);
1125 virtual void Output(CYOutput &out) const;
1126 virtual void Output(CYOutput &out, CYFlags flags) const;
1132 CYDeclarations *declarations_;
1134 CYVar(CYDeclarations *declarations) :
1135 declarations_(declarations)
1139 virtual CYStatement *Replace(CYContext &context);
1140 virtual void Output(CYOutput &out, CYFlags flags) const;
1146 CYDeclarations *declarations_;
1149 CYLet(CYDeclarations *declarations, CYStatement *statements) :
1150 declarations_(declarations),
1155 virtual CYStatement *Replace(CYContext &context);
1156 virtual void Output(CYOutput &out, CYFlags flags) const;
1162 CYForInitialiser *initialiser_;
1163 CYExpression *test_;
1164 CYExpression *increment_;
1167 CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) :
1168 initialiser_(initialiser),
1170 increment_(increment),
1175 virtual CYStatement *Replace(CYContext &context);
1176 virtual void Output(CYOutput &out, CYFlags flags) const;
1182 CYForInInitialiser *initialiser_;
1186 CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1187 initialiser_(initialiser),
1193 virtual CYStatement *Replace(CYContext &context);
1194 virtual void Output(CYOutput &out, CYFlags flags) const;
1197 struct CYForEachIn :
1200 CYForInInitialiser *initialiser_;
1204 CYForEachIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) :
1205 initialiser_(initialiser),
1211 virtual CYStatement *Replace(CYContext &context);
1212 virtual void Output(CYOutput &out, CYFlags flags) const;
1218 CYProperty *properties_;
1220 CYObject(CYProperty *properties) :
1221 properties_(properties)
1225 virtual CYExpression *Replace(CYContext &context);
1226 void Output(CYOutput &out, CYFlags flags) const;
1232 CYExpression *object_;
1233 CYExpression *property_;
1235 CYMember(CYExpression *object, CYExpression *property) :
1241 void SetLeft(CYExpression *object) {
1245 void Replace_(CYContext &context);
1248 struct CYDirectMember :
1251 CYDirectMember(CYExpression *object, CYExpression *property) :
1252 CYMember(object, property)
1259 virtual CYExpression *Replace(CYContext &context);
1260 virtual void Output(CYOutput &out, CYFlags flags) const;
1263 struct CYIndirectMember :
1266 CYIndirectMember(CYExpression *object, CYExpression *property) :
1267 CYMember(object, property)
1274 virtual CYExpression *Replace(CYContext &context);
1275 virtual void Output(CYOutput &out, CYFlags flags) const;
1281 CYExpression *constructor_;
1282 CYArgument *arguments_;
1284 CYNew(CYExpression *constructor, CYArgument *arguments) :
1285 constructor_(constructor),
1286 arguments_(arguments)
1290 virtual unsigned Precedence() const {
1291 return arguments_ == NULL ? 2 : 1;
1296 virtual CYExpression *Replace(CYContext &context);
1297 virtual void Output(CYOutput &out, CYFlags flags) const;
1303 CYExpression *function_;
1304 CYArgument *arguments_;
1306 CYCall(CYExpression *function, CYArgument *arguments = NULL) :
1307 function_(function),
1308 arguments_(arguments)
1315 virtual CYExpression *Replace(CYContext &context);
1316 virtual void Output(CYOutput &out, CYFlags flags) const;
1322 CYExpression *test_;
1324 CYStatement *false_;
1326 CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
1333 virtual CYStatement *Replace(CYContext &context);
1334 virtual void Output(CYOutput &out, CYFlags flags) const;
1340 CYExpression *test_;
1343 CYDoWhile(CYExpression *test, CYStatement *code) :
1349 virtual CYStatement *Replace(CYContext &context);
1350 virtual void Output(CYOutput &out, CYFlags flags) const;
1356 CYExpression *test_;
1359 CYWhile(CYExpression *test, CYStatement *code) :
1365 virtual CYStatement *Replace(CYContext &context);
1366 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),
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*/