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/scopes.h" | 5 #include "src/scopes.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/messages.h" | 9 #include "src/messages.h" |
10 #include "src/parser.h" | 10 #include "src/parser.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash()); | 59 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash()); |
60 if (p != NULL) { | 60 if (p != NULL) { |
61 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name); | 61 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name); |
62 DCHECK(p->value != NULL); | 62 DCHECK(p->value != NULL); |
63 return reinterpret_cast<Variable*>(p->value); | 63 return reinterpret_cast<Variable*>(p->value); |
64 } | 64 } |
65 return NULL; | 65 return NULL; |
66 } | 66 } |
67 | 67 |
68 | 68 |
| 69 SloppyBlockFunctionMap::SloppyBlockFunctionMap(Zone* zone) |
| 70 : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)), |
| 71 zone_(zone) {} |
| 72 SloppyBlockFunctionMap::~SloppyBlockFunctionMap() {} |
| 73 |
| 74 |
| 75 void SloppyBlockFunctionMap::Declare(const AstRawString* name, |
| 76 SloppyBlockFunctionStatement* stmt) { |
| 77 // AstRawStrings are unambiguous, i.e., the same string is always represented |
| 78 // by the same AstRawString*. |
| 79 Entry* p = |
| 80 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), |
| 81 ZoneAllocationPolicy(zone_)); |
| 82 if (p->value == nullptr) { |
| 83 p->value = new (zone_->New(sizeof(Vector))) Vector(zone_); |
| 84 } |
| 85 Vector* delegates = static_cast<Vector*>(p->value); |
| 86 delegates->push_back(stmt); |
| 87 } |
| 88 |
| 89 |
69 // ---------------------------------------------------------------------------- | 90 // ---------------------------------------------------------------------------- |
70 // Implementation of Scope | 91 // Implementation of Scope |
71 | 92 |
72 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, | 93 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, |
73 AstValueFactory* ast_value_factory, FunctionKind function_kind) | 94 AstValueFactory* ast_value_factory, FunctionKind function_kind) |
74 : inner_scopes_(4, zone), | 95 : inner_scopes_(4, zone), |
75 variables_(zone), | 96 variables_(zone), |
76 temps_(4, zone), | 97 temps_(4, zone), |
77 params_(4, zone), | 98 params_(4, zone), |
78 unresolved_(16, zone), | 99 unresolved_(16, zone), |
79 decls_(4, zone), | 100 decls_(4, zone), |
80 module_descriptor_( | 101 module_descriptor_( |
81 scope_type == MODULE_SCOPE ? ModuleDescriptor::New(zone) : NULL), | 102 scope_type == MODULE_SCOPE ? ModuleDescriptor::New(zone) : NULL), |
| 103 sloppy_block_function_map_(zone), |
82 already_resolved_(false), | 104 already_resolved_(false), |
83 ast_value_factory_(ast_value_factory), | 105 ast_value_factory_(ast_value_factory), |
84 zone_(zone), | 106 zone_(zone), |
85 class_declaration_group_start_(-1) { | 107 class_declaration_group_start_(-1) { |
86 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null(), | 108 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null(), |
87 function_kind); | 109 function_kind); |
88 // The outermost scope must be a script scope. | 110 // The outermost scope must be a script scope. |
89 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL); | 111 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL); |
90 DCHECK(!HasIllegalRedeclaration()); | 112 DCHECK(!HasIllegalRedeclaration()); |
91 } | 113 } |
92 | 114 |
93 | 115 |
94 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, | 116 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, |
95 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory) | 117 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory) |
96 : inner_scopes_(4, zone), | 118 : inner_scopes_(4, zone), |
97 variables_(zone), | 119 variables_(zone), |
98 temps_(4, zone), | 120 temps_(4, zone), |
99 params_(4, zone), | 121 params_(4, zone), |
100 unresolved_(16, zone), | 122 unresolved_(16, zone), |
101 decls_(4, zone), | 123 decls_(4, zone), |
102 module_descriptor_(NULL), | 124 module_descriptor_(NULL), |
| 125 sloppy_block_function_map_(zone), |
103 already_resolved_(true), | 126 already_resolved_(true), |
104 ast_value_factory_(value_factory), | 127 ast_value_factory_(value_factory), |
105 zone_(zone), | 128 zone_(zone), |
106 class_declaration_group_start_(-1) { | 129 class_declaration_group_start_(-1) { |
107 SetDefaults(scope_type, NULL, scope_info); | 130 SetDefaults(scope_type, NULL, scope_info); |
108 if (!scope_info.is_null()) { | 131 if (!scope_info.is_null()) { |
109 num_heap_slots_ = scope_info_->ContextLength(); | 132 num_heap_slots_ = scope_info_->ContextLength(); |
110 } | 133 } |
111 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. | 134 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. |
112 num_heap_slots_ = Max(num_heap_slots_, | 135 num_heap_slots_ = Max(num_heap_slots_, |
113 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); | 136 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); |
114 AddInnerScope(inner_scope); | 137 AddInnerScope(inner_scope); |
115 } | 138 } |
116 | 139 |
117 | 140 |
118 Scope::Scope(Zone* zone, Scope* inner_scope, | 141 Scope::Scope(Zone* zone, Scope* inner_scope, |
119 const AstRawString* catch_variable_name, | 142 const AstRawString* catch_variable_name, |
120 AstValueFactory* value_factory) | 143 AstValueFactory* value_factory) |
121 : inner_scopes_(1, zone), | 144 : inner_scopes_(1, zone), |
122 variables_(zone), | 145 variables_(zone), |
123 temps_(0, zone), | 146 temps_(0, zone), |
124 params_(0, zone), | 147 params_(0, zone), |
125 unresolved_(0, zone), | 148 unresolved_(0, zone), |
126 decls_(0, zone), | 149 decls_(0, zone), |
127 module_descriptor_(NULL), | 150 module_descriptor_(NULL), |
| 151 sloppy_block_function_map_(zone), |
128 already_resolved_(true), | 152 already_resolved_(true), |
129 ast_value_factory_(value_factory), | 153 ast_value_factory_(value_factory), |
130 zone_(zone), | 154 zone_(zone), |
131 class_declaration_group_start_(-1) { | 155 class_declaration_group_start_(-1) { |
132 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); | 156 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); |
133 AddInnerScope(inner_scope); | 157 AddInnerScope(inner_scope); |
134 ++num_var_or_const_; | 158 ++num_var_or_const_; |
135 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; | 159 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; |
136 Variable* variable = variables_.Declare(this, | 160 Variable* variable = variables_.Declare(this, |
137 catch_variable_name, | 161 catch_variable_name, |
(...skipping 1487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1625 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1649 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1626 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1650 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1627 (is_function_var_in_context ? 1 : 0); | 1651 (is_function_var_in_context ? 1 : 0); |
1628 } | 1652 } |
1629 | 1653 |
1630 | 1654 |
1631 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1655 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1632 | 1656 |
1633 } // namespace internal | 1657 } // namespace internal |
1634 } // namespace v8 | 1658 } // namespace v8 |
OLD | NEW |