X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/02447eafbae8e4e568a31d049b8f7e8846dd7865..63db22e50caddb75792b67534547cb3ac7ccff61:/Parser.hpp diff --git a/Parser.hpp b/Parser.hpp index a7ac66a..02b08eb 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -272,22 +272,6 @@ struct CYIdentifier : CYIdentifier *Replace(CYContext &context); }; -struct CYComment : - CYStatement -{ - const char *value_; - - CYComment(const char *value) : - value_(value) - { - } - - CYCompact(None) - - virtual CYStatement *Replace(CYContext &context); - virtual void Output(CYOutput &out, CYFlags flags) const; -}; - struct CYLabel : CYStatement { @@ -356,12 +340,12 @@ struct CYScope { void Close(CYContext &context, CYStatement *&statements); }; -struct CYProgram : +struct CYScript : CYThing { CYStatement *code_; - CYProgram(CYStatement *code) : + CYScript(CYStatement *code) : code_(code) { } @@ -478,12 +462,12 @@ struct CYBlock : virtual CYStatement *Return(); }; -struct CYForInitialiser { +struct CYForInitializer { virtual CYExpression *Replace(CYContext &context) = 0; virtual void Output(CYOutput &out, CYFlags flags) const = 0; }; -struct CYForInInitialiser { +struct CYForInInitializer { virtual void ForIn(CYOutput &out, CYFlags flags) const = 0; virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value) = 0; @@ -499,8 +483,8 @@ struct CYNumber; struct CYString; struct CYExpression : - CYForInitialiser, - CYForInInitialiser, + CYForInitializer, + CYForInInitializer, CYClassName, CYThing { @@ -604,9 +588,9 @@ struct CYFunctionParameter : CYNext, CYThing { - CYForInInitialiser *initialiser_; + CYForInInitializer *initialiser_; - CYFunctionParameter(CYForInInitialiser *initialiser, CYFunctionParameter *next = NULL) : + CYFunctionParameter(CYForInInitializer *initialiser, CYFunctionParameter *next = NULL) : CYNext(next), initialiser_(initialiser) { @@ -813,6 +797,43 @@ struct CYString : virtual void PropertyName(CYOutput &out) const; }; +struct CYElementValue; + +struct CYSpan : + CYNext +{ + CYExpression *expression_; + CYString *string_; + + CYSpan(CYExpression *expression, CYString *string, CYSpan *next) : + CYNext(next), + expression_(expression), + string_(string) + { + } + + CYElementValue *Replace(CYContext &context); +}; + +struct CYTemplate : + CYExpression +{ + CYString *string_; + CYSpan *spans_; + + CYTemplate(CYString *string, CYSpan *spans) : + string_(string), + spans_(spans) + { + } + + CYPrecedence(0) + CYRightHand(false) + + virtual CYExpression *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYNumber : CYTrivial, CYPropertyName @@ -839,9 +860,11 @@ struct CYRegEx : CYTrivial { const char *value_; + size_t size_; - CYRegEx(const char *value) : - value_(value) + CYRegEx(const char *value, size_t size) : + value_(value), + size_(size) { } @@ -1048,19 +1071,49 @@ struct CYClause : }; struct CYElement : - CYNext, CYThing +{ + virtual bool Elision() const = 0; + + virtual void Replace(CYContext &context) = 0; +}; + +struct CYElementValue : + CYNext, + CYElement { CYExpression *value_; - CYElement(CYExpression *value, CYElement *next) : + CYElementValue(CYExpression *value, CYElement *next) : CYNext(next), value_(value) { } - void Replace(CYContext &context); - void Output(CYOutput &out) const; + virtual bool Elision() const { + return value_ == NULL; + } + + virtual void Replace(CYContext &context); + virtual void Output(CYOutput &out) const; +}; + +struct CYElementSpread : + CYElement +{ + CYExpression *value_; + + CYElementSpread(CYExpression *value) : + value_(value) + { + } + + virtual bool Elision() const { + return false; + } + + virtual void Replace(CYContext &context); + virtual void Output(CYOutput &out) const; }; struct CYArray : @@ -1096,7 +1149,7 @@ struct CYProperty : }; struct CYDeclaration : - CYForInInitialiser + CYForInInitializer { CYIdentifier *identifier_; CYExpression *initialiser_; @@ -1142,7 +1195,7 @@ struct CYDeclarations : }; struct CYForDeclarations : - CYForInitialiser + CYForInitializer { CYDeclarations *declarations_; @@ -1192,12 +1245,12 @@ struct CYLetStatement : struct CYFor : CYStatement { - CYForInitialiser *initialiser_; + CYForInitializer *initialiser_; CYExpression *test_; CYExpression *increment_; CYStatement *code_; - CYFor(CYForInitialiser *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) : + CYFor(CYForInitializer *initialiser, CYExpression *test, CYExpression *increment, CYStatement *code) : initialiser_(initialiser), test_(test), increment_(increment), @@ -1214,11 +1267,11 @@ struct CYFor : struct CYForIn : CYStatement { - CYForInInitialiser *initialiser_; + CYForInInitializer *initialiser_; CYExpression *set_; CYStatement *code_; - CYForIn(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) : + CYForIn(CYForInInitializer *initialiser, CYExpression *set, CYStatement *code) : initialiser_(initialiser), set_(set), code_(code) @@ -1234,11 +1287,11 @@ struct CYForIn : struct CYForOf : CYStatement { - CYForInInitialiser *initialiser_; + CYForInInitializer *initialiser_; CYExpression *set_; CYStatement *code_; - CYForOf(CYForInInitialiser *initialiser, CYExpression *set, CYStatement *code) : + CYForOf(CYForInInitializer *initialiser, CYExpression *set, CYStatement *code) : initialiser_(initialiser), set_(set), code_(code) @@ -1596,6 +1649,38 @@ struct CYReturn : virtual void Output(CYOutput &out, CYFlags flags) const; }; +struct CYYieldGenerator : + CYExpression +{ + CYExpression *value_; + + CYYieldGenerator(CYExpression *value) : + value_(value) + { + } + + CYPrecedence(0) + + virtual CYExpression *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + +struct CYYieldValue : + CYExpression +{ + CYExpression *value_; + + CYYieldValue(CYExpression *value) : + value_(value) + { + } + + CYPrecedence(0) + + virtual CYExpression *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYEmpty : CYStatement {