Commit 6cf32b13 authored by marja@chromium.org's avatar marja@chromium.org

Move ParseConditionalExpression to ParserBase.

R=mstarzinger@chromium.org
BUG=v8:3126
LOG=N

Review URL: https://codereview.chromium.org/198053002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19994 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f5f67ca5
...@@ -633,8 +633,9 @@ FunctionLiteral* ParserTraits::ParseFunctionLiteral( ...@@ -633,8 +633,9 @@ FunctionLiteral* ParserTraits::ParseFunctionLiteral(
} }
Expression* ParserTraits::ParseConditionalExpression(bool accept_IN, bool* ok) { Expression* ParserTraits::ParseBinaryExpression(int prec, bool accept_IN,
return parser_->ParseConditionalExpression(accept_IN, ok); bool* ok) {
return parser_->ParseBinaryExpression(prec, accept_IN, ok);
} }
...@@ -2922,27 +2923,6 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { ...@@ -2922,27 +2923,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 // Precedence >= 4
Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) { Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
ASSERT(prec >= 4); ASSERT(prec >= 4);
......
...@@ -561,7 +561,7 @@ class ParserTraits { ...@@ -561,7 +561,7 @@ class ParserTraits {
int function_token_position, int function_token_position,
FunctionLiteral::FunctionType type, FunctionLiteral::FunctionType type,
bool* ok); bool* ok);
Expression* ParseConditionalExpression(bool accept_IN, bool* ok); Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
private: private:
Parser* parser_; Parser* parser_;
...@@ -704,7 +704,6 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -704,7 +704,6 @@ class Parser : public ParserBase<ParserTraits> {
// Support for hamony block scoped bindings. // Support for hamony block scoped bindings.
Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); Block* ParseScopedBlock(ZoneStringList* labels, bool* ok);
Expression* ParseConditionalExpression(bool accept_IN, bool* ok);
Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok); Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
Expression* ParseUnaryExpression(bool* ok); Expression* ParseUnaryExpression(bool* ok);
Expression* ParsePostfixExpression(bool* ok); Expression* ParsePostfixExpression(bool* ok);
......
...@@ -146,9 +146,10 @@ PreParserExpression PreParserTraits::ParseFunctionLiteral( ...@@ -146,9 +146,10 @@ PreParserExpression PreParserTraits::ParseFunctionLiteral(
} }
PreParserExpression PreParserTraits::ParseConditionalExpression(bool accept_IN, PreParserExpression PreParserTraits::ParseBinaryExpression(int prec,
bool* ok) { bool accept_IN,
return pre_parser_->ParseConditionalExpression(accept_IN, ok); bool* ok) {
return pre_parser_->ParseBinaryExpression(prec, accept_IN, ok);
} }
...@@ -843,27 +844,6 @@ PreParser::Statement PreParser::ParseDebuggerStatement(bool* ok) { ...@@ -843,27 +844,6 @@ PreParser::Statement PreParser::ParseDebuggerStatement(bool* ok) {
#undef DUMMY #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 // Precedence >= 4
PreParser::Expression PreParser::ParseBinaryExpression(int prec, PreParser::Expression PreParser::ParseBinaryExpression(int prec,
bool accept_IN, bool accept_IN,
......
...@@ -388,6 +388,8 @@ class ParserBase : public Traits { ...@@ -388,6 +388,8 @@ class ParserBase : public Traits {
typename Traits::Type::Expression ParseAssignmentExpression(bool accept_IN, typename Traits::Type::Expression ParseAssignmentExpression(bool accept_IN,
bool* ok); bool* ok);
typename Traits::Type::Expression ParseYieldExpression(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 // Used to detect duplicates in object literals. Each of the values
// kGetterProperty, kSetterProperty and kValueProperty represents // kGetterProperty, kSetterProperty and kValueProperty represents
...@@ -718,6 +720,13 @@ class PreParserFactory { ...@@ -718,6 +720,13 @@ class PreParserFactory {
int pos) { int pos) {
return PreParserExpression::Default(); return PreParserExpression::Default();
} }
PreParserExpression NewConditional(PreParserExpression condition,
PreParserExpression then_expression,
PreParserExpression else_expression,
int pos) {
return PreParserExpression::Default();
}
}; };
...@@ -891,7 +900,7 @@ class PreParserTraits { ...@@ -891,7 +900,7 @@ class PreParserTraits {
int function_token_position, int function_token_position,
FunctionLiteral::FunctionType type, FunctionLiteral::FunctionType type,
bool* ok); bool* ok);
PreParserExpression ParseConditionalExpression(bool accept_IN, bool* ok); PreParserExpression ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
private: private:
PreParser* pre_parser_; PreParser* pre_parser_;
...@@ -1694,6 +1703,32 @@ typename Traits::Type::Expression ParserBase<Traits>::ParseYieldExpression( ...@@ -1694,6 +1703,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
#undef CHECK_OK_CUSTOM #undef CHECK_OK_CUSTOM
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment