Reviewers: rossberg,

Message:
rossberg, one more (this one is trivial, too), ptal

Description:
Move ParseConditionalExpression to ParserBase.

[email protected]
BUG=v8:3126
LOG=N

Please review this at https://codereview.chromium.org/198053002/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+44, -50 lines):
  M src/parser.h
  M src/parser.cc
  M src/preparser.h
  M src/preparser.cc


Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 48d8fffef7c86a9c055cce110bc69668d48df03b..07e8273920f6ee60be6f683db4163ea516f60f16 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -638,8 +638,9 @@ FunctionLiteral* ParserTraits::ParseFunctionLiteral(
 }


-Expression* ParserTraits::ParseConditionalExpression(bool accept_IN, bool* ok) {
-  return parser_->ParseConditionalExpression(accept_IN, ok);
+Expression* ParserTraits::ParseBinaryExpression(int prec, bool accept_IN,
+                                                bool* ok) {
+  return parser_->ParseBinaryExpression(prec, accept_IN, ok);
 }


@@ -2930,27 +2931,6 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
 }


-// Precedence = 3
-Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) {
-  // ConditionalExpression ::
-  //   LogicalOrExpression
- // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
-
-  int pos = peek_position();
-  // We start using the binary expression parser for prec >= 4 only!
-  Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK);
-  if (peek() != Token::CONDITIONAL) return expression;
-  Consume(Token::CONDITIONAL);
-  // In parsing the first assignment expression in conditional
-  // expressions we always accept the 'in' keyword; see ECMA-262,
-  // section 11.12, page 58.
-  Expression* left = ParseAssignmentExpression(true, CHECK_OK);
-  Expect(Token::COLON, CHECK_OK);
-  Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
-  return factory()->NewConditional(expression, left, right, pos);
-}
-
-
 // Precedence >= 4
Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
   ASSERT(prec >= 4);
Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index 202c0b5b0f306feb1835609d2dfd8937ceaae086..1941e9d27508ae36317137958a0140cf09b52da6 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -553,7 +553,7 @@ class ParserTraits {
       int function_token_position,
       FunctionLiteral::FunctionType type,
       bool* ok);
-  Expression* ParseConditionalExpression(bool accept_IN, bool* ok);
+  Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok);

  private:
   Parser* parser_;
@@ -696,7 +696,6 @@ class Parser : public ParserBase<ParserTraits> {
   // Support for hamony block scoped bindings.
   Block* ParseScopedBlock(ZoneStringList* labels, bool* ok);

-  Expression* ParseConditionalExpression(bool accept_IN, bool* ok);
   Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
   Expression* ParseUnaryExpression(bool* ok);
   Expression* ParsePostfixExpression(bool* ok);
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index d6acac0cbb86875675a62adc92107751fa5174b1..8b5e20d9e8cb5190c759fe66f655b90a8858e8f0 100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -142,9 +142,10 @@ PreParserExpression PreParserTraits::ParseFunctionLiteral(
 }


-PreParserExpression PreParserTraits::ParseConditionalExpression(bool accept_IN,
-                                                                bool* ok) {
-  return pre_parser_->ParseConditionalExpression(accept_IN, ok);
+PreParserExpression PreParserTraits::ParseBinaryExpression(int prec,
+                                                           bool accept_IN,
+                                                           bool* ok) {
+  return pre_parser_->ParseBinaryExpression(prec, accept_IN, ok);
 }


@@ -839,27 +840,6 @@ PreParser::Statement PreParser::ParseDebuggerStatement(bool* ok) {
 #undef DUMMY


-// Precedence = 3
-PreParser::Expression PreParser::ParseConditionalExpression(bool accept_IN,
-                                                            bool* ok) {
-  // ConditionalExpression ::
-  //   LogicalOrExpression
- // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
-
-  // We start using the binary expression parser for prec >= 4 only!
-  Expression expression = ParseBinaryExpression(4, accept_IN, CHECK_OK);
-  if (peek() != Token::CONDITIONAL) return expression;
-  Consume(Token::CONDITIONAL);
-  // In parsing the first assignment expression in conditional
-  // expressions we always accept the 'in' keyword; see ECMA-262,
-  // section 11.12, page 58.
-  ParseAssignmentExpression(true, CHECK_OK);
-  Expect(Token::COLON, CHECK_OK);
-  ParseAssignmentExpression(accept_IN, CHECK_OK);
-  return Expression::Default();
-}
-
-
 // Precedence >= 4
 PreParser::Expression PreParser::ParseBinaryExpression(int prec,
                                                        bool accept_IN,
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 7de3805156576ff282254faf2d072ff5ce0b5da9..79c1398a8e8a60eb99d93732a103aa6bb4fb7bdd 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -346,6 +346,8 @@ class ParserBase : public Traits {
typename Traits::Type::Expression ParseAssignmentExpression(bool accept_IN,
                                                               bool* ok);
   typename Traits::Type::Expression ParseYieldExpression(bool* ok);
+ typename Traits::Type::Expression ParseConditionalExpression(bool accept_IN,
+                                                               bool* ok);

   // Used to detect duplicates in object literals. Each of the values
   // kGetterProperty, kSetterProperty and kValueProperty represents
@@ -676,6 +678,13 @@ class PreParserFactory {
                                int pos) {
     return PreParserExpression::Default();
   }
+
+  PreParserExpression NewConditional(PreParserExpression condition,
+                                     PreParserExpression then_expression,
+                                     PreParserExpression else_expression,
+                                     int pos) {
+    return PreParserExpression::Default();
+  }
 };


@@ -844,7 +853,7 @@ class PreParserTraits {
       int function_token_position,
       FunctionLiteral::FunctionType type,
       bool* ok);
-  PreParserExpression ParseConditionalExpression(bool accept_IN, bool* ok);
+ PreParserExpression ParseBinaryExpression(int prec, bool accept_IN, bool* ok);

  private:
   PreParser* pre_parser_;
@@ -1652,6 +1661,32 @@ typename Traits::Type::Expression ParserBase<Traits>::ParseYieldExpression(
 }


+// Precedence = 3
+template <class Traits>
+typename Traits::Type::Expression
+ParserBase<Traits>::ParseConditionalExpression(bool accept_IN, bool* ok) {
+  // ConditionalExpression ::
+  //   LogicalOrExpression
+ // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
+
+  int pos = peek_position();
+  // We start using the binary expression parser for prec >= 4 only!
+  typename Traits::Type::Expression expression =
+      this->ParseBinaryExpression(4, accept_IN, CHECK_OK);
+  if (peek() != Token::CONDITIONAL) return expression;
+  Consume(Token::CONDITIONAL);
+  // In parsing the first assignment expression in conditional
+  // expressions we always accept the 'in' keyword; see ECMA-262,
+  // section 11.12, page 58.
+  typename Traits::Type::Expression left =
+      ParseAssignmentExpression(true, CHECK_OK);
+  Expect(Token::COLON, CHECK_OK);
+  typename Traits::Type::Expression right =
+      ParseAssignmentExpression(accept_IN, CHECK_OK);
+  return factory()->NewConditional(expression, left, right, pos);
+}
+
+
 #undef CHECK_OK
 #undef CHECK_OK_CUSTOM



--
--
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