| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 return NULL; | 109 return NULL; |
| 110 } | 110 } |
| 111 | 111 |
| 112 | 112 |
| 113 // ---------------------------------------------------------------------------- | 113 // ---------------------------------------------------------------------------- |
| 114 // Implementation of Scope | 114 // Implementation of Scope |
| 115 | 115 |
| 116 | 116 |
| 117 // Dummy constructor | 117 // Dummy constructor |
| 118 Scope::Scope(Type type) | 118 Scope::Scope(Type type) |
| 119 : inner_scopes_(0), | 119 : inner_scopes_(ZONE, 0), |
| 120 variables_(false), | 120 variables_(false), |
| 121 temps_(0), | 121 temps_(ZONE, 0), |
| 122 params_(0), | 122 params_(ZONE, 0), |
| 123 unresolved_(0), | 123 unresolved_(ZONE, 0), |
| 124 decls_(0), | 124 decls_(ZONE, 0), |
| 125 already_resolved_(false) { | 125 already_resolved_(false) { |
| 126 SetDefaults(type, NULL, Handle<SerializedScopeInfo>::null()); | 126 SetDefaults(type, NULL, Handle<SerializedScopeInfo>::null()); |
| 127 } | 127 } |
| 128 | 128 |
| 129 | 129 |
| 130 Scope::Scope(Scope* outer_scope, Type type) | 130 Scope::Scope(Scope* outer_scope, Type type) |
| 131 : inner_scopes_(4), | 131 : inner_scopes_(ZONE, 4), |
| 132 variables_(), | 132 variables_(), |
| 133 temps_(4), | 133 temps_(ZONE, 4), |
| 134 params_(4), | 134 params_(ZONE, 4), |
| 135 unresolved_(16), | 135 unresolved_(ZONE, 16), |
| 136 decls_(4), | 136 decls_(ZONE, 4), |
| 137 already_resolved_(false) { | 137 already_resolved_(false) { |
| 138 SetDefaults(type, outer_scope, Handle<SerializedScopeInfo>::null()); | 138 SetDefaults(type, outer_scope, Handle<SerializedScopeInfo>::null()); |
| 139 // At some point we might want to provide outer scopes to | 139 // At some point we might want to provide outer scopes to |
| 140 // eval scopes (by walking the stack and reading the scope info). | 140 // eval scopes (by walking the stack and reading the scope info). |
| 141 // In that case, the ASSERT below needs to be adjusted. | 141 // In that case, the ASSERT below needs to be adjusted. |
| 142 ASSERT((type == GLOBAL_SCOPE || type == EVAL_SCOPE) == (outer_scope == NULL)); | 142 ASSERT((type == GLOBAL_SCOPE || type == EVAL_SCOPE) == (outer_scope == NULL)); |
| 143 ASSERT(!HasIllegalRedeclaration()); | 143 ASSERT(!HasIllegalRedeclaration()); |
| 144 } | 144 } |
| 145 | 145 |
| 146 | 146 |
| 147 Scope::Scope(Scope* inner_scope, Handle<SerializedScopeInfo> scope_info) | 147 Scope::Scope(Scope* inner_scope, Handle<SerializedScopeInfo> scope_info) |
| 148 : inner_scopes_(4), | 148 : inner_scopes_(ZONE, 4), |
| 149 variables_(), | 149 variables_(), |
| 150 temps_(4), | 150 temps_(ZONE, 4), |
| 151 params_(4), | 151 params_(ZONE, 4), |
| 152 unresolved_(16), | 152 unresolved_(ZONE, 16), |
| 153 decls_(4), | 153 decls_(ZONE, 4), |
| 154 already_resolved_(true) { | 154 already_resolved_(true) { |
| 155 ASSERT(!scope_info.is_null()); | 155 ASSERT(!scope_info.is_null()); |
| 156 SetDefaults(FUNCTION_SCOPE, NULL, scope_info); | 156 SetDefaults(FUNCTION_SCOPE, NULL, scope_info); |
| 157 if (scope_info->HasHeapAllocatedLocals()) { | 157 if (scope_info->HasHeapAllocatedLocals()) { |
| 158 num_heap_slots_ = scope_info_->NumberOfContextSlots(); | 158 num_heap_slots_ = scope_info_->NumberOfContextSlots(); |
| 159 } | 159 } |
| 160 AddInnerScope(inner_scope); | 160 AddInnerScope(inner_scope); |
| 161 } | 161 } |
| 162 | 162 |
| 163 | 163 |
| 164 Scope::Scope(Scope* inner_scope, Handle<String> catch_variable_name) | 164 Scope::Scope(Scope* inner_scope, Handle<String> catch_variable_name) |
| 165 : inner_scopes_(1), | 165 : inner_scopes_(ZONE, 1), |
| 166 variables_(), | 166 variables_(), |
| 167 temps_(0), | 167 temps_(ZONE, 0), |
| 168 params_(0), | 168 params_(ZONE, 0), |
| 169 unresolved_(0), | 169 unresolved_(ZONE, 0), |
| 170 decls_(0), | 170 decls_(ZONE, 0), |
| 171 already_resolved_(true) { | 171 already_resolved_(true) { |
| 172 SetDefaults(CATCH_SCOPE, NULL, Handle<SerializedScopeInfo>::null()); | 172 SetDefaults(CATCH_SCOPE, NULL, Handle<SerializedScopeInfo>::null()); |
| 173 AddInnerScope(inner_scope); | 173 AddInnerScope(inner_scope); |
| 174 ++num_var_or_const_; | 174 ++num_var_or_const_; |
| 175 Variable* variable = variables_.Declare(this, | 175 Variable* variable = variables_.Declare(this, |
| 176 catch_variable_name, | 176 catch_variable_name, |
| 177 Variable::VAR, | 177 Variable::VAR, |
| 178 true, // Valid left-hand side. | 178 true, // Valid left-hand side. |
| 179 Variable::NORMAL); | 179 Variable::NORMAL); |
| 180 AllocateHeapSlot(variable); | 180 AllocateHeapSlot(variable); |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 Variable* var = reinterpret_cast<Variable*>(p->value); | 462 Variable* var = reinterpret_cast<Variable*>(p->value); |
| 463 if (var->is_used()) { | 463 if (var->is_used()) { |
| 464 locals->Add(var); | 464 locals->Add(var); |
| 465 } | 465 } |
| 466 } | 466 } |
| 467 } | 467 } |
| 468 | 468 |
| 469 | 469 |
| 470 // Make sure the method gets instantiated by the template system. | 470 // Make sure the method gets instantiated by the template system. |
| 471 template void Scope::CollectUsedVariables( | 471 template void Scope::CollectUsedVariables( |
| 472 List<Variable*, FreeStoreAllocationPolicy>* locals); | 472 List<Variable*, FreeStoreAllocator>* locals); |
| 473 template void Scope::CollectUsedVariables( | 473 template void Scope::CollectUsedVariables( |
| 474 List<Variable*, PreallocatedStorage>* locals); | 474 List<Variable*, PreallocatedStorageAllocator>* locals); |
| 475 template void Scope::CollectUsedVariables( | 475 template void Scope::CollectUsedVariables( |
| 476 List<Variable*, ZoneListAllocationPolicy>* locals); | 476 List<Variable*, ZoneListAllocator>* locals); |
| 477 | 477 |
| 478 | 478 |
| 479 void Scope::AllocateVariables(Handle<Context> context) { | 479 void Scope::AllocateVariables(Handle<Context> context) { |
| 480 ASSERT(outer_scope_ == NULL); // eval or global scopes only | 480 ASSERT(outer_scope_ == NULL); // eval or global scopes only |
| 481 | 481 |
| 482 // 1) Propagate scope information. | 482 // 1) Propagate scope information. |
| 483 // If we are in an eval scope, we may have other outer scopes about | 483 // If we are in an eval scope, we may have other outer scopes about |
| 484 // which we don't know anything at this point. Thus we must be conservative | 484 // which we don't know anything at this point. Thus we must be conservative |
| 485 // and assume they may invoke eval themselves. Eventually we could capture | 485 // and assume they may invoke eval themselves. Eventually we could capture |
| 486 // this information in the ScopeInfo and then use it here (by traversing | 486 // this information in the ScopeInfo and then use it here (by traversing |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && | 1090 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && |
| 1091 !must_have_local_context) { | 1091 !must_have_local_context) { |
| 1092 num_heap_slots_ = 0; | 1092 num_heap_slots_ = 0; |
| 1093 } | 1093 } |
| 1094 | 1094 |
| 1095 // Allocation done. | 1095 // Allocation done. |
| 1096 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); | 1096 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 } } // namespace v8::internal | 1099 } } // namespace v8::internal |
| OLD | NEW |