Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Unified Diff: src/parsing/preparser.cc

Issue 2351233002: [parser] Refactor of Parse*Statement*, part 8 (Closed)
Patch Set: Change after reviewers' comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/preparser.cc
diff --git a/src/parsing/preparser.cc b/src/parsing/preparser.cc
index 9dffa836e90edd906151368c43ea2447aa4b9bea..37beecf5a40aedfc577c3b2432a7085081e26f58 100644
--- a/src/parsing/preparser.cc
+++ b/src/parsing/preparser.cc
@@ -164,140 +164,6 @@ PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
return ParseHoistableDeclaration(pos, flags, nullptr, false, ok);
}
-PreParser::Statement PreParser::ParseForStatement(
- ZoneList<const AstRawString*>* labels, bool* ok) {
- // ForStatement ::
- // 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
-
- // Create an in-between scope for let-bound iteration variables.
- bool has_lexical = false;
-
- BlockState block_state(&scope_state_);
- Expect(Token::FOR, CHECK_OK);
- Expect(Token::LPAREN, CHECK_OK);
- if (peek() != Token::SEMICOLON) {
- ForEachStatement::VisitMode mode;
- if (peek() == Token::VAR || peek() == Token::CONST ||
- (peek() == Token::LET && IsNextLetKeyword())) {
- DeclarationParsingResult parsing_result;
-
- ParseVariableDeclarations(kForStatement, &parsing_result, nullptr,
- CHECK_OK);
- if (parsing_result.descriptor.mode == CONST ||
- parsing_result.descriptor.mode == LET) {
- has_lexical = true;
- }
- if (CheckInOrOf(&mode)) {
- if (!*ok) return Statement::Default();
- if (parsing_result.declarations.length() != 1) {
- ReportMessageAt(parsing_result.bindings_loc,
- MessageTemplate::kForInOfLoopMultiBindings,
- ForEachStatement::VisitModeString(mode));
- *ok = false;
- return Statement::Default();
- }
- bool is_binding_pattern =
- parsing_result.declarations[0].pattern.IsObjectLiteral() ||
- parsing_result.declarations[0].pattern.IsArrayLiteral();
- if (parsing_result.first_initializer_loc.IsValid() &&
- (is_strict(language_mode()) || mode == ForEachStatement::ITERATE ||
- has_lexical || is_binding_pattern || allow_harmony_for_in())) {
- // Only increment the use count if we would have let this through
- // without the flag.
- if (use_counts_ != nullptr && allow_harmony_for_in()) {
- ++use_counts_[v8::Isolate::kForInInitializer];
- }
- ReportMessageAt(parsing_result.first_initializer_loc,
- MessageTemplate::kForInOfLoopInitializer,
- ForEachStatement::VisitModeString(mode));
- *ok = false;
- return Statement::Default();
- }
-
- if (mode == ForEachStatement::ITERATE) {
- ExpressionClassifier classifier(this);
- ParseAssignmentExpression(true, CHECK_OK);
- RewriteNonPattern(CHECK_OK);
- } else {
- ParseExpression(true, CHECK_OK);
- }
-
- Expect(Token::RPAREN, CHECK_OK);
- {
- ReturnExprScope no_tail_calls(function_state_,
- ReturnExprContext::kInsideForInOfBody);
- ParseScopedStatement(nullptr, true, CHECK_OK);
- }
- return Statement::Default();
- }
- } else {
- int lhs_beg_pos = peek_position();
- ExpressionClassifier classifier(this);
- Expression lhs = ParseExpressionCoverGrammar(false, CHECK_OK);
- int lhs_end_pos = scanner()->location().end_pos;
- bool is_for_each = CheckInOrOf(&mode);
- bool is_destructuring = is_for_each &&
- (lhs->IsArrayLiteral() || lhs->IsObjectLiteral());
-
- if (is_destructuring) {
- ValidateAssignmentPattern(CHECK_OK);
- } else {
- ValidateExpression(CHECK_OK);
- }
-
- if (is_for_each) {
- if (!is_destructuring) {
- lhs = CheckAndRewriteReferenceExpression(
- lhs, lhs_beg_pos, lhs_end_pos, MessageTemplate::kInvalidLhsInFor,
- kSyntaxError, CHECK_OK);
- }
-
- if (mode == ForEachStatement::ITERATE) {
- ExpressionClassifier classifier(this);
- ParseAssignmentExpression(true, CHECK_OK);
- RewriteNonPattern(CHECK_OK);
- } else {
- ParseExpression(true, CHECK_OK);
- }
-
- Expect(Token::RPAREN, CHECK_OK);
- {
- BlockState block_state(&scope_state_);
- ParseScopedStatement(nullptr, true, CHECK_OK);
- }
- return Statement::Default();
- }
- }
- }
-
- // Parsed initializer at this point.
- Expect(Token::SEMICOLON, CHECK_OK);
-
- // If there are let bindings, then condition and the next statement of the
- // for loop must be parsed in a new scope.
- Scope* inner_scope = scope();
- // TODO(verwaest): Allocate this through a ScopeState as well.
- if (has_lexical) inner_scope = NewScopeWithParent(inner_scope, BLOCK_SCOPE);
-
- {
- BlockState block_state(&scope_state_, inner_scope);
-
- if (peek() != Token::SEMICOLON) {
- ParseExpression(true, CHECK_OK);
- }
- Expect(Token::SEMICOLON, CHECK_OK);
-
- if (peek() != Token::RPAREN) {
- ParseExpression(true, CHECK_OK);
- }
- Expect(Token::RPAREN, CHECK_OK);
-
- ParseScopedStatement(nullptr, true, ok);
- }
- return Statement::Default();
-}
-
-
// Redefinition of CHECK_OK for parsing expressions.
#undef CHECK_OK
#define CHECK_OK CHECK_OK_VALUE(Expression::Default())
« no previous file with comments | « src/parsing/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698