Commit 5b25cbb5 authored by jochen's avatar jochen Committed by Commit bot

Unify DeclarationScope::Analyze

R=marja@chromium.org
TBR=verwaest@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2294193003
Cr-Commit-Position: refs/heads/master@{#39037}
parent 4999717e
...@@ -399,7 +399,7 @@ int Scope::num_parameters() const { ...@@ -399,7 +399,7 @@ int Scope::num_parameters() const {
return is_declaration_scope() ? AsDeclarationScope()->num_parameters() : 0; return is_declaration_scope() ? AsDeclarationScope()->num_parameters() : 0;
} }
void DeclarationScope::Analyze(ParseInfo* info) { void DeclarationScope::Analyze(ParseInfo* info, AnalyzeMode mode) {
DCHECK(info->literal() != NULL); DCHECK(info->literal() != NULL);
DeclarationScope* scope = info->literal()->scope(); DeclarationScope* scope = info->literal()->scope();
...@@ -411,7 +411,7 @@ void DeclarationScope::Analyze(ParseInfo* info) { ...@@ -411,7 +411,7 @@ void DeclarationScope::Analyze(ParseInfo* info) {
scope->outer_scope()->scope_type() == SCRIPT_SCOPE || scope->outer_scope()->scope_type() == SCRIPT_SCOPE ||
scope->outer_scope()->already_resolved_); scope->outer_scope()->already_resolved_);
scope->AllocateVariables(info, false /* for_debugger */); scope->AllocateVariables(info, mode);
#ifdef DEBUG #ifdef DEBUG
if (info->script_is_native() ? FLAG_print_builtin_scopes if (info->script_is_native() ? FLAG_print_builtin_scopes
...@@ -423,21 +423,6 @@ void DeclarationScope::Analyze(ParseInfo* info) { ...@@ -423,21 +423,6 @@ void DeclarationScope::Analyze(ParseInfo* info) {
#endif #endif
} }
void DeclarationScope::AnalyzeForDebugger(ParseInfo* info) {
DCHECK(info->literal() != NULL);
DeclarationScope* scope = info->literal()->scope();
// We are compiling one of three cases:
// 1) top-level code,
// 2) a function/eval/module on the top-level
// 3) a function/eval in a scope that was already resolved.
DCHECK(scope->scope_type() == SCRIPT_SCOPE ||
scope->outer_scope()->scope_type() == SCRIPT_SCOPE ||
scope->outer_scope()->already_resolved_);
scope->AllocateVariables(info, true /* for_debugger */);
}
void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) { void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) {
DCHECK(!already_resolved_); DCHECK(!already_resolved_);
DCHECK(is_declaration_scope()); DCHECK(is_declaration_scope());
...@@ -892,11 +877,11 @@ Declaration* Scope::CheckLexDeclarationsConflictingWith( ...@@ -892,11 +877,11 @@ Declaration* Scope::CheckLexDeclarationsConflictingWith(
return nullptr; return nullptr;
} }
void DeclarationScope::AllocateVariables(ParseInfo* info, bool for_debugger) { void DeclarationScope::AllocateVariables(ParseInfo* info, AnalyzeMode mode) {
PropagateScopeInfo(); PropagateScopeInfo();
ResolveVariablesRecursively(info); ResolveVariablesRecursively(info);
AllocateVariablesRecursively(); AllocateVariablesRecursively();
AllocateScopeInfosRecursively(info->isolate(), for_debugger); AllocateScopeInfosRecursively(info->isolate(), mode);
} }
bool Scope::AllowsLazyParsing() const { bool Scope::AllowsLazyParsing() const {
...@@ -1643,15 +1628,15 @@ void Scope::AllocateVariablesRecursively() { ...@@ -1643,15 +1628,15 @@ void Scope::AllocateVariablesRecursively() {
DCHECK(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); DCHECK(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS);
} }
void Scope::AllocateScopeInfosRecursively(Isolate* isolate, bool for_debugger) { void Scope::AllocateScopeInfosRecursively(Isolate* isolate, AnalyzeMode mode) {
DCHECK(scope_info_.is_null()); DCHECK(scope_info_.is_null());
if (for_debugger || NeedsScopeInfo()) { if (mode == AnalyzeMode::kDebugger || NeedsScopeInfo()) {
scope_info_ = ScopeInfo::Create(isolate, zone(), this); scope_info_ = ScopeInfo::Create(isolate, zone(), this);
} }
// Allocate ScopeInfos for inner scopes. // Allocate ScopeInfos for inner scopes.
for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
scope->AllocateScopeInfosRecursively(isolate, for_debugger); scope->AllocateScopeInfosRecursively(isolate, mode);
} }
} }
......
...@@ -40,6 +40,7 @@ class SloppyBlockFunctionMap : public ZoneHashMap { ...@@ -40,6 +40,7 @@ class SloppyBlockFunctionMap : public ZoneHashMap {
SloppyBlockFunctionStatement* statement); SloppyBlockFunctionStatement* statement);
}; };
enum class AnalyzeMode { kRegular, kDebugger };
// Global invariants after AST construction: Each reference (i.e. identifier) // Global invariants after AST construction: Each reference (i.e. identifier)
// to a JavaScript variable (including global properties) is represented by a // to a JavaScript variable (including global properties) is represented by a
...@@ -545,7 +546,7 @@ class Scope: public ZoneObject { ...@@ -545,7 +546,7 @@ class Scope: public ZoneObject {
void AllocateNonParameterLocalsAndDeclaredGlobals(); void AllocateNonParameterLocalsAndDeclaredGlobals();
void AllocateVariablesRecursively(); void AllocateVariablesRecursively();
void AllocateScopeInfosRecursively(Isolate* isolate, bool for_debugger); void AllocateScopeInfosRecursively(Isolate* isolate, AnalyzeMode mode);
// Construct a scope based on the scope info. // Construct a scope based on the scope info.
Scope(Zone* zone, ScopeType type, Handle<ScopeInfo> scope_info); Scope(Zone* zone, ScopeType type, Handle<ScopeInfo> scope_info);
...@@ -752,10 +753,7 @@ class DeclarationScope : public Scope { ...@@ -752,10 +753,7 @@ class DeclarationScope : public Scope {
// Compute top scope and allocate variables. For lazy compilation the top // Compute top scope and allocate variables. For lazy compilation the top
// scope only contains the single lazily compiled function, so this // scope only contains the single lazily compiled function, so this
// doesn't re-allocate variables repeatedly. // doesn't re-allocate variables repeatedly.
static void Analyze(ParseInfo* info); static void Analyze(ParseInfo* info, AnalyzeMode mode);
// Version used by the debugger that creates extra ScopeInfos.
static void AnalyzeForDebugger(ParseInfo* info);
// To be called during parsing. Do just enough scope analysis that we can // To be called during parsing. Do just enough scope analysis that we can
// discard the Scope for lazily compiled functions. In particular, this // discard the Scope for lazily compiled functions. In particular, this
...@@ -802,7 +800,7 @@ class DeclarationScope : public Scope { ...@@ -802,7 +800,7 @@ class DeclarationScope : public Scope {
// In the case of code compiled and run using 'eval', the context // In the case of code compiled and run using 'eval', the context
// parameter is the context in which eval was called. In all other // parameter is the context in which eval was called. In all other
// cases the context parameter is an empty handle. // cases the context parameter is an empty handle.
void AllocateVariables(ParseInfo* info, bool for_debugger); void AllocateVariables(ParseInfo* info, AnalyzeMode mode);
void SetDefaults(); void SetDefaults();
......
...@@ -1331,7 +1331,7 @@ Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { ...@@ -1331,7 +1331,7 @@ Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) {
bool Compiler::Analyze(ParseInfo* info) { bool Compiler::Analyze(ParseInfo* info) {
DCHECK_NOT_NULL(info->literal()); DCHECK_NOT_NULL(info->literal());
if (!Rewriter::Rewrite(info)) return false; if (!Rewriter::Rewrite(info)) return false;
DeclarationScope::Analyze(info); DeclarationScope::Analyze(info, AnalyzeMode::kRegular);
if (!Renumber(info)) return false; if (!Renumber(info)) return false;
DCHECK_NOT_NULL(info->scope()); DCHECK_NOT_NULL(info->scope());
return true; return true;
......
...@@ -115,7 +115,7 @@ ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector, ...@@ -115,7 +115,7 @@ ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector,
CollectNonLocals(info.get(), scope); CollectNonLocals(info.get(), scope);
} }
if (!ignore_nested_scopes) { if (!ignore_nested_scopes) {
DeclarationScope::AnalyzeForDebugger(info.get()); DeclarationScope::Analyze(info.get(), AnalyzeMode::kDebugger);
RetrieveScopeChain(scope); RetrieveScopeChain(scope);
} }
} else if (!ignore_nested_scopes) { } else if (!ignore_nested_scopes) {
......
...@@ -37,7 +37,7 @@ struct TestHelper : public HandleAndZoneScope { ...@@ -37,7 +37,7 @@ struct TestHelper : public HandleAndZoneScope {
CHECK(Parser::ParseStatic(&parse_info)); CHECK(Parser::ParseStatic(&parse_info));
CHECK(Rewriter::Rewrite(&parse_info)); CHECK(Rewriter::Rewrite(&parse_info));
DeclarationScope::Analyze(&parse_info); DeclarationScope::Analyze(&parse_info, AnalyzeMode::kRegular);
DeclarationScope* scope = info.literal()->scope(); DeclarationScope* scope = info.literal()->scope();
AstValueFactory* factory = parse_info.ast_value_factory(); AstValueFactory* factory = parse_info.ast_value_factory();
......
...@@ -1046,7 +1046,7 @@ TEST(ScopeUsesArgumentsSuperThis) { ...@@ -1046,7 +1046,7 @@ TEST(ScopeUsesArgumentsSuperThis) {
info.set_global(); info.set_global();
CHECK(parser.Parse(&info)); CHECK(parser.Parse(&info));
CHECK(i::Rewriter::Rewrite(&info)); CHECK(i::Rewriter::Rewrite(&info));
i::DeclarationScope::Analyze(&info); i::DeclarationScope::Analyze(&info, i::AnalyzeMode::kRegular);
CHECK(info.literal() != NULL); CHECK(info.literal() != NULL);
i::DeclarationScope* script_scope = info.literal()->scope(); i::DeclarationScope* script_scope = info.literal()->scope();
......
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