Commit 8cdb64d8 authored by verwaest's avatar verwaest Committed by Commit bot

Reduce number of scope() accesses

To be able to lazily allocate BlockScopes, we need to reduce access to scope(). The explicit accesses removed here just need access to the current scope to allocate unresolved variable proxies. Those in the future should go over ScopeState rather than directly to Scope.

BUG=v8:5209

Review-Url: https://codereview.chromium.org/2224843003
Cr-Commit-Position: refs/heads/master@{#38456}
parent 5de47222
......@@ -1547,7 +1547,7 @@ ParserBase<Traits>::ParsePrimaryExpression(ExpressionClassifier* classifier,
case Token::THIS: {
BindingPatternUnexpectedToken(classifier);
Consume(Token::THIS);
return this->ThisExpression(scope(), factory(), beg_pos);
return this->ThisExpression(factory(), beg_pos);
}
case Token::NULL_LITERAL:
......@@ -1580,7 +1580,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, factory());
}
case Token::STRING: {
......@@ -2004,8 +2004,8 @@ ParserBase<Traits>::ParsePropertyDefinition(
MessageTemplate::kAwaitBindingIdentifier);
}
}
ExpressionT lhs = this->ExpressionFromIdentifier(
*name, next_beg_pos, next_end_pos, scope(), factory());
ExpressionT lhs = this->ExpressionFromIdentifier(*name, next_beg_pos,
next_end_pos, factory());
CheckDestructuringElement(lhs, classifier, next_beg_pos, next_end_pos);
ExpressionT value;
......@@ -2315,7 +2315,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, factory());
}
if (peek() == Token::ARROW) {
......@@ -2760,7 +2760,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, factory());
}
default:
break;
......@@ -2918,7 +2918,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(factory(), pos);
result =
factory()->NewAssignment(Token::INIT, this_expr, result, pos);
}
......@@ -3056,7 +3056,7 @@ ParserBase<Traits>::ParseMemberExpression(ExpressionClassifier* classifier,
return this->EmptyExpression();
}
return this->FunctionSentExpression(scope(), factory(), pos);
return this->FunctionSentExpression(factory(), pos);
}
bool is_generator = Check(Token::MUL);
......@@ -3102,14 +3102,14 @@ ParserBase<Traits>::ParseSuperExpression(bool is_new, bool* ok) {
IsClassConstructor(kind)) {
if (peek() == Token::PERIOD || peek() == Token::LBRACK) {
scope->RecordSuperPropertyUsage();
return this->NewSuperPropertyReference(this->scope(), factory(), pos);
return this->NewSuperPropertyReference(factory(), pos);
}
// new super() is never allowed.
// super() is only allowed in derived constructor
if (!is_new && peek() == Token::LPAREN && IsSubclassConstructor(kind)) {
// TODO(rossberg): This might not be the correct FunctionState for the
// method here.
return this->NewSuperCallReference(this->scope(), factory(), pos);
return this->NewSuperCallReference(factory(), pos);
}
}
......@@ -3145,7 +3145,7 @@ ParserBase<Traits>::ParseNewTargetExpression(bool* ok) {
return this->EmptyExpression();
}
return this->NewTargetExpression(scope(), factory(), pos);
return this->NewTargetExpression(factory(), pos);
}
template <class Traits>
......
......@@ -690,19 +690,16 @@ const AstRawString* ParserTraits::GetNextSymbol(Scanner* scanner) {
return parser_->scanner()->NextSymbol(parser_->ast_value_factory());
}
Expression* ParserTraits::ThisExpression(Scope* scope, AstNodeFactory* factory,
int pos) {
return scope->NewUnresolved(factory,
parser_->ast_value_factory()->this_string(),
Variable::THIS, pos, pos + 4);
Expression* ParserTraits::ThisExpression(AstNodeFactory* factory, int pos) {
return parser_->scope()->NewUnresolved(
factory, parser_->ast_value_factory()->this_string(), Variable::THIS, pos,
pos + 4);
}
Expression* ParserTraits::NewSuperPropertyReference(Scope* scope,
AstNodeFactory* factory,
Expression* ParserTraits::NewSuperPropertyReference(AstNodeFactory* factory,
int pos) {
// this_function[home_object_symbol]
VariableProxy* this_function_proxy = scope->NewUnresolved(
VariableProxy* this_function_proxy = parser_->scope()->NewUnresolved(
factory, parser_->ast_value_factory()->this_function_string(),
Variable::NORMAL, pos);
Expression* home_object_symbol_literal =
......@@ -710,38 +707,33 @@ Expression* ParserTraits::NewSuperPropertyReference(Scope* scope,
Expression* home_object = factory->NewProperty(
this_function_proxy, home_object_symbol_literal, pos);
return factory->NewSuperPropertyReference(
ThisExpression(scope, factory, pos)->AsVariableProxy(), home_object, pos);
ThisExpression(factory, pos)->AsVariableProxy(), home_object, pos);
}
Expression* ParserTraits::NewSuperCallReference(Scope* scope,
AstNodeFactory* factory,
Expression* ParserTraits::NewSuperCallReference(AstNodeFactory* factory,
int pos) {
VariableProxy* new_target_proxy = scope->NewUnresolved(
VariableProxy* new_target_proxy = parser_->scope()->NewUnresolved(
factory, parser_->ast_value_factory()->new_target_string(),
Variable::NORMAL, pos);
VariableProxy* this_function_proxy = scope->NewUnresolved(
VariableProxy* this_function_proxy = parser_->scope()->NewUnresolved(
factory, parser_->ast_value_factory()->this_function_string(),
Variable::NORMAL, pos);
return factory->NewSuperCallReference(
ThisExpression(scope, factory, pos)->AsVariableProxy(), new_target_proxy,
ThisExpression(factory, pos)->AsVariableProxy(), new_target_proxy,
this_function_proxy, pos);
}
Expression* ParserTraits::NewTargetExpression(Scope* scope,
AstNodeFactory* factory,
Expression* ParserTraits::NewTargetExpression(AstNodeFactory* factory,
int pos) {
static const int kNewTargetStringLength = 10;
auto proxy = scope->NewUnresolved(
auto proxy = parser_->scope()->NewUnresolved(
factory, parser_->ast_value_factory()->new_target_string(),
Variable::NORMAL, pos, pos + kNewTargetStringLength);
proxy->set_is_new_target();
return proxy;
}
Expression* ParserTraits::FunctionSentExpression(Scope* scope,
AstNodeFactory* factory,
Expression* ParserTraits::FunctionSentExpression(AstNodeFactory* factory,
int pos) {
// We desugar function.sent into %_GeneratorGetInputOrDebugPos(generator).
Zone* zone = parser_->zone();
......@@ -783,11 +775,10 @@ Literal* ParserTraits::ExpressionFromLiteral(Token::Value token, int pos,
Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name,
int start_position,
int end_position,
Scope* scope,
AstNodeFactory* factory) {
if (parser_->fni_ != NULL) parser_->fni_->PushVariableName(name);
return scope->NewUnresolved(factory, name, Variable::NORMAL, start_position,
end_position);
return parser_->scope()->NewUnresolved(factory, name, Variable::NORMAL,
start_position, end_position);
}
......@@ -1310,7 +1301,7 @@ 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(this->scope()->language_mode())) {
if (is_sloppy(language_mode())) {
RaiseLanguageMode(STRICT);
}
......@@ -2723,7 +2714,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(factory(), loc.beg_pos);
} else {
return_value = GetLiteralUndefined(position());
}
......@@ -2771,9 +2762,9 @@ Statement* Parser::ParseReturnStatement(bool* ok) {
factory()->NewUndefinedLiteral(kNoSourcePosition), pos);
// is_undefined ? this : is_object_conditional
return_value = factory()->NewConditional(
is_undefined, ThisExpression(scope(), factory(), pos),
is_object_conditional, pos);
return_value = factory()->NewConditional(is_undefined,
ThisExpression(factory(), pos),
is_object_conditional, pos);
} else {
ReturnExprScope maybe_allow_tail_calls(
function_state_, ReturnExprContext::kInsideValidReturnStatement);
......@@ -4606,7 +4597,7 @@ void Parser::SkipLazyFunctionBody(int* materialized_literal_count,
// 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(),
*expected_property_count, language_mode(),
scope()->uses_super_property(), scope()->calls_eval());
}
}
......@@ -4781,7 +4772,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(factory(), kNoSourcePosition),
zone());
return factory()->NewCallRuntime(Runtime::kCreateJSGeneratorObject, args,
pos);
......@@ -4902,7 +4893,7 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
if (IsSubclassConstructor(kind)) {
body->Add(factory()->NewReturnStatement(
this->ThisExpression(scope(), factory(), kNoSourcePosition),
this->ThisExpression(factory(), kNoSourcePosition),
kNoSourcePosition),
zone());
}
......@@ -5720,8 +5711,7 @@ Expression* Parser::SpreadCall(Expression* function,
if (function->IsProperty()) {
// Method calls
if (function->AsProperty()->IsSuperAccess()) {
Expression* home =
ThisExpression(scope(), factory(), kNoSourcePosition);
Expression* home = ThisExpression(factory(), kNoSourcePosition);
args->InsertAt(0, function, zone());
args->InsertAt(1, home, zone());
} else {
......@@ -5966,9 +5956,8 @@ Expression* Parser::RewriteAssignExponentiation(Expression* left,
Expression* result;
DCHECK_NOT_NULL(lhs->raw_name());
result =
this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(),
lhs->end_position(), scope(), factory());
result = this->ExpressionFromIdentifier(lhs->raw_name(), lhs->position(),
lhs->end_position(), factory());
args->Add(left, zone());
args->Add(right, zone());
Expression* call =
......@@ -6499,7 +6488,7 @@ Expression* ParserTraits::RewriteYieldStar(
// input = function.sent;
Statement* get_input;
{
Expression* function_sent = FunctionSentExpression(scope, factory, nopos);
Expression* function_sent = FunctionSentExpression(factory, nopos);
Expression* input_proxy = factory->NewVariableProxy(var_input);
Expression* assignment = factory->NewAssignment(
Token::ASSIGN, input_proxy, function_sent, nopos);
......
......@@ -549,21 +549,17 @@ class ParserTraits {
const AstRawString* GetNextSymbol(Scanner* scanner);
const AstRawString* GetNumberAsSymbol(Scanner* scanner);
Expression* ThisExpression(Scope* scope, AstNodeFactory* factory,
Expression* ThisExpression(AstNodeFactory* factory,
int pos = kNoSourcePosition);
Expression* NewSuperPropertyReference(Scope* scope, AstNodeFactory* factory,
int pos);
Expression* NewSuperCallReference(Scope* scope, AstNodeFactory* factory,
int pos);
Expression* NewTargetExpression(Scope* scope, AstNodeFactory* factory,
int pos);
Expression* FunctionSentExpression(Scope* scope, AstNodeFactory* factory,
int pos);
Expression* NewSuperPropertyReference(AstNodeFactory* factory, int pos);
Expression* NewSuperCallReference(AstNodeFactory* factory, int pos);
Expression* NewTargetExpression(AstNodeFactory* factory, int pos);
Expression* FunctionSentExpression(AstNodeFactory* factory, int pos);
Literal* ExpressionFromLiteral(Token::Value token, int pos, Scanner* scanner,
AstNodeFactory* factory);
Expression* ExpressionFromIdentifier(const AstRawString* name,
int start_position, int end_position,
Scope* scope, AstNodeFactory* factory);
AstNodeFactory* factory);
Expression* ExpressionFromString(int pos, Scanner* scanner,
AstNodeFactory* factory);
Expression* GetIterator(Expression* iterable, AstNodeFactory* factory,
......
......@@ -801,31 +801,27 @@ class PreParserTraits {
return PreParserIdentifier::Default();
}
static PreParserExpression ThisExpression(Scope* scope,
PreParserFactory* factory,
static PreParserExpression ThisExpression(PreParserFactory* factory,
int pos) {
return PreParserExpression::This();
}
static PreParserExpression NewSuperPropertyReference(
Scope* scope, PreParserFactory* factory, int pos) {
PreParserFactory* factory, int pos) {
return PreParserExpression::Default();
}
static PreParserExpression NewSuperCallReference(Scope* scope,
PreParserFactory* factory,
static PreParserExpression NewSuperCallReference(PreParserFactory* factory,
int pos) {
return PreParserExpression::SuperCallReference();
}
static PreParserExpression NewTargetExpression(Scope* scope,
PreParserFactory* factory,
static PreParserExpression NewTargetExpression(PreParserFactory* factory,
int pos) {
return PreParserExpression::Default();
}
static PreParserExpression FunctionSentExpression(Scope* scope,
PreParserFactory* factory,
static PreParserExpression FunctionSentExpression(PreParserFactory* factory,
int pos) {
return PreParserExpression::Default();
}
......@@ -838,7 +834,7 @@ class PreParserTraits {
static PreParserExpression ExpressionFromIdentifier(
PreParserIdentifier name, int start_position, int end_position,
Scope* scope, PreParserFactory* factory) {
PreParserFactory* factory) {
return PreParserExpression::FromIdentifier(name);
}
......
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