Commit bc7d63cc authored by adamk's avatar adamk Committed by Commit bot

[cleanup] Remove redundant fields from DeclarationDescriptor

Both the is_const and declaration_scope fields can be reliably derived
from the mode field. needs_init cannot be, unfortunately, due to the
special case of CONST in for loops.

Also inline the sole remaining non-trivial caller of
Parser::DeclarationScope(VariableMode).

Review URL: https://codereview.chromium.org/1487603003

Cr-Commit-Position: refs/heads/master@{#32536}
parent 3aa86289
......@@ -2024,9 +2024,11 @@ VariableProxy* Parser::NewUnresolved(const AstRawString* name,
// scope.
// Let/const variables in harmony mode are always added to the immediately
// enclosing scope.
return DeclarationScope(mode)->NewUnresolved(
factory(), name, Variable::NORMAL, scanner()->location().beg_pos,
scanner()->location().end_pos);
Scope* scope =
IsLexicalVariableMode(mode) ? scope_ : scope_->DeclarationScope();
return scope->NewUnresolved(factory(), name, Variable::NORMAL,
scanner()->location().beg_pos,
scanner()->location().end_pos);
}
......@@ -2211,7 +2213,8 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) {
// isn't lazily compiled. The extension structures are only
// accessible while parsing the first time not when reparsing
// because of lazy compilation.
DeclarationScope(VAR)->ForceEagerCompilation();
// TODO(adamk): Should this be ClosureScope()?
scope_->DeclarationScope()->ForceEagerCompilation();
// TODO(1240846): It's weird that native function declarations are
// introduced dynamically when we meet their declarations, whereas
......@@ -2448,7 +2451,6 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
// need initialization. 'var' declared bindings are always initialized
// immediately by their declaration nodes.
parsing_result->descriptor.needs_init = false;
parsing_result->descriptor.is_const = false;
if (peek() == Token::VAR) {
if (is_strong(language_mode())) {
Scanner::Location location = scanner()->peek_location();
......@@ -2467,7 +2469,6 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
DCHECK(var_context != kStatement);
parsing_result->descriptor.mode = CONST;
}
parsing_result->descriptor.is_const = true;
parsing_result->descriptor.needs_init = true;
} else if (peek() == Token::LET && allow_let()) {
Consume(Token::LET);
......@@ -2478,8 +2479,6 @@ void Parser::ParseVariableDeclarations(VariableDeclarationContext var_context,
UNREACHABLE(); // by current callers
}
parsing_result->descriptor.declaration_scope =
DeclarationScope(parsing_result->descriptor.mode);
parsing_result->descriptor.scope = scope_;
parsing_result->descriptor.hoist_scope = nullptr;
......@@ -3162,11 +3161,9 @@ TryStatement* Parser::ParseTryStatement(bool* ok) {
DeclarationDescriptor descriptor;
descriptor.declaration_kind = DeclarationDescriptor::NORMAL;
descriptor.parser = this;
descriptor.declaration_scope = scope_;
descriptor.scope = scope_;
descriptor.hoist_scope = nullptr;
descriptor.mode = LET;
descriptor.is_const = false;
descriptor.needs_init = true;
descriptor.declaration_pos = pattern->position();
descriptor.initialization_pos = pattern->position();
......@@ -4542,11 +4539,9 @@ Block* Parser::BuildParameterInitializationBlock(
DeclarationDescriptor descriptor;
descriptor.declaration_kind = DeclarationDescriptor::PARAMETER;
descriptor.parser = this;
descriptor.declaration_scope = scope_;
descriptor.scope = scope_;
descriptor.hoist_scope = nullptr;
descriptor.mode = LET;
descriptor.is_const = false;
descriptor.needs_init = true;
descriptor.declaration_pos = parameter.pattern->position();
// The position that will be used by the AssignmentExpression
......
......@@ -960,10 +960,6 @@ class Parser : public ParserBase<ParserTraits> {
bool produce_cached_parse_data() const {
return compile_options_ == ScriptCompiler::kProduceParserCache;
}
Scope* DeclarationScope(VariableMode mode) {
return IsLexicalVariableMode(mode)
? scope_ : scope_->DeclarationScope();
}
// All ParseXXX functions take as the last argument an *ok parameter
// which is set to false if parsing failed; it is unchanged otherwise.
......@@ -1000,11 +996,9 @@ class Parser : public ParserBase<ParserTraits> {
struct DeclarationDescriptor {
enum Kind { NORMAL, PARAMETER };
Parser* parser;
Scope* declaration_scope;
Scope* scope;
Scope* hoist_scope;
VariableMode mode;
bool is_const;
bool needs_init;
int declaration_pos;
int initialization_pos;
......
......@@ -64,8 +64,10 @@ void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
DCHECK(initializer_position_ != RelocInfo::kNoPosition);
if (descriptor_->declaration_scope->num_var_or_const() >
kMaxNumFunctionLocals) {
Scope* declaration_scope = IsLexicalVariableMode(descriptor_->mode)
? descriptor_->scope
: descriptor_->scope->DeclarationScope();
if (declaration_scope->num_var_or_const() > kMaxNumFunctionLocals) {
parser->ReportMessage(MessageTemplate::kTooManyVariables);
*ok_ = false;
return;
......@@ -100,8 +102,8 @@ void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
// The "variable" c initialized to x is the same as the declared
// one - there is no re-lookup (see the last parameter of the
// Declare() call above).
Scope* initialization_scope = descriptor_->is_const
? descriptor_->declaration_scope
Scope* initialization_scope = IsImmutableVariableMode(descriptor_->mode)
? declaration_scope
: descriptor_->scope;
......@@ -135,7 +137,7 @@ void Parser::PatternRewriter::VisitVariableProxy(VariableProxy* pattern) {
zone());
CallRuntime* initialize;
if (descriptor_->is_const) {
if (IsImmutableVariableMode(descriptor_->mode)) {
arguments->Add(value, zone());
value = NULL; // zap the value to avoid the unnecessary assignment
......
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