| Index: src/preparser.h
|
| diff --git a/src/preparser.h b/src/preparser.h
|
| index e99b4b0a181e200030100aa10446cfa2cb7bf923..bcaab743e5ad28e903bdd297154fd6fb7519e593 100644
|
| --- a/src/preparser.h
|
| +++ b/src/preparser.h
|
| @@ -76,12 +76,19 @@ class ParserBase {
|
| }
|
|
|
| protected:
|
| + enum AllowEvalOrArgumentsAsIdentifier {
|
| + kAllowEvalOrArguments,
|
| + kDontAllowEvalOrArguments
|
| + };
|
| +
|
| Scanner* scanner() const { return scanner_; }
|
| int position() { return scanner_->location().beg_pos; }
|
| int peek_position() { return scanner_->peek_location().beg_pos; }
|
| bool stack_overflow() const { return stack_overflow_; }
|
| void set_stack_overflow() { stack_overflow_ = true; }
|
|
|
| + virtual bool is_classic_mode() = 0;
|
| +
|
| INLINE(Token::Value peek()) {
|
| if (stack_overflow_) return Token::ILLEGAL;
|
| return scanner()->peek();
|
| @@ -137,8 +144,13 @@ class ParserBase {
|
| static int Precedence(Token::Value token, bool accept_IN);
|
|
|
| // Report syntax errors.
|
| - virtual void ReportUnexpectedToken(Token::Value token) = 0;
|
| - virtual void ReportMessageAt(Scanner::Location loc, const char* type) = 0;
|
| + void ReportUnexpectedToken(Token::Value token);
|
| + void ReportMessageAt(Scanner::Location location, const char* type) {
|
| + ReportMessageAt(location, type, Vector<const char*>::empty());
|
| + }
|
| + virtual void ReportMessageAt(Scanner::Location source_location,
|
| + const char* message,
|
| + Vector<const char*> args) = 0;
|
|
|
| // Used to detect duplicates in object literals. Each of the values
|
| // kGetterProperty, kSetterProperty and kValueProperty represents
|
| @@ -231,8 +243,6 @@ class PreParser : public ParserBase {
|
| : ParserBase(scanner, stack_limit),
|
| log_(log),
|
| scope_(NULL),
|
| - strict_mode_violation_location_(Scanner::Location::invalid()),
|
| - strict_mode_violation_type_(NULL),
|
| parenthesized_function_(false) { }
|
|
|
| ~PreParser() {}
|
| @@ -342,8 +352,6 @@ class PreParser : public ParserBase {
|
| // if bit 1 is set, it's a string literal.
|
| // If neither is set, it's no particular type, and both set isn't
|
| // use yet.
|
| - // Bit 2 is used to mark the expression as being parenthesized,
|
| - // so "(foo)" isn't recognized as a pure identifier (and possible label).
|
| class Expression {
|
| public:
|
| static Expression Default() {
|
| @@ -384,21 +392,8 @@ class PreParser : public ParserBase {
|
| static_cast<PreParser::Identifier::Type>(code_ >> kIdentifierShift));
|
| }
|
|
|
| - bool IsParenthesized() {
|
| - // If bit 0 or 1 is set, we interpret bit 2 as meaning parenthesized.
|
| - return (code_ & 7) > 4;
|
| - }
|
| -
|
| - bool IsRawIdentifier() {
|
| - return !IsParenthesized() && IsIdentifier();
|
| - }
|
| -
|
| bool IsStringLiteral() { return (code_ & kStringLiteralFlag) != 0; }
|
|
|
| - bool IsRawStringLiteral() {
|
| - return !IsParenthesized() && IsStringLiteral();
|
| - }
|
| -
|
| bool IsUseStrictLiteral() {
|
| return (code_ & kStringLiteralMask) == kUseStrictString;
|
| }
|
| @@ -415,27 +410,10 @@ class PreParser : public ParserBase {
|
| return code_ == kStrictFunctionExpression;
|
| }
|
|
|
| - Expression Parenthesize() {
|
| - int type = code_ & 3;
|
| - if (type != 0) {
|
| - // Identifiers and string literals can be parenthesized.
|
| - // They no longer work as labels or directive prologues,
|
| - // but are still recognized in other contexts.
|
| - return Expression(code_ | kParenthesizedExpressionFlag);
|
| - }
|
| - // For other types of expressions, it's not important to remember
|
| - // the parentheses.
|
| - return *this;
|
| - }
|
| -
|
| private:
|
| // First two/three bits are used as flags.
|
| // Bit 0 and 1 represent identifiers or strings literals, and are
|
| // mutually exclusive, but can both be absent.
|
| - // If bit 0 or 1 are set, bit 2 marks that the expression has
|
| - // been wrapped in parentheses (a string literal can no longer
|
| - // be a directive prologue, and an identifier can no longer be
|
| - // a label.
|
| enum {
|
| kUnknownExpression = 0,
|
| // Identifiers
|
| @@ -447,9 +425,6 @@ class PreParser : public ParserBase {
|
| kUseStrictString = kStringLiteralFlag | 8,
|
| kStringLiteralMask = kUseStrictString,
|
|
|
| - // Only if identifier or string literal.
|
| - kParenthesizedExpressionFlag = 4,
|
| -
|
| // Below here applies if neither identifier nor string literal.
|
| kThisExpression = 4,
|
| kThisPropertyExpression = 8,
|
| @@ -475,13 +450,11 @@ class PreParser : public ParserBase {
|
| // Preserves being an unparenthesized string literal, possibly
|
| // "use strict".
|
| static Statement ExpressionStatement(Expression expression) {
|
| - if (!expression.IsParenthesized()) {
|
| - if (expression.IsUseStrictLiteral()) {
|
| - return Statement(kUseStrictExpressionStatement);
|
| - }
|
| - if (expression.IsStringLiteral()) {
|
| - return Statement(kStringLiteralExpressionStatement);
|
| - }
|
| + if (expression.IsUseStrictLiteral()) {
|
| + return Statement(kUseStrictExpressionStatement);
|
| + }
|
| + if (expression.IsStringLiteral()) {
|
| + return Statement(kStringLiteralExpressionStatement);
|
| }
|
| return Default();
|
| }
|
| @@ -574,9 +547,13 @@ class PreParser : public ParserBase {
|
| };
|
|
|
| // Report syntax error
|
| - void ReportUnexpectedToken(Token::Value token);
|
| - void ReportMessageAt(Scanner::Location location, const char* type) {
|
| - ReportMessageAt(location, type, NULL);
|
| + void ReportMessageAt(Scanner::Location location,
|
| + const char* message,
|
| + Vector<const char*> args) {
|
| + ReportMessageAt(location.beg_pos,
|
| + location.end_pos,
|
| + message,
|
| + args.length() > 0 ? args[0] : NULL);
|
| }
|
| void ReportMessageAt(Scanner::Location location,
|
| const char* type,
|
| @@ -637,10 +614,17 @@ class PreParser : public ParserBase {
|
| Expression ParseV8Intrinsic(bool* ok);
|
|
|
| Arguments ParseArguments(bool* ok);
|
| - Expression ParseFunctionLiteral(bool is_generator, bool* ok);
|
| + Expression ParseFunctionLiteral(
|
| + Identifier name,
|
| + Scanner::Location function_name_location,
|
| + bool name_is_strict_reserved,
|
| + bool is_generator,
|
| + bool* ok);
|
| void ParseLazyFunctionLiteralBody(bool* ok);
|
|
|
| - Identifier ParseIdentifier(bool* ok);
|
| + Identifier ParseIdentifier(AllowEvalOrArgumentsAsIdentifier, bool* ok);
|
| + Identifier ParseIdentifierOrStrictReservedWord(bool* is_strict_reserved,
|
| + bool* ok);
|
| Identifier ParseIdentifierName(bool* ok);
|
| Identifier ParseIdentifierNameOrGetOrSet(bool* is_get,
|
| bool* is_set,
|
| @@ -657,7 +641,7 @@ class PreParser : public ParserBase {
|
| scope_->set_language_mode(language_mode);
|
| }
|
|
|
| - bool is_classic_mode() {
|
| + virtual bool is_classic_mode() {
|
| return scope_->language_mode() == CLASSIC_MODE;
|
| }
|
|
|
| @@ -669,21 +653,8 @@ class PreParser : public ParserBase {
|
|
|
| bool CheckInOrOf(bool accept_OF);
|
|
|
| - void SetStrictModeViolation(Scanner::Location,
|
| - const char* type,
|
| - bool* ok);
|
| -
|
| - void CheckDelayedStrictModeViolation(int beg_pos, int end_pos, bool* ok);
|
| -
|
| - void StrictModeIdentifierViolation(Scanner::Location,
|
| - const char* eval_args_type,
|
| - Identifier identifier,
|
| - bool* ok);
|
| -
|
| ParserRecorder* log_;
|
| Scope* scope_;
|
| - Scanner::Location strict_mode_violation_location_;
|
| - const char* strict_mode_violation_type_;
|
| bool parenthesized_function_;
|
| };
|
|
|
|
|