Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: src/ast/scopes.cc

Issue 2655623005: [parser] Skipping inner funcs: add info about variables. (Closed)
Patch Set: alt fix Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/parsing/preparsed-scope-data.h » ('j') | test/cctest/test-parsing.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/ast/scopes.h" 5 #include "src/ast/scopes.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 } 943 }
944 944
945 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode, 945 Variable* Scope::DeclareLocal(const AstRawString* name, VariableMode mode,
946 InitializationFlag init_flag, VariableKind kind, 946 InitializationFlag init_flag, VariableKind kind,
947 MaybeAssignedFlag maybe_assigned_flag) { 947 MaybeAssignedFlag maybe_assigned_flag) {
948 DCHECK(!already_resolved_); 948 DCHECK(!already_resolved_);
949 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are 949 // This function handles VAR, LET, and CONST modes. DYNAMIC variables are
950 // introduced during variable allocation, and TEMPORARY variables are 950 // introduced during variable allocation, and TEMPORARY variables are
951 // allocated via NewTemporary(). 951 // allocated via NewTemporary().
952 DCHECK(IsDeclaredVariableMode(mode)); 952 DCHECK(IsDeclaredVariableMode(mode));
953 DCHECK(!GetDeclarationScope()->is_being_lazily_parsed()); 953 DCHECK_IMPLIES(GetDeclarationScope()->is_being_lazily_parsed(),
954 mode == VAR || mode == LET || mode == CONST);
954 DCHECK(!GetDeclarationScope()->was_lazily_parsed()); 955 DCHECK(!GetDeclarationScope()->was_lazily_parsed());
955 return Declare(zone(), name, mode, kind, init_flag, maybe_assigned_flag); 956 return Declare(zone(), name, mode, kind, init_flag, maybe_assigned_flag);
956 } 957 }
957 958
958 Variable* Scope::DeclareVariable( 959 Variable* Scope::DeclareVariable(
959 Declaration* declaration, VariableMode mode, InitializationFlag init, 960 Declaration* declaration, VariableMode mode, InitializationFlag init,
960 bool allow_harmony_restrictive_generators, 961 bool allow_harmony_restrictive_generators,
961 bool* sloppy_mode_block_scope_function_redefinition, bool* ok) { 962 bool* sloppy_mode_block_scope_function_redefinition, bool* ok) {
962 DCHECK(IsDeclaredVariableMode(mode)); 963 DCHECK(IsDeclaredVariableMode(mode));
963 DCHECK(!already_resolved_); 964 DCHECK(!already_resolved_);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 DCHECK(!is_with_scope()); 1073 DCHECK(!is_with_scope());
1073 DCHECK(!is_eval_scope()); 1074 DCHECK(!is_eval_scope());
1074 // Unlike DeclareVariable, DeclareVariableName allows declaring variables in 1075 // Unlike DeclareVariable, DeclareVariableName allows declaring variables in
1075 // catch scopes: Parser::RewriteCatchPattern bypasses DeclareVariable by 1076 // catch scopes: Parser::RewriteCatchPattern bypasses DeclareVariable by
1076 // calling DeclareLocal directly, and it doesn't make sense to add a similar 1077 // calling DeclareLocal directly, and it doesn't make sense to add a similar
1077 // bypass mechanism for PreParser. 1078 // bypass mechanism for PreParser.
1078 DCHECK(is_declaration_scope() || (IsLexicalVariableMode(mode) && 1079 DCHECK(is_declaration_scope() || (IsLexicalVariableMode(mode) &&
1079 (is_block_scope() || is_catch_scope()))); 1080 (is_block_scope() || is_catch_scope())));
1080 DCHECK(scope_info_.is_null()); 1081 DCHECK(scope_info_.is_null());
1081 1082
1082 // Declare the variable in the declaration scope. 1083 Variable* var = LookupLocal(name);
jochen (gone - plz use gerrit) 2017/01/25 16:34:14 can you please explain this change?
marja 2017/01/25 17:10:44 This is kinda covered by the title line; in order
1083 variables_.DeclareName(zone(), name, mode); 1084 if (var == nullptr) {
1085 var = DeclareLocal(name, mode);
1086 }
1087 var->set_is_used();
1084 } 1088 }
1085 1089
1086 VariableProxy* Scope::NewUnresolved(AstNodeFactory* factory, 1090 VariableProxy* Scope::NewUnresolved(AstNodeFactory* factory,
1087 const AstRawString* name, 1091 const AstRawString* name,
1088 int start_position, VariableKind kind) { 1092 int start_position, VariableKind kind) {
1089 // Note that we must not share the unresolved variables with 1093 // Note that we must not share the unresolved variables with
1090 // the same name because they may be removed selectively via 1094 // the same name because they may be removed selectively via
1091 // RemoveUnresolved(). 1095 // RemoveUnresolved().
1092 DCHECK(!already_resolved_); 1096 DCHECK(!already_resolved_);
1093 DCHECK_EQ(factory->zone(), zone()); 1097 DCHECK_EQ(factory->zone(), zone());
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after
2077 } 2081 }
2078 2082
2079 for (const auto& it : module()->regular_exports()) { 2083 for (const auto& it : module()->regular_exports()) {
2080 Variable* var = LookupLocal(it.first); 2084 Variable* var = LookupLocal(it.first);
2081 var->AllocateTo(VariableLocation::MODULE, it.second->cell_index); 2085 var->AllocateTo(VariableLocation::MODULE, it.second->cell_index);
2082 DCHECK(var->IsExport()); 2086 DCHECK(var->IsExport());
2083 } 2087 }
2084 } 2088 }
2085 2089
2086 void Scope::AllocateVariablesRecursively() { 2090 void Scope::AllocateVariablesRecursively() {
2087 DCHECK(!already_resolved_);
2088 DCHECK_EQ(0, num_stack_slots_);
2089 // Don't allocate variables of preparsed scopes. 2091 // Don't allocate variables of preparsed scopes.
2090 if (is_declaration_scope() && AsDeclarationScope()->was_lazily_parsed()) { 2092 if (is_declaration_scope() && AsDeclarationScope()->was_lazily_parsed()) {
2091 return; 2093 return;
2092 } 2094 }
2093 2095
2096 DCHECK(!already_resolved_);
2097 DCHECK_EQ(0, num_stack_slots_);
2098
2094 // Allocate variables for inner scopes. 2099 // Allocate variables for inner scopes.
2095 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { 2100 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
2096 scope->AllocateVariablesRecursively(); 2101 scope->AllocateVariablesRecursively();
2097 } 2102 }
2098 2103
2099 DCHECK(!already_resolved_); 2104 DCHECK(!already_resolved_);
2100 DCHECK_EQ(Context::MIN_CONTEXT_SLOTS, num_heap_slots_); 2105 DCHECK_EQ(Context::MIN_CONTEXT_SLOTS, num_heap_slots_);
2101 2106
2102 // Allocate variables for this scope. 2107 // Allocate variables for this scope.
2103 // Parameters must be allocated first, if any. 2108 // Parameters must be allocated first, if any.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2157 MaybeHandle<ScopeInfo> outer = NeedsContext() ? scope_info_ : outer_scope; 2162 MaybeHandle<ScopeInfo> outer = NeedsContext() ? scope_info_ : outer_scope;
2158 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) { 2163 for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
2159 if (scope->is_function_scope()) continue; 2164 if (scope->is_function_scope()) continue;
2160 scope->AllocateDebuggerScopeInfos(isolate, outer); 2165 scope->AllocateDebuggerScopeInfos(isolate, outer);
2161 } 2166 }
2162 } 2167 }
2163 2168
2164 void Scope::CollectVariableData(PreParsedScopeData* data) { 2169 void Scope::CollectVariableData(PreParsedScopeData* data) {
2165 PreParsedScopeData::ScopeScope scope_scope(data, scope_type(), 2170 PreParsedScopeData::ScopeScope scope_scope(data, scope_type(),
2166 start_position(), end_position()); 2171 start_position(), end_position());
2167 // TODO(marja): Add data about the variables. 2172 for (Variable* local : locals_) {
2168 2173 if (local->mode() == VAR || local->mode() == LET ||
2174 local->mode() == CONST) {
2175 scope_scope.AddVariable(local->location(), local->maybe_assigned());
2176 }
2177 }
2169 for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) { 2178 for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) {
2170 inner->CollectVariableData(data); 2179 inner->CollectVariableData(data);
2171 } 2180 }
2172 } 2181 }
2173 2182
2174 int Scope::StackLocalCount() const { 2183 int Scope::StackLocalCount() const {
2175 Variable* function = 2184 Variable* function =
2176 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 2185 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
2177 return num_stack_slots() - 2186 return num_stack_slots() -
2178 (function != nullptr && function->IsStackLocal() ? 1 : 0); 2187 (function != nullptr && function->IsStackLocal() ? 1 : 0);
2179 } 2188 }
2180 2189
2181 2190
2182 int Scope::ContextLocalCount() const { 2191 int Scope::ContextLocalCount() const {
2183 if (num_heap_slots() == 0) return 0; 2192 if (num_heap_slots() == 0) return 0;
2184 Variable* function = 2193 Variable* function =
2185 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 2194 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
2186 bool is_function_var_in_context = 2195 bool is_function_var_in_context =
2187 function != nullptr && function->IsContextSlot(); 2196 function != nullptr && function->IsContextSlot();
2188 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 2197 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
2189 (is_function_var_in_context ? 1 : 0); 2198 (is_function_var_in_context ? 1 : 0);
2190 } 2199 }
2191 2200
2192 } // namespace internal 2201 } // namespace internal
2193 } // namespace v8 2202 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/parsing/preparsed-scope-data.h » ('j') | test/cctest/test-parsing.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698