Revision: 20149
Author:   [email protected]
Date:     Fri Mar 21 09:46:18 2014 UTC
Log:      Move ParsePostfixExpression into ParserBase.

+ enable a test which checks that Parser and PreParser produce the "invalid left
hand side" errors consistently.

[email protected]
BUG=

Review URL: https://codereview.chromium.org/202333004
http://code.google.com/p/v8/source/detail?r=20149

Modified:
 /branches/bleeding_edge/src/parser.cc
 /branches/bleeding_edge/src/parser.h
 /branches/bleeding_edge/src/preparser.cc
 /branches/bleeding_edge/src/preparser.h
 /branches/bleeding_edge/test/cctest/test-parsing.cc

=======================================
--- /branches/bleeding_edge/src/parser.cc       Thu Mar 20 12:27:36 2014 UTC
+++ /branches/bleeding_edge/src/parser.cc       Fri Mar 21 09:46:18 2014 UTC
@@ -740,8 +740,8 @@
 }


-Expression* ParserTraits::ParsePostfixExpression(bool* ok) {
-  return parser_->ParsePostfixExpression(ok);
+Expression* ParserTraits::ParseLeftHandSideExpression(bool* ok) {
+  return parser_->ParseLeftHandSideExpression(ok);
 }


@@ -3041,37 +3041,6 @@
     return loop;
   }
 }
-
-
-Expression* Parser::ParsePostfixExpression(bool* ok) {
-  // PostfixExpression ::
-  //   LeftHandSideExpression ('++' | '--')?
-
-  Scanner::Location lhs_location = scanner()->peek_location();
-  Expression* expression = ParseLeftHandSideExpression(CHECK_OK);
-  if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
-      Token::IsCountOp(peek())) {
-    if (expression == NULL || !expression->IsValidLeftHandSide()) {
-      ReportMessageAt(lhs_location, "invalid_lhs_in_postfix_op", true);
-      *ok = false;
-      return NULL;
-    }
-
-    if (strict_mode() == STRICT) {
- // Postfix expression operand in strict mode may not be eval or arguments.
-      CheckStrictModeLValue(expression, CHECK_OK);
-    }
-    MarkExpressionAsLValue(expression);
-
-    Token::Value next = Next();
-    expression =
-        factory()->NewCountOperation(next,
-                                     false /* postfix */,
-                                     expression,
-                                     position());
-  }
-  return expression;
-}


 Expression* Parser::ParseLeftHandSideExpression(bool* ok) {
=======================================
--- /branches/bleeding_edge/src/parser.h        Thu Mar 20 13:37:26 2014 UTC
+++ /branches/bleeding_edge/src/parser.h        Fri Mar 21 09:46:18 2014 UTC
@@ -489,11 +489,6 @@
   // literal so it can be added as a constant function property.
   static void CheckAssigningFunctionLiteralToProperty(Expression* left,
                                                       Expression* right);
-
-  // Determine whether the expression is a valid assignment left-hand side.
-  static bool IsValidLeftHandSide(Expression* expression) {
-    return expression->IsValidLeftHandSide();
-  }

// Determine if the expression is a variable proxy and mark it as being used // in an assignment or with a increment/decrement operator. This is currently
@@ -589,7 +584,7 @@
       int function_token_position,
       FunctionLiteral::FunctionType type,
       bool* ok);
-  Expression* ParsePostfixExpression(bool* ok);
+  Expression* ParseLeftHandSideExpression(bool* ok);

  private:
   Parser* parser_;
@@ -748,7 +743,6 @@
   Block* ParseScopedBlock(ZoneStringList* labels, bool* ok);

   Expression* ParseUnaryExpression(bool* ok);
-  Expression* ParsePostfixExpression(bool* ok);
   Expression* ParseLeftHandSideExpression(bool* ok);
   Expression* ParseMemberWithNewPrefixesExpression(bool* ok);
   Expression* ParseMemberExpression(bool* ok);
=======================================
--- /branches/bleeding_edge/src/preparser.cc    Thu Mar 20 13:18:15 2014 UTC
+++ /branches/bleeding_edge/src/preparser.cc    Fri Mar 21 09:46:18 2014 UTC
@@ -146,8 +146,8 @@
 }


-PreParserExpression PreParserTraits::ParsePostfixExpression(bool* ok) {
-  return pre_parser_->ParsePostfixExpression(ok);
+PreParserExpression PreParserTraits::ParseLeftHandSideExpression(bool* ok) {
+  return pre_parser_->ParseLeftHandSideExpression(ok);
 }


@@ -842,23 +842,6 @@
 #undef DUMMY


-PreParser::Expression PreParser::ParsePostfixExpression(bool* ok) {
-  // PostfixExpression ::
-  //   LeftHandSideExpression ('++' | '--')?
-
-  Expression expression = ParseLeftHandSideExpression(CHECK_OK);
-  if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
-      Token::IsCountOp(peek())) {
-    if (strict_mode() == STRICT) {
-      CheckStrictModeLValue(expression, CHECK_OK);
-    }
-    Next();
-    return Expression::Default();
-  }
-  return expression;
-}
-
-
 PreParser::Expression PreParser::ParseLeftHandSideExpression(bool* ok) {
   // LeftHandSideExpression ::
   //   (NewExpression | MemberExpression) ...
=======================================
--- /branches/bleeding_edge/src/preparser.h     Thu Mar 20 13:18:15 2014 UTC
+++ /branches/bleeding_edge/src/preparser.h     Fri Mar 21 09:46:18 2014 UTC
@@ -395,6 +395,7 @@
   ExpressionT ParseConditionalExpression(bool accept_IN, bool* ok);
   ExpressionT ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
   ExpressionT ParseUnaryExpression(bool* ok);
+  ExpressionT ParsePostfixExpression(bool* ok);

   // Used to detect duplicates in object literals. Each of the values
   // kGetterProperty, kSetterProperty and kValueProperty represents
@@ -580,7 +581,12 @@
return code_ == kPropertyExpression || code_ == kThisPropertyExpression;
   }

