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

Unified Diff: src/parsing/parser.cc

Issue 2324843005: [parser] Refactor of Parse*Statement*, part 6 (Closed)
Patch Set: The real patch 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 773590c4aeb444c9904c9ec6628138e78f1c274a..24d6fd2f47ef7362d72f751083bdc13713d2b119 100644
--- a/src/parsing/parser.cc
+++ b/src/parsing/parser.cc
@@ -1763,60 +1763,10 @@ Expression* Parser::RewriteDoExpression(Block* body, int pos, bool* ok) {
return expr;
}
-Statement* Parser::ParseFunctionDeclaration(bool* ok) {
- Consume(Token::FUNCTION);
- int pos = position();
- ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
- if (Check(Token::MUL)) {
- flags |= ParseFunctionFlags::kIsGenerator;
- if (allow_harmony_restrictive_declarations()) {
- ReportMessageAt(scanner()->location(),
- MessageTemplate::kGeneratorInLegacyContext);
- *ok = false;
- return nullptr;
- }
- }
-
- return ParseHoistableDeclaration(pos, flags, nullptr, false, CHECK_OK);
-}
-
-CaseClause* Parser::ParseCaseClause(bool* default_seen_ptr, bool* ok) {
- // CaseClause ::
- // 'case' Expression ':' StatementList
- // 'default' ':' StatementList
-
- Expression* label = NULL; // NULL expression indicates default case
- if (peek() == Token::CASE) {
- Expect(Token::CASE, CHECK_OK);
- label = ParseExpression(true, CHECK_OK);
- } else {
- Expect(Token::DEFAULT, CHECK_OK);
- if (*default_seen_ptr) {
- ReportMessage(MessageTemplate::kMultipleDefaultsInSwitch);
- *ok = false;
- return NULL;
- }
- *default_seen_ptr = true;
- }
- Expect(Token::COLON, CHECK_OK);
- int pos = position();
- ZoneList<Statement*>* statements =
- new(zone()) ZoneList<Statement*>(5, zone());
- Statement* stat = NULL;
- while (peek() != Token::CASE &&
- peek() != Token::DEFAULT &&
- peek() != Token::RBRACE) {
- stat = ParseStatementListItem(CHECK_OK);
- statements->Add(stat, zone());
- }
- return factory()->NewCaseClause(label, statements, pos);
-}
-
-
-Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
- bool* ok) {
- // SwitchStatement ::
- // 'switch' '(' Expression ')' '{' CaseClause* '}'
+Statement* Parser::RewriteSwitchStatement(Expression* tag,
+ SwitchStatement* switch_statement,
+ ZoneList<CaseClause*>* cases,
+ Scope* scope) {
// In order to get the CaseClauses to execute in their own lexical scope,
// but without requiring downstream code to have special scope handling
// code for switch statements, desugar into blocks as follows:
@@ -1827,13 +1777,7 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
// }
// }
- Block* switch_block = factory()->NewBlock(NULL, 2, false, kNoSourcePosition);
- int switch_pos = peek_position();
-
- Expect(Token::SWITCH, CHECK_OK);
- Expect(Token::LPAREN, CHECK_OK);
- Expression* tag = ParseExpression(true, CHECK_OK);
- Expect(Token::RPAREN, CHECK_OK);
+ BlockT switch_block = factory()->NewBlock(NULL, 2, false, kNoSourcePosition);
adamk 2016/09/09 17:59:12 s/BlockT/Block*/
nickie 2016/09/10 18:13:11 Done.
Variable* tag_variable =
NewTemporary(ast_value_factory()->dot_switch_tag_string());
@@ -1852,38 +1796,30 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
factory()->NewUndefinedLiteral(kNoSourcePosition), kNoSourcePosition),
zone());
- Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
-
- SwitchStatement* switch_statement =
- factory()->NewSwitchStatement(labels, switch_pos);
-
- {
- BlockState cases_block_state(&scope_state_);
- cases_block_state.set_start_position(scanner()->location().beg_pos);
- cases_block_state.SetNonlinear();
- ParserTarget target(this, switch_statement);
-
- Expression* tag_read = factory()->NewVariableProxy(tag_variable);
+ ExpressionT tag_read = factory()->NewVariableProxy(tag_variable);
adamk 2016/09/09 17:59:12 and here
nickie 2016/09/10 18:13:11 Done.
+ switch_statement->Initialize(tag_read, cases);
+ BlockT cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
adamk 2016/09/09 17:59:12 and here
nickie 2016/09/10 18:13:11 Done.
+ cases_block->statements()->Add(switch_statement, zone());
+ cases_block->set_scope(scope);
+ switch_block->statements()->Add(cases_block, zone());
+ return switch_block;
+}
- bool default_seen = false;
- ZoneList<CaseClause*>* cases =
- new (zone()) ZoneList<CaseClause*>(4, zone());
- Expect(Token::LBRACE, CHECK_OK);
- while (peek() != Token::RBRACE) {
- CaseClause* clause = ParseCaseClause(&default_seen, CHECK_OK);
- cases->Add(clause, zone());
+Statement* Parser::ParseFunctionDeclaration(bool* ok) {
+ Consume(Token::FUNCTION);
+ int pos = position();
+ ParseFunctionFlags flags = ParseFunctionFlags::kIsNormal;
+ if (Check(Token::MUL)) {
+ flags |= ParseFunctionFlags::kIsGenerator;
+ if (allow_harmony_restrictive_declarations()) {
+ ReportMessageAt(scanner()->location(),
+ MessageTemplate::kGeneratorInLegacyContext);
+ *ok = false;
+ return nullptr;
}
- switch_statement->Initialize(tag_read, cases);
- cases_block->statements()->Add(switch_statement, zone());
- Expect(Token::RBRACE, CHECK_OK);
-
- cases_block_state.set_end_position(scanner()->location().end_pos);
- cases_block->set_scope(cases_block_state.FinalizedBlockScope());
}
- switch_block->statements()->Add(cases_block, zone());
-
- return switch_block;
+ return ParseHoistableDeclaration(pos, flags, nullptr, false, CHECK_OK);
}
TryStatement* Parser::ParseTryStatement(bool* ok) {
« 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