Commit 0904b84e authored by verwaest's avatar verwaest Committed by Commit bot

Indirect Get*Scope over parser/parserbase

This avoids direct scope() accesses and allows us to redirect it over ScopeState.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2226243002
Cr-Commit-Position: refs/heads/master@{#38507}
parent a12aa891
...@@ -853,6 +853,9 @@ class ParserBase : public Traits { ...@@ -853,6 +853,9 @@ class ParserBase : public Traits {
typename Traits::Type::Factory* factory() { return &ast_node_factory_; } typename Traits::Type::Factory* factory() { return &ast_node_factory_; }
DeclarationScope* GetReceiverScope() const {
return scope()->GetReceiverScope();
}
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_generator() const { return function_state_->is_generator(); }
bool is_async_function() const { bool is_async_function() const {
...@@ -3096,7 +3099,7 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new, bool* ok) { ...@@ -3096,7 +3099,7 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new, bool* ok) {
Expect(Token::SUPER, CHECK_OK); Expect(Token::SUPER, CHECK_OK);
int pos = position(); int pos = position();
DeclarationScope* scope = this->scope()->GetReceiverScope(); DeclarationScope* scope = GetReceiverScope();
FunctionKind kind = scope->function_kind(); FunctionKind kind = scope->function_kind();
if (IsConciseMethod(kind) || IsAccessorFunction(kind) || if (IsConciseMethod(kind) || IsAccessorFunction(kind) ||
IsClassConstructor(kind)) { IsClassConstructor(kind)) {
...@@ -3138,7 +3141,7 @@ ParserBase<Traits>::ParseNewTargetExpression(bool* ok) { ...@@ -3138,7 +3141,7 @@ ParserBase<Traits>::ParseNewTargetExpression(bool* ok) {
int pos = position(); int pos = position();
ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK); ExpectMetaProperty(CStrVector("target"), "new.target", pos, CHECK_OK);
if (!scope()->GetReceiverScope()->is_function_scope()) { if (!GetReceiverScope()->is_function_scope()) {
ReportMessageAt(scanner()->location(), ReportMessageAt(scanner()->location(),
MessageTemplate::kUnexpectedNewTarget); MessageTemplate::kUnexpectedNewTarget);
*ok = false; *ok = false;
......
...@@ -1954,9 +1954,8 @@ VariableProxy* Parser::NewUnresolved(const AstRawString* name, ...@@ -1954,9 +1954,8 @@ VariableProxy* Parser::NewUnresolved(const AstRawString* name,
// truly local variable, and the scope of the variable is always the function // truly local variable, and the scope of the variable is always the function
// scope. // scope.
// Let/const variables are always added to the immediately enclosing scope. // Let/const variables are always added to the immediately enclosing scope.
Scope* scope = IsLexicalVariableMode(mode) Scope* scope =
? this->scope() IsLexicalVariableMode(mode) ? this->scope() : GetDeclarationScope();
: this->scope()->GetDeclarationScope();
return scope->NewUnresolved(factory(), name, Variable::NORMAL, return scope->NewUnresolved(factory(), name, Variable::NORMAL,
scanner()->location().beg_pos, scanner()->location().beg_pos,
scanner()->location().end_pos); scanner()->location().end_pos);
...@@ -2116,7 +2115,7 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) { ...@@ -2116,7 +2115,7 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) {
// accessible while parsing the first time not when reparsing // accessible while parsing the first time not when reparsing
// because of lazy compilation. // because of lazy compilation.
// TODO(adamk): Should this be GetClosureScope()? // TODO(adamk): Should this be GetClosureScope()?
scope()->GetDeclarationScope()->ForceEagerCompilation(); GetDeclarationScope()->ForceEagerCompilation();
// TODO(1240846): It's weird that native function declarations are // TODO(1240846): It's weird that native function declarations are
// introduced dynamically when we meet their declarations, whereas // introduced dynamically when we meet their declarations, whereas
...@@ -2225,7 +2224,7 @@ Statement* Parser::ParseHoistableDeclaration( ...@@ -2225,7 +2224,7 @@ Statement* Parser::ParseHoistableDeclaration(
!is_async && !(allow_harmony_restrictive_generators() && is_generator)) { !is_async && !(allow_harmony_restrictive_generators() && is_generator)) {
SloppyBlockFunctionStatement* delegate = SloppyBlockFunctionStatement* delegate =
factory()->NewSloppyBlockFunctionStatement(empty, scope()); factory()->NewSloppyBlockFunctionStatement(empty, scope());
DeclarationScope* target_scope = scope()->GetDeclarationScope(); DeclarationScope* target_scope = GetDeclarationScope();
target_scope->DeclareSloppyBlockFunction(variable_name, delegate); target_scope->DeclareSloppyBlockFunction(variable_name, delegate);
return delegate; return delegate;
} }
...@@ -2789,7 +2788,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) { ...@@ -2789,7 +2788,7 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
result = factory()->NewReturnStatement(return_value, loc.beg_pos); result = factory()->NewReturnStatement(return_value, loc.beg_pos);
DeclarationScope* decl_scope = scope()->GetDeclarationScope(); DeclarationScope* decl_scope = GetDeclarationScope();
if (decl_scope->is_script_scope() || decl_scope->is_eval_scope()) { if (decl_scope->is_script_scope() || decl_scope->is_eval_scope()) {
ReportMessageAt(loc, MessageTemplate::kIllegalReturn); ReportMessageAt(loc, MessageTemplate::kIllegalReturn);
*ok = false; *ok = false;
...@@ -4183,8 +4182,7 @@ DoExpression* Parser::ParseDoExpression(bool* ok) { ...@@ -4183,8 +4182,7 @@ DoExpression* Parser::ParseDoExpression(bool* ok) {
scope()->NewTemporary(ast_value_factory()->dot_result_string()); scope()->NewTemporary(ast_value_factory()->dot_result_string());
Block* block = ParseBlock(nullptr, CHECK_OK); Block* block = ParseBlock(nullptr, CHECK_OK);
DoExpression* expr = factory()->NewDoExpression(block, result, pos); DoExpression* expr = factory()->NewDoExpression(block, result, pos);
if (!Rewriter::Rewrite(this, scope()->GetClosureScope(), expr, if (!Rewriter::Rewrite(this, GetClosureScope(), expr, ast_value_factory())) {
ast_value_factory())) {
*ok = false; *ok = false;
return nullptr; return nullptr;
} }
...@@ -5118,8 +5116,7 @@ Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier, ...@@ -5118,8 +5116,7 @@ Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
do_block->statements()->Add( do_block->statements()->Add(
factory()->NewExpressionStatement(class_literal, pos), zone()); factory()->NewExpressionStatement(class_literal, pos), zone());
do_expr->set_represented_function(constructor); do_expr->set_represented_function(constructor);
Rewriter::Rewrite(this, scope()->GetClosureScope(), do_expr, Rewriter::Rewrite(this, GetClosureScope(), do_expr, ast_value_factory());
ast_value_factory());
return do_expr; return do_expr;
} }
...@@ -5144,7 +5141,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) { ...@@ -5144,7 +5141,7 @@ Expression* Parser::ParseV8Intrinsic(bool* ok) {
if (extension_ != NULL) { if (extension_ != NULL) {
// The extension structures are only accessible while parsing the // The extension structures are only accessible while parsing the
// very first time not when reparsing because of lazy compilation. // very first time not when reparsing because of lazy compilation.
scope()->GetDeclarationScope()->ForceEagerCompilation(); GetDeclarationScope()->ForceEagerCompilation();
} }
const Runtime::Function* function = Runtime::FunctionForName(name->string()); const Runtime::Function* function = Runtime::FunctionForName(name->string());
......
...@@ -770,6 +770,13 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -770,6 +770,13 @@ class Parser : public ParserBase<ParserTraits> {
kAbruptCompletion kAbruptCompletion
}; };
DeclarationScope* GetDeclarationScope() const {
return scope()->GetDeclarationScope();
}
DeclarationScope* GetClosureScope() const {
return scope()->GetClosureScope();
}
// Limit the allowed number of local variables in a function. The hard limit // Limit the allowed number of local variables in a function. The hard limit
// is that offsets computed by FullCodeGenerator::StackOperand and similar // is that offsets computed by FullCodeGenerator::StackOperand and similar
// functions are ints, and they should not overflow. In addition, accessing // functions are ints, and they should not overflow. In addition, accessing
......
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