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

Unified Diff: src/parsing/parser.cc

Issue 2321103002: [parser] Refactor of Parse*Statement*, part 5 (Closed)
Patch Set: Rebase 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/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser.cc
diff --git a/src/parsing/parser.cc b/src/parsing/parser.cc
index f8092e6837430404afdf5a887af0b22610f5ec22..d24da8ab9097cb075313ea7d99f958cd0f05216a 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -1702,6 +1702,16 @@ Expression* Parser::RewriteReturn(Expression* return_value, int pos) {
return return_value;
}
+Expression* Parser::RewriteDoExpression(Block* body, int pos, bool* ok) {
+ Variable* result = NewTemporary(ast_value_factory()->dot_result_string());
+ DoExpression* expr = factory()->NewDoExpression(body, result, pos);
+ if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) {
+ *ok = false;
+ return nullptr;
+ }
+ return expr;
+}
+
Statement* Parser::ParseFunctionDeclaration(bool* ok) {
Consume(Token::FUNCTION);
int pos = position();
@@ -1825,26 +1835,6 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
return switch_block;
}
-
-Statement* Parser::ParseThrowStatement(bool* ok) {
- // ThrowStatement ::
- // 'throw' Expression ';'
-
- Expect(Token::THROW, CHECK_OK);
- int pos = position();
- if (scanner()->HasAnyLineTerminatorBeforeNext()) {
- ReportMessage(MessageTemplate::kNewlineAfterThrow);
- *ok = false;
- return NULL;
- }
- Expression* exception = ParseExpression(true, CHECK_OK);
- ExpectSemicolon(CHECK_OK);
-
- return factory()->NewExpressionStatement(
- factory()->NewThrow(exception, pos), pos);
-}
-
-
TryStatement* Parser::ParseTryStatement(bool* ok) {
// TryStatement ::
// 'try' Block Catch
@@ -2038,53 +2028,6 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
}
-DoWhileStatement* Parser::ParseDoWhileStatement(
- ZoneList<const AstRawString*>* labels, bool* ok) {
- // DoStatement ::
- // 'do' Statement 'while' '(' Expression ')' ';'
-
- DoWhileStatement* loop =
- factory()->NewDoWhileStatement(labels, peek_position());
- ParserTarget target(this, loop);
-
- Expect(Token::DO, CHECK_OK);
- Statement* body = ParseScopedStatement(NULL, true, CHECK_OK);
- Expect(Token::WHILE, CHECK_OK);
- Expect(Token::LPAREN, CHECK_OK);
-
- Expression* cond = ParseExpression(true, CHECK_OK);
- Expect(Token::RPAREN, CHECK_OK);
-
- // Allow do-statements to be terminated with and without
- // semi-colons. This allows code such as 'do;while(0)return' to
- // parse, which would not be the case if we had used the
- // ExpectSemicolon() functionality here.
- if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON);
-
- if (loop != NULL) loop->Initialize(cond, body);
- return loop;
-}
-
-
-WhileStatement* Parser::ParseWhileStatement(
- ZoneList<const AstRawString*>* labels, bool* ok) {
- // WhileStatement ::
- // 'while' '(' Expression ')' Statement
-
- WhileStatement* loop = factory()->NewWhileStatement(labels, peek_position());
- ParserTarget target(this, loop);
-
- Expect(Token::WHILE, CHECK_OK);
- Expect(Token::LPAREN, CHECK_OK);
- Expression* cond = ParseExpression(true, CHECK_OK);
- Expect(Token::RPAREN, CHECK_OK);
- Statement* body = ParseScopedStatement(NULL, true, CHECK_OK);
-
- if (loop != NULL) loop->Initialize(cond, body);
- return loop;
-}
-
-
// !%_IsJSReceiver(result = iterator.next()) &&
// %ThrowIteratorResultNotAnObject(result)
Expression* Parser::BuildIteratorNextResult(Expression* iterator,
@@ -2959,22 +2902,6 @@ void Parser::DesugarAsyncFunctionBody(Scope* scope, ZoneList<Statement*>* body,
scope->set_end_position(scanner()->location().end_pos);
}
-DoExpression* Parser::ParseDoExpression(bool* ok) {
- // AssignmentExpression ::
- // do '{' StatementList '}'
- int pos = peek_position();
-
- Expect(Token::DO, CHECK_OK);
- Variable* result = NewTemporary(ast_value_factory()->dot_result_string());
- Block* block = ParseBlock(nullptr, CHECK_OK);
- DoExpression* expr = factory()->NewDoExpression(block, result, pos);
- if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) {
- *ok = false;
- return nullptr;
- }
- return expr;
-}
-
void Parser::ParseArrowFunctionFormalParameterList(
ParserFormalParameters* parameters, Expression* expr,
const Scanner::Location& params_loc, Scanner::Location* duplicate_loc,
« no previous file with comments | « src/parsing/parser.h ('k') | src/parsing/parser-base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698