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);
......
......@@ -1438,8 +1438,8 @@ Variable* Parser::Declare(Declaration* declaration,
Block* Parser::BuildInitializationBlock(
DeclarationParsingResult* parsing_result,
ZoneList<const AstRawString*>* names, bool* ok) {
Block* result = factory()->NewBlock(
NULL, 1, true, parsing_result->descriptor.declaration_pos);
Block* result =
factory()->NewBlock(1, true, parsing_result->descriptor.declaration_pos);
for (auto declaration : parsing_result->declarations) {
DeclareAndInitializeVariables(result, &(parsing_result->descriptor),
&declaration, names, CHECK_OK);
......@@ -1541,7 +1541,7 @@ bool Parser::ContainsLabel(ZoneList<const AstRawString*>* labels,
}
Block* Parser::IgnoreCompletion(Statement* statement) {
Block* block = factory()->NewBlock(nullptr, 1, true, kNoSourcePosition);
Block* block = factory()->NewBlock(1, true);
block->statements()->Add(statement, zone());
return block;
}
......@@ -1599,7 +1599,7 @@ Statement* Parser::RewriteSwitchStatement(Expression* tag,
// }
// }
Block* switch_block = factory()->NewBlock(NULL, 2, false, kNoSourcePosition);
Block* switch_block = factory()->NewBlock(2, false);
Variable* tag_variable =
NewTemporary(ast_value_factory()->dot_switch_tag_string());
......@@ -1620,7 +1620,7 @@ Statement* Parser::RewriteSwitchStatement(Expression* tag,
Expression* tag_read = factory()->NewVariableProxy(tag_variable);
switch_statement->Initialize(tag_read, cases);
Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
Block* cases_block = factory()->NewBlock(1, false);
cases_block->statements()->Add(switch_statement, zone());
cases_block->set_scope(scope);
DCHECK_IMPLIES(scope != nullptr,
......@@ -1653,8 +1653,7 @@ void Parser::RewriteCatchPattern(CatchInfo* catch_info, bool* ok) {
catch_info->pattern, initializer_position,
factory()->NewVariableProxy(catch_variable));
catch_info->init_block =
factory()->NewBlock(nullptr, 8, true, kNoSourcePosition);
catch_info->init_block = factory()->NewBlock(8, true);
DeclareAndInitializeVariables(catch_info->init_block, &descriptor, &decl,
&catch_info->bound_names, ok);
} else {
......@@ -1699,7 +1698,7 @@ Statement* Parser::RewriteTryStatement(Block* try_block, Block* catch_block,
catch_block, kNoSourcePosition);
RecordTryCatchStatementSourceRange(statement, catch_range);
try_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition);
try_block = factory()->NewBlock(1, false);
try_block->statements()->Add(statement, zone());
catch_block = nullptr; // Clear to indicate it's been handled.
}
......@@ -1754,7 +1753,7 @@ void Parser::ParseAndRewriteAsyncGeneratorFunctionBody(
// "done" iterator result object containing a Promise-unwrapped value.
DCHECK(IsAsyncGeneratorFunction(kind));
Block* try_block = factory()->NewBlock(nullptr, 3, false, kNoSourcePosition);
Block* try_block = factory()->NewBlock(3, false);
Expression* initial_yield = BuildInitialYield(pos, kind);
try_block->statements()->Add(
factory()->NewExpressionStatement(initial_yield, kNoSourcePosition),
......@@ -1787,11 +1786,10 @@ void Parser::ParseAndRewriteAsyncGeneratorFunctionBody(
TryStatement* try_catch = factory()->NewTryCatchStatementForAsyncAwait(
try_block, catch_scope, catch_block, kNoSourcePosition);
try_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition);
try_block = factory()->NewBlock(1, false);
try_block->statements()->Add(try_catch, zone());
Block* finally_block =
factory()->NewBlock(nullptr, 1, false, kNoSourcePosition);
Block* finally_block = factory()->NewBlock(1, false);
ZoneList<Expression*>* close_args =
new (zone()) ZoneList<Expression*>(1, zone());
VariableProxy* call_proxy = factory()->NewVariableProxy(
......@@ -1891,7 +1889,7 @@ Statement* Parser::InitializeForEachStatement(ForEachStatement* stmt,
Expression* assign_each =
RewriteDestructuringAssignment(factory()->NewAssignment(
Token::ASSIGN, each, temp_proxy, kNoSourcePosition));
auto block = factory()->NewBlock(nullptr, 2, false, kNoSourcePosition);
auto block = factory()->NewBlock(2, false);
block->statements()->Add(
factory()->NewExpressionStatement(assign_each, kNoSourcePosition),
zone());
......@@ -1930,7 +1928,7 @@ Block* Parser::RewriteForVarInLegacy(const ForInfo& for_info) {
const AstRawString* name = decl.pattern->AsVariableProxy()->raw_name();
VariableProxy* single_var = NewUnresolved(name);
Block* init_block = factory()->NewBlock(
nullptr, 2, true, for_info.parsing_result.descriptor.declaration_pos);
2, true, for_info.parsing_result.descriptor.declaration_pos);
init_block->statements()->Add(
factory()->NewExpressionStatement(
factory()->NewAssignment(Token::ASSIGN, single_var,
......@@ -1964,8 +1962,7 @@ void Parser::DesugarBindingInForEachStatement(ForInfo* for_info,
DeclarationParsingResult::Declaration& decl =
for_info->parsing_result.declarations[0];
Variable* temp = NewTemporary(ast_value_factory()->dot_for_string());
auto each_initialization_block =
factory()->NewBlock(nullptr, 1, true, kNoSourcePosition);
auto each_initialization_block = factory()->NewBlock(1, true);
{
auto descriptor = for_info->parsing_result.descriptor;
descriptor.declaration_pos = kNoSourcePosition;
......@@ -2010,7 +2007,7 @@ void Parser::DesugarBindingInForEachStatement(ForInfo* for_info,
}
}
*body_block = factory()->NewBlock(nullptr, 3, false, kNoSourcePosition);
*body_block = factory()->NewBlock(3, false);
(*body_block)->statements()->Add(each_initialization_block, zone());
*each_variable = factory()->NewVariableProxy(temp, for_info->position);
}
......@@ -2021,7 +2018,7 @@ Block* Parser::CreateForEachStatementTDZ(Block* init_block,
if (IsLexicalVariableMode(for_info.parsing_result.descriptor.mode)) {
DCHECK_NULL(init_block);
init_block = factory()->NewBlock(nullptr, 1, false, kNoSourcePosition);
init_block = factory()->NewBlock(1, false);
for (int i = 0; i < for_info.bound_names.length(); ++i) {
// TODO(adamk): This needs to be some sort of special
......@@ -2134,7 +2131,7 @@ Statement* Parser::InitializeForOfStatement(
// { #loop-body; #set_completion_normal }
// Statement* body (gets overwritten)
if (finalize) {
Block* block = factory()->NewBlock(nullptr, 2, false, nopos);
Block* block = factory()->NewBlock(2, false);
block->statements()->Add(body, zone());
block->statements()->Add(set_completion_normal, zone());
body = block;
......@@ -2189,8 +2186,8 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
DCHECK(for_info.bound_names.length() > 0);
ZoneList<Variable*> temps(for_info.bound_names.length(), zone());
Block* outer_block = factory()->NewBlock(
nullptr, for_info.bound_names.length() + 4, false, kNoSourcePosition);
Block* outer_block =
factory()->NewBlock(for_info.bound_names.length() + 4, false);
// Add statement: let/const x = i.
outer_block->statements()->Add(init, zone());
......@@ -2240,12 +2237,12 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
outer_block->statements()->Add(outer_loop, zone());
outer_block->set_scope(scope());
Block* inner_block = factory()->NewBlock(NULL, 3, false, kNoSourcePosition);
Block* inner_block = factory()->NewBlock(3, false);
{
BlockState block_state(&scope_, inner_scope);
Block* ignore_completion_block = factory()->NewBlock(
nullptr, for_info.bound_names.length() + 3, true, kNoSourcePosition);
Block* ignore_completion_block =
factory()->NewBlock(for_info.bound_names.length() + 3, true);
ZoneList<Variable*> inner_vars(for_info.bound_names.length(), zone());
// For each let variable x:
// make statement: let/const x = temp_x.
......@@ -2898,7 +2895,7 @@ Block* Parser::BuildParameterInitializationBlock(
DCHECK(!parameters.is_simple);
DCHECK(scope()->is_function_scope());
DCHECK_EQ(scope(), parameters.scope);
Block* init_block = factory()->NewBlock(NULL, 1, true, kNoSourcePosition);
Block* init_block = factory()->NewBlock(1, true);
int index = 0;
for (auto parameter : parameters.params) {
DeclarationDescriptor descriptor;
......@@ -2937,7 +2934,7 @@ Block* Parser::BuildParameterInitializationBlock(
param_scope->set_start_position(descriptor.initialization_pos);
param_scope->set_end_position(parameter->initializer_end_position);
param_scope->RecordEvalCall();
param_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition);
param_block = factory()->NewBlock(8, true);
param_block->set_scope(param_scope);
// Pass the appropriate scope in so that PatternRewriter can appropriately
// rewrite inner initializers of the pattern to param_scope
......@@ -2981,7 +2978,7 @@ Block* Parser::BuildRejectPromiseOnException(Block* inner_block) {
// } finally {
// %AsyncFunctionPromiseRelease(.promise);
// }
Block* result = factory()->NewBlock(nullptr, 2, true, kNoSourcePosition);
Block* result = factory()->NewBlock(2, true);
// .promise = %AsyncFunctionPromiseCreate();
Statement* set_promise;
......@@ -3871,7 +3868,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
// $R = lit
Expression* init_result = factory()->NewAssignment(
Token::INIT, factory()->NewVariableProxy(result), lit, kNoSourcePosition);
Block* do_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition);
Block* do_block = factory()->NewBlock(16, false);
do_block->statements()->Add(
factory()->NewExpressionStatement(init_result, kNoSourcePosition),
zone());
......@@ -4193,7 +4190,7 @@ void Parser::FinalizeIteratorUse(Scope* use_scope, Variable* completion,
// }
Block* maybe_close;
{
Block* block = factory()->NewBlock(nullptr, 2, true, nopos);
Block* block = factory()->NewBlock(2, true);
Expression* proxy = factory()->NewVariableProxy(completion);
BuildIteratorCloseForCompletion(use_scope, block->statements(), iter, proxy,
type);
......@@ -4225,7 +4222,7 @@ void Parser::FinalizeIteratorUse(Scope* use_scope, Variable* completion,
factory()->NewCallRuntime(Runtime::kReThrow, args, nopos), nopos);
}
Block* catch_block = factory()->NewBlock(nullptr, 2, false, nopos);
Block* catch_block = factory()->NewBlock(2, false);
catch_block->statements()->Add(set_completion_throw, zone());
catch_block->statements()->Add(rethrow, zone());
......@@ -4236,7 +4233,7 @@ void Parser::FinalizeIteratorUse(Scope* use_scope, Variable* completion,
// try { #try_catch } finally { #maybe_close }
Statement* try_finally;
{
Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos);
Block* try_block = factory()->NewBlock(1, false);
try_block->statements()->Add(try_catch, zone());
try_finally =
......@@ -4321,11 +4318,11 @@ void Parser::BuildIteratorCloseForCompletion(Scope* scope,
call = factory()->NewAwait(call, nopos);
}
Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos);
Block* try_block = factory()->NewBlock(1, false);
try_block->statements()->Add(factory()->NewExpressionStatement(call, nopos),
zone());
Block* catch_block = factory()->NewBlock(nullptr, 0, false, nopos);
Block* catch_block = factory()->NewBlock(0, false);
Scope* catch_scope = NewHiddenCatchScopeWithParent(scope);
try_call_return = factory()->NewTryCatchStatement(try_block, catch_scope,
catch_block, nopos);
......@@ -4376,7 +4373,7 @@ void Parser::BuildIteratorCloseForCompletion(Scope* scope,
is_receiver_call, factory()->NewEmptyStatement(nopos), throw_call,
nopos);
validate_return = factory()->NewBlock(nullptr, 2, false, nopos);
validate_return = factory()->NewBlock(2, false);
validate_return->statements()->Add(call_return, zone());
validate_return->statements()->Add(check_return, zone());
}
......@@ -4393,7 +4390,7 @@ void Parser::BuildIteratorCloseForCompletion(Scope* scope,
Token::EQ_STRICT, completion,
factory()->NewSmiLiteral(Parser::kThrowCompletion, nopos), nopos);
Block* then_block = factory()->NewBlock(nullptr, 2, false, nopos);
Block* then_block = factory()->NewBlock(2, false);
then_block->statements()->Add(check_return_callable, zone());
then_block->statements()->Add(try_call_return, zone());
......@@ -4452,9 +4449,9 @@ Statement* Parser::FinalizeForOfStatement(ForOfStatement* loop,
closing_condition = factory()->NewUnaryOperation(Token::NOT, cmp, nopos);
}
Block* final_loop = factory()->NewBlock(nullptr, 2, false, nopos);
Block* final_loop = factory()->NewBlock(2, false);
{
Block* try_block = factory()->NewBlock(nullptr, 1, false, nopos);
Block* try_block = factory()->NewBlock(1, false);
try_block->statements()->Add(loop, zone());
FinalizeIteratorUse(scope(), var_completion, closing_condition,
......
......@@ -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