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 DelegateStatement* 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(DelegateVector))) DelegateVector(zone_); |
| 84 } |
| 85 ZoneVector<DelegateStatement*>* delegates = |
| 86 static_cast<DelegateVector*>(p->value); |
| 87 delegates->push_back(stmt); |
| 88 } |
| 89 |
| 90 |
69 // ---------------------------------------------------------------------------- | 91 // ---------------------------------------------------------------------------- |
70 // Implementation of Scope | 92 // Implementation of Scope |
71 | 93 |
72 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, | 94 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type, |
73 AstValueFactory* ast_value_factory, FunctionKind function_kind) | 95 AstValueFactory* ast_value_factory, FunctionKind function_kind) |
74 : inner_scopes_(4, zone), | 96 : inner_scopes_(4, zone), |
75 variables_(zone), | 97 variables_(zone), |
76 temps_(4, zone), | 98 temps_(4, zone), |
77 params_(4, zone), | 99 params_(4, zone), |
78 unresolved_(16, zone), | 100 unresolved_(16, zone), |
79 decls_(4, zone), | 101 decls_(4, zone), |
80 module_descriptor_( | 102 module_descriptor_( |
81 scope_type == MODULE_SCOPE ? ModuleDescriptor::New(zone) : NULL), | 103 scope_type == MODULE_SCOPE ? ModuleDescriptor::New(zone) : NULL), |
| 104 sloppy_block_function_map_(zone), |
82 already_resolved_(false), | 105 already_resolved_(false), |
83 ast_value_factory_(ast_value_factory), | 106 ast_value_factory_(ast_value_factory), |
84 zone_(zone), | 107 zone_(zone), |
85 class_declaration_group_start_(-1) { | 108 class_declaration_group_start_(-1) { |
86 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null(), | 109 SetDefaults(scope_type, outer_scope, Handle<ScopeInfo>::null(), |
87 function_kind); | 110 function_kind); |
88 // The outermost scope must be a script scope. | 111 // The outermost scope must be a script scope. |
89 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL); | 112 DCHECK(scope_type == SCRIPT_SCOPE || outer_scope != NULL); |
90 DCHECK(!HasIllegalRedeclaration()); | 113 DCHECK(!HasIllegalRedeclaration()); |
91 } | 114 } |
92 | 115 |
93 | 116 |
94 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, | 117 Scope::Scope(Zone* zone, Scope* inner_scope, ScopeType scope_type, |
95 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory) | 118 Handle<ScopeInfo> scope_info, AstValueFactory* value_factory) |
96 : inner_scopes_(4, zone), | 119 : inner_scopes_(4, zone), |
97 variables_(zone), | 120 variables_(zone), |
98 temps_(4, zone), | 121 temps_(4, zone), |
99 params_(4, zone), | 122 params_(4, zone), |
100 unresolved_(16, zone), | 123 unresolved_(16, zone), |
101 decls_(4, zone), | 124 decls_(4, zone), |
102 module_descriptor_(NULL), | 125 module_descriptor_(NULL), |
| 126 sloppy_block_function_map_(zone), |
103 already_resolved_(true), | 127 already_resolved_(true), |
104 ast_value_factory_(value_factory), | 128 ast_value_factory_(value_factory), |
105 zone_(zone), | 129 zone_(zone), |
106 class_declaration_group_start_(-1) { | 130 class_declaration_group_start_(-1) { |
107 SetDefaults(scope_type, NULL, scope_info); | 131 SetDefaults(scope_type, NULL, scope_info); |
108 if (!scope_info.is_null()) { | 132 if (!scope_info.is_null()) { |
109 num_heap_slots_ = scope_info_->ContextLength(); | 133 num_heap_slots_ = scope_info_->ContextLength(); |
110 } | 134 } |
111 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. | 135 // Ensure at least MIN_CONTEXT_SLOTS to indicate a materialized context. |
112 num_heap_slots_ = Max(num_heap_slots_, | 136 num_heap_slots_ = Max(num_heap_slots_, |
113 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); | 137 static_cast<int>(Context::MIN_CONTEXT_SLOTS)); |
114 AddInnerScope(inner_scope); | 138 AddInnerScope(inner_scope); |
115 } | 139 } |
116 | 140 |
117 | 141 |
118 Scope::Scope(Zone* zone, Scope* inner_scope, | 142 Scope::Scope(Zone* zone, Scope* inner_scope, |
119 const AstRawString* catch_variable_name, | 143 const AstRawString* catch_variable_name, |
120 AstValueFactory* value_factory) | 144 AstValueFactory* value_factory) |
121 : inner_scopes_(1, zone), | 145 : inner_scopes_(1, zone), |
122 variables_(zone), | 146 variables_(zone), |
123 temps_(0, zone), | 147 temps_(0, zone), |
124 params_(0, zone), | 148 params_(0, zone), |
125 unresolved_(0, zone), | 149 unresolved_(0, zone), |
126 decls_(0, zone), | 150 decls_(0, zone), |
127 module_descriptor_(NULL), | 151 module_descriptor_(NULL), |
| 152 sloppy_block_function_map_(zone), |
128 already_resolved_(true), | 153 already_resolved_(true), |
129 ast_value_factory_(value_factory), | 154 ast_value_factory_(value_factory), |
130 zone_(zone), | 155 zone_(zone), |
131 class_declaration_group_start_(-1) { | 156 class_declaration_group_start_(-1) { |
132 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); | 157 SetDefaults(CATCH_SCOPE, NULL, Handle<ScopeInfo>::null()); |
133 AddInnerScope(inner_scope); | 158 AddInnerScope(inner_scope); |
134 ++num_var_or_const_; | 159 ++num_var_or_const_; |
135 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; | 160 num_heap_slots_ = Context::MIN_CONTEXT_SLOTS; |
136 Variable* variable = variables_.Declare(this, | 161 Variable* variable = variables_.Declare(this, |
137 catch_variable_name, | 162 catch_variable_name, |
(...skipping 1487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1625 function_ != NULL && function_->proxy()->var()->IsContextSlot(); | 1650 function_ != NULL && function_->proxy()->var()->IsContextSlot(); |
1626 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1651 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1627 (is_function_var_in_context ? 1 : 0); | 1652 (is_function_var_in_context ? 1 : 0); |
1628 } | 1653 } |
1629 | 1654 |
1630 | 1655 |
1631 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1656 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1632 | 1657 |
1633 } // namespace internal | 1658 } // namespace internal |
1634 } // namespace v8 | 1659 } // namespace v8 |
OLD | NEW |