Commit 232b1af3 authored by Adam Klein's avatar Adam Klein Committed by Commit Bot

[parser] Simplify callers of NewBlock

The vast majority of callers pass null |labels| and kNoSourcePosition,
so make those the default arguments.

Bug: v8:6092
Change-Id: Ifac3f0d49f56b680ec75b1a7afde5e5e788d9cfd
Reviewed-on: https://chromium-review.googlesource.com/639761
Commit-Queue: Adam Klein <adamk@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47691}
parent ce05578a
......@@ -3169,8 +3169,9 @@ class AstNodeFactory final BASE_EMBEDDED {
return new (zone_) FunctionDeclaration(proxy, fun, pos);
}
Block* NewBlock(ZoneList<const AstRawString*>* labels, int capacity,
bool ignore_completion_value, int pos) {
Block* NewBlock(int capacity, bool ignore_completion_value,
int pos = kNoSourcePosition,
ZoneList<const AstRawString*>* labels = nullptr) {
return labels != nullptr ? new (zone_)
LabeledBlock(zone_, labels, capacity,
ignore_completion_value, pos)
......
......@@ -3729,7 +3729,7 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseVariableDeclarations(
BlockT init_block = impl()->NullStatement();
if (var_context != kForStatement) {
init_block = factory()->NewBlock(
nullptr, 1, true, parsing_result->descriptor.declaration_pos);
1, true, parsing_result->descriptor.declaration_pos);
}
switch (peek()) {
......@@ -4062,7 +4062,7 @@ void ParserBase<Impl>::ParseFunctionBody(
if (!parameters.is_simple) {
inner_scope = NewVarblockScope();
inner_scope->set_start_position(scanner()->location().beg_pos);
inner_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition);
inner_block = factory()->NewBlock(8, true);
inner_block->set_scope(inner_scope);
body = inner_block->statements();
}
......@@ -4437,7 +4437,7 @@ void ParserBase<Impl>::ParseSingleExpressionFunctionBody(StatementListT body,
impl()->RewriteNonPattern(CHECK_OK_VOID);
if (is_async) {
BlockT block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition);
BlockT block = factory()->NewBlock(1, true);
impl()->RewriteAsyncFunctionBody(body, block, expression, CHECK_OK_VOID);
} else {
body->Add(BuildReturnStatement(expression, expression->position()), zone());
......@@ -4447,7 +4447,7 @@ void ParserBase<Impl>::ParseSingleExpressionFunctionBody(StatementListT body,
template <typename Impl>
void ParserBase<Impl>::ParseAsyncFunctionBody(Scope* scope, StatementListT body,
bool* ok) {
BlockT block = factory()->NewBlock(nullptr, 8, true, kNoSourcePosition);
BlockT block = factory()->NewBlock(8, true);
ParseStatementList(block->statements(), Token::RBRACE, CHECK_OK_VOID);
impl()->RewriteAsyncFunctionBody(
......@@ -4879,7 +4879,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatement(
return ParseStatementAsUnlabelled(labels, ok);
} else {
BlockT result =
factory()->NewBlock(labels, 1, false, kNoSourcePosition);
factory()->NewBlock(1, false, kNoSourcePosition, labels);
typename Types::Target target(this, result);
StatementT statement = ParseStatementAsUnlabelled(labels, CHECK_OK);
result->statements()->Add(statement, zone());
......@@ -4951,7 +4951,7 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock(
// '{' StatementList '}'
// Construct block expecting 16 statements.
BlockT body = factory()->NewBlock(labels, 16, false, kNoSourcePosition);
BlockT body = factory()->NewBlock(16, false, kNoSourcePosition, labels);
// Parse the statements and collect escaping labels.
Expect(Token::LBRACE, CHECK_OK_CUSTOM(NullStatement));
......@@ -4986,7 +4986,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseScopedStatement(
// is introduced by a FunctionDeclaration.
BlockState block_state(zone(), &scope_);
scope()->set_start_position(scanner()->location().beg_pos);
BlockT block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
BlockT block = factory()->NewBlock(1, false);
StatementT body = ParseFunctionDeclaration(CHECK_OK);
block->statements()->Add(body, zone());
scope()->set_end_position(scanner()->location().end_pos);
......@@ -5482,8 +5482,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseTryStatement(
{
BlockState catch_block_state(&scope_, catch_info.scope);
catch_block =
factory()->NewBlock(nullptr, 16, false, kNoSourcePosition);
catch_block = factory()->NewBlock(16, false);
// Create a block scope to hold any lexical declarations created
// as part of destructuring the catch parameter.
......@@ -5814,7 +5813,7 @@ ParserBase<Impl>::ParseStandardForLoopWithLexicalDeclarations(
// }
//
DCHECK(!impl()->IsNull(init));
BlockT block = factory()->NewBlock(nullptr, 2, false, kNoSourcePosition);
BlockT block = factory()->NewBlock(2, false);
block->statements()->Add(init, zone());
block->statements()->Add(loop, zone());
block->set_scope(for_scope);
......
This diff is collapsed.
......@@ -314,7 +314,7 @@ void PatternRewriter::VisitRewritableExpression(RewritableExpression* node) {
int pos = assign->position();
Block* old_block = block_;
block_ = factory()->NewBlock(nullptr, 8, true, pos);
block_ = factory()->NewBlock(8, true, pos);
Variable* temp = nullptr;
Expression* pattern = assign->target();
Expression* old_value = current_value_;
......@@ -458,7 +458,7 @@ void PatternRewriter::VisitArrayLiteral(ArrayLiteral* node,
// wrap this new block in a try-finally statement, restore block_ to its
// original value, and add the try-finally statement to block_.
auto target = block_;
block_ = factory()->NewBlock(nullptr, 8, true, nopos);
block_ = factory()->NewBlock(8, true);
Spread* spread = nullptr;
for (Expression* value : *node->values()) {
......@@ -503,8 +503,7 @@ void PatternRewriter::VisitArrayLiteral(ArrayLiteral* node,
factory()->NewBooleanLiteral(false, kNoSourcePosition),
kNoSourcePosition);
auto inner_else =
factory()->NewBlock(nullptr, 2, true, kNoSourcePosition);
auto inner_else = factory()->NewBlock(2, true);
inner_else->statements()->Add(
factory()->NewExpressionStatement(assign_value, nopos), zone());
inner_else->statements()->Add(
......@@ -515,8 +514,7 @@ void PatternRewriter::VisitArrayLiteral(ArrayLiteral* node,
factory()->NewExpressionStatement(assign_undefined, nopos),
inner_else, nopos);
auto next_block =
factory()->NewBlock(nullptr, 3, true, kNoSourcePosition);
auto next_block = factory()->NewBlock(3, true);
next_block->statements()->Add(
factory()->NewExpressionStatement(
factory()->NewAssignment(
......@@ -636,7 +634,7 @@ void PatternRewriter::VisitArrayLiteral(ArrayLiteral* node,
ast_value_factory()->done_string(), nopos),
nopos);
Block* then = factory()->NewBlock(nullptr, 2, true, nopos);
Block* then = factory()->NewBlock(2, true);
then->statements()->Add(append_element, zone());
then->statements()->Add(unset_done, zone());
......@@ -654,7 +652,7 @@ void PatternRewriter::VisitArrayLiteral(ArrayLiteral* node,
{
Expression* condition = factory()->NewUnaryOperation(
Token::NOT, factory()->NewVariableProxy(done), nopos);
Block* body = factory()->NewBlock(nullptr, 3, true, nopos);
Block* body = factory()->NewBlock(3, true);
body->statements()->Add(set_done, zone());
body->statements()->Add(get_next, zone());
body->statements()->Add(maybe_append_and_unset_done, zone());
......
......@@ -661,9 +661,9 @@ class PreParserFactory {
return PreParserStatement::Default();
}
PreParserStatement NewBlock(ZoneList<const AstRawString*>* labels,
int capacity, bool ignore_completion_value,
int pos) {
PreParserStatement NewBlock(int capacity, bool ignore_completion_value,
int pos = kNoSourcePosition,
ZoneList<const AstRawString*>* labels = nullptr) {
return PreParserStatement::Default();
}
......
......@@ -114,7 +114,7 @@ class Processor final : public AstVisitor<Processor> {
Statement* Processor::AssignUndefinedBefore(Statement* s) {
Expression* undef = factory()->NewUndefinedLiteral(kNoSourcePosition);
Expression* assignment = SetResult(undef);
Block* b = factory()->NewBlock(NULL, 2, false, kNoSourcePosition);
Block* b = factory()->NewBlock(2, false, kNoSourcePosition);
b->statements()->Add(
factory()->NewExpressionStatement(assignment, kNoSourcePosition), zone());
b->statements()->Add(s, zone());
......
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