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/ast/ast.h" | 10 #include "src/ast/ast.h" |
(...skipping 18 matching lines...) Expand all Loading... |
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(Zone* zone, 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(Zone* zone, 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 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
OLD | NEW |