Chromium Code Reviews| 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/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 23 matching lines...) Expand all Loading... | |
| 34 bool* added) { | 34 bool* added) { |
| 35 // AstRawStrings are unambiguous, i.e., the same string is always represented | 35 // AstRawStrings are unambiguous, i.e., the same string is always represented |
| 36 // by the same AstRawString*. | 36 // by the same AstRawString*. |
| 37 // FIXME(marja): fix the type of Lookup. | 37 // FIXME(marja): fix the type of Lookup. |
| 38 Entry* p = | 38 Entry* p = |
| 39 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), | 39 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), |
| 40 ZoneAllocationPolicy(zone)); | 40 ZoneAllocationPolicy(zone)); |
| 41 if (added) *added = p->value == nullptr; | 41 if (added) *added = p->value == nullptr; |
| 42 if (p->value == nullptr) { | 42 if (p->value == nullptr) { |
| 43 // The variable has not been declared yet -> insert it. | 43 // The variable has not been declared yet -> insert it. |
| 44 DCHECK(p->key == name); | 44 DCHECK_EQ(name, p->key); |
| 45 p->value = new (zone) Variable(scope, name, mode, kind, initialization_flag, | 45 p->value = new (zone) Variable(scope, name, mode, kind, initialization_flag, |
| 46 maybe_assigned_flag); | 46 maybe_assigned_flag); |
| 47 } | 47 } |
| 48 return reinterpret_cast<Variable*>(p->value); | 48 return reinterpret_cast<Variable*>(p->value); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void VariableMap::Remove(Variable* var) { | |
| 52 const AstRawString* name = var->raw_name(); | |
| 53 ZoneHashMap::Remove(const_cast<AstRawString*>(name), name->hash()); | |
| 54 } | |
| 55 | |
| 56 void VariableMap::Add(Zone* zone, Variable* var) { | |
| 57 const AstRawString* name = var->raw_name(); | |
| 58 Entry* p = | |
| 59 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), | |
| 60 ZoneAllocationPolicy(zone)); | |
| 61 DCHECK_NULL(p->value); | |
| 62 DCHECK_EQ(name, p->key); | |
| 63 p->value = var; | |
| 64 } | |
| 51 | 65 |
| 52 Variable* VariableMap::Lookup(const AstRawString* name) { | 66 Variable* VariableMap::Lookup(const AstRawString* name) { |
| 53 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash()); | 67 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash()); |
| 54 if (p != NULL) { | 68 if (p != NULL) { |
| 55 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name); | 69 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name); |
| 56 DCHECK(p->value != NULL); | 70 DCHECK(p->value != NULL); |
| 57 return reinterpret_cast<Variable*>(p->value); | 71 return reinterpret_cast<Variable*>(p->value); |
| 58 } | 72 } |
| 59 return NULL; | 73 return NULL; |
| 60 } | 74 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 74 } | 88 } |
| 75 | 89 |
| 76 | 90 |
| 77 // ---------------------------------------------------------------------------- | 91 // ---------------------------------------------------------------------------- |
| 78 // Implementation of Scope | 92 // Implementation of Scope |
| 79 | 93 |
| 80 Scope::Scope(Zone* zone, ScopeType scope_type) | 94 Scope::Scope(Zone* zone, ScopeType scope_type) |
| 81 : zone_(zone), | 95 : zone_(zone), |
| 82 outer_scope_(nullptr), | 96 outer_scope_(nullptr), |
| 83 variables_(zone), | 97 variables_(zone), |
| 84 ordered_variables_(4, zone), | 98 locals_(4, zone), |
| 85 decls_(4, zone), | 99 decls_(4, zone), |
| 86 scope_type_(scope_type) { | 100 scope_type_(scope_type) { |
| 87 DCHECK(scope_type == SCRIPT_SCOPE || scope_type == WITH_SCOPE); | 101 DCHECK(scope_type == SCRIPT_SCOPE || scope_type == WITH_SCOPE); |
| 88 SetDefaults(); | 102 SetDefaults(); |
| 89 #ifdef DEBUG | 103 #ifdef DEBUG |
| 90 if (scope_type == WITH_SCOPE) { | 104 if (scope_type == WITH_SCOPE) { |
| 91 already_resolved_ = true; | 105 already_resolved_ = true; |
| 92 } | 106 } |
| 93 #endif | 107 #endif |
| 94 } | 108 } |
| 95 | 109 |
| 96 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) | 110 Scope::Scope(Zone* zone, Scope* outer_scope, ScopeType scope_type) |
| 97 : zone_(zone), | 111 : zone_(zone), |
| 98 outer_scope_(outer_scope), | 112 outer_scope_(outer_scope), |
| 99 variables_(zone), | 113 variables_(zone), |
| 100 ordered_variables_(4, zone), | 114 locals_(4, zone), |
| 101 decls_(4, zone), | 115 decls_(4, zone), |
| 102 scope_type_(scope_type) { | 116 scope_type_(scope_type) { |
| 103 DCHECK_NE(SCRIPT_SCOPE, scope_type); | 117 DCHECK_NE(SCRIPT_SCOPE, scope_type); |
| 104 SetDefaults(); | 118 SetDefaults(); |
| 105 set_language_mode(outer_scope->language_mode()); | 119 set_language_mode(outer_scope->language_mode()); |
| 106 force_context_allocation_ = | 120 force_context_allocation_ = |
| 107 !is_function_scope() && outer_scope->has_forced_context_allocation(); | 121 !is_function_scope() && outer_scope->has_forced_context_allocation(); |
| 108 outer_scope_->AddInnerScope(this); | 122 outer_scope_->AddInnerScope(this); |
| 109 } | 123 } |
| 110 | 124 |
| 111 Scope::Snapshot::Snapshot(Scope* scope) | 125 Scope::Snapshot::Snapshot(Scope* scope) |
| 112 : outer_scope_(scope), | 126 : outer_scope_(scope), |
| 113 top_inner_scope_(scope->inner_scope_), | 127 top_inner_scope_(scope->inner_scope_), |
| 114 top_unresolved_(scope->unresolved_), | 128 top_unresolved_(scope->unresolved_), |
| 115 top_temp_(scope->GetClosureScope()->temps()->length()) {} | 129 top_local_(scope->GetClosureScope()->locals_.length()), |
| 130 top_decl_(scope->GetClosureScope()->decls_.length()) {} | |
| 116 | 131 |
| 117 DeclarationScope::DeclarationScope(Zone* zone) | 132 DeclarationScope::DeclarationScope(Zone* zone) |
| 118 : Scope(zone), | 133 : Scope(zone), |
| 119 function_kind_(kNormalFunction), | 134 function_kind_(kNormalFunction), |
| 120 temps_(4, zone), | |
| 121 params_(4, zone), | 135 params_(4, zone), |
| 122 sloppy_block_function_map_(zone) { | 136 sloppy_block_function_map_(zone) { |
| 123 SetDefaults(); | 137 SetDefaults(); |
| 124 } | 138 } |
| 125 | 139 |
| 126 DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope, | 140 DeclarationScope::DeclarationScope(Zone* zone, Scope* outer_scope, |
| 127 ScopeType scope_type, | 141 ScopeType scope_type, |
| 128 FunctionKind function_kind) | 142 FunctionKind function_kind) |
| 129 : Scope(zone, outer_scope, scope_type), | 143 : Scope(zone, outer_scope, scope_type), |
| 130 function_kind_(function_kind), | 144 function_kind_(function_kind), |
| 131 temps_(4, zone), | |
| 132 params_(4, zone), | 145 params_(4, zone), |
| 133 sloppy_block_function_map_(zone) { | 146 sloppy_block_function_map_(zone) { |
| 134 SetDefaults(); | 147 SetDefaults(); |
| 135 asm_function_ = outer_scope_->IsAsmModule(); | 148 asm_function_ = outer_scope_->IsAsmModule(); |
| 136 } | 149 } |
| 137 | 150 |
| 138 ModuleScope::ModuleScope(Zone* zone, DeclarationScope* script_scope, | 151 ModuleScope::ModuleScope(Zone* zone, DeclarationScope* script_scope, |
| 139 AstValueFactory* ast_value_factory) | 152 AstValueFactory* ast_value_factory) |
| 140 : DeclarationScope(zone, script_scope, MODULE_SCOPE) { | 153 : DeclarationScope(zone, script_scope, MODULE_SCOPE) { |
| 141 module_descriptor_ = new (zone) ModuleDescriptor(zone); | 154 module_descriptor_ = new (zone) ModuleDescriptor(zone); |
| 142 set_language_mode(STRICT); | 155 set_language_mode(STRICT); |
| 143 DeclareThis(ast_value_factory); | 156 DeclareThis(ast_value_factory); |
| 144 } | 157 } |
| 145 | 158 |
| 146 Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info) | 159 Scope::Scope(Zone* zone, ScopeType scope_type, Handle<ScopeInfo> scope_info) |
| 147 : zone_(zone), | 160 : zone_(zone), |
| 148 outer_scope_(nullptr), | 161 outer_scope_(nullptr), |
| 149 variables_(zone), | 162 variables_(zone), |
| 150 ordered_variables_(0, zone), | 163 locals_(0, zone), |
| 151 decls_(0, zone), | 164 decls_(0, zone), |
| 152 scope_info_(scope_info), | 165 scope_info_(scope_info), |
| 153 scope_type_(scope_type) { | 166 scope_type_(scope_type) { |
| 154 DCHECK(!scope_info.is_null()); | 167 DCHECK(!scope_info.is_null()); |
| 155 SetDefaults(); | 168 SetDefaults(); |
| 156 #ifdef DEBUG | 169 #ifdef DEBUG |
| 157 already_resolved_ = true; | 170 already_resolved_ = true; |
| 158 #endif | 171 #endif |
| 159 if (scope_info->CallsEval()) RecordEvalCall(); | 172 if (scope_info->CallsEval()) RecordEvalCall(); |
| 160 set_language_mode(scope_info->language_mode()); | 173 set_language_mode(scope_info->language_mode()); |
| 161 num_heap_slots_ = scope_info->ContextLength(); | 174 num_heap_slots_ = scope_info->ContextLength(); |
| 162 DCHECK_LE(Context::MIN_CONTEXT_SLOTS, num_heap_slots_); | 175 DCHECK_LE(Context::MIN_CONTEXT_SLOTS, num_heap_slots_); |
| 163 } | 176 } |
| 164 | 177 |
| 165 DeclarationScope::DeclarationScope(Zone* zone, ScopeType scope_type, | 178 DeclarationScope::DeclarationScope(Zone* zone, ScopeType scope_type, |
| 166 Handle<ScopeInfo> scope_info) | 179 Handle<ScopeInfo> scope_info) |
| 167 : Scope(zone, scope_type, scope_info), | 180 : Scope(zone, scope_type, scope_info), |
| 168 function_kind_(scope_info->function_kind()), | 181 function_kind_(scope_info->function_kind()), |
| 169 temps_(0, zone), | |
| 170 params_(0, zone), | 182 params_(0, zone), |
| 171 sloppy_block_function_map_(zone) { | 183 sloppy_block_function_map_(zone) { |
| 172 SetDefaults(); | 184 SetDefaults(); |
| 173 } | 185 } |
| 174 | 186 |
| 175 Scope::Scope(Zone* zone, const AstRawString* catch_variable_name) | 187 Scope::Scope(Zone* zone, const AstRawString* catch_variable_name) |
| 176 : zone_(zone), | 188 : zone_(zone), |
| 177 outer_scope_(nullptr), | 189 outer_scope_(nullptr), |
| 178 variables_(zone), | 190 variables_(zone), |
| 179 ordered_variables_(0, zone), | 191 locals_(0, zone), |
| 180 decls_(0, zone), | 192 decls_(0, zone), |
| 181 scope_type_(CATCH_SCOPE) { | 193 scope_type_(CATCH_SCOPE) { |
| 182 SetDefaults(); | 194 SetDefaults(); |
| 183 #ifdef DEBUG | 195 #ifdef DEBUG |
| 184 already_resolved_ = true; | 196 already_resolved_ = true; |
| 185 #endif | 197 #endif |
| 186 Variable* variable = | 198 Variable* variable = |
| 187 variables_.Declare(zone, this, catch_variable_name, VAR, Variable::NORMAL, | 199 variables_.Declare(zone, this, catch_variable_name, VAR, Variable::NORMAL, |
| 188 kCreatedInitialized); | 200 kCreatedInitialized); |
| 189 AllocateHeapSlot(variable); | 201 AllocateHeapSlot(variable); |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 num_heap_slots_ = 0; | 535 num_heap_slots_ = 0; |
| 524 return NULL; | 536 return NULL; |
| 525 } | 537 } |
| 526 | 538 |
| 527 void Scope::Snapshot::Reparent(DeclarationScope* new_parent) const { | 539 void Scope::Snapshot::Reparent(DeclarationScope* new_parent) const { |
| 528 DCHECK_EQ(new_parent, outer_scope_->inner_scope_); | 540 DCHECK_EQ(new_parent, outer_scope_->inner_scope_); |
| 529 DCHECK_EQ(new_parent->outer_scope_, outer_scope_); | 541 DCHECK_EQ(new_parent->outer_scope_, outer_scope_); |
| 530 DCHECK_EQ(new_parent, new_parent->GetClosureScope()); | 542 DCHECK_EQ(new_parent, new_parent->GetClosureScope()); |
| 531 DCHECK_NULL(new_parent->inner_scope_); | 543 DCHECK_NULL(new_parent->inner_scope_); |
| 532 DCHECK_NULL(new_parent->unresolved_); | 544 DCHECK_NULL(new_parent->unresolved_); |
| 533 DCHECK_EQ(0, new_parent->temps()->length()); | 545 DCHECK_EQ(0, new_parent->locals_.length()); |
| 534 Scope* inner_scope = new_parent->sibling_; | 546 Scope* inner_scope = new_parent->sibling_; |
| 535 if (inner_scope != top_inner_scope_) { | 547 if (inner_scope != top_inner_scope_) { |
| 536 for (; inner_scope->sibling() != top_inner_scope_; | 548 for (; inner_scope->sibling() != top_inner_scope_; |
| 537 inner_scope = inner_scope->sibling()) { | 549 inner_scope = inner_scope->sibling()) { |
| 538 inner_scope->outer_scope_ = new_parent; | 550 inner_scope->outer_scope_ = new_parent; |
| 539 DCHECK_NE(inner_scope, new_parent); | 551 DCHECK_NE(inner_scope, new_parent); |
| 540 } | 552 } |
| 541 inner_scope->outer_scope_ = new_parent; | 553 inner_scope->outer_scope_ = new_parent; |
| 542 | 554 |
| 543 new_parent->inner_scope_ = new_parent->sibling_; | 555 new_parent->inner_scope_ = new_parent->sibling_; |
| 544 inner_scope->sibling_ = nullptr; | 556 inner_scope->sibling_ = nullptr; |
| 545 // Reset the sibling rather than the inner_scope_ since we | 557 // Reset the sibling rather than the inner_scope_ since we |
| 546 // want to keep new_parent there. | 558 // want to keep new_parent there. |
| 547 new_parent->sibling_ = top_inner_scope_; | 559 new_parent->sibling_ = top_inner_scope_; |
| 548 } | 560 } |
| 549 | 561 |
| 550 if (outer_scope_->unresolved_ != top_unresolved_) { | 562 if (outer_scope_->unresolved_ != top_unresolved_) { |
| 551 VariableProxy* last = outer_scope_->unresolved_; | 563 VariableProxy* last = outer_scope_->unresolved_; |
| 552 while (last->next_unresolved() != top_unresolved_) { | 564 while (last->next_unresolved() != top_unresolved_) { |
| 553 last = last->next_unresolved(); | 565 last = last->next_unresolved(); |
| 554 } | 566 } |
| 555 last->set_next_unresolved(nullptr); | 567 last->set_next_unresolved(nullptr); |
| 556 new_parent->unresolved_ = outer_scope_->unresolved_; | 568 new_parent->unresolved_ = outer_scope_->unresolved_; |
| 557 outer_scope_->unresolved_ = top_unresolved_; | 569 outer_scope_->unresolved_ = top_unresolved_; |
| 558 } | 570 } |
| 559 | 571 |
| 560 if (outer_scope_->GetClosureScope()->temps()->length() != top_temp_) { | 572 // TODO(verwaest): This currently only moves do-expression declared variables |
| 561 ZoneList<Variable*>* temps = outer_scope_->GetClosureScope()->temps(); | 573 // in default arguments that weren't already previously declared with the same |
| 562 for (int i = top_temp_; i < temps->length(); i++) { | 574 // name in the closure-scope. See |
| 563 Variable* temp = temps->at(i); | 575 // test/mjsunit/harmony/default-parameter-do-expression.js. |
| 564 DCHECK_EQ(temp->scope(), temp->scope()->GetClosureScope()); | 576 DeclarationScope* outer_closure = outer_scope_->GetClosureScope(); |
| 565 DCHECK_NE(temp->scope(), new_parent); | 577 for (int i = top_local_; i < outer_closure->locals_.length(); i++) { |
| 566 temp->set_scope(new_parent); | 578 Variable* local = outer_closure->locals_.at(i); |
| 567 new_parent->AddTemporary(temp); | 579 DCHECK(local->mode() == TEMPORARY || local->mode() == VAR); |
| 580 DCHECK_EQ(local->scope(), local->scope()->GetClosureScope()); | |
| 581 DCHECK_NE(local->scope(), new_parent); | |
| 582 local->set_scope(new_parent); | |
| 583 new_parent->AddLocal(local); | |
| 584 if (local->mode() == VAR) { | |
| 585 outer_closure->variables_.Remove(local); | |
| 586 new_parent->variables_.Add(new_parent->zone(), local); | |
| 568 } | 587 } |
| 569 temps->Rewind(top_temp_); | |
| 570 } | 588 } |
| 589 outer_closure->locals_.Rewind(top_local_); | |
| 590 outer_closure->decls_.Rewind(top_decl_); | |
| 571 } | 591 } |
| 572 | 592 |
| 573 void Scope::ReplaceOuterScope(Scope* outer) { | 593 void Scope::ReplaceOuterScope(Scope* outer) { |
| 574 DCHECK_NOT_NULL(outer); | 594 DCHECK_NOT_NULL(outer); |
| 575 DCHECK_NOT_NULL(outer_scope_); | 595 DCHECK_NOT_NULL(outer_scope_); |
| 576 DCHECK(!already_resolved_); | 596 DCHECK(!already_resolved_); |
| 577 DCHECK(!outer->already_resolved_); | 597 DCHECK(!outer->already_resolved_); |
| 578 DCHECK(!outer_scope_->already_resolved_); | 598 DCHECK(!outer_scope_->already_resolved_); |
| 579 outer_scope_->RemoveInnerScope(this); | 599 outer_scope_->RemoveInnerScope(this); |
| 580 outer->AddInnerScope(this); | 600 outer->AddInnerScope(this); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 741 } | 761 } |
| 742 | 762 |
| 743 | 763 |
| 744 Variable* Scope::NewTemporary(const AstRawString* name) { | 764 Variable* Scope::NewTemporary(const AstRawString* name) { |
| 745 DeclarationScope* scope = GetClosureScope(); | 765 DeclarationScope* scope = GetClosureScope(); |
| 746 Variable* var = new(zone()) Variable(scope, | 766 Variable* var = new(zone()) Variable(scope, |
| 747 name, | 767 name, |
| 748 TEMPORARY, | 768 TEMPORARY, |
| 749 Variable::NORMAL, | 769 Variable::NORMAL, |
| 750 kCreatedInitialized); | 770 kCreatedInitialized); |
| 751 scope->AddTemporary(var); | 771 scope->AddLocal(var); |
|
adamk
2016/08/25 17:37:10
This means that it's now possible to close over te
adamk
2016/08/25 17:40:12
Okay, I was confused, these still aren't lookup-ab
| |
| 752 return var; | 772 return var; |
| 753 } | 773 } |
| 754 | 774 |
| 755 void Scope::AddDeclaration(Declaration* declaration) { | 775 void Scope::AddDeclaration(Declaration* declaration) { |
| 756 DCHECK(!already_resolved_); | 776 DCHECK(!already_resolved_); |
| 757 decls_.Add(declaration, zone()); | 777 decls_.Add(declaration, zone()); |
| 758 } | 778 } |
| 759 | 779 |
| 760 | 780 |
| 761 Declaration* Scope::CheckConflictingVarDeclarations() { | 781 Declaration* Scope::CheckConflictingVarDeclarations() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 } | 823 } |
| 804 DCHECK(false); | 824 DCHECK(false); |
| 805 } | 825 } |
| 806 } | 826 } |
| 807 return nullptr; | 827 return nullptr; |
| 808 } | 828 } |
| 809 | 829 |
| 810 void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, | 830 void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals, |
| 811 ZoneList<Variable*>* context_locals, | 831 ZoneList<Variable*>* context_locals, |
| 812 ZoneList<Variable*>* context_globals) { | 832 ZoneList<Variable*>* context_globals) { |
| 813 DCHECK(stack_locals != NULL); | 833 // TODO(verwaest): Just pass out locals_ directly and walk it? |
| 814 DCHECK(context_locals != NULL); | 834 DCHECK_NOT_NULL(stack_locals); |
| 815 DCHECK(context_globals != NULL); | 835 DCHECK_NOT_NULL(context_locals); |
| 836 DCHECK_NOT_NULL(context_globals); | |
| 816 | 837 |
| 817 // Collect temporaries which are always allocated on the stack, unless the | 838 for (int i = 0; i < locals_.length(); i++) { |
| 818 // context as a whole has forced context allocation. | 839 Variable* var = locals_[i]; |
| 819 if (is_declaration_scope()) { | |
| 820 ZoneList<Variable*>* temps = AsDeclarationScope()->temps(); | |
| 821 for (int i = 0; i < temps->length(); i++) { | |
| 822 Variable* var = (*temps)[i]; | |
| 823 if (var->is_used()) { | |
| 824 if (var->IsContextSlot()) { | |
| 825 DCHECK(has_forced_context_allocation()); | |
| 826 context_locals->Add(var, zone()); | |
| 827 } else if (var->IsStackLocal()) { | |
| 828 stack_locals->Add(var, zone()); | |
| 829 } else { | |
| 830 DCHECK(var->IsParameter()); | |
| 831 } | |
| 832 } | |
| 833 } | |
| 834 } | |
| 835 | |
| 836 for (int i = 0; i < ordered_variables_.length(); i++) { | |
| 837 Variable* var = ordered_variables_[i]; | |
| 838 if (var->IsStackLocal()) { | 840 if (var->IsStackLocal()) { |
| 839 stack_locals->Add(var, zone()); | 841 stack_locals->Add(var, zone()); |
| 840 } else if (var->IsContextSlot()) { | 842 } else if (var->IsContextSlot()) { |
| 841 context_locals->Add(var, zone()); | 843 context_locals->Add(var, zone()); |
| 842 } else if (var->IsGlobalSlot()) { | 844 } else if (var->IsGlobalSlot()) { |
| 843 context_globals->Add(var, zone()); | 845 context_globals->Add(var, zone()); |
| 844 } | 846 } |
| 845 } | 847 } |
| 846 } | 848 } |
| 847 | 849 |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1154 PrintF("%d heap slots (including %d global slots)\n", num_heap_slots_, | 1156 PrintF("%d heap slots (including %d global slots)\n", num_heap_slots_, |
| 1155 num_global_slots_); | 1157 num_global_slots_); |
| 1156 } | 1158 } |
| 1157 | 1159 |
| 1158 // Print locals. | 1160 // Print locals. |
| 1159 if (function != nullptr) { | 1161 if (function != nullptr) { |
| 1160 Indent(n1, "// function var:\n"); | 1162 Indent(n1, "// function var:\n"); |
| 1161 PrintVar(n1, function); | 1163 PrintVar(n1, function); |
| 1162 } | 1164 } |
| 1163 | 1165 |
| 1164 if (is_declaration_scope()) { | |
| 1165 bool printed_header = false; | |
| 1166 ZoneList<Variable*>* temps = AsDeclarationScope()->temps(); | |
| 1167 for (int i = 0; i < temps->length(); i++) { | |
| 1168 if (!printed_header) { | |
| 1169 printed_header = true; | |
| 1170 Indent(n1, "// temporary vars:\n"); | |
| 1171 } | |
| 1172 PrintVar(n1, (*temps)[i]); | |
| 1173 } | |
| 1174 } | |
| 1175 | |
| 1176 if (variables_.Start() != NULL) { | 1166 if (variables_.Start() != NULL) { |
| 1177 Indent(n1, "// local vars:\n"); | 1167 Indent(n1, "// local vars:\n"); |
| 1178 PrintMap(n1, &variables_, true); | 1168 PrintMap(n1, &variables_, true); |
| 1179 | 1169 |
| 1180 Indent(n1, "// dynamic vars:\n"); | 1170 Indent(n1, "// dynamic vars:\n"); |
| 1181 PrintMap(n1, &variables_, false); | 1171 PrintMap(n1, &variables_, false); |
| 1182 } | 1172 } |
| 1183 | 1173 |
| 1184 // Print inner scopes (disable by providing negative n). | 1174 // Print inner scopes (disable by providing negative n). |
| 1185 if (n >= 0) { | 1175 if (n >= 0) { |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1547 var->AllocateTo(VariableLocation::GLOBAL, num_heap_slots_++); | 1537 var->AllocateTo(VariableLocation::GLOBAL, num_heap_slots_++); |
| 1548 num_global_slots_++; | 1538 num_global_slots_++; |
| 1549 } else { | 1539 } else { |
| 1550 // There must be only DYNAMIC_GLOBAL in the script scope. | 1540 // There must be only DYNAMIC_GLOBAL in the script scope. |
| 1551 DCHECK(!is_script_scope() || DYNAMIC_GLOBAL == var->mode()); | 1541 DCHECK(!is_script_scope() || DYNAMIC_GLOBAL == var->mode()); |
| 1552 } | 1542 } |
| 1553 } | 1543 } |
| 1554 } | 1544 } |
| 1555 | 1545 |
| 1556 void Scope::AllocateNonParameterLocalsAndDeclaredGlobals() { | 1546 void Scope::AllocateNonParameterLocalsAndDeclaredGlobals() { |
| 1557 // All variables that have no rewrite yet are non-parameter locals. | 1547 for (int i = 0; i < locals_.length(); i++) { |
| 1558 if (is_declaration_scope()) { | 1548 AllocateNonParameterLocal(locals_[i]); |
| 1559 ZoneList<Variable*>* temps = AsDeclarationScope()->temps(); | 1549 } |
| 1560 for (int i = 0; i < temps->length(); i++) { | 1550 |
| 1561 AllocateNonParameterLocal((*temps)[i]); | 1551 if (FLAG_global_var_shortcuts) { |
| 1552 for (int i = 0; i < locals_.length(); i++) { | |
| 1553 AllocateDeclaredGlobal(locals_[i]); | |
| 1562 } | 1554 } |
| 1563 } | 1555 } |
| 1564 | 1556 |
| 1565 for (int i = 0; i < ordered_variables_.length(); i++) { | |
| 1566 AllocateNonParameterLocal(ordered_variables_[i]); | |
| 1567 } | |
| 1568 | |
| 1569 if (FLAG_global_var_shortcuts) { | |
| 1570 for (int i = 0; i < ordered_variables_.length(); i++) { | |
| 1571 AllocateDeclaredGlobal(ordered_variables_[i]); | |
| 1572 } | |
| 1573 } | |
| 1574 | |
| 1575 if (is_declaration_scope()) { | 1557 if (is_declaration_scope()) { |
| 1576 AsDeclarationScope()->AllocateLocals(); | 1558 AsDeclarationScope()->AllocateLocals(); |
| 1577 } | 1559 } |
| 1578 } | 1560 } |
| 1579 | 1561 |
| 1580 void DeclarationScope::AllocateLocals() { | 1562 void DeclarationScope::AllocateLocals() { |
| 1581 // For now, function_ must be allocated at the very end. If it gets | 1563 // For now, function_ must be allocated at the very end. If it gets |
| 1582 // allocated in the context, it must be the last slot in the context, | 1564 // allocated in the context, it must be the last slot in the context, |
| 1583 // because of the current ScopeInfo implementation (see | 1565 // because of the current ScopeInfo implementation (see |
| 1584 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). | 1566 // ScopeInfo::ScopeInfo(FunctionScope* scope) constructor). |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1673 function != nullptr && function->IsContextSlot(); | 1655 function != nullptr && function->IsContextSlot(); |
| 1674 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1656 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
| 1675 (is_function_var_in_context ? 1 : 0); | 1657 (is_function_var_in_context ? 1 : 0); |
| 1676 } | 1658 } |
| 1677 | 1659 |
| 1678 | 1660 |
| 1679 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1661 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
| 1680 | 1662 |
| 1681 } // namespace internal | 1663 } // namespace internal |
| 1682 } // namespace v8 | 1664 } // namespace v8 |
| OLD | NEW |