Commit ee46e648 authored by marja@chromium.org's avatar marja@chromium.org

Move ParseYieldExpression to ParserBase.

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

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19921 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a89f68c6
...@@ -638,11 +638,6 @@ FunctionLiteral* ParserTraits::ParseFunctionLiteral( ...@@ -638,11 +638,6 @@ FunctionLiteral* ParserTraits::ParseFunctionLiteral(
} }
Expression* ParserTraits::ParseYieldExpression(bool* ok) {
return parser_->ParseYieldExpression(ok);
}
Expression* ParserTraits::ParseConditionalExpression(bool accept_IN, bool* ok) { Expression* ParserTraits::ParseConditionalExpression(bool accept_IN, bool* ok) {
return parser_->ParseConditionalExpression(accept_IN, ok); return parser_->ParseConditionalExpression(accept_IN, ok);
} }
...@@ -2935,24 +2930,6 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { ...@@ -2935,24 +2930,6 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) {
} }
Expression* Parser::ParseYieldExpression(bool* ok) {
// YieldExpression ::
// 'yield' '*'? AssignmentExpression
int pos = peek_position();
Expect(Token::YIELD, CHECK_OK);
Yield::Kind kind =
Check(Token::MUL) ? Yield::DELEGATING : Yield::SUSPEND;
Expression* generator_object = factory()->NewVariableProxy(
function_state_->generator_object_variable());
Expression* expression = ParseAssignmentExpression(false, CHECK_OK);
Yield* yield = factory()->NewYield(generator_object, expression, kind, pos);
if (kind == Yield::DELEGATING) {
yield->set_index(function_state_->NextHandlerIndex());
}
return yield;
}
// Precedence = 3 // Precedence = 3
Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) { Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) {
// ConditionalExpression :: // ConditionalExpression ::
......
...@@ -420,6 +420,7 @@ class ParserTraits { ...@@ -420,6 +420,7 @@ class ParserTraits {
// Return types for traversing functions. // Return types for traversing functions.
typedef Handle<String> Identifier; typedef Handle<String> Identifier;
typedef v8::internal::Expression* Expression; typedef v8::internal::Expression* Expression;
typedef Yield* YieldExpression;
typedef v8::internal::FunctionLiteral* FunctionLiteral; typedef v8::internal::FunctionLiteral* FunctionLiteral;
typedef v8::internal::Literal* Literal; typedef v8::internal::Literal* Literal;
typedef ObjectLiteral::Property* ObjectLiteralProperty; typedef ObjectLiteral::Property* ObjectLiteralProperty;
...@@ -556,7 +557,6 @@ class ParserTraits { ...@@ -556,7 +557,6 @@ class ParserTraits {
int function_token_position, int function_token_position,
FunctionLiteral::FunctionType type, FunctionLiteral::FunctionType type,
bool* ok); bool* ok);
Expression* ParseYieldExpression(bool* ok);
Expression* ParseConditionalExpression(bool accept_IN, bool* ok); Expression* ParseConditionalExpression(bool accept_IN, bool* ok);
private: private:
...@@ -700,7 +700,6 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -700,7 +700,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* ParseYieldExpression(bool* ok);
Expression* ParseConditionalExpression(bool accept_IN, 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);
......
...@@ -142,11 +142,6 @@ PreParserExpression PreParserTraits::ParseFunctionLiteral( ...@@ -142,11 +142,6 @@ PreParserExpression PreParserTraits::ParseFunctionLiteral(
} }
PreParserExpression PreParserTraits::ParseYieldExpression(bool* ok) {
return pre_parser_->ParseYieldExpression(ok);
}
PreParserExpression PreParserTraits::ParseConditionalExpression(bool accept_IN, PreParserExpression PreParserTraits::ParseConditionalExpression(bool accept_IN,
bool* ok) { bool* ok) {
return pre_parser_->ParseConditionalExpression(accept_IN, ok); return pre_parser_->ParseConditionalExpression(accept_IN, ok);
...@@ -844,19 +839,6 @@ PreParser::Statement PreParser::ParseDebuggerStatement(bool* ok) { ...@@ -844,19 +839,6 @@ PreParser::Statement PreParser::ParseDebuggerStatement(bool* ok) {
#undef DUMMY #undef DUMMY
// Precedence = 3
PreParser::Expression PreParser::ParseYieldExpression(bool* ok) {
// YieldExpression ::
// 'yield' '*'? AssignmentExpression
Consume(Token::YIELD);
Check(Token::MUL);
ParseAssignmentExpression(false, CHECK_OK);
return Expression::Default();
}
// Precedence = 3 // Precedence = 3
PreParser::Expression PreParser::ParseConditionalExpression(bool accept_IN, PreParser::Expression PreParser::ParseConditionalExpression(bool accept_IN,
bool* ok) { bool* ok) {
......
...@@ -384,6 +384,7 @@ class ParserBase : public Traits { ...@@ -384,6 +384,7 @@ class ParserBase : public Traits {
typename Traits::Type::ExpressionList ParseArguments(bool* ok); typename Traits::Type::ExpressionList ParseArguments(bool* ok);
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);
// 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
...@@ -574,6 +575,9 @@ class PreParserExpression { ...@@ -574,6 +575,9 @@ class PreParserExpression {
void* AsCall() const { return NULL; } void* AsCall() const { return NULL; }
void* AsCallNew() const { return NULL; } void* AsCallNew() const { return NULL; }
// More dummy implementations of things PreParser doesn't need to track:
void set_index(int index) {} // For YieldExpressions
private: private:
// First two/three bits are used as flags. // First two/three bits are used as flags.
// Bit 0 and 1 represent identifiers or strings literals, and are // Bit 0 and 1 represent identifiers or strings literals, and are
...@@ -700,6 +704,17 @@ class PreParserFactory { ...@@ -700,6 +704,17 @@ class PreParserFactory {
int pos) { int pos) {
return PreParserExpression::Default(); return PreParserExpression::Default();
} }
PreParserExpression NewVariableProxy(void* generator_variable) {
return PreParserExpression::Default();
}
PreParserExpression NewYield(PreParserExpression generator_object,
PreParserExpression expression,
Yield::Kind yield_kind,
int pos) {
return PreParserExpression::Default();
}
}; };
...@@ -722,6 +737,7 @@ class PreParserTraits { ...@@ -722,6 +737,7 @@ class PreParserTraits {
// Return types for traversing functions. // Return types for traversing functions.
typedef PreParserIdentifier Identifier; typedef PreParserIdentifier Identifier;
typedef PreParserExpression Expression; typedef PreParserExpression Expression;
typedef PreParserExpression YieldExpression;
typedef PreParserExpression FunctionLiteral; typedef PreParserExpression FunctionLiteral;
typedef PreParserExpression ObjectLiteralProperty; typedef PreParserExpression ObjectLiteralProperty;
typedef PreParserExpression Literal; typedef PreParserExpression Literal;
...@@ -871,7 +887,6 @@ class PreParserTraits { ...@@ -871,7 +887,6 @@ class PreParserTraits {
int function_token_position, int function_token_position,
FunctionLiteral::FunctionType type, FunctionLiteral::FunctionType type,
bool* ok); bool* ok);
PreParserExpression ParseYieldExpression(bool* ok);
PreParserExpression ParseConditionalExpression(bool accept_IN, bool* ok); PreParserExpression ParseConditionalExpression(bool accept_IN, bool* ok);
private: private:
...@@ -1037,7 +1052,6 @@ class PreParser : public ParserBase<PreParserTraits> { ...@@ -1037,7 +1052,6 @@ class PreParser : public ParserBase<PreParserTraits> {
Statement ParseThrowStatement(bool* ok); Statement ParseThrowStatement(bool* ok);
Statement ParseTryStatement(bool* ok); Statement ParseTryStatement(bool* ok);
Statement ParseDebuggerStatement(bool* ok); Statement ParseDebuggerStatement(bool* ok);
Expression ParseYieldExpression(bool* ok);
Expression ParseConditionalExpression(bool accept_IN, 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);
...@@ -1653,6 +1667,28 @@ typename Traits::Type::Expression ParserBase<Traits>::ParseAssignmentExpression( ...@@ -1653,6 +1667,28 @@ typename Traits::Type::Expression ParserBase<Traits>::ParseAssignmentExpression(
return factory()->NewAssignment(op, expression, right, pos); return factory()->NewAssignment(op, expression, right, pos);
} }
template <class Traits>
typename Traits::Type::Expression ParserBase<Traits>::ParseYieldExpression(
bool* ok) {
// YieldExpression ::
// 'yield' '*'? AssignmentExpression
int pos = peek_position();
Expect(Token::YIELD, CHECK_OK);
Yield::Kind kind =
Check(Token::MUL) ? Yield::DELEGATING : Yield::SUSPEND;
typename Traits::Type::Expression generator_object =
factory()->NewVariableProxy(function_state_->generator_object_variable());
typename Traits::Type::Expression expression =
ParseAssignmentExpression(false, CHECK_OK);
typename Traits::Type::YieldExpression yield =
factory()->NewYield(generator_object, expression, kind, pos);
if (kind == Yield::DELEGATING) {
yield->set_index(function_state_->NextHandlerIndex());
}
return yield;
}
#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