| 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_AST_MODULES_H_ | 5 #ifndef V8_AST_MODULES_H_ |
| 6 #define V8_AST_MODULES_H_ | 6 #define V8_AST_MODULES_H_ |
| 7 | 7 |
| 8 #include "src/parsing/scanner.h" // Only for Scanner::Location. | 8 #include "src/parsing/scanner.h" // Only for Scanner::Location. |
| 9 #include "src/pending-compilation-error-handler.h" | 9 #include "src/pending-compilation-error-handler.h" |
| 10 #include "src/zone/zone-containers.h" | 10 #include "src/zone/zone-containers.h" |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 | 14 |
| 15 | 15 |
| 16 class AstRawString; | 16 class AstRawString; |
| 17 class ModuleInfoEntry; | 17 class ModuleInfoEntry; |
| 18 | 18 |
| 19 class ModuleDescriptor : public ZoneObject { | 19 class ModuleDescriptor : public ZoneObject { |
| 20 public: | 20 public: |
| 21 explicit ModuleDescriptor(Zone* zone) | 21 explicit ModuleDescriptor(Zone* zone) |
| 22 : module_requests_(zone), | 22 : module_requests_(zone), |
| 23 special_exports_(1, zone), | 23 special_exports_(1, zone), |
| 24 special_imports_(1, zone), | 24 namespace_imports_(1, zone), |
| 25 regular_exports_(zone), | 25 regular_exports_(zone), |
| 26 regular_imports_(zone) {} | 26 regular_imports_(zone) {} |
| 27 | 27 |
| 28 // The following Add* methods are high-level convenience functions for use by | 28 // The following Add* methods are high-level convenience functions for use by |
| 29 // the parser. | 29 // the parser. |
| 30 | 30 |
| 31 // import x from "foo.js"; | 31 // import x from "foo.js"; |
| 32 // import {x} from "foo.js"; | 32 // import {x} from "foo.js"; |
| 33 // import {x as y} from "foo.js"; | 33 // import {x as y} from "foo.js"; |
| 34 void AddImport( | 34 void AddImport( |
| 35 const AstRawString* import_name, const AstRawString* local_name, | 35 const AstRawString* import_name, const AstRawString* local_name, |
| 36 const AstRawString* module_request, const Scanner::Location loc, | 36 const AstRawString* module_request, const Scanner::Location loc, |
| 37 Zone* zone); | 37 Zone* zone); |
| 38 | 38 |
| 39 // import * as x from "foo.js"; | 39 // import * as x from "foo.js"; |
| 40 void AddStarImport( | 40 void AddStarImport( |
| 41 const AstRawString* local_name, const AstRawString* module_request, | 41 const AstRawString* local_name, const AstRawString* module_request, |
| 42 const Scanner::Location loc, Zone* zone); | 42 const Scanner::Location loc, Zone* zone); |
| 43 | 43 |
| 44 // import "foo.js"; | 44 // import "foo.js"; |
| 45 // import {} from "foo.js"; | 45 // import {} from "foo.js"; |
| 46 // export {} from "foo.js"; (sic!) | 46 // export {} from "foo.js"; (sic!) |
| 47 void AddEmptyImport( | 47 void AddEmptyImport(const AstRawString* module_request); |
| 48 const AstRawString* module_request, const Scanner::Location loc, | |
| 49 Zone* zone); | |
| 50 | 48 |
| 51 // export {x}; | 49 // export {x}; |
| 52 // export {x as y}; | 50 // export {x as y}; |
| 53 // export VariableStatement | 51 // export VariableStatement |
| 54 // export Declaration | 52 // export Declaration |
| 55 // export default ... | 53 // export default ... |
| 56 void AddExport( | 54 void AddExport( |
| 57 const AstRawString* local_name, const AstRawString* export_name, | 55 const AstRawString* local_name, const AstRawString* export_name, |
| 58 const Scanner::Location loc, Zone* zone); | 56 const Scanner::Location loc, Zone* zone); |
| 59 | 57 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 Handle<ModuleInfoEntry> Serialize(Isolate* isolate) const; | 97 Handle<ModuleInfoEntry> Serialize(Isolate* isolate) const; |
| 100 static Entry* Deserialize(Isolate* isolate, AstValueFactory* avfactory, | 98 static Entry* Deserialize(Isolate* isolate, AstValueFactory* avfactory, |
| 101 Handle<ModuleInfoEntry> entry); | 99 Handle<ModuleInfoEntry> entry); |
| 102 }; | 100 }; |
| 103 | 101 |
| 104 // Module requests. | 102 // Module requests. |
| 105 const ZoneMap<const AstRawString*, int>& module_requests() const { | 103 const ZoneMap<const AstRawString*, int>& module_requests() const { |
| 106 return module_requests_; | 104 return module_requests_; |
| 107 } | 105 } |
| 108 | 106 |
| 109 // Empty imports and namespace imports. | 107 // Namespace imports. |
| 110 const ZoneList<const Entry*>& special_imports() const { | 108 const ZoneList<const Entry*>& namespace_imports() const { |
| 111 return special_imports_; | 109 return namespace_imports_; |
| 112 } | 110 } |
| 113 | 111 |
| 114 // All the remaining imports, indexed by local name. | 112 // All the remaining imports, indexed by local name. |
| 115 const ZoneMap<const AstRawString*, const Entry*>& regular_imports() const { | 113 const ZoneMap<const AstRawString*, const Entry*>& regular_imports() const { |
| 116 return regular_imports_; | 114 return regular_imports_; |
| 117 } | 115 } |
| 118 | 116 |
| 119 // Star exports and explicitly indirect exports. | 117 // Star exports and explicitly indirect exports. |
| 120 const ZoneList<const Entry*>& special_exports() const { | 118 const ZoneList<const Entry*>& special_exports() const { |
| 121 return special_exports_; | 119 return special_exports_; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 144 void AddRegularImport(const Entry* entry) { | 142 void AddRegularImport(const Entry* entry) { |
| 145 DCHECK_NOT_NULL(entry->import_name); | 143 DCHECK_NOT_NULL(entry->import_name); |
| 146 DCHECK_NOT_NULL(entry->local_name); | 144 DCHECK_NOT_NULL(entry->local_name); |
| 147 DCHECK_NULL(entry->export_name); | 145 DCHECK_NULL(entry->export_name); |
| 148 DCHECK_LE(0, entry->module_request); | 146 DCHECK_LE(0, entry->module_request); |
| 149 regular_imports_.insert(std::make_pair(entry->local_name, entry)); | 147 regular_imports_.insert(std::make_pair(entry->local_name, entry)); |
| 150 // We don't care if there's already an entry for this local name, as in that | 148 // We don't care if there's already an entry for this local name, as in that |
| 151 // case we will report an error when declaring the variable. | 149 // case we will report an error when declaring the variable. |
| 152 } | 150 } |
| 153 | 151 |
| 154 void AddSpecialImport(const Entry* entry, Zone* zone) { | 152 void AddNamespaceImport(const Entry* entry, Zone* zone) { |
| 153 DCHECK_NULL(entry->import_name); |
| 155 DCHECK_NULL(entry->export_name); | 154 DCHECK_NULL(entry->export_name); |
| 155 DCHECK_NOT_NULL(entry->local_name); |
| 156 DCHECK_LE(0, entry->module_request); | 156 DCHECK_LE(0, entry->module_request); |
| 157 special_imports_.Add(entry, zone); | 157 namespace_imports_.Add(entry, zone); |
| 158 } | 158 } |
| 159 | 159 |
| 160 Handle<FixedArray> SerializeRegularExports(Isolate* isolate, | 160 Handle<FixedArray> SerializeRegularExports(Isolate* isolate, |
| 161 Zone* zone) const; | 161 Zone* zone) const; |
| 162 void DeserializeRegularExports(Isolate* isolate, AstValueFactory* avfactory, | 162 void DeserializeRegularExports(Isolate* isolate, AstValueFactory* avfactory, |
| 163 Handle<FixedArray> data); | 163 Handle<FixedArray> data); |
| 164 | 164 |
| 165 private: | 165 private: |
| 166 // TODO(neis): Use STL datastructure instead of ZoneList? | 166 // TODO(neis): Use STL datastructure instead of ZoneList? |
| 167 ZoneMap<const AstRawString*, int> module_requests_; | 167 ZoneMap<const AstRawString*, int> module_requests_; |
| 168 ZoneList<const Entry*> special_exports_; | 168 ZoneList<const Entry*> special_exports_; |
| 169 ZoneList<const Entry*> special_imports_; | 169 ZoneList<const Entry*> namespace_imports_; |
| 170 ZoneMultimap<const AstRawString*, Entry*> regular_exports_; | 170 ZoneMultimap<const AstRawString*, Entry*> regular_exports_; |
| 171 ZoneMap<const AstRawString*, const Entry*> regular_imports_; | 171 ZoneMap<const AstRawString*, const Entry*> regular_imports_; |
| 172 | 172 |
| 173 // If there are multiple export entries with the same export name, return the | 173 // If there are multiple export entries with the same export name, return the |
| 174 // last of them (in source order). Otherwise return nullptr. | 174 // last of them (in source order). Otherwise return nullptr. |
| 175 const Entry* FindDuplicateExport(Zone* zone) const; | 175 const Entry* FindDuplicateExport(Zone* zone) const; |
| 176 | 176 |
| 177 // Find any implicitly indirect exports and make them explicit. | 177 // Find any implicitly indirect exports and make them explicit. |
| 178 // | 178 // |
| 179 // An explicitly indirect export is an export entry arising from an export | 179 // An explicitly indirect export is an export entry arising from an export |
| (...skipping 18 matching lines...) Expand all Loading... |
| 198 .insert(std::make_pair(specifier, module_requests_.size())) | 198 .insert(std::make_pair(specifier, module_requests_.size())) |
| 199 .first; | 199 .first; |
| 200 return it->second; | 200 return it->second; |
| 201 } | 201 } |
| 202 }; | 202 }; |
| 203 | 203 |
| 204 } // namespace internal | 204 } // namespace internal |
| 205 } // namespace v8 | 205 } // namespace v8 |
| 206 | 206 |
| 207 #endif // V8_AST_MODULES_H_ | 207 #endif // V8_AST_MODULES_H_ |
| OLD | NEW |