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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 void AddExport( | 55 void AddExport( |
56 const AstRawString* export_name, const AstRawString* import_name, | 56 const AstRawString* export_name, const AstRawString* import_name, |
57 const AstRawString* module_request, const Scanner::Location loc, | 57 const AstRawString* module_request, const Scanner::Location loc, |
58 Zone* zone); | 58 Zone* zone); |
59 | 59 |
60 // export * from "foo.js"; | 60 // export * from "foo.js"; |
61 void AddStarExport( | 61 void AddStarExport( |
62 const AstRawString* module_request, const Scanner::Location loc, | 62 const AstRawString* module_request, const Scanner::Location loc, |
63 Zone* zone); | 63 Zone* zone); |
64 | 64 |
65 // Find any implicitly indirect exports and make them explicit. | |
66 // | |
67 // An explicitly indirect export is an export entry arising from an export | |
68 // statement of the following form: | |
69 // export {a as c} from "X"; | |
70 // An implicitly indirect export corresponds to | |
71 // export {b as c}; | |
72 // in the presence of an import statement of the form | |
73 // import {a as b} from "X"; | |
74 // This function finds such implicitly indirect export entries and rewrites | |
75 // them by filling in the import name and module request, as well as nulling | |
76 // out the local name. Effectively, it turns | |
77 // import {a as b} from "X"; export {b as c}; | |
78 // into: | |
79 // import {a as b} from "X"; export {a as c} from "X"; | |
80 // (The import entry is never deleted.) | |
81 void MakeIndirectExportsExplicit(); | |
82 | |
65 // Check if module is well-formed and report error if not. | 83 // Check if module is well-formed and report error if not. |
66 bool Validate(DeclarationScope* module_scope, | 84 bool Validate(DeclarationScope* module_scope, |
67 PendingCompilationErrorHandler* error_handler, | 85 PendingCompilationErrorHandler* error_handler, |
68 Zone* zone) const; | 86 Zone* zone) const; |
69 | 87 |
70 struct ModuleEntry : public ZoneObject { | 88 struct ModuleEntry : public ZoneObject { |
71 const Scanner::Location location; | 89 const Scanner::Location location; |
72 const AstRawString* export_name; | 90 const AstRawString* export_name; |
73 const AstRawString* local_name; | 91 const AstRawString* local_name; |
74 const AstRawString* import_name; | 92 const AstRawString* import_name; |
75 const AstRawString* module_request; | 93 const AstRawString* module_request; |
76 | 94 |
77 explicit ModuleEntry(Scanner::Location loc) | 95 explicit ModuleEntry(Scanner::Location loc) |
78 : location(loc), | 96 : location(loc), |
79 export_name(nullptr), | 97 export_name(nullptr), |
80 local_name(nullptr), | 98 local_name(nullptr), |
81 import_name(nullptr), | 99 import_name(nullptr), |
82 module_request(nullptr) {} | 100 module_request(nullptr) {} |
83 }; | 101 }; |
84 | 102 |
85 const ZoneList<const ModuleEntry*>& exports() const { return exports_; } | 103 const ZoneList<ModuleEntry*>& exports() const { return exports_; } |
adamk
2016/08/09 16:52:51
Maybe remove the const-ness of this method? I real
neis
2016/08/10 11:53:30
I don't understand, it's just a getter.
adamk
2016/08/10 17:30:28
But it now lets callers mutate the internal state
| |
86 | 104 |
87 // Empty imports and namespace imports. | 105 // Empty imports and namespace imports. |
88 const ZoneList<const ModuleEntry*>& special_imports() const { | 106 const ZoneList<const ModuleEntry*>& special_imports() const { |
89 return special_imports_; | 107 return special_imports_; |
90 } | 108 } |
91 | 109 |
92 // All the remaining imports, indexed by local name. | 110 // All the remaining imports, indexed by local name. |
93 const ZoneMap<const AstRawString*, const ModuleEntry*>& regular_imports() | 111 const ZoneMap<const AstRawString*, const ModuleEntry*>& regular_imports() |
94 const { | 112 const { |
95 return regular_imports_; | 113 return regular_imports_; |
96 } | 114 } |
97 | 115 |
98 private: | 116 private: |
99 ZoneList<const ModuleEntry*> exports_; | 117 ZoneList<ModuleEntry*> exports_; |
100 ZoneList<const ModuleEntry*> special_imports_; | 118 ZoneList<const ModuleEntry*> special_imports_; |
101 ZoneMap<const AstRawString*, const ModuleEntry*> regular_imports_; | 119 ZoneMap<const AstRawString*, const ModuleEntry*> regular_imports_; |
102 }; | 120 }; |
103 | 121 |
104 } // namespace internal | 122 } // namespace internal |
105 } // namespace v8 | 123 } // namespace v8 |
106 | 124 |
107 #endif // V8_AST_MODULES_H_ | 125 #endif // V8_AST_MODULES_H_ |
OLD | NEW |