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