| 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 { |
| 11 namespace internal { | 11 namespace internal { |
| 12 | 12 |
| 13 | 13 |
| 14 class AstRawString; | 14 class AstRawString; |
| 15 | 15 |
| 16 | 16 |
| 17 class ModuleDescriptor : public ZoneObject { | 17 class ModuleDescriptor : public ZoneObject { |
| 18 public: | 18 public: |
| 19 // --------------------------------------------------------------------------- | 19 // --------------------------------------------------------------------------- |
| 20 // Factory methods. | 20 // Factory methods. |
| 21 | 21 |
| 22 static ModuleDescriptor* New(Zone* zone) { | 22 static ModuleDescriptor* New(Zone* zone) { |
| 23 return new (zone) ModuleDescriptor(); | 23 return new (zone) ModuleDescriptor(zone); |
| 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 AddLocalExport(const AstRawString* export_name, | 31 void AddLocalExport(const AstRawString* export_name, |
| 32 const AstRawString* local_name, Zone* zone, bool* ok); | 32 const AstRawString* local_name, Zone* zone, bool* ok); |
| 33 | 33 |
| 34 // Add module_specifier to the list of requested modules, |
| 35 // if not already present. |
| 36 void AddModuleRequest(const AstRawString* module_specifier, Zone* zone); |
| 37 |
| 34 // Do not allow any further refinements, directly or through unification. | 38 // Do not allow any further refinements, directly or through unification. |
| 35 void Freeze() { frozen_ = true; } | 39 void Freeze() { frozen_ = true; } |
| 36 | 40 |
| 37 // Assign an index. | 41 // Assign an index. |
| 38 void Allocate(int index) { | 42 void Allocate(int index) { |
| 39 DCHECK(IsFrozen() && index_ == -1); | 43 DCHECK(IsFrozen() && index_ == -1); |
| 40 index_ = index; | 44 index_ = index; |
| 41 } | 45 } |
| 42 | 46 |
| 43 // --------------------------------------------------------------------------- | 47 // --------------------------------------------------------------------------- |
| (...skipping 10 matching lines...) Expand all Loading... |
| 54 | 58 |
| 55 // The context slot in the hosting script context pointing to this module. | 59 // The context slot in the hosting script context pointing to this module. |
| 56 int Index() { | 60 int Index() { |
| 57 DCHECK(IsFrozen()); | 61 DCHECK(IsFrozen()); |
| 58 return index_; | 62 return index_; |
| 59 } | 63 } |
| 60 | 64 |
| 61 const AstRawString* LookupLocalExport(const AstRawString* export_name, | 65 const AstRawString* LookupLocalExport(const AstRawString* export_name, |
| 62 Zone* zone); | 66 Zone* zone); |
| 63 | 67 |
| 68 const ZoneList<const AstRawString*>& requested_modules() const { |
| 69 return requested_modules_; |
| 70 } |
| 71 |
| 64 // --------------------------------------------------------------------------- | 72 // --------------------------------------------------------------------------- |
| 65 // Iterators. | 73 // Iterators. |
| 66 | 74 |
| 67 // Use like: | 75 // Use like: |
| 68 // for (auto it = descriptor->iterator(); !it.done(); it.Advance()) { | 76 // for (auto it = descriptor->iterator(); !it.done(); it.Advance()) { |
| 69 // ... it.name() ... | 77 // ... it.name() ... |
| 70 // } | 78 // } |
| 71 class Iterator { | 79 class Iterator { |
| 72 public: | 80 public: |
| 73 bool done() const { return entry_ == NULL; } | 81 bool done() const { return entry_ == NULL; } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 88 | 96 |
| 89 const ZoneHashMap* exports_; | 97 const ZoneHashMap* exports_; |
| 90 ZoneHashMap::Entry* entry_; | 98 ZoneHashMap::Entry* entry_; |
| 91 }; | 99 }; |
| 92 | 100 |
| 93 Iterator iterator() const { return Iterator(this->exports_); } | 101 Iterator iterator() const { return Iterator(this->exports_); } |
| 94 | 102 |
| 95 // --------------------------------------------------------------------------- | 103 // --------------------------------------------------------------------------- |
| 96 // Implementation. | 104 // Implementation. |
| 97 private: | 105 private: |
| 106 explicit ModuleDescriptor(Zone* zone) |
| 107 : frozen_(false), |
| 108 exports_(NULL), |
| 109 requested_modules_(1, zone), |
| 110 index_(-1) {} |
| 111 |
| 98 bool frozen_; | 112 bool frozen_; |
| 99 ZoneHashMap* exports_; // Module exports and their types (allocated lazily) | 113 ZoneHashMap* exports_; // Module exports and their types (allocated lazily) |
| 114 ZoneList<const AstRawString*> requested_modules_; |
| 100 int index_; | 115 int index_; |
| 101 | |
| 102 ModuleDescriptor() : frozen_(false), exports_(NULL), index_(-1) {} | |
| 103 }; | 116 }; |
| 104 | 117 |
| 105 } } // namespace v8::internal | 118 } } // namespace v8::internal |
| 106 | 119 |
| 107 #endif // V8_MODULES_H_ | 120 #endif // V8_MODULES_H_ |
| OLD | NEW |