X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/e06e5ee1f12b9b79b34570e65c1f5e9c12b9b8c3..975cde38d8631f5e80bb54b3fbd87ce7d4aa2766:/Parser.hpp diff --git a/Parser.hpp b/Parser.hpp index 7197428..ba896b7 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -350,11 +350,14 @@ struct CYProgram : }; struct CYNonLocal; +struct CYThisScope; struct CYContext { CYOptions &options_; CYScope *scope_; + CYThisScope *this_; + CYIdentifierUsageVector rename_; CYNonLocal *nonlocal_; @@ -364,6 +367,7 @@ struct CYContext { CYContext(CYOptions &options) : options_(options), scope_(NULL), + this_(NULL), nonlocal_(NULL), nextlocal_(NULL), unique_(0) @@ -414,6 +418,25 @@ struct CYNonLocal { } }; +struct CYThisScope : + CYNext +{ + CYIdentifier *identifier_; + + CYThisScope() : + identifier_(NULL) + { + } + + CYIdentifier *Identifier(CYContext &context) { + if (next_ != NULL) + return next_->Identifier(context); + if (identifier_ == NULL) + identifier_ = context.Unique(); + return identifier_; + } +}; + struct CYBlock : CYStatement, CYThing @@ -430,7 +453,7 @@ struct CYBlock : } void AddPrev(CYStatement *statement) { - CYSetLast(statement, statements_); + CYSetLast(statement) = statements_; statements_ = statement; } @@ -451,9 +474,14 @@ class CYDriver { void *scanner_; CYState state_; - bool nobrace_; std::stack in_; + struct { + bool AtImplementation; + bool Function; + bool OpenBrace; + } no_; + const char *data_; size_t size_; FILE *file_; @@ -619,7 +647,7 @@ struct CYCompound : } void AddPrev(CYExpression *expression) { - CYSetLast(expression, expressions_); + CYSetLast(expression) = expressions_; expressions_ = expression; } @@ -653,6 +681,11 @@ struct CYComprehension : CYNext, CYThing { + CYComprehension(CYComprehension *next = NULL) : + CYNext(next) + { + } + virtual const char *Name() const = 0; virtual CYFunctionParameter *Parameter(CYContext &context) const = 0; @@ -667,7 +700,8 @@ struct CYForInComprehension : CYIdentifier *name_; CYExpression *set_; - CYForInComprehension(CYIdentifier *name, CYExpression *set) : + CYForInComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) : + CYComprehension(next), name_(name), set_(set) { @@ -688,7 +722,8 @@ struct CYForOfComprehension : CYIdentifier *name_; CYExpression *set_; - CYForOfComprehension(CYIdentifier *name, CYExpression *set) : + CYForOfComprehension(CYIdentifier *name, CYExpression *set, CYComprehension *next = NULL) : + CYComprehension(next), name_(name), set_(set) { @@ -1475,7 +1510,9 @@ struct CYFunction { CYIdentifier *name_; CYFunctionParameter *parameters_; CYBlock code_; + CYNonLocal *nonlocal_; + CYThisScope this_; CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : name_(name), @@ -1510,6 +1547,23 @@ struct CYFunctionExpression : virtual void Output(CYOutput &out, CYFlags flags) const; }; +// XXX: this should derive from CYAnonymousFunction +struct CYFatArrow : + CYFunction, + CYExpression +{ + CYFatArrow(CYFunctionParameter *parameters, CYStatement *statements) : + CYFunction(NULL, parameters, statements) + { + } + + CYPrecedence(0) + CYRightHand(false) + + virtual CYExpression *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + // XXX: this should derive from CYAnonymousFunctionExpression struct CYRubyProc : CYFunctionExpression