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
This commit is contained in:
parent
f5f67ca58e
commit
6cf32b134a
@ -633,8 +633,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);
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) {
|
||||
ASSERT(prec >= 4);
|
||||
|
@ -561,7 +561,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_;
|
||||
@ -704,7 +704,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);
|
||||
|
@ -146,9 +146,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);
|
||||
}
|
||||
|
||||
|
||||
@ -843,27 +844,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,
|
||||
|
@ -388,6 +388,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
|
||||
@ -718,6 +720,13 @@ class PreParserFactory {
|
||||
int pos) {
|
||||
return PreParserExpression::Default();
|
||||
}
|
||||
|
||||
PreParserExpression NewConditional(PreParserExpression condition,
|
||||
PreParserExpression then_expression,
|
||||
PreParserExpression else_expression,
|
||||
int pos) {
|
||||
return PreParserExpression::Default();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -891,7 +900,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_;
|
||||
@ -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_CUSTOM
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user