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 #ifdef DEBUG |
| 9 // TODO: Remove before landing. |
| 10 #include "src/ast/ast-value-factory.h" |
| 11 #endif // DEBUG |
| 12 |
8 #include "src/parsing/scanner.h" // Only for Scanner::Location. | 13 #include "src/parsing/scanner.h" // Only for Scanner::Location. |
9 #include "src/pending-compilation-error-handler.h" | 14 #include "src/pending-compilation-error-handler.h" |
10 #include "src/zone-containers.h" | 15 #include "src/zone-containers.h" |
11 | 16 |
12 namespace v8 { | 17 namespace v8 { |
13 namespace internal { | 18 namespace internal { |
14 | 19 |
15 | 20 |
16 class AstRawString; | 21 class AstRawString; |
| 22 class ModuleInfoEntry; |
17 | 23 |
18 | 24 |
19 class ModuleDescriptor : public ZoneObject { | 25 class ModuleDescriptor : public ZoneObject { |
20 public: | 26 public: |
21 explicit ModuleDescriptor(Zone* zone) | 27 explicit ModuleDescriptor(Zone* zone) |
22 : special_exports_(1, zone), | 28 : special_exports_(1, zone), |
23 special_imports_(1, zone), | 29 special_imports_(1, zone), |
24 regular_exports_(zone), | 30 regular_exports_(zone), |
25 regular_imports_(zone) {} | 31 regular_imports_(zone) {} |
26 | 32 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 bool Validate(ModuleScope* module_scope, | 79 bool Validate(ModuleScope* module_scope, |
74 PendingCompilationErrorHandler* error_handler, Zone* zone); | 80 PendingCompilationErrorHandler* error_handler, Zone* zone); |
75 | 81 |
76 struct Entry : public ZoneObject { | 82 struct Entry : public ZoneObject { |
77 const Scanner::Location location; | 83 const Scanner::Location location; |
78 const AstRawString* export_name; | 84 const AstRawString* export_name; |
79 const AstRawString* local_name; | 85 const AstRawString* local_name; |
80 const AstRawString* import_name; | 86 const AstRawString* import_name; |
81 const AstRawString* module_request; | 87 const AstRawString* module_request; |
82 | 88 |
| 89 // TODO(neis): Remove local_name component? |
83 explicit Entry(Scanner::Location loc) | 90 explicit Entry(Scanner::Location loc) |
84 : location(loc), | 91 : location(loc), |
85 export_name(nullptr), | 92 export_name(nullptr), |
86 local_name(nullptr), | 93 local_name(nullptr), |
87 import_name(nullptr), | 94 import_name(nullptr), |
88 module_request(nullptr) {} | 95 module_request(nullptr) {} |
89 | 96 |
90 Handle<FixedArray> Serialize(Isolate* isolate) const; | 97 #ifdef DEBUG |
| 98 // TODO: Remove before landing. |
| 99 void Print() const { |
| 100 PrintF("export name: "); |
| 101 if (export_name != nullptr) { |
| 102 PrintF("%.*s\n", export_name->length(), export_name->raw_data()); |
| 103 } |
| 104 PrintF("local name: "); |
| 105 if (local_name != nullptr) { |
| 106 PrintF("%.*s\n", local_name->length(), local_name->raw_data()); |
| 107 // local_name->string()->ShortPrint(); |
| 108 } |
| 109 } |
| 110 #endif // DEBUG |
| 111 |
| 112 // (De-)serialization support. |
| 113 // Note that the location value is not preserved as it's only needed by the |
| 114 // parser. (A Deserialize'd entry has an invalid location.) |
| 115 Handle<ModuleInfoEntry> Serialize(Isolate* isolate) const; |
91 static Entry* Deserialize(Isolate* isolate, AstValueFactory* avfactory, | 116 static Entry* Deserialize(Isolate* isolate, AstValueFactory* avfactory, |
92 Handle<FixedArray> data); | 117 Handle<ModuleInfoEntry> entry); |
93 }; | 118 }; |
94 | 119 |
95 // Empty imports and namespace imports. | 120 // Empty imports and namespace imports. |
96 const ZoneList<const Entry*>& special_imports() const { | 121 const ZoneList<const Entry*>& special_imports() const { |
97 return special_imports_; | 122 return special_imports_; |
98 } | 123 } |
99 | 124 |
100 // All the remaining imports, indexed by local name. | 125 // All the remaining imports, indexed by local name. |
101 const ZoneMap<const AstRawString*, const Entry*>& regular_imports() const { | 126 const ZoneMap<const AstRawString*, const Entry*>& regular_imports() const { |
102 return regular_imports_; | 127 return regular_imports_; |
103 } | 128 } |
104 | 129 |
105 // Star exports and explicitly indirect exports. | 130 // Star exports and explicitly indirect exports. |
106 const ZoneList<const Entry*>& special_exports() const { | 131 const ZoneList<const Entry*>& special_exports() const { |
107 return special_exports_; | 132 return special_exports_; |
108 } | 133 } |
109 | 134 |
110 // All the remaining exports, indexed by local name. | 135 // All the remaining exports, indexed by local name. |
111 const ZoneMultimap<const AstRawString*, Entry*>& regular_exports() const { | 136 const ZoneMultimap<const AstRawString*, Entry*>& regular_exports() const { |
112 return regular_exports_; | 137 return regular_exports_; |
113 } | 138 } |
114 | 139 |
| 140 #ifdef DEBUG |
| 141 void Print() const; |
| 142 #endif // DEBUG |
| 143 |
115 void AddRegularExport(Entry* entry) { | 144 void AddRegularExport(Entry* entry) { |
116 DCHECK_NOT_NULL(entry->export_name); | 145 DCHECK_NOT_NULL(entry->export_name); |
117 DCHECK_NOT_NULL(entry->local_name); | 146 DCHECK_NOT_NULL(entry->local_name); |
118 DCHECK_NULL(entry->import_name); | 147 DCHECK_NULL(entry->import_name); |
119 regular_exports_.insert(std::make_pair(entry->local_name, entry)); | 148 regular_exports_.insert(std::make_pair(entry->local_name, entry)); |
120 } | 149 } |
121 | 150 |
122 void AddSpecialExport(const Entry* entry, Zone* zone) { | 151 void AddSpecialExport(const Entry* entry, Zone* zone) { |
123 DCHECK_NOT_NULL(entry->module_request); | 152 DCHECK_NOT_NULL(entry->module_request); |
124 special_exports_.Add(entry, zone); | 153 special_exports_.Add(entry, zone); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // into: | 196 // into: |
168 // import {a as b} from "X"; export {a as c} from "X"; | 197 // import {a as b} from "X"; export {a as c} from "X"; |
169 // (The import entry is never deleted.) | 198 // (The import entry is never deleted.) |
170 void MakeIndirectExportsExplicit(Zone* zone); | 199 void MakeIndirectExportsExplicit(Zone* zone); |
171 }; | 200 }; |
172 | 201 |
173 } // namespace internal | 202 } // namespace internal |
174 } // namespace v8 | 203 } // namespace v8 |
175 | 204 |
176 #endif // V8_AST_MODULES_H_ | 205 #endif // V8_AST_MODULES_H_ |
OLD | NEW |