Reviewers: rossberg,
Message:
rossberg, ptal
Description:
Move ParseYieldExpression to ParserBase.
R=rossberg
BUG=v8:3126
LOG=N
Please review this at https://codereview.chromium.org/197353003/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+39, -45 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
845e9201d3d848a7f2bc1f88ce02dda3c53abb3d..48d8fffef7c86a9c055cce110bc69668d48df03b
100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -638,11 +638,6 @@ FunctionLiteral* ParserTraits::ParseFunctionLiteral(
}
-Expression* ParserTraits::ParseYieldExpression(bool* ok) {
- return parser_->ParseYieldExpression(ok);
-}
-
-
Expression* ParserTraits::ParseConditionalExpression(bool accept_IN, bool*
ok) {
return parser_->ParseConditionalExpression(accept_IN, 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
Expression* Parser::ParseConditionalExpression(bool accept_IN, bool* ok) {
// ConditionalExpression ::
Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index
c9a77aa527c86c656f95fcad188da91db096053a..202c0b5b0f306feb1835609d2dfd8937ceaae086
100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -419,6 +419,7 @@ class ParserTraits {
// Return types for traversing functions.
typedef Handle<String> Identifier;
typedef v8::internal::Expression* Expression;
+ typedef Yield* YieldExpression;
typedef v8::internal::FunctionLiteral* FunctionLiteral;
typedef v8::internal::Literal* Literal;
typedef ObjectLiteral::Property* ObjectLiteralProperty;
@@ -552,7 +553,6 @@ class ParserTraits {
int function_token_position,
FunctionLiteral::FunctionType type,
bool* ok);
- Expression* ParseYieldExpression(bool* ok);
Expression* ParseConditionalExpression(bool accept_IN, bool* ok);
private:
@@ -696,7 +696,6 @@ class Parser : public ParserBase<ParserTraits> {
// Support for hamony block scoped bindings.
Block* ParseScopedBlock(ZoneStringList* labels, bool* ok);
- Expression* ParseYieldExpression(bool* ok);
Expression* ParseConditionalExpression(bool accept_IN, bool* ok);
Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
Expression* ParseUnaryExpression(bool* ok);
Index: src/preparser.cc
diff --git a/src/preparser.cc b/src/preparser.cc
index
4bb813711e06244d2f520c40a8f440a448108912..d6acac0cbb86875675a62adc92107751fa5174b1
100644
--- a/src/preparser.cc
+++ b/src/preparser.cc
@@ -142,11 +142,6 @@ PreParserExpression
PreParserTraits::ParseFunctionLiteral(
}
-PreParserExpression PreParserTraits::ParseYieldExpression(bool* ok) {
- return pre_parser_->ParseYieldExpression(ok);
-}
-
-
PreParserExpression PreParserTraits::ParseConditionalExpression(bool
accept_IN,
bool* ok) {
return pre_parser_->ParseConditionalExpression(accept_IN, ok);
@@ -845,19 +840,6 @@ PreParser::Statement
PreParser::ParseDebuggerStatement(bool* ok) {
// 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
PreParser::Expression PreParser::ParseConditionalExpression(bool accept_IN,
bool* ok) {
// ConditionalExpression ::
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index
b77bc7a22251a6e0b8866670b26ed4133253be20..7de3805156576ff282254faf2d072ff5ce0b5da9
100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -345,6 +345,7 @@ class ParserBase : public Traits {
typename Traits::Type::ExpressionList ParseArguments(bool* ok);
typename Traits::Type::Expression ParseAssignmentExpression(bool
accept_IN,
bool* ok);
+ typename Traits::Type::Expression ParseYieldExpression(bool* ok);
// Used to detect duplicates in object literals. Each of the values
// kGetterProperty, kSetterProperty and kValueProperty represents
@@ -535,6 +536,9 @@ class PreParserExpression {
void* AsCall() 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:
// First two/three bits are used as flags.
// Bit 0 and 1 represent identifiers or strings literals, and are
@@ -661,6 +665,17 @@ class PreParserFactory {
int pos) {
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();
+ }
};
@@ -682,6 +697,7 @@ class PreParserTraits {
// Return types for traversing functions.
typedef PreParserIdentifier Identifier;
typedef PreParserExpression Expression;
+ typedef PreParserExpression YieldExpression;
typedef PreParserExpression FunctionLiteral;
typedef PreParserExpression ObjectLiteralProperty;
typedef PreParserExpression Literal;
@@ -828,7 +844,6 @@ class PreParserTraits {
int function_token_position,
FunctionLiteral::FunctionType type,
bool* ok);
- PreParserExpression ParseYieldExpression(bool* ok);
PreParserExpression ParseConditionalExpression(bool accept_IN, bool* ok);
private:
@@ -994,7 +1009,6 @@ class PreParser : public ParserBase<PreParserTraits> {
Statement ParseThrowStatement(bool* ok);
Statement ParseTryStatement(bool* ok);
Statement ParseDebuggerStatement(bool* ok);
- Expression ParseYieldExpression(bool* ok);
Expression ParseConditionalExpression(bool accept_IN, bool* ok);
Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
Expression ParseUnaryExpression(bool* ok);
@@ -1616,6 +1630,28 @@ typename Traits::Type::Expression
ParserBase<Traits>::ParseAssignmentExpression(
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_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.