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/zone-inl.h" // For operator new. | 9 #include "src/zone-inl.h" // For operator new. |
9 | 10 |
10 namespace v8 { | 11 namespace v8 { |
11 namespace internal { | 12 namespace internal { |
12 | 13 |
13 | 14 |
14 // This class implements the following abstract grammar of interfaces | 15 // This class implements the following abstract grammar of interfaces |
15 // (i.e. module types): | 16 // (i.e. module types): |
16 // interface ::= UNDETERMINED | VALUE | CONST | MODULE(exports) | 17 // interface ::= UNDETERMINED | VALUE | CONST | MODULE(exports) |
17 // exports ::= {name : interface, ...} | 18 // exports ::= {name : interface, ...} |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 53 |
53 static Interface* NewModule(Zone* zone) { | 54 static Interface* NewModule(Zone* zone) { |
54 return new(zone) Interface(MODULE); | 55 return new(zone) Interface(MODULE); |
55 } | 56 } |
56 | 57 |
57 // --------------------------------------------------------------------------- | 58 // --------------------------------------------------------------------------- |
58 // Mutators. | 59 // Mutators. |
59 | 60 |
60 // Add a name to the list of exports. If it already exists, unify with | 61 // Add a name to the list of exports. If it already exists, unify with |
61 // interface, otherwise insert unless this is closed. | 62 // interface, otherwise insert unless this is closed. |
62 void Add(Handle<String> name, Interface* interface, Zone* zone, bool* ok) { | 63 void Add(const AstString* name, Interface* interface, Zone* zone, |
63 DoAdd(name.location(), name->Hash(), interface, zone, ok); | 64 bool* ok) { |
| 65 DoAdd(name, name->hash(), interface, zone, ok); |
64 } | 66 } |
65 | 67 |
66 // Unify with another interface. If successful, both interface objects will | 68 // Unify with another interface. If successful, both interface objects will |
67 // represent the same type, and changes to one are reflected in the other. | 69 // represent the same type, and changes to one are reflected in the other. |
68 void Unify(Interface* that, Zone* zone, bool* ok); | 70 void Unify(Interface* that, Zone* zone, bool* ok); |
69 | 71 |
70 // Determine this interface to be a value interface. | 72 // Determine this interface to be a value interface. |
71 void MakeValue(bool* ok) { | 73 void MakeValue(bool* ok) { |
72 *ok = !IsModule(); | 74 *ok = !IsModule(); |
73 if (*ok) Chase()->flags_ |= VALUE; | 75 if (*ok) Chase()->flags_ |= VALUE; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // --------------------------------------------------------------------------- | 141 // --------------------------------------------------------------------------- |
140 // Iterators. | 142 // Iterators. |
141 | 143 |
142 // Use like: | 144 // Use like: |
143 // for (auto it = interface->iterator(); !it.done(); it.Advance()) { | 145 // for (auto it = interface->iterator(); !it.done(); it.Advance()) { |
144 // ... it.name() ... it.interface() ... | 146 // ... it.name() ... it.interface() ... |
145 // } | 147 // } |
146 class Iterator { | 148 class Iterator { |
147 public: | 149 public: |
148 bool done() const { return entry_ == NULL; } | 150 bool done() const { return entry_ == NULL; } |
149 Handle<String> name() const { | 151 const AstString* name() const { |
150 ASSERT(!done()); | 152 ASSERT(!done()); |
151 return Handle<String>(*static_cast<String**>(entry_->key)); | 153 return static_cast<const AstString*>(entry_->key); |
152 } | 154 } |
153 Interface* interface() const { | 155 Interface* interface() const { |
154 ASSERT(!done()); | 156 ASSERT(!done()); |
155 return static_cast<Interface*>(entry_->value); | 157 return static_cast<Interface*>(entry_->value); |
156 } | 158 } |
157 void Advance() { entry_ = exports_->Next(entry_); } | 159 void Advance() { entry_ = exports_->Next(entry_); } |
158 | 160 |
159 private: | 161 private: |
160 friend class Interface; | 162 friend class Interface; |
161 explicit Iterator(const ZoneHashMap* exports) | 163 explicit Iterator(const ZoneHashMap* exports) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 #endif | 202 #endif |
201 } | 203 } |
202 | 204 |
203 Interface* Chase() { | 205 Interface* Chase() { |
204 Interface* result = this; | 206 Interface* result = this; |
205 while (result->forward_ != NULL) result = result->forward_; | 207 while (result->forward_ != NULL) result = result->forward_; |
206 if (result != this) forward_ = result; // On-the-fly path compression. | 208 if (result != this) forward_ = result; // On-the-fly path compression. |
207 return result; | 209 return result; |
208 } | 210 } |
209 | 211 |
210 void DoAdd(void* name, uint32_t hash, Interface* interface, Zone* zone, | 212 void DoAdd(const void* name, uint32_t hash, Interface* interface, Zone* zone, |
211 bool* ok); | 213 bool* ok); |
212 void DoUnify(Interface* that, bool* ok, Zone* zone); | 214 void DoUnify(Interface* that, bool* ok, Zone* zone); |
213 }; | 215 }; |
214 | 216 |
215 } } // namespace v8::internal | 217 } } // namespace v8::internal |
216 | 218 |
217 #endif // V8_INTERFACE_H_ | 219 #endif // V8_INTERFACE_H_ |
OLD | NEW |