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" |
11 #include "src/bootstrapper.h" | 11 #include "src/bootstrapper.h" |
12 #include "src/messages.h" | 12 #include "src/messages.h" |
13 #include "src/parsing/parse-info.h" | 13 #include "src/parsing/parse-info.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 | 17 |
18 // ---------------------------------------------------------------------------- | 18 // ---------------------------------------------------------------------------- |
19 // Implementation of LocalsMap | 19 // Implementation of LocalsMap |
20 // | 20 // |
21 // Note: We are storing the handle locations as key values in the hash map. | 21 // Note: We are storing the handle locations as key values in the hash map. |
22 // When inserting a new variable via Declare(), we rely on the fact that | 22 // When inserting a new variable via Declare(), we rely on the fact that |
23 // the handle location remains alive for the duration of that variable | 23 // the handle location remains alive for the duration of that variable |
24 // use. Because a Variable holding a handle with the same location exists | 24 // use. Because a Variable holding a handle with the same location exists |
25 // this is ensured. | 25 // this is ensured. |
26 | 26 |
27 VariableMap::VariableMap(Zone* zone) | 27 VariableMap::VariableMap(Zone* zone) |
28 : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)) {} | 28 : ZoneHashMap(8, ZoneAllocationPolicy(zone)) {} |
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. |
(...skipping 29 matching lines...) Loading... |
68 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash()); | 68 Entry* p = ZoneHashMap::Lookup(const_cast<AstRawString*>(name), name->hash()); |
69 if (p != NULL) { | 69 if (p != NULL) { |
70 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name); | 70 DCHECK(reinterpret_cast<const AstRawString*>(p->key) == name); |
71 DCHECK(p->value != NULL); | 71 DCHECK(p->value != NULL); |
72 return reinterpret_cast<Variable*>(p->value); | 72 return reinterpret_cast<Variable*>(p->value); |
73 } | 73 } |
74 return NULL; | 74 return NULL; |
75 } | 75 } |
76 | 76 |
77 SloppyBlockFunctionMap::SloppyBlockFunctionMap(Zone* zone) | 77 SloppyBlockFunctionMap::SloppyBlockFunctionMap(Zone* zone) |
78 : ZoneHashMap(ZoneHashMap::PointersMatch, 8, ZoneAllocationPolicy(zone)) {} | 78 : ZoneHashMap(8, ZoneAllocationPolicy(zone)) {} |
79 | 79 |
80 void SloppyBlockFunctionMap::Declare(Zone* zone, const AstRawString* name, | 80 void SloppyBlockFunctionMap::Declare(Zone* zone, const AstRawString* name, |
81 SloppyBlockFunctionStatement* stmt) { | 81 SloppyBlockFunctionStatement* stmt) { |
82 // AstRawStrings are unambiguous, i.e., the same string is always represented | 82 // AstRawStrings are unambiguous, i.e., the same string is always represented |
83 // by the same AstRawString*. | 83 // by the same AstRawString*. |
84 Entry* p = | 84 Entry* p = |
85 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), | 85 ZoneHashMap::LookupOrInsert(const_cast<AstRawString*>(name), name->hash(), |
86 ZoneAllocationPolicy(zone)); | 86 ZoneAllocationPolicy(zone)); |
87 stmt->set_next(static_cast<SloppyBlockFunctionStatement*>(p->value)); | 87 stmt->set_next(static_cast<SloppyBlockFunctionStatement*>(p->value)); |
88 p->value = stmt; | 88 p->value = stmt; |
(...skipping 1739 matching lines...) Loading... |
1828 Variable* function = | 1828 Variable* function = |
1829 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; | 1829 is_function_scope() ? AsDeclarationScope()->function_var() : nullptr; |
1830 bool is_function_var_in_context = | 1830 bool is_function_var_in_context = |
1831 function != nullptr && function->IsContextSlot(); | 1831 function != nullptr && function->IsContextSlot(); |
1832 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - | 1832 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - |
1833 (is_function_var_in_context ? 1 : 0); | 1833 (is_function_var_in_context ? 1 : 0); |
1834 } | 1834 } |
1835 | 1835 |
1836 } // namespace internal | 1836 } // namespace internal |
1837 } // namespace v8 | 1837 } // namespace v8 |
OLD | NEW |