| 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_MODULES_H_ | 5 #ifndef V8_MODULES_H_ |
| 6 #define V8_MODULES_H_ | 6 #define V8_MODULES_H_ |
| 7 | 7 |
| 8 #include "src/zone.h" | 8 #include "src/zone.h" |
| 9 | 9 |
| 10 namespace v8 { | 10 namespace v8 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 static ModuleDescriptor* New(Zone* zone) { | 22 static ModuleDescriptor* New(Zone* zone) { |
| 23 return new (zone) ModuleDescriptor(); | 23 return new (zone) ModuleDescriptor(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 // --------------------------------------------------------------------------- | 26 // --------------------------------------------------------------------------- |
| 27 // Mutators. | 27 // Mutators. |
| 28 | 28 |
| 29 // Add a name to the list of exports. If it already exists, or this descriptor | 29 // Add a name to the list of exports. If it already exists, or this descriptor |
| 30 // is frozen, that's an error. | 30 // is frozen, that's an error. |
| 31 void Add(const AstRawString* name, Zone* zone, bool* ok); | 31 void AddLocalExport(const AstRawString* export_name, |
| 32 const AstRawString* local_name, Zone* zone, bool* ok); |
| 32 | 33 |
| 33 // Do not allow any further refinements, directly or through unification. | 34 // Do not allow any further refinements, directly or through unification. |
| 34 void Freeze() { frozen_ = true; } | 35 void Freeze() { frozen_ = true; } |
| 35 | 36 |
| 36 // Assign an index. | 37 // Assign an index. |
| 37 void Allocate(int index) { | 38 void Allocate(int index) { |
| 38 DCHECK(IsFrozen() && index_ == -1); | 39 DCHECK(IsFrozen() && index_ == -1); |
| 39 index_ = index; | 40 index_ = index; |
| 40 } | 41 } |
| 41 | 42 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 60 // --------------------------------------------------------------------------- | 61 // --------------------------------------------------------------------------- |
| 61 // Iterators. | 62 // Iterators. |
| 62 | 63 |
| 63 // Use like: | 64 // Use like: |
| 64 // for (auto it = descriptor->iterator(); !it.done(); it.Advance()) { | 65 // for (auto it = descriptor->iterator(); !it.done(); it.Advance()) { |
| 65 // ... it.name() ... | 66 // ... it.name() ... |
| 66 // } | 67 // } |
| 67 class Iterator { | 68 class Iterator { |
| 68 public: | 69 public: |
| 69 bool done() const { return entry_ == NULL; } | 70 bool done() const { return entry_ == NULL; } |
| 70 const AstRawString* name() const { | 71 const AstRawString* export_name() const { |
| 71 DCHECK(!done()); | 72 DCHECK(!done()); |
| 72 return static_cast<const AstRawString*>(entry_->key); | 73 return static_cast<const AstRawString*>(entry_->key); |
| 73 } | 74 } |
| 75 const AstRawString* local_name() const { |
| 76 DCHECK(!done()); |
| 77 return static_cast<const AstRawString*>(entry_->value); |
| 78 } |
| 74 void Advance() { entry_ = exports_->Next(entry_); } | 79 void Advance() { entry_ = exports_->Next(entry_); } |
| 75 | 80 |
| 76 private: | 81 private: |
| 77 friend class ModuleDescriptor; | 82 friend class ModuleDescriptor; |
| 78 explicit Iterator(const ZoneHashMap* exports) | 83 explicit Iterator(const ZoneHashMap* exports) |
| 79 : exports_(exports), entry_(exports ? exports->Start() : NULL) {} | 84 : exports_(exports), entry_(exports ? exports->Start() : NULL) {} |
| 80 | 85 |
| 81 const ZoneHashMap* exports_; | 86 const ZoneHashMap* exports_; |
| 82 ZoneHashMap::Entry* entry_; | 87 ZoneHashMap::Entry* entry_; |
| 83 }; | 88 }; |
| 84 | 89 |
| 85 Iterator iterator() const { return Iterator(this->exports_); } | 90 Iterator iterator() const { return Iterator(this->exports_); } |
| 86 | 91 |
| 87 // --------------------------------------------------------------------------- | 92 // --------------------------------------------------------------------------- |
| 88 // Implementation. | 93 // Implementation. |
| 89 private: | 94 private: |
| 90 bool frozen_; | 95 bool frozen_; |
| 91 ZoneHashMap* exports_; // Module exports and their types (allocated lazily) | 96 ZoneHashMap* exports_; // Module exports and their types (allocated lazily) |
| 92 int index_; | 97 int index_; |
| 93 | 98 |
| 94 ModuleDescriptor() : frozen_(false), exports_(NULL), index_(-1) {} | 99 ModuleDescriptor() : frozen_(false), exports_(NULL), index_(-1) {} |
| 95 }; | 100 }; |
| 96 | 101 |
| 97 } } // namespace v8::internal | 102 } } // namespace v8::internal |
| 98 | 103 |
| 99 #endif // V8_MODULES_H_ | 104 #endif // V8_MODULES_H_ |
| OLD | NEW |