| OLD | NEW |
| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/scopes.h" | 7 #include "src/scopes.h" |
| 8 | 8 |
| 9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, | 68 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, |
| 69 AstValueFactory* ast_value_factory) | 69 AstValueFactory* ast_value_factory) |
| 70 : inner_scopes_(4, zone), | 70 : inner_scopes_(4, zone), |
| 71 variables_(zone), | 71 variables_(zone), |
| 72 internals_(4, zone), | 72 internals_(4, zone), |
| 73 temps_(4, zone), | 73 temps_(4, zone), |
| 74 params_(4, zone), | 74 params_(4, zone), |
| 75 unresolved_(16, zone), | 75 unresolved_(16, zone), |
| 76 decls_(4, zone), | 76 decls_(4, zone), |
| 77 interface_(scope_type == MODULE_SCOPE ? Interface::New(zone) | 77 module_descriptor_( |
| 78 : NULL), | 78 scope_type == MODULE_SCOPE ? ModuleDescriptor::New(zone) : NULL), |
| 79 already_resolved_(false), | 79 already_resolved_(false), |
| 80 ast_value_factory_(ast_value_factory), | 80 ast_value_factory_(ast_value_factory), |
| 81 zone_(zone) { | 81 zone_(zone) { |
| 82 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null()); | 82 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null()); |
| 83 // The outermost scope must be a script scope. | 83 // The outermost scope must be a script scope. |
| 84 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL); | 84 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL); |
| 85 DCHECK(!HasIllegalRedeclaration()); | 85 DCHECK(!HasIllegalRedeclaration()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 | 88 |
| 89 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, | 89 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, |
| 90 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory) | 90 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory) |
| 91 : inner_scopes_(4, zone), | 91 : inner_scopes_(4, zone), |
| 92 variables_(zone), | 92 variables_(zone), |
| 93 internals_(4, zone), | 93 internals_(4, zone), |
| 94 temps_(4, zone), | 94 temps_(4, zone), |
| 95 params_(4, zone), | 95 params_(4, zone), |
| 96 unresolved_(16, zone), | 96 unresolved_(16, zone), |
| 97 decls_(4, zone), | 97 decls_(4, zone), |
| 98 interface_(NULL), | 98 module_descriptor_(NULL), |
| 99 already_resolved_(true), | 99 already_resolved_(true), |
| 100 ast_value_factory_(value_factory), | 100 ast_value_factory_(value_factory), |
| 101 zone_(zone) { | 101 zone_(zone) { |
| 102 SetDefaults(scope_type, NULL, scope_info); | 102 SetDefaults(scope_type, NULL, scope_info); |
| 103 if (!scope_info.is_null()) { | 103 if (!scope_info.is_null()) { |
| 104 num_heap_slots_ = scope_info_->ContextLength(); | 104 num_heap_slots_ = scope_info_->ContextLength(); |
| 105 } | 105 } |
| 106 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. | 106 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. |
| 107 num_heap_slots_ = Max(num_heap_slots_, | 107 num_heap_slots_ = Max(num_heap_slots_, |
| 108 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); | 108 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); |
| 109 AddInnerScope(inner_scope); | 109 AddInnerScope(inner_scope); |
| 110 } | 110 } |
| 111 | 111 |
| 112 | 112 |
| 113 Scope::Scope(Zone* zone, Scope* inner_scope, | 113 Scope::Scope(Zone* zone, Scope* inner_scope, |
| 114 const AstRawString* catch_variable_name, | 114 const AstRawString* catch_variable_name, |
| 115 AstValueFactory* value_factory) | 115 AstValueFactory* value_factory) |
| 116 : inner_scopes_(1, zone), | 116 : inner_scopes_(1, zone), |
| 117 variables_(zone), | 117 variables_(zone), |
| 118 internals_(0, zone), | 118 internals_(0, zone), |
| 119 temps_(0, zone), | 119 temps_(0, zone), |
| 120 params_(0, zone), | 120 params_(0, zone), |
| 121 unresolved_(0, zone), | 121 unresolved_(0, zone), |
| 122 decls_(0, zone), | 122 decls_(0, zone), |
| 123 interface_(NULL), | 123 module_descriptor_(NULL), |
| 124 already_resolved_(true), | 124 already_resolved_(true), |
| 125 ast_value_factory_(value_factory), | 125 ast_value_factory_(value_factory), |
| 126 zone_(zone) { | 126 zone_(zone) { |
| 127 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); | 127 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); |
| 128 AddInnerScope(inner_scope); | 128 AddInnerScope(inner_scope); |
| 129 ++num_var_or_const_; | 129 ++num_var_or_const_; |
| 130 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; | 130 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; |
| 131 Variable* variable = variables_.Declare(this, | 131 Variable* variable = variables_.Declare(this, |
| 132 catch_variable_name, | 132 catch_variable_name, |
| 133 VAR, | 133 VAR, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 AstNodeFactory ast_node_factory(info->ast_value_factory()); | 265 AstNodeFactory ast_node_factory(info->ast_value_factory()); |
| 266 if (!top->AllocateVariables(info, &ast_node_factory)) return false; | 266 if (!top->AllocateVariables(info, &ast_node_factory)) return false; |
| 267 } | 267 } |
| 268 | 268 |
| 269 #ifdef DEBUG | 269 #ifdef DEBUG |
| 270 if (info->isolate()->bootstrapper()->IsActive() | 270 if (info->isolate()->bootstrapper()->IsActive() |
| 271 ? FLAG_print_builtin_scopes | 271 ? FLAG_print_builtin_scopes |
| 272 : FLAG_print_scopes) { | 272 : FLAG_print_scopes) { |
| 273 scope->Print(); | 273 scope->Print(); |
| 274 } | 274 } |
| 275 | |
| 276 if (FLAG_harmony_modules && FLAG_print_interfaces && top->is_script_scope()) { | |
| 277 PrintF("global : "); | |
| 278 top->interface()->Print(); | |
| 279 } | |
| 280 #endif | 275 #endif |
| 281 | 276 |
| 282 info->PrepareForCompilation(scope); | 277 info->PrepareForCompilation(scope); |
| 283 return true; | 278 return true; |
| 284 } | 279 } |
| 285 | 280 |
| 286 | 281 |
| 287 void Scope::Initialize(bool subclass_constructor) { | 282 void Scope::Initialize(bool subclass_constructor) { |
| 288 DCHECK(!already_resolved()); | 283 DCHECK(!already_resolved()); |
| 289 | 284 |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 } | 1354 } |
| 1360 | 1355 |
| 1361 // Allocation done. | 1356 // Allocation done. |
| 1362 DCHECK(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1357 DCHECK(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
| 1363 } | 1358 } |
| 1364 | 1359 |
| 1365 | 1360 |
| 1366 void Scope::AllocateModulesRecursively(Scope* host_scope) { | 1361 void Scope::AllocateModulesRecursively(Scope* host_scope) { |
| 1367 if (already_resolved()) return; | 1362 if (already_resolved()) return; |
| 1368 if (is_module_scope()) { | 1363 if (is_module_scope()) { |
| 1369 DCHECK(interface_->IsFrozen()); | 1364 DCHECK(module_descriptor_->IsFrozen()); |
| 1370 DCHECK(module_var_ == NULL); | 1365 DCHECK(module_var_ == NULL); |
| 1371 module_var_ = | 1366 module_var_ = |
| 1372 host_scope->NewInternal(ast_value_factory_->dot_module_string()); | 1367 host_scope->NewInternal(ast_value_factory_->dot_module_string()); |
| 1373 ++host_scope->num_modules_; | 1368 ++host_scope->num_modules_; |
| 1374 } | 1369 } |
| 1375 | 1370 |
| 1376 for (int i = 0; i < inner_scopes_.length(); i++) { | 1371 for (int i = 0; i < inner_scopes_.length(); i++) { |
| 1377 Scope* inner_scope = inner_scopes_.at(i); | 1372 Scope* inner_scope = inner_scopes_.at(i); |
| 1378 inner_scope->AllocateModulesRecursively(host_scope); | 1373 inner_scope->AllocateModulesRecursively(host_scope); |
| 1379 } | 1374 } |
| 1380 } | 1375 } |
| 1381 | 1376 |
| 1382 | 1377 |
| 1383 int Scope::StackLocalCount() const { | 1378 int Scope::StackLocalCount() const { |
| 1384 return num_stack_slots() - | 1379 return num_stack_slots() - |
| 1385 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); | 1380 (function_ != NULL && function_->proxy()->var()->IsStackLocal() ? 1 : 0); |
| 1386 } | 1381 } |
| 1387 | 1382 |
| 1388 | 1383 |
| 1389 int Scope::ContextLocalCount() const { | 1384 int Scope::ContextLocalCount() const { |
| 1390 if (num_heap_slots() == 0) return 0; | 1385 if (num_heap_slots() == 0) return 0; |
| 1391 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1386 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
| 1392 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); | 1387 (function_ != NULL && function_->proxy()->var()->IsContextSlot() ? 1 : 0); |
| 1393 } | 1388 } |
| 1394 | 1389 |
| 1395 } } // namespace v8::internal | 1390 } } // namespace v8::internal |
| OLD | NEW |