-  // Dummy implementation for making expression->AsCall() work (see below).
+  bool IsValidLeftHandSide() {
+    return IsIdentifier() || IsProperty();
+  }
+
+ // Dummy implementation for making expression->somefunc() work in both Parser
+  // and PreParser.
   PreParserExpression* operator->() { return this; }

   // These are only used when doing function name inferring, and PreParser
@@ -832,11 +838,6 @@

   static void CheckAssigningFunctionLiteralToProperty(
       PreParserExpression left, PreParserExpression right) {}
-
-  // Determine whether the expression is a valid assignment left-hand side.
-  static bool IsValidLeftHandSide(PreParserExpression expression) {
-    return expression.IsIdentifier() || expression.IsProperty();
-  }

   static PreParserExpression MarkExpressionAsLValue(
       PreParserExpression expression) {
@@ -944,7 +945,7 @@
       int function_token_position,
       FunctionLiteral::FunctionType type,
       bool* ok);
-  PreParserExpression ParsePostfixExpression(bool* ok);
+  PreParserExpression ParseLeftHandSideExpression(bool* ok);

  private:
   PreParser* pre_parser_;
@@ -1108,7 +1109,6 @@
   Statement ParseTryStatement(bool* ok);
   Statement ParseDebuggerStatement(bool* ok);
   Expression ParseConditionalExpression(bool accept_IN, bool* ok);
-  Expression ParsePostfixExpression(bool* ok);
   Expression ParseLeftHandSideExpression(bool* ok);
   Expression ParseMemberExpression(bool* ok);
Expression ParseMemberExpressionContinuation(PreParserExpression expression,
@@ -1664,7 +1664,7 @@
     return expression;
   }

-  if (!this->IsValidLeftHandSide(expression)) {
+  if (!expression->IsValidLeftHandSide()) {
     this->ReportMessageAt(lhs_location, "invalid_lhs_in_assignment", true);
     *ok = false;
     return this->EmptyExpression();
@@ -1834,7 +1834,7 @@
     op = Next();
     Scanner::Location lhs_location = scanner()->peek_location();
     ExpressionT expression = ParseUnaryExpression(CHECK_OK);
-    if (!this->IsValidLeftHandSide(expression)) {
+    if (!expression->IsValidLeftHandSide()) {
       ReportMessageAt(lhs_location, "invalid_lhs_in_prefix_op", true);
       *ok = false;
       return this->EmptyExpression();
@@ -1855,6 +1855,39 @@
     return this->ParsePostfixExpression(ok);
   }
 }
+
+
+template <class Traits>
+typename ParserBase<Traits>::ExpressionT
+ParserBase<Traits>::ParsePostfixExpression(bool* ok) {
+  // PostfixExpression ::
+  //   LeftHandSideExpression ('++' | '--')?
+
+  Scanner::Location lhs_location = scanner()->peek_location();
+  ExpressionT expression = this->ParseLeftHandSideExpression(CHECK_OK);
+  if (!scanner()->HasAnyLineTerminatorBeforeNext() &&
+      Token::IsCountOp(peek())) {
+    if (!expression->IsValidLeftHandSide()) {
+      ReportMessageAt(lhs_location, "invalid_lhs_in_postfix_op", true);
+      *ok = false;
+      return this->EmptyExpression();
+    }
+
+    if (strict_mode() == STRICT) {
+ // Postfix expression operand in strict mode may not be eval or arguments.
+      this->CheckStrictModeLValue(expression, CHECK_OK);
+    }
+    expression = this->MarkExpressionAsLValue(expression);
+
+    Token::Value next = Next();
+    expression =
+        factory()->NewCountOperation(next,
+                                     false /* postfix */,
+                                     expression,
+                                     position());
+  }
+  return expression;
+}


 #undef CHECK_OK
=======================================
--- /branches/bleeding_edge/test/cctest/test-parsing.cc Thu Mar 20 13:18:15 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-parsing.cc Fri Mar 21 09:46:18 2014 UTC
@@ -2332,8 +2332,7 @@
     "new foo bar",
     "new ) foo",
     "new ++foo",
-    // TODO(marja): Activate this test once the preparser checks correctly.
-    // "new foo ++",
+    "new foo ++",
     NULL
   };

@@ -2528,7 +2527,7 @@
 }


-TEST(ErrorInvalidLeftHandSide) {
+TEST(InvalidLeftHandSide) {
   const char* assignment_context_data[][2] = {
     // {"", " = 1;"},
     // {"\"use strict\"; ", " = 1;"},
@@ -2593,6 +2592,5 @@
RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError);

   RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess);
-  // TODO(marja): This doesn't work yet.
- // RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError); + RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError);
 }

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to