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-containers.h" | 10 #include "src/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 | 17 |
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 : exports_(1, zone), special_imports_(1, zone), regular_imports_(zone) {} | 22 : special_exports_(1, zone), |
| 23 special_imports_(1, zone), |
| 24 regular_exports_(zone), |
| 25 regular_imports_(zone) {} |
23 | 26 |
24 // import x from "foo.js"; | 27 // import x from "foo.js"; |
25 // import {x} from "foo.js"; | 28 // import {x} from "foo.js"; |
26 // import {x as y} from "foo.js"; | 29 // import {x as y} from "foo.js"; |
27 void AddImport( | 30 void AddImport( |
28 const AstRawString* import_name, const AstRawString* local_name, | 31 const AstRawString* import_name, const AstRawString* local_name, |
29 const AstRawString* module_request, const Scanner::Location loc, | 32 const AstRawString* module_request, const Scanner::Location loc, |
30 Zone* zone); | 33 Zone* zone); |
31 | 34 |
32 // import * as x from "foo.js"; | 35 // import * as x from "foo.js"; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 const AstRawString* module_request; | 78 const AstRawString* module_request; |
76 | 79 |
77 explicit ModuleEntry(Scanner::Location loc) | 80 explicit ModuleEntry(Scanner::Location loc) |
78 : location(loc), | 81 : location(loc), |
79 export_name(nullptr), | 82 export_name(nullptr), |
80 local_name(nullptr), | 83 local_name(nullptr), |
81 import_name(nullptr), | 84 import_name(nullptr), |
82 module_request(nullptr) {} | 85 module_request(nullptr) {} |
83 }; | 86 }; |
84 | 87 |
85 const ZoneList<ModuleEntry*>& exports() const { return exports_; } | |
86 | |
87 // Empty imports and namespace imports. | 88 // Empty imports and namespace imports. |
88 const ZoneList<const ModuleEntry*>& special_imports() const { | 89 const ZoneList<const ModuleEntry*>& special_imports() const { |
89 return special_imports_; | 90 return special_imports_; |
90 } | 91 } |
91 | 92 |
92 // All the remaining imports, indexed by local name. | 93 // All the remaining imports, indexed by local name. |
93 const ZoneMap<const AstRawString*, const ModuleEntry*>& regular_imports() | 94 const ZoneMap<const AstRawString*, const ModuleEntry*>& regular_imports() |
94 const { | 95 const { |
95 return regular_imports_; | 96 return regular_imports_; |
96 } | 97 } |
97 | 98 |
| 99 // Star exports and explicitly indirect exports. |
| 100 const ZoneList<const ModuleEntry*>& special_exports() const { |
| 101 return special_exports_; |
| 102 } |
| 103 |
| 104 // All the remaining exports, indexed by local name. |
| 105 const ZoneMultimap<const AstRawString*, ModuleEntry*>& regular_exports() |
| 106 const { |
| 107 return regular_exports_; |
| 108 } |
| 109 |
98 private: | 110 private: |
99 ZoneList<ModuleEntry*> exports_; | 111 // TODO(neis): Use STL datastructure instead of ZoneList? |
| 112 ZoneList<const ModuleEntry*> special_exports_; |
100 ZoneList<const ModuleEntry*> special_imports_; | 113 ZoneList<const ModuleEntry*> special_imports_; |
| 114 ZoneMultimap<const AstRawString*, ModuleEntry*> regular_exports_; |
101 ZoneMap<const AstRawString*, const ModuleEntry*> regular_imports_; | 115 ZoneMap<const AstRawString*, const ModuleEntry*> regular_imports_; |
102 | 116 |
| 117 // If there are multiple export entries with the same export name, return one |
| 118 // of them. Otherwise return nullptr. |
| 119 const ModuleEntry* FindDuplicateExport(Zone* zone) const; |
| 120 |
103 // Find any implicitly indirect exports and make them explicit. | 121 // Find any implicitly indirect exports and make them explicit. |
104 // | 122 // |
105 // An explicitly indirect export is an export entry arising from an export | 123 // An explicitly indirect export is an export entry arising from an export |
106 // statement of the following form: | 124 // statement of the following form: |
107 // export {a as c} from "X"; | 125 // export {a as c} from "X"; |
108 // An implicitly indirect export corresponds to | 126 // An implicitly indirect export corresponds to |
109 // export {b as c}; | 127 // export {b as c}; |
110 // in the presence of an import statement of the form | 128 // in the presence of an import statement of the form |
111 // import {a as b} from "X"; | 129 // import {a as b} from "X"; |
112 // This function finds such implicitly indirect export entries and rewrites | 130 // This function finds such implicitly indirect export entries and rewrites |
113 // them by filling in the import name and module request, as well as nulling | 131 // them by filling in the import name and module request, as well as nulling |
114 // out the local name. Effectively, it turns | 132 // out the local name. Effectively, it turns |
115 // import {a as b} from "X"; export {b as c}; | 133 // import {a as b} from "X"; export {b as c}; |
116 // into: | 134 // into: |
117 // import {a as b} from "X"; export {a as c} from "X"; | 135 // import {a as b} from "X"; export {a as c} from "X"; |
118 // (The import entry is never deleted.) | 136 // (The import entry is never deleted.) |
119 void MakeIndirectExportsExplicit(); | 137 void MakeIndirectExportsExplicit(Zone* zone); |
120 }; | 138 }; |
121 | 139 |
122 } // namespace internal | 140 } // namespace internal |
123 } // namespace v8 | 141 } // namespace v8 |
124 | 142 |
125 #endif // V8_AST_MODULES_H_ | 143 #endif // V8_AST_MODULES_H_ |
OLD | NEW |