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 #ifndef V8_INTERFACE_H_ | 5 #ifndef V8_INTERFACE_H_ |
6 #define V8_INTERFACE_H_ | 6 #define V8_INTERFACE_H_ |
7 | 7 |
8 #include "src/ast-value-factory.h" | 8 #include "src/ast-value-factory.h" |
9 #include "src/zone-inl.h" // For operator new. | 9 #include "src/zone-inl.h" // For operator new. |
10 | 10 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 } | 88 } |
89 | 89 |
90 // Do not allow any further refinements, directly or through unification. | 90 // Do not allow any further refinements, directly or through unification. |
91 void Freeze(bool* ok) { | 91 void Freeze(bool* ok) { |
92 *ok = IsValue() || IsModule(); | 92 *ok = IsValue() || IsModule(); |
93 if (*ok) Chase()->flags_ |= FROZEN; | 93 if (*ok) Chase()->flags_ |= FROZEN; |
94 } | 94 } |
95 | 95 |
96 // Assign an index. | 96 // Assign an index. |
97 void Allocate(int index) { | 97 void Allocate(int index) { |
98 ASSERT(IsModule() && IsFrozen() && Chase()->index_ == -1); | 98 DCHECK(IsModule() && IsFrozen() && Chase()->index_ == -1); |
99 Chase()->index_ = index; | 99 Chase()->index_ = index; |
100 } | 100 } |
101 | 101 |
102 // --------------------------------------------------------------------------- | 102 // --------------------------------------------------------------------------- |
103 // Accessors. | 103 // Accessors. |
104 | 104 |
105 // Check whether this is still a fully undetermined type. | 105 // Check whether this is still a fully undetermined type. |
106 bool IsUnknown() { return Chase()->flags_ == NONE; } | 106 bool IsUnknown() { return Chase()->flags_ == NONE; } |
107 | 107 |
108 // Check whether this is a value type. | 108 // Check whether this is a value type. |
109 bool IsValue() { return Chase()->flags_ & VALUE; } | 109 bool IsValue() { return Chase()->flags_ & VALUE; } |
110 | 110 |
111 // Check whether this is a constant type. | 111 // Check whether this is a constant type. |
112 bool IsConst() { return Chase()->flags_ & CONST; } | 112 bool IsConst() { return Chase()->flags_ & CONST; } |
113 | 113 |
114 // Check whether this is a module type. | 114 // Check whether this is a module type. |
115 bool IsModule() { return Chase()->flags_ & MODULE; } | 115 bool IsModule() { return Chase()->flags_ & MODULE; } |
116 | 116 |
117 // Check whether this is closed (i.e. fully determined). | 117 // Check whether this is closed (i.e. fully determined). |
118 bool IsFrozen() { return Chase()->flags_ & FROZEN; } | 118 bool IsFrozen() { return Chase()->flags_ & FROZEN; } |
119 | 119 |
120 bool IsUnified(Interface* that) { | 120 bool IsUnified(Interface* that) { |
121 return Chase() == that->Chase() | 121 return Chase() == that->Chase() |
122 || (this->IsValue() == that->IsValue() && | 122 || (this->IsValue() == that->IsValue() && |
123 this->IsConst() == that->IsConst()); | 123 this->IsConst() == that->IsConst()); |
124 } | 124 } |
125 | 125 |
126 int Length() { | 126 int Length() { |
127 ASSERT(IsModule() && IsFrozen()); | 127 DCHECK(IsModule() && IsFrozen()); |
128 ZoneHashMap* exports = Chase()->exports_; | 128 ZoneHashMap* exports = Chase()->exports_; |
129 return exports ? exports->occupancy() : 0; | 129 return exports ? exports->occupancy() : 0; |
130 } | 130 } |
131 | 131 |
132 // The context slot in the hosting global context pointing to this module. | 132 // The context slot in the hosting global context pointing to this module. |
133 int Index() { | 133 int Index() { |
134 ASSERT(IsModule() && IsFrozen()); | 134 DCHECK(IsModule() && IsFrozen()); |
135 return Chase()->index_; | 135 return Chase()->index_; |
136 } | 136 } |
137 | 137 |
138 // Look up an exported name. Returns NULL if not (yet) defined. | 138 // Look up an exported name. Returns NULL if not (yet) defined. |
139 Interface* Lookup(Handle<String> name, Zone* zone); | 139 Interface* Lookup(Handle<String> name, Zone* zone); |
140 | 140 |
141 // --------------------------------------------------------------------------- | 141 // --------------------------------------------------------------------------- |
142 // Iterators. | 142 // Iterators. |
143 | 143 |
144 // Use like: | 144 // Use like: |
145 // for (auto it = interface->iterator(); !it.done(); it.Advance()) { | 145 // for (auto it = interface->iterator(); !it.done(); it.Advance()) { |
146 // ... it.name() ... it.interface() ... | 146 // ... it.name() ... it.interface() ... |
147 // } | 147 // } |
148 class Iterator { | 148 class Iterator { |
149 public: | 149 public: |
150 bool done() const { return entry_ == NULL; } | 150 bool done() const { return entry_ == NULL; } |
151 const AstRawString* name() const { | 151 const AstRawString* name() const { |
152 ASSERT(!done()); | 152 DCHECK(!done()); |
153 return static_cast<const AstRawString*>(entry_->key); | 153 return static_cast<const AstRawString*>(entry_->key); |
154 } | 154 } |
155 Interface* interface() const { | 155 Interface* interface() const { |
156 ASSERT(!done()); | 156 DCHECK(!done()); |
157 return static_cast<Interface*>(entry_->value); | 157 return static_cast<Interface*>(entry_->value); |
158 } | 158 } |
159 void Advance() { entry_ = exports_->Next(entry_); } | 159 void Advance() { entry_ = exports_->Next(entry_); } |
160 | 160 |
161 private: | 161 private: |
162 friend class Interface; | 162 friend class Interface; |
163 explicit Iterator(const ZoneHashMap* exports) | 163 explicit Iterator(const ZoneHashMap* exports) |
164 : exports_(exports), entry_(exports ? exports->Start() : NULL) {} | 164 : exports_(exports), entry_(exports ? exports->Start() : NULL) {} |
165 | 165 |
166 const ZoneHashMap* exports_; | 166 const ZoneHashMap* exports_; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 } | 210 } |
211 | 211 |
212 void DoAdd(const void* name, uint32_t hash, Interface* interface, Zone* zone, | 212 void DoAdd(const void* name, uint32_t hash, Interface* interface, Zone* zone, |
213 bool* ok); | 213 bool* ok); |
214 void DoUnify(Interface* that, bool* ok, Zone* zone); | 214 void DoUnify(Interface* that, bool* ok, Zone* zone); |
215 }; | 215 }; |
216 | 216 |
217 } } // namespace v8::internal | 217 } } // namespace v8::internal |
218 | 218 |
219 #endif // V8_INTERFACE_H_ | 219 #endif // V8_INTERFACE_H_ |
OLD | NEW |