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

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

Issue 2253913002: Move asm_module_ and asm_function_ down to DeclarationScope (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 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
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/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 outer_scope_(outer_scope), 80 outer_scope_(outer_scope),
81 variables_(zone), 81 variables_(zone),
82 decls_(4, zone), 82 decls_(4, zone),
83 scope_type_(scope_type) { 83 scope_type_(scope_type) {
84 SetDefaults(); 84 SetDefaults();
85 if (outer_scope == nullptr) { 85 if (outer_scope == nullptr) {
86 // If the outer scope is null, this cannot be a with scope. The outermost 86 // If the outer scope is null, this cannot be a with scope. The outermost
87 // scope must be a script scope. 87 // scope must be a script scope.
88 DCHECK_EQ(SCRIPT_SCOPE, scope_type); 88 DCHECK_EQ(SCRIPT_SCOPE, scope_type);
89 } else { 89 } else {
90 asm_function_ = outer_scope_->asm_module_;
91 // Inherit the language mode from the parent scope unless we're a module 90 // Inherit the language mode from the parent scope unless we're a module
92 // scope. 91 // scope.
93 if (!is_module_scope()) language_mode_ = outer_scope->language_mode_; 92 if (!is_module_scope()) language_mode_ = outer_scope->language_mode_;
94 force_context_allocation_ = 93 force_context_allocation_ =
95 !is_function_scope() && outer_scope->has_forced_context_allocation(); 94 !is_function_scope() && outer_scope->has_forced_context_allocation();
96 outer_scope_->AddInnerScope(this); 95 outer_scope_->AddInnerScope(this);
97 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope(); 96 scope_inside_with_ = outer_scope_->scope_inside_with_ || is_with_scope();
98 } 97 }
99 } 98 }
100 99
101 Scope::Snapshot::Snapshot(Scope* scope) 100 Scope::Snapshot::Snapshot(Scope* scope)
102 : outer_scope_(scope), 101 : outer_scope_(scope),
103 top_inner_scope_(scope->inner_scope_), 102 top_inner_scope_(scope->inner_scope_),
104 top_unresolved_(scope->unresolved_), 103 top_unresolved_(scope->unresolved_),
105 top_temp_(scope->GetClosureScope()->temps()->length()) {} 104 top_temp_(scope->GetClosureScope()->temps()->length()) {}
106 105
107 DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope, 106 DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope,
108 ScopeType scope_type, 107 ScopeType scope_type,
109 FunctionKind function_kind) 108 FunctionKind function_kind)
110 : Scope(zone, outer_scope, scope_type), 109 : Scope(zone, outer_scope, scope_type),
111 function_kind_(function_kind), 110 function_kind_(function_kind),
112 temps_(4, zone), 111 temps_(4, zone),
113 params_(4, zone), 112 params_(4, zone),
114 sloppy_block_function_map_(zone) { 113 sloppy_block_function_map_(zone) {
115 SetDefaults(); 114 SetDefaults();
116 if (scope_type == MODULE_SCOPE) { 115 if (scope_type == MODULE_SCOPE) {
117 module_descriptor_ = new (zone) ModuleDescriptor(zone); 116 module_descriptor_ = new (zone) ModuleDescriptor(zone);
118 language_mode_ = STRICT; 117 language_mode_ = STRICT;
118 } else if (outer_scope != nullptr) {
119 asm_function_ = outer_scope_->IsAsmModule();
119 } 120 }
120 } 121 }
121 122
122 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, 123 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type,
123 Handle<ScopeInfo> scope_info) 124 Handle<ScopeInfo> scope_info)
124 : zone_(zone), 125 : zone_(zone),
125 outer_scope_(nullptr), 126 outer_scope_(nullptr),
126 variables_(zone), 127 variables_(zone),
127 decls_(0, zone), 128 decls_(0, zone),
128 scope_info_(scope_info), 129 scope_info_(scope_info),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 if (inner_scope != nullptr) AddInnerScope(inner_scope); 169 if (inner_scope != nullptr) AddInnerScope(inner_scope);
169 Variable* variable = 170 Variable* variable =
170 variables_.Declare(zone, this, catch_variable_name, VAR, Variable::NORMAL, 171 variables_.Declare(zone, this, catch_variable_name, VAR, Variable::NORMAL,
171 kCreatedInitialized); 172 kCreatedInitialized);
172 AllocateHeapSlot(variable); 173 AllocateHeapSlot(variable);
173 } 174 }
174 175
175 void DeclarationScope::SetDefaults() { 176 void DeclarationScope::SetDefaults() {
176 is_declaration_scope_ = true; 177 is_declaration_scope_ = true;
177 has_simple_parameters_ = true; 178 has_simple_parameters_ = true;
179 asm_module_ = false;
180 asm_function_ = false;
178 receiver_ = nullptr; 181 receiver_ = nullptr;
179 new_target_ = nullptr; 182 new_target_ = nullptr;
180 function_ = nullptr; 183 function_ = nullptr;
181 arguments_ = nullptr; 184 arguments_ = nullptr;
182 this_function_ = nullptr; 185 this_function_ = nullptr;
183 arity_ = 0; 186 arity_ = 0;
184 rest_parameter_ = nullptr; 187 rest_parameter_ = nullptr;
185 rest_index_ = -1; 188 rest_index_ = -1;
186 module_descriptor_ = nullptr; 189 module_descriptor_ = nullptr;
187 } 190 }
(...skipping 14 matching lines...) Expand all
202 num_stack_slots_ = 0; 205 num_stack_slots_ = 0;
203 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; 206 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS;
204 num_global_slots_ = 0; 207 num_global_slots_ = 0;
205 208
206 language_mode_ = SLOPPY; 209 language_mode_ = SLOPPY;
207 210
208 scope_inside_with_ = false; 211 scope_inside_with_ = false;
209 scope_calls_eval_ = false; 212 scope_calls_eval_ = false;
210 scope_uses_super_property_ = false; 213 scope_uses_super_property_ = false;
211 has_arguments_parameter_ = false; 214 has_arguments_parameter_ = false;
212 asm_module_ = false;
213 asm_function_ = false;
214 scope_nonlinear_ = false; 215 scope_nonlinear_ = false;
215 is_hidden_ = false; 216 is_hidden_ = false;
216 is_debug_evaluate_scope_ = false; 217 is_debug_evaluate_scope_ = false;
217 218
218 outer_scope_calls_sloppy_eval_ = false; 219 outer_scope_calls_sloppy_eval_ = false;
219 inner_scope_calls_eval_ = false; 220 inner_scope_calls_eval_ = false;
220 force_eager_compilation_ = false; 221 force_eager_compilation_ = false;
221 force_context_allocation_ = false; 222 force_context_allocation_ = false;
222 223
223 is_declaration_scope_ = false; 224 is_declaration_scope_ = false;
224 } 225 }
225 226
226 bool Scope::HasSimpleParameters() { 227 bool Scope::HasSimpleParameters() {
227 DeclarationScope* scope = GetClosureScope(); 228 DeclarationScope* scope = GetClosureScope();
228 return !scope->is_function_scope() || scope->has_simple_parameters(); 229 return !scope->is_function_scope() || scope->has_simple_parameters();
229 } 230 }
230 231
232 bool Scope::IsAsmModule() const {
233 return is_function_scope() && AsDeclarationScope()->asm_module();
234 }
235
236 bool Scope::IsAsmFunction() const {
237 return is_function_scope() && AsDeclarationScope()->asm_function();
238 }
239
231 Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone, 240 Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
232 Context* context, 241 Context* context,
233 DeclarationScope* script_scope, 242 DeclarationScope* script_scope,
234 AstValueFactory* ast_value_factory, 243 AstValueFactory* ast_value_factory,
235 DeserializationMode deserialization_mode) { 244 DeserializationMode deserialization_mode) {
236 // Reconstruct the outer scope chain from a closure's context chain. 245 // Reconstruct the outer scope chain from a closure's context chain.
237 Scope* current_scope = nullptr; 246 Scope* current_scope = nullptr;
238 Scope* innermost_scope = nullptr; 247 Scope* innermost_scope = nullptr;
239 while (!context->IsNativeContext()) { 248 while (!context->IsNativeContext()) {
240 if (context->IsWithContext() || context->IsDebugEvaluateContext()) { 249 if (context->IsWithContext() || context->IsDebugEvaluateContext()) {
(...skipping 10 matching lines...) Expand all
251 for (Scope* s = innermost_scope; s != nullptr; s = s->outer_scope()) { 260 for (Scope* s = innermost_scope; s != nullptr; s = s->outer_scope()) {
252 s->scope_inside_with_ = true; 261 s->scope_inside_with_ = true;
253 } 262 }
254 } else if (context->IsScriptContext()) { 263 } else if (context->IsScriptContext()) {
255 Handle<ScopeInfo> scope_info(context->scope_info(), isolate); 264 Handle<ScopeInfo> scope_info(context->scope_info(), isolate);
256 current_scope = new (zone) 265 current_scope = new (zone)
257 DeclarationScope(zone, current_scope, SCRIPT_SCOPE, scope_info); 266 DeclarationScope(zone, current_scope, SCRIPT_SCOPE, scope_info);
258 } else if (context->IsFunctionContext()) { 267 } else if (context->IsFunctionContext()) {
259 Handle<ScopeInfo> scope_info(context->closure()->shared()->scope_info(), 268 Handle<ScopeInfo> scope_info(context->closure()->shared()->scope_info(),
260 isolate); 269 isolate);
261 current_scope = new (zone) 270 DeclarationScope* function_scope = new (zone)
262 DeclarationScope(zone, current_scope, FUNCTION_SCOPE, scope_info); 271 DeclarationScope(zone, current_scope, FUNCTION_SCOPE, scope_info);
263 if (scope_info->IsAsmFunction()) current_scope->asm_function_ = true; 272 if (scope_info->IsAsmFunction()) function_scope->set_asm_function();
264 if (scope_info->IsAsmModule()) current_scope->asm_module_ = true; 273 if (scope_info->IsAsmModule()) function_scope->set_asm_module();
274 current_scope = function_scope;
265 } else if (context->IsBlockContext()) { 275 } else if (context->IsBlockContext()) {
266 Handle<ScopeInfo> scope_info(context->scope_info(), isolate); 276 Handle<ScopeInfo> scope_info(context->scope_info(), isolate);
267 if (scope_info->is_declaration_scope()) { 277 if (scope_info->is_declaration_scope()) {
268 current_scope = new (zone) 278 current_scope = new (zone)
269 DeclarationScope(zone, current_scope, BLOCK_SCOPE, scope_info); 279 DeclarationScope(zone, current_scope, BLOCK_SCOPE, scope_info);
270 } else { 280 } else {
271 current_scope = 281 current_scope =
272 new (zone) Scope(zone, current_scope, BLOCK_SCOPE, scope_info); 282 new (zone) Scope(zone, current_scope, BLOCK_SCOPE, scope_info);
273 } 283 }
274 } else { 284 } else {
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 PrintF("\n"); 1152 PrintF("\n");
1143 } 1153 }
1144 1154
1145 // Scope info. 1155 // Scope info.
1146 if (HasTrivialOuterContext()) { 1156 if (HasTrivialOuterContext()) {
1147 Indent(n1, "// scope has trivial outer context\n"); 1157 Indent(n1, "// scope has trivial outer context\n");
1148 } 1158 }
1149 if (is_strict(language_mode())) { 1159 if (is_strict(language_mode())) {
1150 Indent(n1, "// strict mode scope\n"); 1160 Indent(n1, "// strict mode scope\n");
1151 } 1161 }
1152 if (asm_module_) Indent(n1, "// scope is an asm module\n"); 1162 if (IsAsmModule()) Indent(n1, "// scope is an asm module\n");
1153 if (asm_function_) Indent(n1, "// scope is an asm function\n"); 1163 if (IsAsmFunction()) Indent(n1, "// scope is an asm function\n");
1154 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n"); 1164 if (scope_inside_with_) Indent(n1, "// scope inside 'with'\n");
1155 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n"); 1165 if (scope_calls_eval_) Indent(n1, "// scope calls 'eval'\n");
1156 if (scope_uses_super_property_) 1166 if (scope_uses_super_property_)
1157 Indent(n1, "// scope uses 'super' property\n"); 1167 Indent(n1, "// scope uses 'super' property\n");
1158 if (outer_scope_calls_sloppy_eval_) { 1168 if (outer_scope_calls_sloppy_eval_) {
1159 Indent(n1, "// outer scope calls 'eval' in sloppy context\n"); 1169 Indent(n1, "// outer scope calls 'eval' in sloppy context\n");
1160 } 1170 }
1161 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n"); 1171 if (inner_scope_calls_eval_) Indent(n1, "// inner scope calls 'eval'\n");
1162 if (num_stack_slots_ > 0) { 1172 if (num_stack_slots_ > 0) {
1163 Indent(n1, "// "); 1173 Indent(n1, "// ");
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 bool calls_sloppy_eval = 1483 bool calls_sloppy_eval =
1474 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_; 1484 this->calls_sloppy_eval() || outer_scope_calls_sloppy_eval_;
1475 for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) { 1485 for (Scope* inner = inner_scope_; inner != nullptr; inner = inner->sibling_) {
1476 inner->PropagateScopeInfo(calls_sloppy_eval); 1486 inner->PropagateScopeInfo(calls_sloppy_eval);
1477 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) { 1487 if (inner->scope_calls_eval_ || inner->inner_scope_calls_eval_) {
1478 inner_scope_calls_eval_ = true; 1488 inner_scope_calls_eval_ = true;
1479 } 1489 }
1480 if (inner->force_eager_compilation_) { 1490 if (inner->force_eager_compilation_) {
1481 force_eager_compilation_ = true; 1491 force_eager_compilation_ = true;
1482 } 1492 }
1483 if (asm_module_ && inner->scope_type() == FUNCTION_SCOPE) { 1493 if (IsAsmModule() && inner->is_function_scope()) {
1484 inner->asm_function_ = true; 1494 inner->AsDeclarationScope()->set_asm_function();
1485 } 1495 }
1486 } 1496 }
1487 } 1497 }
1488 1498
1489 1499
1490 bool Scope::MustAllocate(Variable* var) { 1500 bool Scope::MustAllocate(Variable* var) {
1491 DCHECK(var->location() != VariableLocation::MODULE); 1501 DCHECK(var->location() != VariableLocation::MODULE);
1492 // Give var a read/write use if there is a chance it might be accessed 1502 // Give var a read/write use if there is a chance it might be accessed
1493 // via an eval() call. This is only possible if the variable has a 1503 // via an eval() call. This is only possible if the variable has a
1494 // visible name. 1504 // visible name.
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1767 function != nullptr && function->IsContextSlot(); 1777 function != nullptr && function->IsContextSlot();
1768 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - 1778 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() -
1769 (is_function_var_in_context ? 1 : 0); 1779 (is_function_var_in_context ? 1 : 0);
1770 } 1780 }
1771 1781
1772 1782
1773 int Scope::ContextGlobalCount() const { return num_global_slots(); } 1783 int Scope::ContextGlobalCount() const { return num_global_slots(); }
1774 1784
1775 } // namespace internal 1785 } // namespace internal
1776 } // namespace v8 1786 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.h ('k') | src/parsing/parser.cc » ('j') | src/parsing/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698