Commit f9c5997c authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Directly keep track of the scope stack on the parser again.

By now lazy allocation of block scopes probably doesn't make that much sense anymore, since the memory overhead significantly reduced. Not indirecting scope() over ScopeState is faster, which is more important at this point.

BUG=v8:5209

Change-Id: I2968f01252769e7b1198a0a0876765a06ab0d3bd
Reviewed-on: https://chromium-review.googlesource.com/445025Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43313}
parent 9dae9206
......@@ -201,7 +201,7 @@ class ParserBase {
v8::Extension* extension, AstValueFactory* ast_value_factory,
RuntimeCallStats* runtime_call_stats,
bool parsing_on_main_thread = true)
: scope_state_(nullptr),
: scope_(nullptr),
function_state_(nullptr),
extension_(extension),
fni_(nullptr),
......@@ -290,57 +290,26 @@ class ParserBase {
class ObjectLiteralChecker;
// ---------------------------------------------------------------------------
// ScopeState and its subclasses implement the parser's scope stack.
// ScopeState keeps track of the current scope, and the outer ScopeState. The
// parser's scope_state_ points to the top ScopeState. ScopeState's
// constructor push on the scope stack and the destructors pop. BlockState and
// FunctionState are used to hold additional per-block and per-function state.
class ScopeState BASE_EMBEDDED {
// BlockState and FunctionState implement the parser's scope stack.
// The parser's current scope is in scope_. BlockState and FunctionState
// constructors push on the scope stack and the destructors pop. They are also
// used to hold the parser's per-funcion state.
class BlockState BASE_EMBEDDED {
public:
V8_INLINE Scope* scope() const { return scope_; }
Zone* zone() const { return scope_->zone(); }
protected:
ScopeState(ScopeState** scope_stack, Scope* scope)
: scope_stack_(scope_stack), outer_scope_(*scope_stack), scope_(scope) {
*scope_stack = this;
BlockState(Scope** scope_stack, Scope* scope)
: scope_stack_(scope_stack), outer_scope_(*scope_stack) {
*scope_stack_ = scope;
}
~ScopeState() { *scope_stack_ = outer_scope_; }
private:
ScopeState** const scope_stack_;
ScopeState* const outer_scope_;
Scope* const scope_;
};
class BlockState final : public ScopeState {
public:
BlockState(ScopeState** scope_stack, Scope* scope)
: ScopeState(scope_stack, scope) {}
BlockState(Zone* zone, Scope** scope_stack)
: BlockState(scope_stack,
new (zone) Scope(zone, *scope_stack, BLOCK_SCOPE)) {}
// BlockState(ScopeState**) automatically manages Scope(BLOCK_SCOPE)
// allocation.
// TODO(verwaest): Move to LazyBlockState class that only allocates the
// scope when needed.
explicit BlockState(Zone* zone, ScopeState** scope_stack)
: ScopeState(scope_stack, NewScope(zone, *scope_stack)) {}
void SetNonlinear() { this->scope()->SetNonlinear(); }
void set_start_position(int pos) { this->scope()->set_start_position(pos); }
void set_end_position(int pos) { this->scope()->set_end_position(pos); }
void set_is_hidden() { this->scope()->set_is_hidden(); }
Scope* FinalizedBlockScope() const {
return this->scope()->FinalizeBlockScope();
}
LanguageMode language_mode() const {
return this->scope()->language_mode();
}
~BlockState() { *scope_stack_ = outer_scope_; }
private:
Scope* NewScope(Zone* zone, ScopeState* outer_state) {
Scope* parent = outer_state->scope();
return new (zone) Scope(zone, parent, BLOCK_SCOPE);
}
Scope** const scope_stack_;
Scope* const outer_scope_;
};
struct DestructuringAssignment {
......@@ -402,15 +371,13 @@ class ParserBase {
kInsideForInOfBody,
};
class FunctionState final : public ScopeState {
class FunctionState final : public BlockState {
public:
FunctionState(FunctionState** function_state_stack,
ScopeState** scope_stack, DeclarationScope* scope);
FunctionState(FunctionState** function_state_stack, Scope** scope_stack,
DeclarationScope* scope);
~FunctionState();
DeclarationScope* scope() const {
return ScopeState::scope()->AsDeclarationScope();
}
DeclarationScope* scope() const { return scope_->AsDeclarationScope(); }
void AddProperty() { expected_property_count_++; }
int expected_property_count() { return expected_property_count_; }
......@@ -470,11 +437,11 @@ class ParserBase {
private:
void AddDestructuringAssignment(DestructuringAssignment pair) {
destructuring_assignments_to_rewrite_.Add(pair, this->zone());
destructuring_assignments_to_rewrite_.Add(pair, scope_->zone());
}
void AddNonPatternForRewriting(ExpressionT expr, bool* ok) {
non_patterns_to_rewrite_.Add(expr, this->zone());
non_patterns_to_rewrite_.Add(expr, scope_->zone());
if (non_patterns_to_rewrite_.length() >=
std::numeric_limits<uint16_t>::max())
*ok = false;
......@@ -490,6 +457,7 @@ class ParserBase {
FunctionState** function_state_stack_;
FunctionState* outer_function_state_;
DeclarationScope* scope_;
ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_;
TailCallExpressionList tail_call_expressions_;
......@@ -1270,12 +1238,11 @@ class ParserBase {
StatementT ParseTryStatement(bool* ok);
StatementT ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok);
StatementT ParseForEachStatementWithDeclarations(
int stmt_pos, ForInfo* for_info, BlockState* for_state,
ZoneList<const AstRawString*>* labels, bool* ok);
int stmt_pos, ForInfo* for_info, ZoneList<const AstRawString*>* labels,
bool* ok);
StatementT ParseForEachStatementWithoutDeclarations(
int stmt_pos, ExpressionT expression, int lhs_beg_pos, int lhs_end_pos,
ForInfo* for_info, BlockState* for_state,
ZoneList<const AstRawString*>* labels, bool* ok);
ForInfo* for_info, ZoneList<const AstRawString*>* labels, bool* ok);
// Parse a C-style for loop: 'for (<init>; <cond>; <step>) { ... }'
StatementT ParseStandardForLoop(int stmt_pos, StatementT init,
......@@ -1405,7 +1372,7 @@ class ParserBase {
ModuleDescriptor* module() const {
return scope()->AsModuleScope()->module();
}
Scope* scope() const { return scope_state_->scope(); }
Scope* scope() const { return scope_; }
// Stack of expression classifiers.
// The top of the stack is always pointed to by classifier().
......@@ -1448,7 +1415,7 @@ class ParserBase {
// Parser base's protected field members.
ScopeState* scope_state_; // Scope stack.
Scope* scope_; // Scope stack.
FunctionState* function_state_; // Function state stack.
v8::Extension* extension_;
FuncNameInferrer* fni_;
......@@ -1488,13 +1455,14 @@ class ParserBase {
template <typename Impl>
ParserBase<Impl>::FunctionState::FunctionState(
FunctionState** function_state_stack, ScopeState** scope_stack,
FunctionState** function_state_stack, Scope** scope_stack,
DeclarationScope* scope)
: ScopeState(scope_stack, scope),
: BlockState(scope_stack, scope),
next_materialized_literal_index_(0),
expected_property_count_(0),
function_state_stack_(function_state_stack),
outer_function_state_(*function_state_stack),
scope_(scope),
destructuring_assignments_to_rewrite_(16, scope->zone()),
tail_call_expressions_(scope->zone()),
return_expr_context_(ReturnExprContext::kInsideValidBlock),
......@@ -2334,9 +2302,8 @@ ParserBase<Impl>::ParseClassFieldForInitializer(bool has_initializer,
FunctionKind kind = FunctionKind::kConciseMethod;
DeclarationScope* initializer_scope = NewFunctionScope(kind);
initializer_scope->set_start_position(scanner()->location().end_pos);
FunctionState initializer_state(&function_state_, &scope_state_,
initializer_scope);
DCHECK(scope() == initializer_scope);
FunctionState initializer_state(&function_state_, &scope_, initializer_scope);
DCHECK_EQ(initializer_scope, scope());
scope()->SetLanguageMode(STRICT);
ExpressionClassifier expression_classifier(this);
ExpressionT value;
......@@ -3972,7 +3939,7 @@ void ParserBase<Impl>::ParseFunctionBody(
}
{
BlockState block_state(&scope_state_, inner_scope);
BlockState block_state(&scope_, inner_scope);
if (IsGeneratorFunction(kind)) {
impl()->ParseAndRewriteGeneratorFunctionBody(pos, kind, body, ok);
......@@ -4152,7 +4119,7 @@ ParserBase<Impl>::ParseArrowFunctionLiteral(
bool should_be_used_once_hint = false;
bool has_braces = true;
{
FunctionState function_state(&function_state_, &scope_state_,
FunctionState function_state(&function_state_, &scope_,
formal_parameters.scope);
Expect(Token::ARROW, CHECK_OK);
......@@ -4295,20 +4262,18 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseClassLiteral(
return impl()->EmptyExpression();
}
BlockState block_state(zone(), &scope_state_);
BlockState block_state(zone(), &scope_);
RaiseLanguageMode(STRICT);
ClassInfo class_info(this);
impl()->DeclareClassVariable(name, &class_info, class_token_pos, CHECK_OK);
scope()->set_start_position(scanner()->location().end_pos);
if (Check(Token::EXTENDS)) {
block_state.set_start_position(scanner()->location().end_pos);
ExpressionClassifier extends_classifier(this);
class_info.extends = ParseLeftHandSideExpression(CHECK_OK);
impl()->RewriteNonPattern(CHECK_OK);
impl()->AccumulateFormalParameterContainmentErrors();
} else {
block_state.set_start_position(scanner()->location().end_pos);
}
ClassLiteralChecker checker(this);
......@@ -4850,8 +4815,8 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock(
// Parse the statements and collect escaping labels.
Expect(Token::LBRACE, CHECK_OK_CUSTOM(NullBlock));
{
BlockState block_state(zone(), &scope_state_);
block_state.set_start_position(scanner()->location().beg_pos);
BlockState block_state(zone(), &scope_);
scope()->set_start_position(scanner()->location().beg_pos);
typename Types::Target target(this, body);
while (peek() != Token::RBRACE) {
......@@ -4862,8 +4827,8 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock(
}
Expect(Token::RBRACE, CHECK_OK_CUSTOM(NullBlock));
block_state.set_end_position(scanner()->location().end_pos);
body->set_scope(block_state.FinalizedBlockScope());
scope()->set_end_position(scanner()->location().end_pos);
body->set_scope(scope()->FinalizeBlockScope());
}
return body;
}
......@@ -4876,13 +4841,13 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseScopedStatement(
} else {
// Make a block around the statement for a lexical binding
// is introduced by a FunctionDeclaration.
BlockState block_state(zone(), &scope_state_);
block_state.set_start_position(scanner()->location().beg_pos);
BlockState block_state(zone(), &scope_);
scope()->set_start_position(scanner()->location().beg_pos);
BlockT block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
StatementT body = ParseFunctionDeclaration(CHECK_OK);
block->statements()->Add(body, zone());
block_state.set_end_position(scanner()->location().end_pos);
block->set_scope(block_state.FinalizedBlockScope());
scope()->set_end_position(scanner()->location().end_pos);
block->set_scope(scope()->FinalizeBlockScope());
return block;
}
}
......@@ -5165,7 +5130,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseWithStatement(
Scope* with_scope = NewScope(WITH_SCOPE);
StatementT body = impl()->NullStatement();
{
BlockState block_state(&scope_state_, with_scope);
BlockState block_state(&scope_, with_scope);
with_scope->set_start_position(scanner()->peek_location().beg_pos);
body = ParseStatement(labels, CHECK_OK);
with_scope->set_end_position(scanner()->location().end_pos);
......@@ -5257,9 +5222,9 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseSwitchStatement(
auto switch_statement = factory()->NewSwitchStatement(labels, switch_pos);
{
BlockState cases_block_state(zone(), &scope_state_);
cases_block_state.set_start_position(scanner()->location().beg_pos);
cases_block_state.SetNonlinear();
BlockState cases_block_state(zone(), &scope_);
scope()->set_start_position(scanner()->location().beg_pos);
scope()->SetNonlinear();
typename Types::Target target(this, switch_statement);
bool default_seen = false;
......@@ -5292,9 +5257,9 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseSwitchStatement(
}
Expect(Token::RBRACE, CHECK_OK);
cases_block_state.set_end_position(scanner()->location().end_pos);
return impl()->RewriteSwitchStatement(
tag, switch_statement, cases, cases_block_state.FinalizedBlockScope());
scope()->set_end_position(scanner()->location().end_pos);
return impl()->RewriteSwitchStatement(tag, switch_statement, cases,
scope()->FinalizeBlockScope());
}
}
......@@ -5340,16 +5305,15 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseTryStatement(
CollectExpressionsInTailPositionToListScope
collect_tail_call_expressions_scope(
function_state_, &catch_info.tail_call_expressions);
BlockState catch_block_state(&scope_state_, catch_info.scope);
BlockState catch_block_state(&scope_, catch_info.scope);
catch_block = factory()->NewBlock(nullptr, 16, false, kNoSourcePosition);
// Create a block scope to hold any lexical declarations created
// as part of destructuring the catch parameter.
{
BlockState catch_variable_block_state(zone(), &scope_state_);
catch_variable_block_state.set_start_position(
scanner()->location().beg_pos);
BlockState catch_variable_block_state(zone(), &scope_);
scope()->set_start_position(scanner()->location().beg_pos);
typename Types::Target target(this, catch_block);
// This does not simply call ParsePrimaryExpression to avoid
......@@ -5374,10 +5338,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseTryStatement(
catch_info.inner_block = ParseBlock(nullptr, CHECK_OK);
catch_block->statements()->Add(catch_info.inner_block, zone());
impl()->ValidateCatchBlock(catch_info, CHECK_OK);
catch_variable_block_state.set_end_position(
scanner()->location().end_pos);
catch_block->set_scope(
catch_variable_block_state.FinalizedBlockScope());
scope()->set_end_position(scanner()->location().end_pos);
catch_block->set_scope(scope()->FinalizeBlockScope());
}
}
......@@ -5402,11 +5364,11 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement(
bool bound_names_are_lexical = false;
// Create an in-between scope for let-bound iteration variables.
BlockState for_state(zone(), &scope_state_);
BlockState for_state(zone(), &scope_);
Expect(Token::FOR, CHECK_OK);
Expect(Token::LPAREN, CHECK_OK);
for_state.set_start_position(scanner()->location().beg_pos);
for_state.set_is_hidden();
scope()->set_start_position(scanner()->location().beg_pos);
scope()->set_is_hidden();
StatementT init = impl()->NullStatement();
......@@ -5420,8 +5382,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement(
for_info.position = scanner()->location().beg_pos;
if (CheckInOrOf(&for_info.mode)) {
return ParseForEachStatementWithDeclarations(stmt_pos, &for_info,
&for_state, labels, ok);
return ParseForEachStatementWithDeclarations(stmt_pos, &for_info, labels,
ok);
}
// One or more declaration not followed by in/of.
......@@ -5446,9 +5408,9 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement(
}
if (is_for_each) {
return ParseForEachStatementWithoutDeclarations(
stmt_pos, expression, lhs_beg_pos, lhs_end_pos, &for_info, &for_state,
labels, ok);
return ParseForEachStatementWithoutDeclarations(stmt_pos, expression,
lhs_beg_pos, lhs_end_pos,
&for_info, labels, ok);
}
// Initializer is just an expression.
init = factory()->NewExpressionStatement(expression, lhs_beg_pos);
......@@ -5462,8 +5424,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForStatement(
template <typename Impl>
typename ParserBase<Impl>::StatementT
ParserBase<Impl>::ParseForEachStatementWithDeclarations(
int stmt_pos, ForInfo* for_info, BlockState* for_state,
ZoneList<const AstRawString*>* labels, bool* ok) {
int stmt_pos, ForInfo* for_info, ZoneList<const AstRawString*>* labels,
bool* ok) {
// Just one declaration followed by in/of.
if (for_info->parsing_result.declarations.length() != 1) {
impl()->ReportMessageAt(for_info->parsing_result.bindings_loc,
......@@ -5507,8 +5469,8 @@ ParserBase<Impl>::ParseForEachStatementWithDeclarations(
{
ReturnExprScope no_tail_calls(function_state_,
ReturnExprContext::kInsideForInOfBody);
BlockState block_state(zone(), &scope_state_);
block_state.set_start_position(scanner()->location().beg_pos);
BlockState block_state(zone(), &scope_);
scope()->set_start_position(scanner()->location().beg_pos);
StatementT body = ParseStatement(nullptr, CHECK_OK);
......@@ -5520,14 +5482,14 @@ ParserBase<Impl>::ParseForEachStatementWithDeclarations(
final_loop = impl()->InitializeForEachStatement(
loop, each_variable, enumerable, body_block, each_keyword_pos);
block_state.set_end_position(scanner()->location().end_pos);
body_block->set_scope(block_state.FinalizedBlockScope());
scope()->set_end_position(scanner()->location().end_pos);
body_block->set_scope(scope()->FinalizeBlockScope());
}
init_block = impl()->CreateForEachStatementTDZ(init_block, *for_info, ok);
for_state->set_end_position(scanner()->location().end_pos);
Scope* for_scope = for_state->FinalizedBlockScope();
scope()->set_end_position(scanner()->location().end_pos);
Scope* for_scope = scope()->FinalizeBlockScope();
// Parsed for-in loop w/ variable declarations.
if (!impl()->IsNullStatement(init_block)) {
init_block->statements()->Add(final_loop, zone());
......@@ -5543,8 +5505,7 @@ template <typename Impl>
typename ParserBase<Impl>::StatementT
ParserBase<Impl>::ParseForEachStatementWithoutDeclarations(
int stmt_pos, ExpressionT expression, int lhs_beg_pos, int lhs_end_pos,
ForInfo* for_info, BlockState* for_state,
ZoneList<const AstRawString*>* labels, bool* ok) {
ForInfo* for_info, ZoneList<const AstRawString*>* labels, bool* ok) {
// Initializer is reference followed by in/of.
if (!expression->IsArrayLiteral() && !expression->IsObjectLiteral()) {
expression = impl()->CheckAndRewriteReferenceExpression(
......@@ -5567,24 +5528,25 @@ ParserBase<Impl>::ParseForEachStatementWithoutDeclarations(
}
Expect(Token::RPAREN, CHECK_OK);
Scope* for_scope = scope();
{
ReturnExprScope no_tail_calls(function_state_,
ReturnExprContext::kInsideForInOfBody);
BlockState block_state(zone(), &scope_state_);
block_state.set_start_position(scanner()->location().beg_pos);
BlockState block_state(zone(), &scope_);
scope()->set_start_position(scanner()->location().beg_pos);
StatementT body = ParseStatement(nullptr, CHECK_OK);
block_state.set_end_position(scanner()->location().end_pos);
scope()->set_end_position(scanner()->location().end_pos);
StatementT final_loop = impl()->InitializeForEachStatement(
loop, expression, enumerable, body, each_keyword_pos);
Scope* for_scope = for_state->FinalizedBlockScope();
DCHECK_NULL(for_scope);
for_scope = for_scope->FinalizeBlockScope();
USE(for_scope);
Scope* block_scope = block_state.FinalizedBlockScope();
DCHECK_NULL(block_scope);
DCHECK_NULL(for_scope);
Scope* block_scope = scope()->FinalizeBlockScope();
USE(block_scope);
DCHECK_NULL(block_scope);
return final_loop;
}
}
......@@ -5606,13 +5568,12 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStandardForLoop(
// 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 (bound_names_are_lexical && for_info->bound_names.length() > 0) {
inner_scope = NewScopeWithParent(inner_scope, BLOCK_SCOPE);
inner_scope->set_start_position(scanner()->location().beg_pos);
}
{
BlockState block_state(&scope_state_, inner_scope);
BlockState block_state(&scope_, inner_scope);
if (peek() != Token::SEMICOLON) {
cond = ParseExpression(true, CHECK_OK);
......@@ -5631,13 +5592,13 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStandardForLoop(
if (bound_names_are_lexical && for_info->bound_names.length() > 0) {
auto result = impl()->DesugarLexicalBindingsInForStatement(
loop, init, cond, next, body, inner_scope, *for_info, CHECK_OK);
for_state->set_end_position(scanner()->location().end_pos);
scope()->set_end_position(scanner()->location().end_pos);
inner_scope->set_end_position(scanner()->location().end_pos);
return result;
}
for_state->set_end_position(scanner()->location().end_pos);
Scope* for_scope = for_state->FinalizedBlockScope();
scope()->set_end_position(scanner()->location().end_pos);
Scope* for_scope = scope()->FinalizeBlockScope();
if (for_scope != nullptr) {
// Rewrite a for statement of the form
// for (const x = i; c; n) b
......@@ -5691,12 +5652,12 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForAwaitStatement(
for_info.mode = ForEachStatement::ITERATE;
// Create an in-between scope for let-bound iteration variables.
BlockState for_state(zone(), &scope_state_);
BlockState for_state(zone(), &scope_);
Expect(Token::FOR, CHECK_OK);
Expect(Token::AWAIT, CHECK_OK);
Expect(Token::LPAREN, CHECK_OK);
for_state.set_start_position(scanner()->location().beg_pos);
for_state.set_is_hidden();
scope()->set_start_position(scanner()->location().beg_pos);
scope()->set_is_hidden();
auto loop = factory()->NewForOfStatement(labels, stmt_pos);
typename Types::Target target(this, loop);
......@@ -5768,22 +5729,22 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForAwaitStatement(
Expect(Token::RPAREN, CHECK_OK);
StatementT final_loop = impl()->NullStatement();
Scope* for_scope = scope();
{
ReturnExprScope no_tail_calls(function_state_,
ReturnExprContext::kInsideForInOfBody);
BlockState block_state(zone(), &scope_state_);
block_state.set_start_position(scanner()->location().beg_pos);
BlockState block_state(zone(), &scope_);
scope()->set_start_position(scanner()->location().beg_pos);
StatementT body = ParseStatement(nullptr, CHECK_OK);
block_state.set_end_position(scanner()->location().end_pos);
scope()->set_end_position(scanner()->location().end_pos);
if (has_declarations) {
BlockT body_block = impl()->NullBlock();
impl()->DesugarBindingInForEachStatement(&for_info, &body_block,
&each_variable, CHECK_OK);
body_block->statements()->Add(body, zone());
body_block->set_scope(block_state.FinalizedBlockScope());
for_state.set_end_position(scanner()->location().end_pos);
body_block->set_scope(scope()->FinalizeBlockScope());
const bool finalize = true;
final_loop = impl()->InitializeForOfStatement(
......@@ -5795,10 +5756,10 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForAwaitStatement(
loop, each_variable, iterable, body, finalize, IteratorType::kAsync,
each_keyword_pos);
Scope* for_scope = for_state.FinalizedBlockScope();
for_scope = for_scope->FinalizeBlockScope();
DCHECK_NULL(for_scope);
USE(for_scope);
Scope* block_scope = block_state.FinalizedBlockScope();
Scope* block_scope = scope()->FinalizeBlockScope();
DCHECK_NULL(block_scope);
USE(block_scope);
return final_loop;
......@@ -5809,8 +5770,8 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForAwaitStatement(
BlockT init_block =
impl()->CreateForEachStatementTDZ(impl()->NullBlock(), for_info, ok);
for_state.set_end_position(scanner()->location().end_pos);
Scope* for_scope = for_state.FinalizedBlockScope();
for_scope->set_end_position(scanner()->location().end_pos);
for_scope = for_scope->FinalizeBlockScope();
// Parsed for-in loop w/ variable declarations.
if (!impl()->IsNullStatement(init_block)) {
init_block->statements()->Add(final_loop, zone());
......
......@@ -181,8 +181,7 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
ZoneList<Statement*>* body = NULL;
{
FunctionState function_state(&function_state_, &scope_state_,
function_scope);
FunctionState function_state(&function_state_, &scope_, function_scope);
body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone());
if (call_super) {
......@@ -657,7 +656,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
// Note that this function can be called from the main thread or from a
// background thread. We should not access anything Isolate / heap dependent
// via ParseInfo, and also not pass it forward.
DCHECK_NULL(scope_state_);
DCHECK_NULL(scope_);
DCHECK_NULL(target_stack_);
ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY);
......@@ -681,7 +680,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
scope->set_start_position(0);
FunctionState function_state(&function_state_, &scope_state_, scope);
FunctionState function_state(&function_state_, &scope_, scope);
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
bool ok = true;
......@@ -823,7 +822,7 @@ FunctionLiteral* Parser::DoParseFunction(ParseInfo* info,
const AstRawString* raw_name,
Utf16CharacterStream* source) {
scanner_.Initialize(source);
DCHECK_NULL(scope_state_);
DCHECK_NULL(scope_);
DCHECK_NULL(target_stack_);
DCHECK(ast_value_factory());
......@@ -844,9 +843,8 @@ FunctionLiteral* Parser::DoParseFunction(ParseInfo* info,
Scope* outer = original_scope_;
DeclarationScope* outer_function = outer->GetClosureScope();
DCHECK(outer);
FunctionState function_state(&function_state_, &scope_state_,
outer_function);
BlockState block_state(&scope_state_, outer);
FunctionState function_state(&function_state_, &scope_, outer_function);
BlockState block_state(&scope_, outer);
DCHECK(is_sloppy(outer->language_mode()) ||
is_strict(info->language_mode()));
FunctionLiteral::FunctionType function_type = ComputeFunctionType(info);
......@@ -886,7 +884,7 @@ FunctionLiteral* Parser::DoParseFunction(ParseInfo* info,
// Parsing patterns as variable reference expression creates
// NewUnresolved references in current scope. Entrer arrow function
// scope for formal parameter parsing.
BlockState block_state(&scope_state_, scope);
BlockState block_state(&scope_, scope);
if (Check(Token::LPAREN)) {
// '(' StrictFormalParameters ')'
ParseFormalParameterList(&formals, &ok);
......@@ -2252,7 +2250,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
Block* inner_block = factory()->NewBlock(NULL, 3, false, kNoSourcePosition);
{
BlockState block_state(&scope_state_, inner_scope);
BlockState block_state(&scope_, inner_scope);
Block* ignore_completion_block = factory()->NewBlock(
nullptr, for_info.bound_names.length() + 3, true, kNoSourcePosition);
......@@ -2962,14 +2960,14 @@ Block* Parser::BuildParameterInitializationBlock(
param_scope);
}
BlockState block_state(&scope_state_, param_scope);
BlockState block_state(&scope_, param_scope);
DeclarationParsingResult::Declaration decl(
parameter->pattern, parameter->initializer_end_position, initial_value);
PatternRewriter::DeclareAndInitializeVariables(
this, param_block, &descriptor, &decl, nullptr, CHECK_OK);
if (param_block != init_block) {
param_scope = block_state.FinalizedBlockScope();
param_scope = param_scope->FinalizeBlockScope();
if (param_scope != nullptr) {
CheckConflictingVarDeclarations(param_scope, CHECK_OK);
}
......@@ -3122,7 +3120,7 @@ ZoneList<Statement*>* Parser::ParseFunction(
bool* has_duplicate_parameters, int* expected_property_count, bool* ok) {
ParsingModeScope mode(this, allow_lazy_ ? PARSE_LAZILY : PARSE_EAGERLY);
FunctionState function_state(&function_state_, &scope_state_, function_scope);
FunctionState function_state(&function_state_, &scope_, function_scope);
DuplicateFinder duplicate_finder;
ExpressionClassifier formals_classifier(this, &duplicate_finder);
......@@ -3307,7 +3305,7 @@ void Parser::InsertShadowingVarBindingInitializers(Block* inner_block) {
DCHECK(inner_scope->is_declaration_scope());
Scope* function_scope = inner_scope->outer_scope();
DCHECK(function_scope->is_function_scope());
BlockState block_state(&scope_state_, inner_scope);
BlockState block_state(&scope_, inner_scope);
for (Declaration* decl : *inner_scope->declarations()) {
if (decl->proxy()->var()->mode() != VAR || !decl->IsVariableDeclaration()) {
continue;
......
......@@ -103,10 +103,11 @@ PreParser::PreParseResult PreParser::PreParseFunction(
ResetFunctionLiteralId();
// The caller passes the function_scope which is not yet inserted into the
// scope_state_. All scopes above the function_scope are ignored by the
// scope stack. All scopes above the function_scope are ignored by the
// PreParser.
DCHECK_NULL(scope_state_);
FunctionState function_state(&function_state_, &scope_state_, function_scope);
DCHECK_NULL(function_state_);
DCHECK_NULL(scope_);
FunctionState function_state(&function_state_, &scope_, function_scope);
// This indirection is needed so that we can use the CHECK_OK macros.
bool ok_holder = true;
bool* ok = &ok_holder;
......@@ -143,7 +144,7 @@ PreParser::PreParseResult PreParser::PreParseFunction(
}
{
BlockState block_state(&scope_state_, inner_scope);
BlockState block_state(&scope_, inner_scope);
result = ParseStatementListAndLogFunction(
&formals, has_duplicate_parameters, may_abort, ok);
}
......@@ -234,7 +235,7 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
DeclarationScope* function_scope = NewFunctionScope(kind);
function_scope->SetLanguageMode(language_mode);
FunctionState function_state(&function_state_, &scope_state_, function_scope);
FunctionState function_state(&function_state_, &scope_, function_scope);
DuplicateFinder duplicate_finder;
ExpressionClassifier formals_classifier(this, &duplicate_finder);
GetNextFunctionLiteralId();
......
......@@ -905,7 +905,7 @@ class PreParser : public ParserBase<PreParser> {
// captured the syntax error), and false if a stack-overflow happened
// during parsing.
PreParseResult PreParseProgram(bool is_module = false) {
DCHECK_NULL(scope_state_);
DCHECK_NULL(scope_);
DeclarationScope* scope = NewScriptScope();
#ifdef DEBUG
scope->set_is_being_lazily_parsed(true);
......@@ -916,7 +916,7 @@ class PreParser : public ParserBase<PreParser> {
// the global scope.
if (is_module) scope = NewModuleScope(scope);
FunctionState top_scope(&function_state_, &scope_state_, scope);
FunctionState top_scope(&function_state_, &scope_, scope);
bool ok = true;
int start_position = scanner()->peek_location().beg_pos;
parsing_module_ = is_module;
......
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