Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: src/ast/scopes.cc

Issue 2345233003: [base] Move hashmap allocator to a field (Closed)
Patch Set: Remove zone arguments where the parameters were removed so that the bloody thing compiles again Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/scopes.h ('k') | src/base/hashmap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 18 matching lines...) Expand all
29 29
30 Variable* VariableMap::Declare(Zone* zone, Scope* scope, 30 Variable* VariableMap::Declare(Zone* zone, Scope* scope,
31 const AstRawString* name, VariableMode mode, 31 const AstRawString* name, VariableMode mode,
32 VariableKind kind, 32 VariableKind kind,
33 InitializationFlag initialization_flag, 33 InitializationFlag initialization_flag,
34 MaybeAssignedFlag maybe_assigned_flag, 34 MaybeAssignedFlag maybe_assigned_flag,
35 bool* added) { 35 bool* added) {
36 // AstRawStrings are unambiguous, i.e., the same string is always represented 36 // AstRawStrings are unambiguous, i.e., the same string is always represented
37 // by the same AstRawString*. 37 // by the same AstRawString*.
38 // FIXME(marja): fix the type of Lookup. 38 // FIXME(marja): fix the type of Lookup.
39 Entry* p = 39 Entry* p = ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name),
40 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), 40 name->hash());
41 ZoneAllocationPolicy(zone));
42 if (added) *added = p->value == nullptr; 41 if (added) *added = p->value == nullptr;
43 if (p->value == nullptr) { 42 if (p->value == nullptr) {
44 // The variable has not been declared yet -> insert it. 43 // The variable has not been declared yet -> insert it.
45 DCHECK_EQ(name, p->key); 44 DCHECK_EQ(name, p->key);
46 p->value = new (zone) Variable(scope, name, mode, kind, initialization_flag, 45 p->value = new (zone) Variable(scope, name, mode, kind, initialization_flag,
47 maybe_assigned_flag); 46 maybe_assigned_flag);
48 } 47 }
49 return reinterpret_cast<Variable*>(p->value); 48 return reinterpret_cast<Variable*>(p->value);
50 } 49 }
51 50
52 void VariableMap::Remove(Variable* var) { 51 void VariableMap::Remove(Variable* var) {
53 const AstRawString* name = var->raw_name(); 52 const AstRawString* name = var->raw_name();
54 ZoneHashMap::Remove(const_cast<AstRawString*>(name), name->hash()); 53 ZoneHashMap::Remove(const_cast<AstRawString*>(name), name->hash());
55 } 54 }
56 55
57 void VariableMap::Add(Zone* zone, Variable* var) { 56 void VariableMap::Add(Variable* var) {
58 const AstRawString* name = var->raw_name(); 57 const AstRawString* name = var->raw_name();
59 Entry* p = 58 Entry* p = ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name),
60 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), 59 name->hash());
61 ZoneAllocationPolicy(zone));
62 DCHECK_NULL(p->value); 60 DCHECK_NULL(p->value);
63 DCHECK_EQ(name, p->key); 61 DCHECK_EQ(name, p->key);
64 p->value = var; 62 p->value = var;
65 } 63 }
66 64
67 Variable* VariableMap::Lookup(const AstRawString* name) { 65 Variable* VariableMap::Lookup(const AstRawString* name) {
68 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash()); 66 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash());
69 if (p != NULL) { 67 if (p != NULL) {
70 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name); 68 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name);
71 DCHECK(p->value != NULL); 69 DCHECK(p->value != NULL);
72 return reinterpret_cast<Variable*>(p->value); 70 return reinterpret_cast<Variable*>(p->value);
73 } 71 }
74 return NULL; 72 return NULL;
75 } 73 }
76 74
77 SloppyBlockFunctionMap::SloppyBlockFunctionMap(Zone* zone) 75 SloppyBlockFunctionMap::SloppyBlockFunctionMap(Zone* zone)
78 : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)) {} 76 : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)) {}
79 77
80 void SloppyBlockFunctionMap::Declare(Zone* zone, const AstRawString* name, 78 void SloppyBlockFunctionMap::Declare(const AstRawString* name,
81 SloppyBlockFunctionStatement* stmt) { 79 SloppyBlockFunctionStatement* stmt) {
82 // AstRawStrings are unambiguous, i.e., the same string is always represented 80 // AstRawStrings are unambiguous, i.e., the same string is always represented
83 // by the same AstRawString*. 81 // by the same AstRawString*.
84 Entry* p = 82 Entry* p = ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name),
85 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), 83 name->hash());
86 ZoneAllocationPolicy(zone));
87 stmt->set_next(static_cast<SloppyBlockFunctionStatement*>(p->value)); 84 stmt->set_next(static_cast<SloppyBlockFunctionStatement*>(p->value));
88 p->value = stmt; 85 p->value = stmt;
89 } 86 }
90 87
91 88
92 // ---------------------------------------------------------------------------- 89 // ----------------------------------------------------------------------------
93 // Implementation of Scope 90 // Implementation of Scope
94 91
95 Scope::Scope(Zone* zone) 92 Scope::Scope(Zone* zone)
96 : zone_(zone), 93 : zone_(zone),
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 DeclarationScope* outer_closure = outer_scope_->GetClosureScope(); 684 DeclarationScope* outer_closure = outer_scope_->GetClosureScope();
688 for (int i = top_local_; i < outer_closure->locals_.length(); i++) { 685 for (int i = top_local_; i < outer_closure->locals_.length(); i++) {
689 Variable* local = outer_closure->locals_.at(i); 686 Variable* local = outer_closure->locals_.at(i);
690 DCHECK(local->mode() == TEMPORARY || local->mode() == VAR); 687 DCHECK(local->mode() == TEMPORARY || local->mode() == VAR);
691 DCHECK_EQ(local->scope(), local->scope()->GetClosureScope()); 688 DCHECK_EQ(local->scope(), local->scope()->GetClosureScope());
692 DCHECK_NE(local->scope(), new_parent); 689 DCHECK_NE(local->scope(), new_parent);
693 local->set_scope(new_parent); 690 local->set_scope(new_parent);
694 new_parent->AddLocal(local); 691 new_parent->AddLocal(local);
695 if (local->mode() == VAR) { 692 if (local->mode() == VAR) {
696 outer_closure->variables_.Remove(local); 693 outer_closure->variables_.Remove(local);
697 new_parent->variables_.Add(new_parent->zone(), local); 694 new_parent->variables_.Add(local);
698 } 695 }
699 } 696 }
700 outer_closure->locals_.Rewind(top_local_); 697 outer_closure->locals_.Rewind(top_local_);
701 outer_closure->decls_.Rewind(top_decl_); 698 outer_closure->decls_.Rewind(top_decl_);
702 } 699 }
703 700
704 void Scope::ReplaceOuterScope(Scope* outer) { 701 void Scope::ReplaceOuterScope(Scope* outer) {
705 DCHECK_NOT_NULL(outer); 702 DCHECK_NOT_NULL(outer);
706 DCHECK_NOT_NULL(outer_scope_); 703 DCHECK_NOT_NULL(outer_scope_);
707 DCHECK(!already_resolved_); 704 DCHECK(!already_resolved_);
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 Variable* function = 1808 Variable* function =
1812 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; 1809 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr;
1813 bool is_function_var_in_context = 1810 bool is_function_var_in_context =
1814 function != nullptr && function->IsContextSlot(); 1811 function != nullptr && function->IsContextSlot();
1815 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - 1812 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS -
1816 (is_function_var_in_context ? 1 : 0); 1813 (is_function_var_in_context ? 1 : 0);
1817 } 1814 }
1818 1815
1819 } // namespace internal 1816 } // namespace internal
1820 } // namespace v8 1817 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/scopes.h ('k') | src/base/hashmap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698