Commit 4f552f5a authored by verwaest's avatar verwaest Committed by Commit bot

Introduce parent ScopeState class and track the scope through the state in the parser

This will allow us to move more state from Scope into ScopeState and lazily allocate full Scopes only when needed.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2160593002
Cr-Commit-Position: refs/heads/master@{#37858}
parent 7c3ddd2c
......@@ -201,10 +201,10 @@ class ParserBase : public Traits {
v8::Extension* extension, AstValueFactory* ast_value_factory,
ParserRecorder* log, typename Traits::Type::Parser this_object)
: Traits(this_object),
scope_(NULL),
function_state_(NULL),
scope_state_(nullptr),
function_state_(nullptr),
extension_(extension),
fni_(NULL),
fni_(nullptr),
ast_value_factory_(ast_value_factory),
log_(log),
mode_(PARSE_EAGERLY), // Lazy mode must be set explicitly.
......@@ -272,21 +272,34 @@ class ParserBase : public Traits {
class ObjectLiteralCheckerBase;
// ---------------------------------------------------------------------------
// FunctionState and BlockState together 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-function and per-block state.
class BlockState BASE_EMBEDDED {
// 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 {
public:
BlockState(Scope** scope_stack, Scope* scope)
: scope_stack_(scope_stack), outer_scope_(*scope_stack) {
*scope_stack_ = scope;
V8_INLINE Scope* scope() const { return scope_; }
protected:
ScopeState(ScopeState** scope_stack, Scope* scope)
: scope_stack_(scope_stack), outer_scope_(*scope_stack), scope_(scope) {
*scope_stack = this;
}
~BlockState() { *scope_stack_ = outer_scope_; }
~ScopeState() { *scope_stack_ = outer_scope_; }
Zone* zone() const { return scope_->zone(); }
private:
Scope** scope_stack_;
Scope* outer_scope_;
ScopeState** scope_stack_;
ScopeState* outer_scope_;
Scope* scope_;
};
class BlockState final : public ScopeState {
public:
BlockState(ScopeState** scope_stack, Scope* scope)
: ScopeState(scope_stack, scope) {}
};
struct DestructuringAssignment {
......@@ -356,10 +369,10 @@ class ParserBase : public Traits {
kInsideForInOfBody,
};
class FunctionState BASE_EMBEDDED {
class FunctionState final : public ScopeState {
public:
FunctionState(FunctionState** function_state_stack, Scope** scope_stack,
Scope* scope, FunctionKind kind,
FunctionState(FunctionState** function_state_stack,
ScopeState** scope_stack, Scope* scope, FunctionKind kind,
typename Traits::Type::Factory* factory);
~FunctionState();
......@@ -458,13 +471,11 @@ class ParserBase : public Traits {
private:
void AddDestructuringAssignment(DestructuringAssignment pair) {
destructuring_assignments_to_rewrite_.Add(pair, (*scope_stack_)->zone());
destructuring_assignments_to_rewrite_.Add(pair, this->zone());
}
V8_INLINE Scope* scope() { return *scope_stack_; }
void AddNonPatternForRewriting(ExpressionT expr, bool* ok) {
non_patterns_to_rewrite_.Add(expr, (*scope_stack_)->zone());
non_patterns_to_rewrite_.Add(expr, this->zone());
if (non_patterns_to_rewrite_.length() >=
std::numeric_limits<uint16_t>::max())
*ok = false;
......@@ -495,8 +506,6 @@ class ParserBase : public Traits {
FunctionState** function_state_stack_;
FunctionState* outer_function_state_;
Scope** scope_stack_;
Scope* outer_scope_;
ZoneList<DestructuringAssignment> destructuring_assignments_to_rewrite_;
TailCallExpressionList tail_call_expressions_;
......@@ -815,7 +824,7 @@ class ParserBase : public Traits {
return function_state_->factory();
}
LanguageMode language_mode() { return scope_->language_mode(); }
LanguageMode language_mode() { return scope()->language_mode(); }
bool is_generator() const { return function_state_->is_generator(); }
bool is_async_function() const {
return function_state_->is_async_function();
......@@ -1191,7 +1200,10 @@ class ParserBase : public Traits {
bool has_seen_constructor_;
};
Scope* scope_; // Scope stack.
ModuleDescriptor* module() const { return scope()->module(); }
Scope* scope() const { return scope_state_->scope(); }
ScopeState* scope_state_; // Scope stack.
FunctionState* function_state_; // Function state stack.
v8::Extension* extension_;
FuncNameInferrer* fni_;
......@@ -1221,9 +1233,10 @@ class ParserBase : public Traits {
template <class Traits>
ParserBase<Traits>::FunctionState::FunctionState(
FunctionState** function_state_stack, Scope** scope_stack, Scope* scope,
FunctionKind kind, typename Traits::Type::Factory* factory)
: next_materialized_literal_index_(0),
FunctionState** function_state_stack, ScopeState** scope_stack,
Scope* scope, FunctionKind kind, typename Traits::Type::Factory* factory)
: ScopeState(scope_stack, scope),
next_materialized_literal_index_(0),
expected_property_count_(0),
this_location_(Scanner::Location::invalid()),
return_location_(Scanner::Location::invalid()),
......@@ -1232,8 +1245,6 @@ ParserBase<Traits>::FunctionState::FunctionState(
generator_object_variable_(NULL),
function_state_stack_(function_state_stack),
outer_function_state_(*function_state_stack),
scope_stack_(scope_stack),
outer_scope_(*scope_stack),
destructuring_assignments_to_rewrite_(16, scope->zone()),
tail_call_expressions_(scope->zone()),
return_expr_context_(ReturnExprContext::kInsideValidBlock),
......@@ -1242,7 +1253,6 @@ ParserBase<Traits>::FunctionState::FunctionState(
factory_(factory),
next_function_is_parenthesized_(false),
this_function_is_parenthesized_(false) {
*scope_stack_ = scope;
*function_state_stack = this;
if (outer_function_state_) {
this_function_is_parenthesized_ =
......@@ -1254,7 +1264,6 @@ ParserBase<Traits>::FunctionState::FunctionState(
template <class Traits>
ParserBase<Traits>::FunctionState::~FunctionState() {
*scope_stack_ = outer_scope_;
*function_state_stack_ = outer_function_state_;
}
......@@ -1370,7 +1379,7 @@ ParserBase<Traits>::ParseAndClassifyIdentifier(ExpressionClassifier* classifier,
}
}
if (this->IsArguments(name)) {
scope_->RecordArgumentsUsage();
scope()->RecordArgumentsUsage();
classifier->RecordStrictModeFormalParameterError(
scanner()->location(), MessageTemplate::kStrictEvalArguments);
if (is_strict(language_mode())) {
......@@ -1438,7 +1447,7 @@ ParserBase<Traits>::ParseIdentifierOrStrictReservedWord(
}
IdentifierT name = this->GetSymbol(scanner());
if (this->IsArguments(name)) scope_->RecordArgumentsUsage();
if (this->IsArguments(name)) scope()->RecordArgumentsUsage();
return name;
}
......@@ -1458,7 +1467,7 @@ ParserBase<Traits>::ParseIdentifierName(bool* ok) {
}
IdentifierT name = this->GetSymbol(scanner());
if (this->IsArguments(name)) scope_->RecordArgumentsUsage();
if (this->IsArguments(name)) scope()->RecordArgumentsUsage();
return name;
}
......@@ -1516,7 +1525,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
case Token::THIS: {
BindingPatternUnexpectedToken(classifier);
Consume(Token::THIS);
return this->ThisExpression(scope_, factory(), beg_pos);
return this->ThisExpression(scope(), factory(), beg_pos);
}
case Token::NULL_LITERAL:
......@@ -1549,7 +1558,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
// Using eval or arguments in this context is OK even in strict mode.
IdentifierT name = ParseAndClassifyIdentifier(classifier, CHECK_OK);
return this->ExpressionFromIdentifier(
name, beg_pos, scanner()->location().end_pos, scope_, factory());
name, beg_pos, scanner()->location().end_pos, scope(), factory());
}
case Token::STRING: {
......@@ -1975,7 +1984,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
}
}
ExpressionT lhs = this->ExpressionFromIdentifier(
*name, next_beg_pos, next_end_pos, scope_, factory());
*name, next_beg_pos, next_end_pos, scope(), factory());
CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos);
if (peek() == Token::ASSIGN) {
......@@ -2282,7 +2291,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
IdentifierT name =
ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK);
expression = this->ExpressionFromIdentifier(
name, position(), scanner()->location().end_pos, scope_, factory());
name, position(), scanner()->location().end_pos, scope(), factory());
}
if (peek() == Token::ARROW) {
......@@ -2298,13 +2307,13 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
ValidateFormalParameterInitializer(&arrow_formals_classifier, ok);
Scanner::Location loc(lhs_beg_pos, scanner()->location().end_pos);
Scope* scope = this->NewScope(scope_, FUNCTION_SCOPE,
Scope* scope = this->NewScope(this->scope(), FUNCTION_SCOPE,
is_async ? FunctionKind::kAsyncArrowFunction
: FunctionKind::kArrowFunction);
// Because the arrow's parameters were parsed in the outer scope, any
// usage flags that might have been triggered there need to be copied
// to the arrow scope.
scope_->PropagateUsageFlagsToScope(scope);
this->scope()->PropagateUsageFlagsToScope(scope);
FormalParametersT parameters(scope);
if (!arrow_formals_classifier.is_simple_parameter_list()) {
scope->SetHasNonSimpleParameters();
......@@ -2726,7 +2735,7 @@ ParserBase<Traits>::ParseUnaryExpression(ExpressionClassifier* classifier,
MessageTemplate::kAwaitBindingIdentifier);
return this->ExpressionFromIdentifier(
name, beg_pos, scanner()->location().end_pos, scope_, factory());
name, beg_pos, scanner()->location().end_pos, scope(), factory());
}
default:
break;
......@@ -2871,7 +2880,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
// no explicit receiver.
// These calls are marked as potentially direct eval calls. Whether
// they are actually direct calls to eval is determined at run time.
this->CheckPossibleEvalCall(result, scope_);
this->CheckPossibleEvalCall(result, scope());
bool is_super_call = result->IsSuperCallReference();
if (spread_pos.IsValid()) {
......@@ -2884,7 +2893,7 @@ ParserBase<Traits>::ParseLeftHandSideExpression(
// Explicit calls to the super constructor using super() perform an
// implicit binding assignment to the 'this' variable.
if (is_super_call) {
ExpressionT this_expr = this->ThisExpression(scope_, factory(), pos);
ExpressionT this_expr = this->ThisExpression(scope(), factory(), pos);
result =
factory()->NewAssignment(Token::INIT, this_expr, result, pos);
}
......@@ -3022,7 +3031,7 @@ ParserBase<Traits>::ParseMemberExpression(ExpressionClassifier* classifier,
return this->EmptyExpression();
}
return this->FunctionSentExpression(scope_, factory(), pos);
return this->FunctionSentExpression(scope(), factory(), pos);
}
bool is_generator = Check(Token::MUL);
......@@ -3065,13 +3074,13 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new,
Expect(Token::SUPER, CHECK_OK);
int pos = position();
Scope* scope = scope_->ReceiverScope();
Scope* scope = this->scope()->ReceiverScope();
FunctionKind kind = scope->function_kind();
if (IsConciseMethod(kind) || IsAccessorFunction(kind) ||
IsClassConstructor(kind)) {
if (peek() == Token::PERIOD || peek() == Token::LBRACK) {
scope->RecordSuperPropertyUsage();
return this->NewSuperPropertyReference(scope_, factory(), pos);
return this->NewSuperPropertyReference(this->scope(), factory(), pos);
}
// new super() is never allowed.
// super() is only allowed in derived constructor
......@@ -3079,7 +3088,7 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new,
// TODO(rossberg): This might not be the correct FunctionState for the
// method here.
function_state_->set_super_location(scanner()->location());
return this->NewSuperCallReference(scope_, factory(), pos);
return this->NewSuperCallReference(this->scope(), factory(), pos);
}
}
......@@ -3108,14 +3117,14 @@ ParserBase<Traits>::ParseNewTargetExpression(bool* ok) {
int pos = position();
ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK);
if (!scope_->ReceiverScope()->is_function_scope()) {
if (!scope()->ReceiverScope()->is_function_scope()) {
ReportMessageAt(scanner()->location(),
MessageTemplate::kUnexpectedNewTarget);
*ok = false;
return this->EmptyExpression();
}
return this->NewTargetExpression(scope_, factory(), pos);
return this->NewTargetExpression(scope(), factory(), pos);
}
template <class Traits>
......@@ -3357,7 +3366,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
FunctionKind arrow_kind = is_async ? kAsyncArrowFunction : kArrowFunction;
{
typename Traits::Type::Factory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_,
FunctionState function_state(&function_state_, &scope_state_,
formal_parameters.scope, arrow_kind,
&function_factory);
......@@ -3372,7 +3381,7 @@ ParserBase<Traits>::ParseArrowFunctionLiteral(
// Multiple statement body
Consume(Token::LBRACE);
bool is_lazily_parsed =
(mode() == PARSE_LAZILY && scope_->AllowsLazyParsing());
(mode() == PARSE_LAZILY && scope()->AllowsLazyParsing());
if (is_lazily_parsed) {
body = this->NewStatementList(0, zone());
this->SkipLazyFunctionBody(&materialized_literal_count,
......
......@@ -199,8 +199,8 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
{
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, function_scope,
kind, &function_factory);
FunctionState function_state(&function_state_, &scope_state_,
function_scope, kind, &function_factory);
body = new (zone()) ZoneList<Statement*>(call_super ? 2 : 1, zone());
if (call_super) {
......@@ -217,7 +217,7 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
ZoneList<Expression*>* args =
new (zone()) ZoneList<Expression*>(2, zone());
VariableProxy* this_function_proxy = scope_->NewUnresolved(
VariableProxy* this_function_proxy = this->scope()->NewUnresolved(
factory(), ast_value_factory()->this_function_string(),
Variable::NORMAL, pos);
ZoneList<Expression*>* tmp =
......@@ -232,7 +232,7 @@ FunctionLiteral* Parser::DefaultConstructor(const AstRawString* name,
new (zone()) ZoneList<Expression*>(1, zone());
spread_args_expr->Add(spread_args, zone());
args->AddAll(*PrepareSpreadArguments(spread_args_expr), zone());
VariableProxy* new_target_proxy = scope_->NewUnresolved(
VariableProxy* new_target_proxy = this->scope()->NewUnresolved(
factory(), ast_value_factory()->new_target_string(), Variable::NORMAL,
pos);
args->Add(new_target_proxy, zone());
......@@ -909,8 +909,8 @@ 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(scope_ == NULL);
DCHECK(target_stack_ == NULL);
DCHECK_NULL(scope_state_);
DCHECK_NULL(target_stack_);
Mode parsing_mode = FLAG_lazy && allow_lazy() ? PARSE_LAZILY : PARSE_EAGERLY;
if (allow_natives() || extension_ != NULL) parsing_mode = PARSE_EAGERLY;
......@@ -919,7 +919,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
{
// TODO(wingo): Add an outer SCRIPT_SCOPE corresponding to the native
// context, which will have the "this" binding for script scopes.
Scope* scope = NewScope(scope_, SCRIPT_SCOPE);
Scope* scope = NewScope(nullptr, SCRIPT_SCOPE);
info->set_script_scope(scope);
if (!info->context().is_null() && !info->context()->IsNativeContext()) {
scope = Scope::DeserializeScopeChain(info->isolate(), zone(),
......@@ -946,7 +946,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
// Enter 'scope' with the given parsing mode.
ParsingModeScope parsing_mode_scope(this, parsing_mode);
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, scope,
FunctionState function_state(&function_state_, &scope_state_, scope,
kNormalFunction, &function_factory);
ZoneList<Statement*>* body = new(zone()) ZoneList<Statement*>(16, zone());
......@@ -956,11 +956,11 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
if (parsing_module_) {
ParseModuleItemList(body, &ok);
ok = ok &&
scope_->module()->Validate(scope_, &pending_error_handler_, zone());
module()->Validate(this->scope(), &pending_error_handler_, zone());
} else {
// Don't count the mode in the use counters--give the program a chance
// to enable script-wide strict mode below.
scope_->SetLanguageMode(info->language_mode());
this->scope()->SetLanguageMode(info->language_mode());
ParseStatementList(body, Token::EOS, &ok);
}
......@@ -981,7 +981,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
InsertSloppyBlockFunctionVarBindings(scope, nullptr, &ok);
}
if (ok) {
CheckConflictingVarDeclarations(scope_, &ok);
CheckConflictingVarDeclarations(this->scope(), &ok);
}
if (ok && info->parse_restriction() == ONLY_SINGLE_FUNCTION_LITERAL) {
......@@ -997,7 +997,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
if (ok) {
ParserTraits::RewriteDestructuringAssignments();
result = factory()->NewScriptOrEvalFunctionLiteral(
scope_, body, function_state.materialized_literal_count(),
this->scope(), body, function_state.materialized_literal_count(),
function_state.expected_property_count());
}
}
......@@ -1066,8 +1066,8 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
Utf16CharacterStream* source) {
Handle<SharedFunctionInfo> shared_info = info->shared_info();
scanner_.Initialize(source);
DCHECK(scope_ == NULL);
DCHECK(target_stack_ == NULL);
DCHECK_NULL(scope_state_);
DCHECK_NULL(target_stack_);
Handle<String> name(String::cast(shared_info->name()));
DCHECK(ast_value_factory());
......@@ -1078,11 +1078,11 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
// Place holder for the result.
FunctionLiteral* result = NULL;
FunctionLiteral* result = nullptr;
{
// Parse the function literal.
Scope* scope = NewScope(scope_, SCRIPT_SCOPE);
Scope* scope = NewScope(nullptr, SCRIPT_SCOPE);
info->set_script_scope(scope);
if (!info->context().is_null()) {
// Ok to use Isolate here, since lazy function parsing is only done in the
......@@ -1093,7 +1093,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
}
original_scope_ = scope;
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, scope,
FunctionState function_state(&function_state_, &scope_state_, scope,
shared_info->kind(), &function_factory);
DCHECK(is_sloppy(scope->language_mode()) ||
is_strict(info->language_mode()));
......@@ -1118,7 +1118,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
// TODO(adamk): We should construct this scope from the ScopeInfo.
Scope* scope =
NewScope(scope_, FUNCTION_SCOPE, FunctionKind::kArrowFunction);
NewScope(this->scope(), FUNCTION_SCOPE, FunctionKind::kArrowFunction);
// These two bits only need to be explicitly set because we're
// not passing the ScopeInfo to the Scope constructor.
......@@ -1137,7 +1137,7 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, 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_, scope);
BlockState block_state(&scope_state_, scope);
if (Check(Token::LPAREN)) {
// '(' StrictFormalParameters ')'
ParseFormalParameterList(&formals, &formals_classifier, &ok);
......@@ -1187,13 +1187,13 @@ FunctionLiteral* Parser::ParseLazy(Isolate* isolate, ParseInfo* info,
shared_info->language_mode(), &ok);
}
// Make sure the results agree.
DCHECK(ok == (result != NULL));
DCHECK(ok == (result != nullptr));
}
// Make sure the target stack is empty.
DCHECK(target_stack_ == NULL);
DCHECK_NULL(target_stack_);
if (result != NULL) {
if (result != nullptr) {
Handle<String> inferred_name(shared_info->inferred_name());
result->set_inferred_name(inferred_name);
}
......@@ -1242,11 +1242,11 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
token_loc.end_pos - token_loc.beg_pos ==
ast_value_factory()->use_strict_string()->length() + 2;
if (use_strict_found) {
if (is_sloppy(scope_->language_mode())) {
if (is_sloppy(this->scope()->language_mode())) {
RaiseLanguageMode(STRICT);
}
if (!scope_->HasSimpleParameters()) {
if (!this->scope()->HasSimpleParameters()) {
// TC39 deemed "use strict" directives to be an error when occurring
// in the body of a function with non-simple parameter list, on
// 29/7/2015. https://goo.gl/ueA7Ln
......@@ -1261,7 +1261,7 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
// of the eval call, it is likely that functions declared in strict
// eval code will be used within the eval code, so lazy parsing is
// probably not a win.
if (scope_->is_eval_scope()) mode_ = PARSE_EAGERLY;
if (this->scope()->is_eval_scope()) mode_ = PARSE_EAGERLY;
} else if (literal->raw_value()->AsString() ==
ast_value_factory()->use_asm_string() &&
token_loc.end_pos - token_loc.beg_pos ==
......@@ -1269,7 +1269,7 @@ void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
// Store the usage count; The actual use counter on the isolate is
// incremented after parsing is done.
++use_counts_[v8::Isolate::kUseAsm];
scope_->SetAsmModule();
this->scope()->SetAsmModule();
} else {
// Should not change mode, but will increment UseCounter
// if appropriate. Ditto usages below.
......@@ -1354,7 +1354,7 @@ void* Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) {
// ModuleBody :
// ModuleItem*
DCHECK(scope_->is_module_scope());
DCHECK(scope()->is_module_scope());
while (peek() != Token::EOS) {
Statement* stat = ParseModuleItem(CHECK_OK);
if (stat && !stat->IsEmpty()) {
......@@ -1499,8 +1499,7 @@ void* Parser::ParseImportDeclaration(bool* ok) {
if (tok == Token::STRING) {
const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK);
ExpectSemicolon(CHECK_OK);
scope_->module()->AddEmptyImport(
module_specifier, scanner()->location(), zone());
module()->AddEmptyImport(module_specifier, scanner()->location(), zone());
return nullptr;
}
......@@ -1548,9 +1547,8 @@ void* Parser::ParseImportDeclaration(bool* ok) {
// declarations.
if (module_namespace_binding != nullptr) {
scope_->module()->AddStarImport(
module_namespace_binding, module_specifier,
module_namespace_binding_loc, zone());
module()->AddStarImport(module_namespace_binding, module_specifier,
module_namespace_binding_loc, zone());
// TODO(neis): Create special immutable binding for the namespace object.
}
......@@ -1560,22 +1558,20 @@ void* Parser::ParseImportDeclaration(bool* ok) {
// location?
if (import_default_binding != nullptr) {
scope_->module()->AddImport(
ast_value_factory()->default_string(), import_default_binding,
module_specifier, import_default_binding_loc, zone());
module()->AddImport(ast_value_factory()->default_string(),
import_default_binding, module_specifier,
import_default_binding_loc, zone());
// DeclareImport(import_default_binding, pos, CHECK_OK);
}
if (named_imports != nullptr) {
if (named_imports->length() == 0) {
scope_->module()->AddEmptyImport(
module_specifier, scanner()->location(), zone());
module()->AddEmptyImport(module_specifier, scanner()->location(), zone());
} else {
for (int i = 0; i < named_imports->length(); ++i) {
const NamedImport* import = named_imports->at(i);
scope_->module()->AddImport(
import->import_name, import->local_name,
module_specifier, import->location, zone());
module()->AddImport(import->import_name, import->local_name,
module_specifier, import->location, zone());
// DeclareImport(import->local_name, pos, CHECK_OK);
}
}
......@@ -1631,7 +1627,7 @@ Statement* Parser::ParseExportDefault(bool* ok) {
// writing to it.
VariableProxy* proxy = NewUnresolved(local_name, CONST);
Declaration* declaration =
factory()->NewVariableDeclaration(proxy, CONST, scope_, pos);
factory()->NewVariableDeclaration(proxy, CONST, scope(), pos);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
proxy->var()->set_initializer_position(position());
......@@ -1645,9 +1641,9 @@ Statement* Parser::ParseExportDefault(bool* ok) {
}
DCHECK_EQ(local_names.length(), 1);
scope_->module()->AddExport(
local_names.first(), ast_value_factory()->default_string(), default_loc,
zone());
module()->AddExport(local_names.first(),
ast_value_factory()->default_string(), default_loc,
zone());
DCHECK_NOT_NULL(result);
return result;
......@@ -1675,8 +1671,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) {
ExpectContextualKeyword(CStrVector("from"), CHECK_OK);
const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK);
ExpectSemicolon(CHECK_OK);
scope_->module()->AddStarExport(
module_specifier, scanner()->location(), zone());
module()->AddStarExport(module_specifier, scanner()->location(), zone());
return factory()->NewEmptyStatement(pos);
}
......@@ -1713,17 +1708,16 @@ Statement* Parser::ParseExportDeclaration(bool* ok) {
DCHECK_EQ(length, export_locations.length());
if (module_specifier == nullptr) {
for (int i = 0; i < length; ++i) {
scope_->module()->AddExport(original_names[i], export_names[i],
export_locations[i], zone());
module()->AddExport(original_names[i], export_names[i],
export_locations[i], zone());
}
} else if (length == 0) {
scope_->module()->AddEmptyImport(
module_specifier, scanner()->location(), zone());
module()->AddEmptyImport(module_specifier, scanner()->location(),
zone());
} else {
for (int i = 0; i < length; ++i) {
scope_->module()->AddExport(
original_names[i], export_names[i], module_specifier,
export_locations[i], zone());
module()->AddExport(original_names[i], export_names[i],
module_specifier, export_locations[i], zone());
}
}
return factory()->NewEmptyStatement(pos);
......@@ -1760,7 +1754,7 @@ Statement* Parser::ParseExportDeclaration(bool* ok) {
return nullptr;
}
ModuleDescriptor* descriptor = scope_->module();
ModuleDescriptor* descriptor = module();
for (int i = 0; i < names.length(); ++i) {
// TODO(neis): Provide better location.
descriptor->AddExport(names[i], names[i], scanner()->location(), zone());
......@@ -1910,8 +1904,9 @@ VariableProxy* Parser::NewUnresolved(const AstRawString* name,
// truly local variable, and the scope of the variable is always the function
// scope.
// Let/const variables are always added to the immediately enclosing scope.
Scope* scope =
IsLexicalVariableMode(mode) ? scope_ : scope_->DeclarationScope();
Scope* scope = IsLexicalVariableMode(mode)
? this->scope()
: this->scope()->DeclarationScope();
return scope->NewUnresolved(factory(), name, Variable::NORMAL,
scanner()->location().beg_pos,
scanner()->location().end_pos);
......@@ -1922,7 +1917,7 @@ void* Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) {
DCHECK_NOT_NULL(local_name);
VariableProxy* proxy = NewUnresolved(local_name, IMPORT);
Declaration* declaration =
factory()->NewVariableDeclaration(proxy, IMPORT, scope_, pos);
factory()->NewVariableDeclaration(proxy, IMPORT, scope(), pos);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
return nullptr;
}
......@@ -1937,7 +1932,7 @@ Variable* Parser::Declare(Declaration* declaration,
VariableMode mode = declaration->mode();
DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY);
bool is_function_declaration = declaration->IsFunctionDeclaration();
if (scope == nullptr) scope = scope_;
if (scope == nullptr) scope = this->scope();
Scope* declaration_scope =
IsLexicalVariableMode(mode) ? scope : scope->DeclarationScope();
Variable* var = NULL;
......@@ -2109,14 +2104,14 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) {
// accessible while parsing the first time not when reparsing
// because of lazy compilation.
// TODO(adamk): Should this be ClosureScope()?
scope_->DeclarationScope()->ForceEagerCompilation();
scope()->DeclarationScope()->ForceEagerCompilation();
// TODO(1240846): It's weird that native function declarations are
// introduced dynamically when we meet their declarations, whereas
// other functions are set up when entering the surrounding scope.
VariableProxy* proxy = NewUnresolved(name, VAR);
Declaration* declaration =
factory()->NewVariableDeclaration(proxy, VAR, scope_, pos);
factory()->NewVariableDeclaration(proxy, VAR, scope(), pos);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
NativeFunctionLiteral* lit =
factory()->NewNativeFunctionLiteral(name, extension_, kNoSourcePosition);
......@@ -2202,11 +2197,11 @@ Statement* Parser::ParseHoistableDeclaration(
// In ES6, a function behaves as a lexical binding, except in
// a script scope, or the initial scope of eval or another function.
VariableMode mode =
(!scope_->is_declaration_scope() || scope_->is_module_scope()) ? LET
: VAR;
(!scope()->is_declaration_scope() || scope()->is_module_scope()) ? LET
: VAR;
VariableProxy* proxy = NewUnresolved(variable_name, mode);
Declaration* declaration =
factory()->NewFunctionDeclaration(proxy, mode, fun, scope_, pos);
factory()->NewFunctionDeclaration(proxy, mode, fun, scope(), pos);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
if (names) names->Add(variable_name, zone());
EmptyStatement* empty = factory()->NewEmptyStatement(kNoSourcePosition);
......@@ -2215,11 +2210,11 @@ Statement* Parser::ParseHoistableDeclaration(
// sloppy_block_function_map. Don't add them to the map for async functions.
// Generators are also supposed to be prohibited; currently doing this behind
// a flag and UseCounting violations to assess web compatibility.
if (is_sloppy(language_mode()) && !scope_->is_declaration_scope() &&
if (is_sloppy(language_mode()) && !scope()->is_declaration_scope() &&
!is_async && !(allow_harmony_restrictive_generators() && is_generator)) {
SloppyBlockFunctionStatement* delegate =
factory()->NewSloppyBlockFunctionStatement(empty, scope_);
scope_->DeclarationScope()->sloppy_block_function_map()->Declare(
factory()->NewSloppyBlockFunctionStatement(empty, scope());
scope()->DeclarationScope()->sloppy_block_function_map()->Declare(
variable_name, delegate);
return delegate;
}
......@@ -2265,7 +2260,7 @@ Statement* Parser::ParseClassDeclaration(ZoneList<const AstRawString*>* names,
VariableProxy* proxy = NewUnresolved(variable_name, LET);
Declaration* declaration =
factory()->NewVariableDeclaration(proxy, LET, scope_, pos);
factory()->NewVariableDeclaration(proxy, LET, scope(), pos);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
proxy->var()->set_initializer_position(position());
Assignment* assignment =
......@@ -2286,12 +2281,13 @@ Block* Parser::ParseBlock(ZoneList<const AstRawString*>* labels,
// Construct block expecting 16 statements.
Block* body = factory()->NewBlock(labels, 16, false, kNoSourcePosition);
Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
Scope* block_scope = NewScope(scope(), BLOCK_SCOPE);
// Parse the statements and collect escaping labels.
Expect(Token::LBRACE, CHECK_OK);
block_scope->set_start_position(scanner()->location().beg_pos);
{ BlockState block_state(&scope_, block_scope);
{
BlockState block_state(&scope_state_, block_scope);
Target target(&this->target_stack_, body);
while (peek() != Token::RBRACE) {
......@@ -2397,7 +2393,7 @@ Block* Parser::ParseVariableDeclarations(
UNREACHABLE(); // by current callers
}
parsing_result->descriptor.scope = scope_;
parsing_result->descriptor.scope = scope();
parsing_result->descriptor.hoist_scope = nullptr;
......@@ -2585,7 +2581,7 @@ Statement* Parser::ParseExpressionOrLabelledStatement(
// Remove the "ghost" variable that turned out to be a label
// from the top scope. This way, we don't try to resolve it
// during the scope processing.
scope_->RemoveUnresolved(var);
scope()->RemoveUnresolved(var);
Expect(Token::COLON, CHECK_OK);
// ES#sec-labelled-function-declarations Labelled Function Declarations
if (peek() == Token::FUNCTION && is_sloppy(language_mode())) {
......@@ -2724,7 +2720,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
tok == Token::RBRACE ||
tok == Token::EOS) {
if (IsSubclassConstructor(function_state_->kind())) {
return_value = ThisExpression(scope_, factory(), loc.beg_pos);
return_value = ThisExpression(scope(), factory(), loc.beg_pos);
} else {
return_value = GetLiteralUndefined(position());
}
......@@ -2749,8 +2745,8 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
// %_IsJSReceiver(temp) ? temp : 1;
// temp = expr
Variable* temp = scope_->NewTemporary(
ast_value_factory()->empty_string());
Variable* temp =
scope()->NewTemporary(ast_value_factory()->empty_string());
Assignment* assign = factory()->NewAssignment(
Token::ASSIGN, factory()->NewVariableProxy(temp), return_value, pos);
......@@ -2773,7 +2769,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
// is_undefined ? this : is_object_conditional
return_value = factory()->NewConditional(
is_undefined, ThisExpression(scope_, factory(), pos),
is_undefined, ThisExpression(scope(), factory(), pos),
is_object_conditional, pos);
} else {
ReturnExprScope maybe_allow_tail_calls(
......@@ -2796,7 +2792,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
result = factory()->NewReturnStatement(return_value, loc.beg_pos);
Scope* decl_scope = scope_->DeclarationScope();
Scope* decl_scope = scope()->DeclarationScope();
if (decl_scope->is_script_scope() || decl_scope->is_eval_scope()) {
ReportMessageAt(loc, MessageTemplate::kIllegalReturn);
*ok = false;
......@@ -2824,9 +2820,10 @@ Statement* Parser::ParseWithStatement(ZoneList<const AstRawString*>* labels,
Expression* expr = ParseExpression(true, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
Scope* with_scope = NewScope(scope_, WITH_SCOPE);
Scope* with_scope = NewScope(scope(), WITH_SCOPE);
Statement* body;
{ BlockState block_state(&scope_, with_scope);
{
BlockState block_state(&scope_state_, with_scope);
with_scope->set_start_position(scanner()->peek_location().beg_pos);
body = ParseScopedStatement(labels, true, CHECK_OK);
with_scope->set_end_position(scanner()->location().end_pos);
......@@ -2891,7 +2888,7 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
Expect(Token::RPAREN, CHECK_OK);
Variable* tag_variable =
scope_->NewTemporary(ast_value_factory()->dot_switch_tag_string());
scope()->NewTemporary(ast_value_factory()->dot_switch_tag_string());
Assignment* tag_assign = factory()->NewAssignment(
Token::ASSIGN, factory()->NewVariableProxy(tag_variable), tag,
tag->position());
......@@ -2908,7 +2905,7 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
zone());
Block* cases_block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE);
Scope* cases_scope = NewScope(scope(), BLOCK_SCOPE);
cases_scope->SetNonlinear();
SwitchStatement* switch_statement =
......@@ -2916,7 +2913,7 @@ Statement* Parser::ParseSwitchStatement(ZoneList<const AstRawString*>* labels,
cases_scope->set_start_position(scanner()->location().beg_pos);
{
BlockState cases_block_state(&scope_, cases_scope);
BlockState cases_block_state(&scope_state_, cases_scope);
Target target(&this->target_stack_, switch_statement);
Expression* tag_read = factory()->NewVariableProxy(tag_variable);
......@@ -3000,23 +2997,23 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
Consume(Token::CATCH);
Expect(Token::LPAREN, CHECK_OK);
catch_scope = NewScope(scope_, CATCH_SCOPE);
catch_scope = NewScope(scope(), CATCH_SCOPE);
catch_scope->set_start_position(scanner()->location().beg_pos);
{
CollectExpressionsInTailPositionToListScope
collect_tail_call_expressions_scope(
function_state_, &tail_call_expressions_in_catch_block);
BlockState block_state(&scope_, catch_scope);
BlockState block_state(&scope_state_, catch_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.
Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
Scope* block_scope = NewScope(scope(), BLOCK_SCOPE);
block_scope->set_start_position(scanner()->location().beg_pos);
{
BlockState block_state(&scope_, block_scope);
BlockState block_state(&scope_state_, block_scope);
Target target(&this->target_stack_, catch_block);
const AstRawString* name = ast_value_factory()->dot_catch_string();
......@@ -3038,7 +3035,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
DeclarationDescriptor descriptor;
descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
descriptor.parser = this;
descriptor.scope = scope_;
descriptor.scope = scope();
descriptor.hoist_scope = nullptr;
descriptor.mode = LET;
descriptor.declaration_pos = pattern->position();
......@@ -3240,12 +3237,12 @@ Statement* Parser::InitializeForEachStatement(ForEachStatement* stmt,
} else {
if (each->IsArrayLiteral() || each->IsObjectLiteral()) {
Variable* temp =
scope_->NewTemporary(ast_value_factory()->empty_string());
scope()->NewTemporary(ast_value_factory()->empty_string());
VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
Expression* assign_each = PatternRewriter::RewriteDestructuringAssignment(
this, factory()->NewAssignment(Token::ASSIGN, each, temp_proxy,
kNoSourcePosition),
scope_);
scope());
auto block = factory()->NewBlock(nullptr, 2, false, kNoSourcePosition);
block->statements()->Add(
factory()->NewExpressionStatement(assign_each, kNoSourcePosition),
......@@ -3274,10 +3271,10 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of,
auto avfactory = ast_value_factory();
Variable* iterator =
scope_->NewTemporary(ast_value_factory()->dot_iterator_string());
scope()->NewTemporary(ast_value_factory()->dot_iterator_string());
Variable* result =
scope_->NewTemporary(ast_value_factory()->dot_result_string());
Variable* completion = scope_->NewTemporary(avfactory->empty_string());
scope()->NewTemporary(ast_value_factory()->dot_result_string());
Variable* completion = scope()->NewTemporary(avfactory->empty_string());
// iterator = iterable[Symbol.iterator]()
Expression* assign_iterator;
......@@ -3333,7 +3330,7 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of,
// do { let tmp = #result_value; #set_completion_abrupt; tmp }
// Expression* result_value (gets overwritten)
if (finalize) {
Variable* var_tmp = scope_->NewTemporary(avfactory->empty_string());
Variable* var_tmp = scope()->NewTemporary(avfactory->empty_string());
Expression* tmp = factory()->NewVariableProxy(var_tmp);
Expression* assignment =
factory()->NewAssignment(Token::ASSIGN, tmp, result_value, nopos);
......@@ -3353,7 +3350,7 @@ Statement* Parser::InitializeForOfStatement(ForOfStatement* for_of,
factory()->NewAssignment(Token::ASSIGN, each, result_value, nopos);
if (each->IsArrayLiteral() || each->IsObjectLiteral()) {
assign_each = PatternRewriter::RewriteDestructuringAssignment(
this, assign_each->AsAssignment(), scope_);
this, assign_each->AsAssignment(), scope());
}
}
......@@ -3443,7 +3440,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
// make statement: temp_x = x.
for (int i = 0; i < names->length(); i++) {
VariableProxy* proxy = NewUnresolved(names->at(i), LET);
Variable* temp = scope_->NewTemporary(temp_name);
Variable* temp = scope()->NewTemporary(temp_name);
VariableProxy* temp_proxy = factory()->NewVariableProxy(temp);
Assignment* assignment = factory()->NewAssignment(Token::ASSIGN, temp_proxy,
proxy, kNoSourcePosition);
......@@ -3456,7 +3453,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
Variable* first = NULL;
// Make statement: first = 1.
if (next) {
first = scope_->NewTemporary(temp_name);
first = scope()->NewTemporary(temp_name);
VariableProxy* first_proxy = factory()->NewVariableProxy(first);
Expression* const1 = factory()->NewSmiLiteral(1, kNoSourcePosition);
Assignment* assignment = factory()->NewAssignment(
......@@ -3480,11 +3477,11 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
ForStatement* outer_loop =
factory()->NewForStatement(NULL, kNoSourcePosition);
outer_block->statements()->Add(outer_loop, zone());
outer_block->set_scope(scope_);
outer_block->set_scope(scope());
Block* inner_block = factory()->NewBlock(NULL, 3, false, kNoSourcePosition);
{
BlockState block_state(&scope_, inner_scope);
BlockState block_state(&scope_state_, inner_scope);
Block* ignore_completion_block =
factory()->NewBlock(NULL, names->length() + 3, true, kNoSourcePosition);
......@@ -3494,7 +3491,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
for (int i = 0; i < names->length(); i++) {
VariableProxy* proxy = NewUnresolved(names->at(i), mode);
Declaration* declaration = factory()->NewVariableDeclaration(
proxy, mode, scope_, kNoSourcePosition);
proxy, mode, scope(), kNoSourcePosition);
Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK);
inner_vars.Add(declaration->proxy()->var(), zone());
VariableProxy* temp_proxy = factory()->NewVariableProxy(temps.at(i));
......@@ -3533,7 +3530,7 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
ignore_completion_block->statements()->Add(clear_first_or_next, zone());
}
Variable* flag = scope_->NewTemporary(temp_name);
Variable* flag = scope()->NewTemporary(temp_name);
// Make statement: flag = 1.
{
VariableProxy* flag_proxy = factory()->NewVariableProxy(flag);
......@@ -3640,9 +3637,9 @@ Statement* Parser::ParseScopedStatement(ZoneList<const AstRawString*>* labels,
}
// Make a block around the statement for a lexical binding
// is introduced by a FunctionDeclaration.
Scope* body_scope = NewScope(scope_, BLOCK_SCOPE);
Scope* body_scope = NewScope(scope(), BLOCK_SCOPE);
body_scope->set_start_position(scanner()->location().beg_pos);
BlockState block_state(&scope_, body_scope);
BlockState block_state(&scope_state_, body_scope);
Block* block = factory()->NewBlock(NULL, 1, false, kNoSourcePosition);
Statement* body = ParseFunctionDeclaration(CHECK_OK);
block->statements()->Add(body, zone());
......@@ -3661,9 +3658,9 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
bool bound_names_are_lexical = false;
// Create an in-between scope for let-bound iteration variables.
Scope* for_scope = NewScope(scope_, BLOCK_SCOPE);
Scope* for_scope = NewScope(scope(), BLOCK_SCOPE);
BlockState block_state(&scope_, for_scope);
BlockState block_state(&scope_state_, for_scope);
Expect(Token::FOR, CHECK_OK);
Expect(Token::LPAREN, CHECK_OK);
for_scope->set_start_position(scanner()->location().beg_pos);
......@@ -3719,7 +3716,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
++use_counts_[v8::Isolate::kForInInitializer];
const AstRawString* name =
decl.pattern->AsVariableProxy()->raw_name();
VariableProxy* single_var = scope_->NewUnresolved(
VariableProxy* single_var = scope()->NewUnresolved(
factory(), name, Variable::NORMAL, each_beg_pos, each_end_pos);
init_block = factory()->NewBlock(
nullptr, 2, true, parsing_result.descriptor.declaration_pos);
......@@ -3748,7 +3745,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
// }
Variable* temp =
scope_->NewTemporary(ast_value_factory()->dot_for_string());
scope()->NewTemporary(ast_value_factory()->dot_for_string());
ForEachStatement* loop =
factory()->NewForEachStatement(mode, labels, stmt_pos);
Target target(&this->target_stack_, loop);
......@@ -3766,7 +3763,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
Expect(Token::RPAREN, CHECK_OK);
Scope* body_scope = NewScope(scope_, BLOCK_SCOPE);
Scope* body_scope = NewScope(scope(), BLOCK_SCOPE);
body_scope->set_start_position(scanner()->location().beg_pos);
Block* body_block =
......@@ -3776,7 +3773,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
{
ReturnExprScope no_tail_calls(function_state_,
ReturnExprContext::kInsideForInOfBody);
BlockState block_state(&scope_, body_scope);
BlockState block_state(&scope_state_, body_scope);
Statement* body = ParseScopedStatement(NULL, true, CHECK_OK);
......@@ -3806,7 +3803,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
// all of the names declared in the init of the for-of we're
// parsing.
if (is_for_var_of) {
Scope* catch_scope = scope_;
Scope* catch_scope = scope();
while (catch_scope != nullptr &&
!catch_scope->is_declaration_scope()) {
if (catch_scope->is_catch_scope()) {
......@@ -3852,7 +3849,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
// but visible to everything else.
VariableProxy* tdz_proxy = NewUnresolved(bound_names[i], LET);
Declaration* tdz_decl = factory()->NewVariableDeclaration(
tdz_proxy, LET, scope_, kNoSourcePosition);
tdz_proxy, LET, scope(), kNoSourcePosition);
Variable* tdz_var = Declare(
tdz_decl, DeclarationDescriptor::NORMAL, true, CHECK_OK);
tdz_var->set_initializer_position(position());
......@@ -3947,13 +3944,13 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
// 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_;
Scope* inner_scope = scope();
if (bound_names_are_lexical && bound_names.length() > 0) {
inner_scope = NewScope(for_scope, BLOCK_SCOPE);
inner_scope->set_start_position(scanner()->location().beg_pos);
}
{
BlockState block_state(&scope_, inner_scope);
BlockState block_state(&scope_state_, inner_scope);
if (peek() != Token::SEMICOLON) {
cond = ParseExpression(true, CHECK_OK);
......@@ -3971,7 +3968,7 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
Statement* result = NULL;
if (bound_names_are_lexical && bound_names.length() > 0) {
BlockState block_state(&scope_, for_scope);
BlockState block_state(&scope_state_, for_scope);
result = DesugarLexicalBindingsInForStatement(
inner_scope, parsing_result.descriptor.mode, &bound_names, loop, init,
cond, next, body, CHECK_OK);
......@@ -4120,7 +4117,7 @@ void ParserTraits::ParseArrowFunctionFormalParameters(
// parse-time side-effect for parameters that are single-names (not
// patterns; for patterns that happens uniformly in
// PatternRewriter::VisitVariableProxy).
parser_->scope_->RemoveUnresolved(expr->AsVariableProxy());
parser_->scope()->RemoveUnresolved(expr->AsVariableProxy());
} else if (expr->IsAssignment()) {
Assignment* assignment = expr->AsAssignment();
DCHECK(!assignment->is_compound());
......@@ -4129,7 +4126,7 @@ void ParserTraits::ParseArrowFunctionFormalParameters(
// TODO(adamk): Only call this if necessary.
RewriteParameterInitializerScope(parser_->stack_limit(), initializer,
parser_->scope_, parameters->scope);
parser_->scope(), parameters->scope);
}
AddFormalParameter(parameters, expr, initializer, end_pos, is_rest);
......@@ -4139,7 +4136,7 @@ void ParserTraits::ParseAsyncArrowSingleExpressionBody(
ZoneList<Statement*>* body, bool accept_IN,
Type::ExpressionClassifier* classifier, int pos, bool* ok) {
parser_->DesugarAsyncFunctionBody(
parser_->ast_value_factory()->empty_string(), parser_->scope_, body,
parser_->ast_value_factory()->empty_string(), parser_->scope(), body,
classifier, kAsyncArrowFunction, FunctionBody::SingleExpression,
accept_IN, pos, ok);
}
......@@ -4158,8 +4155,8 @@ void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name,
// }
// }
scope->ForceContextAllocation();
Variable* temp =
scope_->NewTemporary(ast_value_factory()->dot_generator_object_string());
Variable* temp = this->scope()->NewTemporary(
ast_value_factory()->dot_generator_object_string());
function_state_->set_generator_object_variable(temp);
Expression* init_generator_variable = factory()->NewAssignment(
......@@ -4198,7 +4195,7 @@ DoExpression* Parser::ParseDoExpression(bool* ok) {
Expect(Token::DO, CHECK_OK);
Variable* result =
scope_->NewTemporary(ast_value_factory()->dot_result_string());
scope()->NewTemporary(ast_value_factory()->dot_result_string());
Block* block = ParseBlock(nullptr, false, CHECK_OK);
DoExpression* expr = factory()->NewDoExpression(block, result, pos);
if (!Rewriter::Rewrite(this, expr, ast_value_factory())) {
......@@ -4284,7 +4281,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
function_name = ast_value_factory()->empty_string();
}
Scope* scope = NewScope(scope_, FUNCTION_SCOPE, kind);
Scope* scope = NewScope(this->scope(), FUNCTION_SCOPE, kind);
SetLanguageMode(scope, language_mode);
ZoneList<Statement*>* body = NULL;
int arity = -1;
......@@ -4298,9 +4295,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// Parse function.
{
AstNodeFactory function_factory(ast_value_factory());
FunctionState function_state(&function_state_, &scope_, scope, kind,
FunctionState function_state(&function_state_, &scope_state_, scope, kind,
&function_factory);
scope_->SetScopeName(function_name);
this->scope()->SetScopeName(function_name);
ExpressionClassifier formals_classifier(this, &duplicate_finder);
eager_compile_hint = function_state_->this_function_is_parenthesized()
......@@ -4312,19 +4309,19 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// because it minimizes the work needed to suspend and resume an
// activation. The machine code produced for generators (by full-codegen)
// relies on this forced context allocation, but not in an essential way.
scope_->ForceContextAllocation();
this->scope()->ForceContextAllocation();
// Calling a generator returns a generator object. That object is stored
// in a temporary variable, a definition that is used by "yield"
// expressions. This also marks the FunctionState as a generator.
Variable* temp = scope_->NewTemporary(
Variable* temp = this->scope()->NewTemporary(
ast_value_factory()->dot_generator_object_string());
function_state.set_generator_object_variable(temp);
}
Expect(Token::LPAREN, CHECK_OK);
int start_position = scanner()->location().beg_pos;
scope_->set_start_position(start_position);
this->scope()->set_start_position(start_position);
ParserFormalParameters formals(scope);
ParseFormalParameterList(&formals, &formals_classifier, CHECK_OK);
arity = formals.Arity();
......@@ -4373,7 +4370,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
// To make this additional case work, both Parser and PreParser implement a
// logic where only top-level functions will be parsed lazily.
bool is_lazily_parsed = mode() == PARSE_LAZILY &&
scope_->AllowsLazyParsing() &&
this->scope()->AllowsLazyParsing() &&
!function_state_->this_function_is_parenthesized();
// Eager or lazy parse?
......@@ -4540,14 +4537,14 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count,
if (entry.is_valid() && entry.end_pos() > function_block_pos) {
scanner()->SeekForward(entry.end_pos() - 1);
scope_->set_end_position(entry.end_pos());
scope()->set_end_position(entry.end_pos());
Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void));
total_preparse_skipped_ += scope_->end_position() - function_block_pos;
total_preparse_skipped_ += scope()->end_position() - function_block_pos;
*materialized_literal_count = entry.literal_count();
*expected_property_count = entry.property_count();
SetLanguageMode(scope_, entry.language_mode());
if (entry.uses_super_property()) scope_->RecordSuperPropertyUsage();
if (entry.calls_eval()) scope_->RecordEvalCall();
SetLanguageMode(scope(), entry.language_mode());
if (entry.uses_super_property()) scope()->RecordSuperPropertyUsage();
if (entry.calls_eval()) scope()->RecordEvalCall();
return;
}
cached_parse_data_->Reject();
......@@ -4573,25 +4570,25 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count,
*ok = false;
return;
}
scope_->set_end_position(logger.end());
scope()->set_end_position(logger.end());
Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void));
total_preparse_skipped_ += scope_->end_position() - function_block_pos;
total_preparse_skipped_ += scope()->end_position() - function_block_pos;
*materialized_literal_count = logger.literals();
*expected_property_count = logger.properties();
SetLanguageMode(scope_, logger.language_mode());
SetLanguageMode(scope(), logger.language_mode());
if (logger.uses_super_property()) {
scope_->RecordSuperPropertyUsage();
scope()->RecordSuperPropertyUsage();
}
if (logger.calls_eval()) {
scope_->RecordEvalCall();
scope()->RecordEvalCall();
}
if (produce_cached_parse_data()) {
DCHECK(log_);
// Position right after terminal '}'.
int body_end = scanner()->location().end_pos;
log_->LogFunction(function_block_pos, body_end, *materialized_literal_count,
*expected_property_count, scope_->language_mode(),
scope_->uses_super_property(), scope_->calls_eval());
*expected_property_count, scope()->language_mode(),
scope()->uses_super_property(), scope()->calls_eval());
}
}
......@@ -4656,7 +4653,7 @@ void Parser::RewriteParameterInitializer(Expression* expr, Scope* scope) {
Block* Parser::BuildParameterInitializationBlock(
const ParserFormalParameters& parameters, bool* ok) {
DCHECK(!parameters.is_simple);
DCHECK(scope_->is_function_scope());
DCHECK(scope()->is_function_scope());
Block* init_block = factory()->NewBlock(NULL, 1, true, kNoSourcePosition);
for (int i = 0; i < parameters.params.length(); ++i) {
auto parameter = parameters.params[i];
......@@ -4664,7 +4661,7 @@ Block* Parser::BuildParameterInitializationBlock(
DeclarationDescriptor descriptor;
descriptor.declaration_kind = DeclarationDescriptor::PARAMETER;
descriptor.parser = this;
descriptor.scope = scope_;
descriptor.scope = scope();
descriptor.hoist_scope = nullptr;
descriptor.mode = LET;
descriptor.declaration_pos = parameter.pattern->position();
......@@ -4683,7 +4680,7 @@ Block* Parser::BuildParameterInitializationBlock(
// IS_UNDEFINED($param) ? initializer : $param
// Ensure initializer is rewritten
RewriteParameterInitializer(parameter.initializer, scope_);
RewriteParameterInitializer(parameter.initializer, scope());
auto condition = factory()->NewCompareOperation(
Token::EQ_STRICT,
......@@ -4695,34 +4692,34 @@ Block* Parser::BuildParameterInitializationBlock(
initializer_position = parameter.initializer_end_position;
}
Scope* param_scope = scope_;
Scope* param_scope = scope();
Block* param_block = init_block;
if (!parameter.is_simple() && scope_->calls_sloppy_eval()) {
param_scope = NewScope(scope_, BLOCK_SCOPE);
if (!parameter.is_simple() && scope()->calls_sloppy_eval()) {
param_scope = NewScope(scope(), BLOCK_SCOPE);
param_scope->set_is_declaration_scope();
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->set_scope(param_scope);
descriptor.hoist_scope = scope_;
descriptor.hoist_scope = scope();
// Pass the appropriate scope in so that PatternRewriter can appropriately
// rewrite inner initializers of the pattern to param_scope
descriptor.scope = param_scope;
// Rewrite the outer initializer to point to param_scope
RewriteParameterInitializerScope(stack_limit(), initial_value, scope_,
RewriteParameterInitializerScope(stack_limit(), initial_value, scope(),
param_scope);
}
{
BlockState block_state(&scope_, param_scope);
BlockState block_state(&scope_state_, param_scope);
DeclarationParsingResult::Declaration decl(
parameter.pattern, initializer_position, initial_value);
PatternRewriter::DeclareAndInitializeVariables(param_block, &descriptor,
&decl, nullptr, CHECK_OK);
}
if (!parameter.is_simple() && scope_->calls_sloppy_eval()) {
if (!parameter.is_simple() && scope()->calls_sloppy_eval()) {
param_scope = param_scope->FinalizeBlockScope();
if (param_scope != nullptr) {
CheckConflictingVarDeclarations(param_scope, CHECK_OK);
......@@ -4736,7 +4733,7 @@ Block* Parser::BuildParameterInitializationBlock(
Block* Parser::BuildRejectPromiseOnException(Block* block) {
// try { <block> } catch (error) { return Promise.reject(error); }
Block* try_block = block;
Scope* catch_scope = NewScope(scope_, CATCH_SCOPE);
Scope* catch_scope = NewScope(scope(), CATCH_SCOPE);
catch_scope->set_is_hidden();
Variable* catch_variable =
catch_scope->DeclareLocal(ast_value_factory()->dot_catch_string(), VAR,
......@@ -4763,7 +4760,7 @@ Expression* Parser::BuildCreateJSGeneratorObject(int pos, FunctionKind kind) {
args->Add(factory()->NewThisFunction(pos), zone());
args->Add(IsArrowFunction(kind)
? GetLiteralUndefined(pos)
: ThisExpression(scope_, factory(), kNoSourcePosition),
: ThisExpression(scope(), factory(), kNoSourcePosition),
zone());
return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args,
pos);
......@@ -4805,10 +4802,10 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
}
ZoneList<Statement*>* body = result;
Scope* inner_scope = scope_;
Scope* inner_scope = scope();
Block* inner_block = nullptr;
if (!parameters.is_simple) {
inner_scope = NewScope(scope_, BLOCK_SCOPE);
inner_scope = NewScope(scope(), BLOCK_SCOPE);
inner_scope->set_is_declaration_scope();
inner_scope->set_start_position(scanner()->location().beg_pos);
inner_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition);
......@@ -4817,7 +4814,7 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
}
{
BlockState block_state(&scope_, inner_scope);
BlockState block_state(&scope_state_, inner_scope);
if (IsGeneratorFunction(kind)) {
// We produce:
......@@ -4845,9 +4842,9 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
// The position of the yield is important for reporting the exception
// caused by calling the .throw method on a generator suspended at the
// initial yield (i.e. right after generator instantiation).
Yield* yield =
factory()->NewYield(get_proxy, assignment, scope_->start_position(),
Yield::kOnExceptionThrow);
Yield* yield = factory()->NewYield(get_proxy, assignment,
scope()->start_position(),
Yield::kOnExceptionThrow);
try_block->statements()->Add(
factory()->NewExpressionStatement(yield, kNoSourcePosition),
zone());
......@@ -4884,19 +4881,19 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
if (IsSubclassConstructor(kind)) {
body->Add(factory()->NewReturnStatement(
this->ThisExpression(scope_, factory(), kNoSourcePosition),
this->ThisExpression(scope(), factory(), kNoSourcePosition),
kNoSourcePosition),
zone());
}
}
Expect(Token::RBRACE, CHECK_OK);
scope_->set_end_position(scanner()->location().end_pos);
scope()->set_end_position(scanner()->location().end_pos);
if (!parameters.is_simple) {
DCHECK_NOT_NULL(inner_scope);
DCHECK_EQ(body, inner_block->statements());
SetLanguageMode(scope_, inner_scope->language_mode());
SetLanguageMode(scope(), inner_scope->language_mode());
Block* init_block = BuildParameterInitializationBlock(parameters, CHECK_OK);
if (is_sloppy(inner_scope->language_mode())) {
......@@ -4933,12 +4930,12 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
// instead of Variables and Proxies as is the case now.
VariableMode fvar_mode = is_strict(language_mode()) ? CONST : CONST_LEGACY;
Variable* fvar = new (zone())
Variable(scope_, function_name, fvar_mode, Variable::NORMAL,
Variable(scope(), function_name, fvar_mode, Variable::NORMAL,
kCreatedInitialized, kNotAssigned);
VariableProxy* proxy = factory()->NewVariableProxy(fvar);
VariableDeclaration* fvar_declaration = factory()->NewVariableDeclaration(
proxy, fvar_mode, scope_, kNoSourcePosition);
scope_->DeclareFunctionVar(fvar_declaration);
proxy, fvar_mode, scope(), kNoSourcePosition);
scope()->DeclareFunctionVar(fvar_declaration);
VariableProxy* fproxy = factory()->NewVariableProxy(fvar);
result->Set(kFunctionNameAssignmentIndex,
......@@ -4981,8 +4978,9 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
#undef SET_ALLOW
}
PreParser::PreParseResult result = reusable_preparser_->PreParseLazyFunction(
language_mode(), function_state_->kind(), scope_->has_simple_parameters(),
parsing_module_, logger, bookmark, use_counts_);
language_mode(), function_state_->kind(),
scope()->has_simple_parameters(), parsing_module_, logger, bookmark,
use_counts_);
if (pre_parse_timer_ != NULL) {
pre_parse_timer_->Stop();
}
......@@ -5007,10 +5005,10 @@ ClassLiteral* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
return NULL;
}
Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
BlockState block_state(&scope_, block_scope);
Scope* block_scope = NewScope(scope(), BLOCK_SCOPE);
BlockState block_state(&scope_state_, block_scope);
RaiseLanguageMode(STRICT);
scope_->SetScopeName(name);
scope()->SetScopeName(name);
VariableProxy* proxy = NULL;
if (name != NULL) {
......@@ -5118,7 +5116,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
if (extension_ != NULL) {
// The extension structures are only accessible while parsing the
// very first time not when reparsing because of lazy compilation.
scope_->DeclarationScope()->ForceEagerCompilation();
scope()->DeclarationScope()->ForceEagerCompilation();
}
const Runtime::Function* function = Runtime::FunctionForName(name->string());
......@@ -5666,12 +5664,13 @@ Expression* Parser::SpreadCall(Expression* function,
if (function->IsProperty()) {
// Method calls
if (function->AsProperty()->IsSuperAccess()) {
Expression* home = ThisExpression(scope_, factory(), kNoSourcePosition);
Expression* home =
ThisExpression(scope(), factory(), kNoSourcePosition);
args->InsertAt(0, function, zone());
args->InsertAt(1, home, zone());
} else {
Variable* temp =
scope_->NewTemporary(ast_value_factory()->empty_string());
scope()->NewTemporary(ast_value_factory()->empty_string());
VariableProxy* obj = factory()->NewVariableProxy(temp);
Assignment* assign_obj = factory()->NewAssignment(
Token::ASSIGN, obj, function->AsProperty()->obj(),
......@@ -5716,8 +5715,8 @@ void Parser::SetLanguageMode(Scope* scope, LanguageMode mode) {
void Parser::RaiseLanguageMode(LanguageMode mode) {
LanguageMode old = scope_->language_mode();
SetLanguageMode(scope_, old > mode ? old : mode);
LanguageMode old = scope()->language_mode();
SetLanguageMode(scope(), old > mode ? old : mode);
}
void Parser::MarkCollectedTailCallExpressions() {
......@@ -5776,7 +5775,7 @@ Expression* ParserTraits::RewriteAwaitExpression(Expression* value,
auto factory = parser_->factory();
const int nopos = kNoSourcePosition;
Variable* temp_var = parser_->scope_->NewTemporary(
Variable* temp_var = parser_->scope()->NewTemporary(
parser_->ast_value_factory()->empty_string());
VariableProxy* temp_proxy = factory->NewVariableProxy(temp_var);
Block* do_block = factory->NewBlock(nullptr, 2, false, nopos);
......@@ -5913,7 +5912,7 @@ Expression* Parser::RewriteAssignExponentiation(Expression* left,
DCHECK_NOT_NULL(lhs->raw_name());
result =
this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(),
lhs->end_position(), scope_, factory());
lhs->end_position(), scope(), factory());
args->Add(left, zone());
args->Add(right, zone());
Expression* call =
......@@ -5921,8 +5920,8 @@ Expression* Parser::RewriteAssignExponentiation(Expression* left,
return factory()->NewAssignment(Token::ASSIGN, result, call, pos);
} else if (left->IsProperty()) {
Property* prop = left->AsProperty();
auto temp_obj = scope_->NewTemporary(ast_value_factory()->empty_string());
auto temp_key = scope_->NewTemporary(ast_value_factory()->empty_string());
auto temp_obj = scope()->NewTemporary(ast_value_factory()->empty_string());
auto temp_key = scope()->NewTemporary(ast_value_factory()->empty_string());
Expression* assign_obj = factory()->NewAssignment(
Token::ASSIGN, factory()->NewVariableProxy(temp_obj), prop->obj(),
kNoSourcePosition);
......@@ -5966,7 +5965,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
ZoneList<Expression*>::iterator s = lit->FirstSpread();
if (s == lit->EndValue()) return nullptr; // no spread, no rewriting...
Variable* result =
scope_->NewTemporary(ast_value_factory()->dot_result_string());
scope()->NewTemporary(ast_value_factory()->dot_result_string());
// NOTE: The value assigned to R is the whole original array literal,
// spreads included. This will be fixed before the rewritten AST is returned.
// $R = lit
......@@ -5995,7 +5994,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
} else {
// If it's a spread, we're adding a for/of loop iterating through it.
Variable* each =
scope_->NewTemporary(ast_value_factory()->dot_for_string());
scope()->NewTemporary(ast_value_factory()->dot_for_string());
Expression* subject = spread->expression();
// %AppendElement($R, each)
Statement* append_body;
......@@ -6029,7 +6028,7 @@ Expression* Parser::RewriteSpreads(ArrayLiteral* lit) {
void ParserTraits::QueueDestructuringAssignmentForRewriting(Expression* expr) {
DCHECK(expr->IsRewritableExpression());
parser_->function_state_->AddDestructuringAssignment(
Parser::DestructuringAssignment(expr, parser_->scope_));
Parser::DestructuringAssignment(expr, parser_->scope()));
}
......@@ -6180,7 +6179,7 @@ Expression* ParserTraits::RewriteYieldStar(
auto factory = parser_->factory();
auto avfactory = parser_->ast_value_factory();
auto scope = parser_->scope_;
auto scope = parser_->scope();
auto zone = parser_->zone();
......@@ -6745,7 +6744,7 @@ void ParserTraits::FinalizeIteratorUse(Variable* completion,
const int nopos = kNoSourcePosition;
auto factory = parser_->factory();
auto avfactory = parser_->ast_value_factory();
auto scope = parser_->scope_;
auto scope = parser_->scope();
auto zone = parser_->zone();
// completion = kNormalCompletion;
......@@ -6864,7 +6863,7 @@ void ParserTraits::BuildIteratorCloseForCompletion(
const int nopos = kNoSourcePosition;
auto factory = parser_->factory();
auto avfactory = parser_->ast_value_factory();
auto scope = parser_->scope_;
auto scope = parser_->scope();
auto zone = parser_->zone();
......
......@@ -130,16 +130,17 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
log_ = log;
use_counts_ = use_counts;
// Lazy functions always have trivial outer scopes (no with/catch scopes).
Scope* top_scope = NewScope(scope_, SCRIPT_SCOPE);
PreParserFactory top_factory(NULL);
FunctionState top_state(&function_state_, &scope_, top_scope, kNormalFunction,
&top_factory);
scope_->SetLanguageMode(language_mode);
Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind);
DCHECK_NULL(scope_state_);
Scope* top_scope = NewScope(nullptr, SCRIPT_SCOPE);
PreParserFactory top_factory(nullptr);
FunctionState top_state(&function_state_, &scope_state_, top_scope,
kNormalFunction, &top_factory);
scope()->SetLanguageMode(language_mode);
Scope* function_scope = NewScope(scope(), FUNCTION_SCOPE, kind);
if (!has_simple_parameters) function_scope->SetHasNonSimpleParameters();
PreParserFactory function_factory(NULL);
FunctionState function_state(&function_state_, &scope_, function_scope, kind,
&function_factory);
PreParserFactory function_factory(nullptr);
FunctionState function_state(&function_state_, &scope_state_, function_scope,
kind, &function_factory);
DCHECK_EQ(Token::LBRACE, scanner()->current_token());
bool ok = true;
int start_position = peek_position();
......@@ -153,7 +154,7 @@ PreParser::PreParseResult PreParser::PreParseLazyFunction(
ReportUnexpectedToken(scanner()->current_token());
} else {
DCHECK_EQ(Token::RBRACE, scanner()->peek());
if (is_strict(scope_->language_mode())) {
if (is_strict(scope()->language_mode())) {
int end_pos = scanner()->location().end_pos;
CheckStrictOctalLiteral(start_position, end_pos, &ok);
CheckDecimalLiteralWithLeadingZero(use_counts, start_position, end_pos);
......@@ -253,13 +254,13 @@ void PreParser::ParseStatementList(int end_token, bool* ok,
bool use_strict_found = statement.IsUseStrictLiteral();
if (use_strict_found) {
scope_->SetLanguageMode(
static_cast<LanguageMode>(scope_->language_mode() | STRICT));
scope()->SetLanguageMode(
static_cast<LanguageMode>(scope()->language_mode() | STRICT));
} else if (!statement.IsStringLiteral()) {
directive_prologue = false;
}
if (use_strict_found && !scope_->HasSimpleParameters()) {
if (use_strict_found && !scope()->HasSimpleParameters()) {
// TC39 deemed "use strict" directives to be an error when occurring
// in the body of a function with non-simple parameter list, on
// 29/7/2015. https://goo.gl/ueA7Ln
......@@ -306,8 +307,8 @@ PreParser::Statement PreParser::ParseScopedStatement(bool legacy, bool* ok) {
(legacy && allow_harmony_restrictive_declarations())) {
return ParseSubStatement(kDisallowLabelledFunctionStatement, ok);
} else {
Scope* body_scope = NewScope(scope_, BLOCK_SCOPE);
BlockState block_state(&scope_, body_scope);
Scope* body_scope = NewScope(scope(), BLOCK_SCOPE);
BlockState block_state(&scope_state_, body_scope);
return ParseFunctionDeclaration(ok);
}
}
......@@ -477,11 +478,11 @@ PreParser::Statement PreParser::ParseBlock(bool* ok) {
// Block ::
// '{' StatementList '}'
Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
Scope* block_scope = NewScope(scope(), BLOCK_SCOPE);
Expect(Token::LBRACE, CHECK_OK);
Statement final = Statement::Default();
{
BlockState block_state(&scope_, block_scope);
BlockState block_state(&scope_state_, block_scope);
while (peek() != Token::RBRACE) {
final = ParseStatementListItem(CHECK_OK);
}
......@@ -791,8 +792,8 @@ PreParser::Statement PreParser::ParseWithStatement(bool* ok) {
ParseExpression(true, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
Scope* with_scope = NewScope(scope_, WITH_SCOPE);
BlockState block_state(&scope_, with_scope);
Scope* with_scope = NewScope(scope(), WITH_SCOPE);
BlockState block_state(&scope_state_, with_scope);
ParseScopedStatement(true, CHECK_OK);
return Statement::Default();
}
......@@ -807,9 +808,9 @@ PreParser::Statement PreParser::ParseSwitchStatement(bool* ok) {
ParseExpression(true, CHECK_OK);
Expect(Token::RPAREN, CHECK_OK);
Scope* cases_scope = NewScope(scope_, BLOCK_SCOPE);
Scope* cases_scope = NewScope(scope(), BLOCK_SCOPE);
{
BlockState cases_block_state(&scope_, cases_scope);
BlockState cases_block_state(&scope_state_, cases_scope);
Expect(Token::LBRACE, CHECK_OK);
Token::Value token = peek();
while (token != Token::RBRACE) {
......@@ -868,10 +869,10 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
// 'for' '(' Expression? ';' Expression? ';' Expression? ')' Statement
// Create an in-between scope for let-bound iteration variables.
Scope* for_scope = NewScope(scope_, BLOCK_SCOPE);
Scope* for_scope = NewScope(scope(), BLOCK_SCOPE);
bool has_lexical = false;
BlockState block_state(&scope_, for_scope);
BlockState block_state(&scope_state_, for_scope);
Expect(Token::FOR, CHECK_OK);
Expect(Token::LPAREN, CHECK_OK);
if (peek() != Token::SEMICOLON) {
......@@ -958,9 +959,9 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
}
Expect(Token::RPAREN, CHECK_OK);
Scope* body_scope = NewScope(scope_, BLOCK_SCOPE);
Scope* body_scope = NewScope(scope(), BLOCK_SCOPE);
{
BlockState block_state(&scope_, body_scope);
BlockState block_state(&scope_state_, body_scope);
ParseScopedStatement(true, CHECK_OK);
}
return Statement::Default();
......@@ -973,11 +974,11 @@ PreParser::Statement PreParser::ParseForStatement(bool* ok) {
// 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_;
Scope* inner_scope = scope();
if (has_lexical) inner_scope = NewScope(for_scope, BLOCK_SCOPE);
{
BlockState block_state(&scope_, inner_scope);
BlockState block_state(&scope_state_, inner_scope);
if (peek() != Token::SEMICOLON) {
ParseExpression(true, CHECK_OK);
......@@ -1042,7 +1043,7 @@ PreParser::Statement PreParser::ParseTryStatement(bool* ok) {
if (tok == Token::CATCH) {
Consume(Token::CATCH);
Expect(Token::LPAREN, CHECK_OK);
Scope* catch_scope = NewScope(scope_, CATCH_SCOPE);
Scope* catch_scope = NewScope(scope(), CATCH_SCOPE);
ExpressionClassifier pattern_classifier(this);
ParsePrimaryExpression(&pattern_classifier, CHECK_OK);
ValidateBindingPattern(&pattern_classifier, CHECK_OK);
......@@ -1051,10 +1052,10 @@ PreParser::Statement PreParser::ParseTryStatement(bool* ok) {
CollectExpressionsInTailPositionToListScope
collect_tail_call_expressions_scope(
function_state_, &tail_call_expressions_in_catch_block);
BlockState block_state(&scope_, catch_scope);
Scope* block_scope = NewScope(scope_, BLOCK_SCOPE);
BlockState block_state(&scope_state_, catch_scope);
Scope* block_scope = NewScope(scope(), BLOCK_SCOPE);
{
BlockState block_state(&scope_, block_scope);
BlockState block_state(&scope_state_, block_scope);
ParseBlock(CHECK_OK);
}
}
......@@ -1109,12 +1110,12 @@ PreParser::Expression PreParser::ParseFunctionLiteral(
// '(' FormalParameterList? ')' '{' FunctionBody '}'
// Parse function body.
bool outer_is_script_scope = scope_->is_script_scope();
Scope* function_scope = NewScope(scope_, FUNCTION_SCOPE, kind);
bool outer_is_script_scope = scope()->is_script_scope();
Scope* function_scope = NewScope(scope(), FUNCTION_SCOPE, kind);
function_scope->SetLanguageMode(language_mode);
PreParserFactory factory(NULL);
FunctionState function_state(&function_state_, &scope_, function_scope, kind,
&factory);
FunctionState function_state(&function_state_, &scope_state_, function_scope,
kind, &factory);
DuplicateFinder duplicate_finder(scanner()->unicode_cache());
ExpressionClassifier formals_classifier(this, &duplicate_finder);
......@@ -1209,7 +1210,7 @@ void PreParser::ParseLazyFunctionLiteralBody(bool* ok,
log_->LogFunction(body_start, body_end,
function_state_->materialized_literal_count(),
function_state_->expected_property_count(), language_mode(),
scope_->uses_super_property(), scope_->calls_eval());
scope()->uses_super_property(), scope()->calls_eval());
}
PreParserExpression PreParser::ParseClassLiteral(
......@@ -1230,12 +1231,12 @@ PreParserExpression PreParser::ParseClassLiteral(
}
LanguageMode class_language_mode = language_mode();
Scope* scope = NewScope(scope_, BLOCK_SCOPE);
BlockState block_state(&scope_, scope);
scope_->SetLanguageMode(
Scope* scope = NewScope(this->scope(), BLOCK_SCOPE);
BlockState block_state(&scope_state_, scope);
this->scope()->SetLanguageMode(
static_cast<LanguageMode>(class_language_mode | STRICT));
// TODO(marja): Make PreParser use scope names too.
// scope_->SetScopeName(name);
// this->scope()->SetScopeName(name);
bool has_extends = Check(Token::EXTENDS);
if (has_extends) {
......@@ -1312,7 +1313,7 @@ PreParserExpression PreParser::ParseDoExpression(bool* ok) {
void PreParserTraits::ParseAsyncArrowSingleExpressionBody(
PreParserStatementList body, bool accept_IN,
Type::ExpressionClassifier* classifier, int pos, bool* ok) {
Scope* scope = pre_parser_->scope_;
Scope* scope = pre_parser_->scope();
scope->ForceContextAllocation();
PreParserExpression return_value = pre_parser_->ParseAssignmentExpression(
......
......@@ -1037,7 +1037,8 @@ class PreParser : public ParserBase<PreParserTraits> {
// during parsing.
PreParseResult PreParseProgram(int* materialized_literals = 0,
bool is_module = false) {
Scope* scope = NewScope(scope_, SCRIPT_SCOPE);
DCHECK_NULL(scope_state_);
Scope* scope = NewScope(nullptr, SCRIPT_SCOPE);
// ModuleDeclarationInstantiation for Source Text Module Records creates a
// new Module Environment Record whose outer lexical environment record is
......@@ -1046,9 +1047,9 @@ class PreParser : public ParserBase<PreParserTraits> {
scope = NewScope(scope, MODULE_SCOPE);
}
PreParserFactory factory(NULL);
FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction,
&factory);
PreParserFactory factory(nullptr);
FunctionState top_scope(&function_state_, &scope_state_, scope,
kNormalFunction, &factory);
bool ok = true;
int start_position = scanner()->peek_location().beg_pos;
parsing_module_ = is_module;
......@@ -1056,7 +1057,7 @@ class PreParser : public ParserBase<PreParserTraits> {
if (stack_overflow()) return kPreParseStackOverflow;
if (!ok) {
ReportUnexpectedToken(scanner()->current_token());
} else if (is_strict(scope_->language_mode())) {
} else if (is_strict(this->scope()->language_mode())) {
CheckStrictOctalLiteral(start_position, scanner()->location().end_pos,
&ok);
CheckDecimalLiteralWithLeadingZero(use_counts_, start_position,
......@@ -1245,11 +1246,11 @@ PreParserStatementList PreParser::ParseEagerFunctionBody(
FunctionLiteral::FunctionType function_type, bool* ok) {
ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
Scope* inner_scope = scope_;
if (!parameters.is_simple) inner_scope = NewScope(scope_, BLOCK_SCOPE);
Scope* inner_scope = scope();
if (!parameters.is_simple) inner_scope = NewScope(scope(), BLOCK_SCOPE);
{
BlockState block_state(&scope_, inner_scope);
BlockState block_state(&scope_state_, inner_scope);
ParseStatementList(Token::RBRACE, ok);
if (!*ok) return PreParserStatementList();
}
......
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