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