X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/d5618df7c804163dceb3eb48e5406aeb9de79c96..975cde38d8631f5e80bb54b3fbd87ce7d4aa2766:/Parser.hpp diff --git a/Parser.hpp b/Parser.hpp index 47a60c0..ba896b7 100644 --- a/Parser.hpp +++ b/Parser.hpp @@ -1,5 +1,5 @@ /* Cycript - Optimizing JavaScript Compiler/Runtime - * Copyright (C) 2009-2010 Jay Freeman (saurik) + * Copyright (C) 2009-2012 Jay Freeman (saurik) */ /* GNU Lesser General Public License, Version 3 {{{ */ @@ -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; } @@ -627,6 +655,8 @@ struct CYCompound : virtual CYExpression *Replace(CYContext &context); void Output(CYOutput &out, CYFlags flags) const; + + virtual CYExpression *Primitive(CYContext &context); }; struct CYDeclaration; @@ -651,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; @@ -665,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) { @@ -686,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) { @@ -1473,7 +1510,9 @@ struct CYFunction { CYIdentifier *name_; CYFunctionParameter *parameters_; CYBlock code_; + CYNonLocal *nonlocal_; + CYThisScope this_; CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) : name_(name), @@ -1508,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