X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/11c1cc16b7cda02473081cc398195484a1ab82f2..1e7ce5572cfc83d260cbe73d66814f54e5760c37:/Parser.hpp?ds=sidebyside diff --git a/Parser.hpp b/Parser.hpp index 0ef73f5..e954748 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -75,20 +75,31 @@ struct CYOutput { bool pretty_; unsigned indent_; + enum { + NoMode, + NoLetter, + NoPlus, + NoHyphen, + Terminated + } mode_; + CYOutput(std::ostream &out) : out_(out), pretty_(false), - indent_(0) + indent_(0), + mode_(NoMode) { } - _finline CYOutput &operator <<(char rhs) { - out_ << rhs; - return *this; - } + void Check(char value); + void Terminate(); + + CYOutput &operator <<(char rhs); + CYOutput &operator <<(const char *rhs); - _finline CYOutput &operator <<(const char *rhs) { - out_ << rhs; + _finline CYOutput &operator <<(const CYThing *rhs) { + if (rhs != NULL) + rhs->Output(*this); return *this; } @@ -96,15 +107,92 @@ struct CYOutput { rhs.Output(*this); return *this; } - - void Indent(); }; struct CYPropertyName { virtual void PropertyName(CYOutput &out) const = 0; }; +struct CYExpression; + +enum CYNeeded { + CYNever = -1, + CYSometimes = 0, + CYAlways = 1, +}; + +enum CYFlags { + CYNoFlags = 0, + CYNoBrace = (1 << 0), + CYNoFunction = (1 << 1), + CYNoIn = (1 << 2), + CYNoCall = (1 << 3), + CYNoRightHand = (1 << 4), + CYNoDangle = (1 << 5), + CYNoBF = (CYNoBrace | CYNoFunction), +}; + +struct CYContext { + apr_pool_t *pool_; + + CYContext(apr_pool_t *pool) : + pool_(pool) + { + } + + template + void Replace(Type_ *&value) { + if (value != NULL) + while (Type_ *replace = value->Replace(*this)) + value = replace; + } +}; + +struct CYStatement : + CYNext +{ + void Single(CYOutput &out, CYFlags flags) const; + void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const; + + CYStatement *ReplaceAll(CYContext &context); + + virtual CYStatement *Replace(CYContext &context) = 0; + + private: + virtual void Output(CYOutput &out, CYFlags flags) const = 0; +}; + +struct CYStatements { + CYStatement *first_; + CYStatement *last_; + + CYStatements() : + first_(NULL), + last_(NULL) + { + } + + operator CYStatement *() const { + return first_; + } + + CYStatements &operator ->*(CYStatement *next) { + if (next != NULL) + if (first_ == NULL) { + first_ = next; + last_ = next; + } else for (;; last_ = last_->next_) + if (last_->next_ == NULL) { + last_->next_ = next; + last_ = next; + break; + } + return *this; + } +}; + struct CYClassName { + virtual CYExpression *ClassName(CYContext &context, bool object) = 0; virtual void ClassName(CYOutput &out, bool object) const = 0; }; @@ -126,6 +214,7 @@ struct CYWord : virtual void Output(CYOutput &out) const; + virtual CYExpression *ClassName(CYContext &context, bool object); virtual void ClassName(CYOutput &out, bool object) const; virtual void PropertyName(CYOutput &out) const; }; @@ -144,65 +233,39 @@ struct CYIdentifier : }; struct CYLabel : - CYNext + CYStatement { CYIdentifier *name_; + CYStatement *statement_; - CYLabel(CYIdentifier *name, CYLabel *next) : - CYNext(next), - name_(name) + CYLabel(CYIdentifier *name, CYStatement *statement) : + name_(name), + statement_(statement) { } -}; - -enum CYNeeded { - CYNever = -1, - CYSometimes = 0, - CYAlways = 1, -}; -enum CYFlags { - CYNoFlags = 0, - CYNoBrace = (1 << 0), - CYNoFunction = (1 << 1), - CYNoLeader = (1 << 2), - CYNoTrailer = (1 << 3), - CYNoIn = (1 << 4), - CYNoHyphen = (1 << 5), - CYNoCall = (1 << 6), - CYNoRightHand = (1 << 7), - CYNoDangle = (1 << 8), - CYNoTerminator = (1 << 9), - CYNoBF = (CYNoBrace | CYNoFunction), + virtual CYStatement *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYStatement : - CYNext +struct CYProgram : + CYThing { - CYLabel *labels_; + CYStatement *statements_; - CYStatement() : - labels_(NULL) + CYProgram(CYStatement *statements) : + statements_(statements) { } - void AddLabel(CYIdentifier *identifier) { - labels_ = new CYLabel(identifier, labels_); - } - - virtual bool IsBlock() const { - return next_ != NULL; - } + virtual void Replace(CYContext &context); - virtual void Single(CYOutput &out, CYFlags flags) const; - virtual void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const; - - private: - virtual void Output(CYOutput &out, CYFlags flags) const = 0; + virtual void Output(CYOutput &out) const; }; struct CYBlock : - CYStatement + CYStatement, + CYThing { CYStatement *statements_; @@ -211,10 +274,9 @@ struct CYBlock : { } - virtual bool IsBlock() const { - return true; - } + virtual CYStatement *Replace(CYContext &context); + virtual void Output(CYOutput &out) const; virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -252,7 +314,7 @@ class CYDriver { typedef std::vector Errors; - CYStatement *program_; + CYProgram *program_; Errors errors_; private: @@ -276,13 +338,15 @@ struct CYForInInitialiser { virtual void ForIn(CYOutput &out, CYFlags flags) const = 0; virtual const char *ForEachIn() const = 0; virtual void ForEachIn(CYOutput &out) const = 0; + virtual CYExpression *ForEachIn(CYContext &out) = 0; }; struct CYExpression : CYNext, CYForInitialiser, CYForInInitialiser, - CYClassName + CYClassName, + CYThing { virtual unsigned Precedence() const = 0; @@ -295,12 +359,19 @@ struct CYExpression : virtual const char *ForEachIn() const; virtual void ForEachIn(CYOutput &out) const; + virtual CYExpression *ForEachIn(CYContext &out); + virtual void Output(CYOutput &out) const; virtual void Output(CYOutput &out, CYFlags flags) const = 0; void Output(CYOutput &out, unsigned precedence, CYFlags flags) const; + virtual CYExpression *ClassName(CYContext &context, bool object); virtual void ClassName(CYOutput &out, bool object) const; + CYExpression *ReplaceAll(CYContext &context); + + virtual CYExpression *Replace(CYContext &context) = 0; + virtual const char *Word() const { return NULL; } @@ -341,11 +412,28 @@ struct CYCompound : CYPrecedence(17) + virtual CYExpression *Replace(CYContext &context); void Output(CYOutput &out, CYFlags flags) const; }; +struct CYFunctionParameter : + CYNext, + CYThing +{ + CYIdentifier *name_; + + CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) : + CYNext(next), + name_(name) + { + } + + virtual void Output(CYOutput &out) const; +}; + struct CYComprehension : - CYNext + CYNext, + CYThing { void Output(CYOutput &out) const; virtual const char *Name() const = 0; @@ -354,6 +442,10 @@ struct CYComprehension : virtual void End_(CYOutput &out) const { } + + virtual CYFunctionParameter *Parameter(CYContext &context) const = 0; + CYFunctionParameter *Parameters(CYContext &context) const; + virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; }; struct CYForInComprehension : @@ -373,6 +465,9 @@ struct CYForInComprehension : } virtual void Begin_(CYOutput &out) const; + + virtual CYFunctionParameter *Parameter(CYContext &context) const; + virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; }; struct CYForEachInComprehension : @@ -393,6 +488,9 @@ struct CYForEachInComprehension : virtual void Begin_(CYOutput &out) const; virtual void End_(CYOutput &out) const; + + virtual CYFunctionParameter *Parameter(CYContext &context) const; + virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; }; struct CYIfComprehension : @@ -410,6 +508,9 @@ struct CYIfComprehension : } virtual void Begin_(CYOutput &out) const; + + virtual CYFunctionParameter *Parameter(CYContext &context) const; + virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const; }; struct CYArrayComprehension : @@ -426,6 +527,7 @@ struct CYArrayComprehension : CYPrecedence(0) + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -436,6 +538,12 @@ struct CYLiteral : CYRightHand(false) }; +struct CYTrivial : + CYLiteral +{ + virtual CYExpression *Replace(CYContext &context); +}; + struct CYMagic : CYExpression { @@ -443,37 +551,6 @@ struct CYMagic : CYRightHand(false) }; -struct CYSelectorPart : - CYNext -{ - CYWord *name_; - bool value_; - - CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) : - CYNext(next), - name_(name), - value_(value) - { - } - - virtual void Output(CYOutput &out) const; -}; - -struct CYSelector : - CYLiteral -{ - CYSelectorPart *name_; - - CYSelector(CYSelectorPart *name) : - name_(name) - { - } - - CYPrecedence(1) - - virtual void Output(CYOutput &out, CYFlags flags) const; -}; - struct CYRange { uint64_t lo_; uint64_t hi_; @@ -499,20 +576,32 @@ extern CYRange WordStartRange_; extern CYRange WordEndRange_; struct CYString : - CYLiteral, + CYTrivial, CYPropertyName { const char *value_; size_t size_; + CYString() : + value_(NULL), + size_(0) + { + } + + CYString(const char *value) : + value_(value), + size_(strlen(value)) + { + } + CYString(const char *value, size_t size) : value_(value), size_(size) { } - CYString(const CYIdentifier *identifier) : - value_(identifier->Value()), + CYString(const CYWord *word) : + value_(word->Value()), size_(strlen(value_)) { } @@ -527,8 +616,42 @@ struct CYString : virtual void PropertyName(CYOutput &out) const; }; +struct CYSelectorPart : + CYNext, + CYThing +{ + CYWord *name_; + bool value_; + + CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) : + CYNext(next), + name_(name), + value_(value) + { + } + + CYString *Replace(CYContext &context); + virtual void Output(CYOutput &out) const; +}; + +struct CYSelector : + CYLiteral +{ + CYSelectorPart *name_; + + CYSelector(CYSelectorPart *name) : + name_(name) + { + } + + CYPrecedence(1) + + virtual CYExpression *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYNumber : - CYLiteral, + CYTrivial, CYPropertyName { double value_; @@ -547,7 +670,7 @@ struct CYNumber : }; struct CYRegEx : - CYLiteral + CYTrivial { const char *value_; @@ -565,7 +688,7 @@ struct CYRegEx : struct CYNull : CYWord, - CYLiteral + CYTrivial { CYNull() : CYWord("null") @@ -584,11 +707,12 @@ struct CYThis : { } + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYBoolean : - CYLiteral + CYTrivial { virtual bool Value() const = 0; virtual void Output(CYOutput &out, CYFlags flags) const; @@ -635,6 +759,7 @@ struct CYVariable : CYPrecedence(0) CYRightHand(false) + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -651,6 +776,9 @@ struct CYPrefix : virtual bool Alphabetic() const = 0; virtual const char *Operator() const = 0; + CYPrecedence(4) + + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -673,6 +801,7 @@ struct CYInfix : virtual bool Alphabetic() const = 0; virtual const char *Operator() const = 0; + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -688,6 +817,9 @@ struct CYPostfix : virtual const char *Operator() const = 0; + CYPrecedence(3) + + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -709,15 +841,24 @@ struct CYAssignment : virtual const char *Operator() const = 0; + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYArgument : - CYNext + CYNext, + CYThing { CYWord *name_; CYExpression *value_; + CYArgument(CYExpression *value, CYArgument *next = NULL) : + CYNext(next), + name_(NULL), + value_(value) + { + } + CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) : CYNext(next), name_(name), @@ -725,6 +866,7 @@ struct CYArgument : { } + void Replace(CYContext &context); void Output(CYOutput &out) const; }; @@ -742,19 +884,21 @@ struct CYClause : CYNext { CYExpression *case_; - CYStatement *code_; + CYStatement *statements_; - CYClause(CYExpression *_case, CYStatement *code) : + CYClause(CYExpression *_case, CYStatement *statements) : case_(_case), - code_(code) + statements_(statements) { } + virtual void Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; struct CYElement : - CYNext + CYNext, + CYThing { CYExpression *value_; @@ -764,6 +908,7 @@ struct CYElement : { } + void Replace(CYContext &context); void Output(CYOutput &out) const; }; @@ -772,11 +917,12 @@ struct CYArray : { CYElement *elements_; - CYArray(CYElement *elements) : + CYArray(CYElement *elements = NULL) : elements_(elements) { } + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -796,13 +942,17 @@ struct CYDeclaration : virtual const char *ForEachIn() const; virtual void ForEachIn(CYOutput &out) const; + virtual CYExpression *ForEachIn(CYContext &out); + + void Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYDeclarations : CYNext, - CYForInitialiser + CYForInitialiser, + CYThing { CYDeclaration *declaration_; @@ -813,6 +963,10 @@ struct CYDeclarations : } virtual void For(CYOutput &out) const; + + void Replace(CYContext &context); + + virtual void Output(CYOutput &out) const; virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -826,6 +980,7 @@ struct CYVar : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -833,21 +988,23 @@ struct CYLet : CYStatement { CYDeclarations *declarations_; - CYStatement *statements_; + CYBlock code_; CYLet(CYDeclarations *declarations, CYStatement *statements) : declarations_(declarations), - statements_(statements) + code_(statements) { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYField : CYNext { - virtual void Output(CYOutput &out) const; + CYStatement *Replace(CYContext &context) const; + void Output(CYOutput &out) const; }; struct CYMessageParameter : @@ -863,6 +1020,10 @@ struct CYMessageParameter : name_(name) { } + + CYFunctionParameter *Parameters(CYContext &context) const; + CYSelector *Selector(CYContext &context) const; + CYSelectorPart *SelectorPart(CYContext &context) const; }; struct CYMessage : @@ -870,18 +1031,19 @@ struct CYMessage : { bool instance_; CYExpression *type_; - CYMessageParameter *parameter_; - CYStatement *body_; + CYMessageParameter *parameters_; + CYStatement *statements_; - CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *body) : + CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *statements) : instance_(instance), type_(type), - parameter_(parameter), - body_(body) + parameters_(parameter), + statements_(statements) { } - virtual void Output(CYOutput &out, bool replace) const; + CYStatement *Replace(CYContext &context, bool replace) const; + void Output(CYOutput &out, bool replace) const; }; struct CYClass { @@ -898,6 +1060,7 @@ struct CYClass { { } + CYExpression *Replace_(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -912,6 +1075,7 @@ struct CYClassExpression : CYPrecedence(0) + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -924,6 +1088,7 @@ struct CYClassStatement : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -939,24 +1104,10 @@ struct CYCategory : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYFunctionParameter : - CYNext, - CYThing -{ - CYIdentifier *name_; - - CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next) : - CYNext(next), - name_(name) - { - } - - virtual void Output(CYOutput &out) const; -}; - struct CYFor : CYStatement { @@ -973,6 +1124,7 @@ struct CYFor : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -990,6 +1142,7 @@ struct CYForIn : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1007,35 +1160,39 @@ struct CYForEachIn : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYProperty : - CYNext + CYNext, + CYThing { CYPropertyName *name_; CYExpression *value_; - CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next) : + CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) : CYNext(next), name_(name), value_(value) { } + void Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; struct CYObject : CYLiteral { - CYProperty *property_; + CYProperty *properties_; - CYObject(CYProperty *property) : - property_(property) + CYObject(CYProperty *properties) : + properties_(properties) { } + virtual CYExpression *Replace(CYContext &context); void Output(CYOutput &out, CYFlags flags) const; }; @@ -1043,14 +1200,15 @@ struct CYCatch : CYThing { CYIdentifier *name_; - CYStatement *code_; + CYBlock code_; - CYCatch(CYIdentifier *name, CYStatement *code) : + CYCatch(CYIdentifier *name, CYStatement *statements) : name_(name), - code_(code) + code_(statements) { } + void Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; @@ -1068,6 +1226,7 @@ struct CYSend : CYPrecedence(0) + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1086,6 +1245,8 @@ struct CYMember : void SetLeft(CYExpression *object) { object_ = object; } + + void Replace_(CYContext &context); }; struct CYDirectMember : @@ -1099,6 +1260,7 @@ struct CYDirectMember : CYPrecedence(1) CYRightHand(false) + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1113,6 +1275,7 @@ struct CYIndirectMember : CYPrecedence(1) CYRightHand(false) + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1134,6 +1297,7 @@ struct CYNew : CYRightHand(false) + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1143,7 +1307,7 @@ struct CYCall : CYExpression *function_; CYArgument *arguments_; - CYCall(CYExpression *function, CYArgument *arguments) : + CYCall(CYExpression *function, CYArgument *arguments = NULL) : function_(function), arguments_(arguments) { @@ -1152,6 +1316,7 @@ struct CYCall : CYPrecedence(1) CYRightHand(false) + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1162,13 +1327,14 @@ struct CYIf : CYStatement *true_; CYStatement *false_; - CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) : + CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) : test_(test), true_(_true), false_(_false) { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1184,6 +1350,7 @@ struct CYDoWhile : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1199,21 +1366,23 @@ struct CYWhile : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYFunction { CYIdentifier *name_; CYFunctionParameter *parameters_; - CYStatement *body_; + CYBlock code_; - CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *body) : + CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : name_(name), parameters_(parameters), - body_(body) + code_(statements) { } + virtual void Replace_(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1221,14 +1390,15 @@ struct CYFunctionExpression : CYFunction, CYExpression { - CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *body) : - CYFunction(name, parameters, body) + CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : + CYFunction(name, parameters, statements) { } CYPrecedence(0) CYRightHand(false) + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1236,11 +1406,12 @@ struct CYFunctionStatement : CYFunction, CYStatement { - CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *body) : - CYFunction(name, parameters, body) + CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : + CYFunction(name, parameters, statements) { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1254,6 +1425,7 @@ struct CYExpress : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1267,6 +1439,7 @@ struct CYContinue : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1280,6 +1453,7 @@ struct CYBreak : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1293,40 +1467,46 @@ struct CYReturn : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; struct CYEmpty : CYStatement { + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; -struct CYFinally { - CYStatement *code_; +struct CYFinally : + CYThing +{ + CYBlock code_; - CYFinally(CYStatement *code) : - code_(code) + CYFinally(CYStatement *statements) : + code_(statements) { } + void Replace(CYContext &context); virtual void Output(CYOutput &out) const; }; struct CYTry : CYStatement { - CYStatement *code_; + CYBlock code_; CYCatch *catch_; CYFinally *finally_; - CYTry(CYStatement *code, CYCatch *_catch, CYFinally *finally) : - code_(code), + CYTry(CYStatement *statements, CYCatch *_catch, CYFinally *finally) : + code_(statements), catch_(_catch), finally_(finally) { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1340,6 +1520,7 @@ struct CYThrow : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1355,6 +1536,7 @@ struct CYWith : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1370,6 +1552,7 @@ struct CYSwitch : { } + virtual CYStatement *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1389,6 +1572,7 @@ struct CYCondition : CYPrecedence(15) + virtual CYExpression *Replace(CYContext &context); virtual void Output(CYOutput &out, CYFlags flags) const; }; @@ -1405,9 +1589,8 @@ struct CYAddressOf : } CYAlphabetic(false) - CYPrecedence(2) - virtual void Output(CYOutput &out, CYFlags flags) const; + virtual CYExpression *Replace(CYContext &context); }; struct CYIndirect : @@ -1423,9 +1606,8 @@ struct CYIndirect : } CYAlphabetic(false) - CYPrecedence(1) - virtual void Output(CYOutput &out, CYFlags flags) const; + virtual CYExpression *Replace(CYContext &context); }; #define CYPostfix_(op, name) \ @@ -1436,8 +1618,6 @@ struct CYIndirect : CYPostfix(lhs) \ { \ } \ - \ - CYPrecedence(3) \ \ virtual const char *Operator() const { \ return op; \ @@ -1454,7 +1634,6 @@ struct CYIndirect : } \ \ CYAlphabetic(alphabetic) \ - CYPrecedence(4) \ \ virtual const char *Operator() const { \ return op; \ @@ -1502,6 +1681,7 @@ CYPrefix_(true, "void", Void) CYPrefix_(true, "typeof", TypeOf) CYPrefix_(false, "++", PreIncrement) CYPrefix_(false, "--", PreDecrement) +CYPrefix_(false, "+", Affirm) CYPrefix_(false, "-", Negate) CYPrefix_(false, "~", BitwiseNot) CYPrefix_(false, "!", LogicalNot)