Index: src/ast/modules.h |
diff --git a/src/ast/modules.h b/src/ast/modules.h |
index 1fdf526cd136145bc38167fb72458adff7b40de8..c672f2494917b60bbc310638c7786024410642a5 100644 |
--- a/src/ast/modules.h |
+++ b/src/ast/modules.h |
@@ -5,6 +5,8 @@ |
#ifndef V8_AST_MODULES_H_ |
#define V8_AST_MODULES_H_ |
+#include "src/parsing/scanner.h" // Only for Scanner::Location. |
+#include "src/pending-compilation-error-handler.h" |
#include "src/zone.h" |
namespace v8 { |
@@ -16,90 +18,74 @@ class AstRawString; |
class ModuleDescriptor : public ZoneObject { |
public: |
- // --------------------------------------------------------------------------- |
- // Factory methods. |
- |
- static ModuleDescriptor* New(Zone* zone) { |
- return new (zone) ModuleDescriptor(zone); |
- } |
- |
- // --------------------------------------------------------------------------- |
- // Mutators. |
- |
- // Add a name to the list of exports. If it already exists, that's an error. |
- void AddLocalExport(const AstRawString* export_name, |
- const AstRawString* local_name, Zone* zone, bool* ok); |
- |
- // Add module_specifier to the list of requested modules, |
- // if not already present. |
- void AddModuleRequest(const AstRawString* module_specifier, Zone* zone); |
- |
- // Assign an index. |
- void Allocate(int index) { |
- DCHECK_EQ(-1, index_); |
- index_ = index; |
- } |
- |
- // --------------------------------------------------------------------------- |
- // Accessors. |
- |
- int Length() { |
- ZoneHashMap* exports = exports_; |
- return exports ? exports->occupancy() : 0; |
- } |
- |
- // The context slot in the hosting script context pointing to this module. |
- int Index() { |
- return index_; |
- } |
- |
- const AstRawString* LookupLocalExport(const AstRawString* export_name, |
- Zone* zone); |
- |
- const ZoneList<const AstRawString*>& requested_modules() const { |
- return requested_modules_; |
- } |
- |
- // --------------------------------------------------------------------------- |
- // Iterators. |
- |
- // Use like: |
- // for (auto it = descriptor->iterator(); !it.done(); it.Advance()) { |
- // ... it.name() ... |
- // } |
- class Iterator { |
- public: |
- bool done() const { return entry_ == NULL; } |
- const AstRawString* export_name() const { |
- DCHECK(!done()); |
- return static_cast<const AstRawString*>(entry_->key); |
- } |
- const AstRawString* local_name() const { |
- DCHECK(!done()); |
- return static_cast<const AstRawString*>(entry_->value); |
- } |
- void Advance() { entry_ = exports_->Next(entry_); } |
- |
- private: |
- friend class ModuleDescriptor; |
- explicit Iterator(const ZoneHashMap* exports) |
- : exports_(exports), entry_(exports ? exports->Start() : NULL) {} |
- |
- const ZoneHashMap* exports_; |
- ZoneHashMap::Entry* entry_; |
- }; |
+ explicit ModuleDescriptor(Zone* zone) |
+ : exports_(1, zone), imports_(1, zone) {} |
+ |
+ // import x from "foo.js"; |
+ // import {x} from "foo.js"; |
+ // import {x as y} from "foo.js"; |
+ void AddImport( |
+ const AstRawString* import_name, const AstRawString* local_name, |
+ const AstRawString* module_request, const Scanner::Location loc, |
+ Zone* zone); |
+ |
+ // import * as x from "foo.js"; |
+ void AddStarImport( |
+ const AstRawString* local_name, const AstRawString* module_request, |
+ const Scanner::Location loc, Zone* zone); |
+ |
+ // import "foo.js"; |
+ // import {} from "foo.js"; |
+ // export {} from "foo.js"; (sic!) |
+ void AddEmptyImport( |
+ const AstRawString* module_request, const Scanner::Location loc, |
+ Zone* zone); |
+ |
+ // export {x}; |
+ // export {x as y}; |
+ // export VariableStatement |
+ // export Declaration |
+ // export default ... |
+ void AddExport( |
+ const AstRawString* local_name, const AstRawString* export_name, |
+ const Scanner::Location loc, Zone* zone); |
+ |
+ // export {x} from "foo.js"; |
+ // export {x as y} from "foo.js"; |
+ void AddExport( |
+ const AstRawString* export_name, const AstRawString* import_name, |
+ const AstRawString* module_request, const Scanner::Location loc, |
+ Zone* zone); |
+ |
+ // export * from "foo.js"; |
+ void AddStarExport( |
+ const AstRawString* module_request, const Scanner::Location loc, |
+ Zone* zone); |
+ |
+ // Check if module is well-formed and report error if not. |
+ bool Validate( |
+ Scope* module_scope, PendingCompilationErrorHandler* error_handler, |
+ Zone* zone) const; |
- Iterator iterator() const { return Iterator(this->exports_); } |
- // --------------------------------------------------------------------------- |
- // Implementation. |
private: |
- explicit ModuleDescriptor(Zone* zone) |
- : exports_(NULL), requested_modules_(1, zone), index_(-1) {} |
+ struct ModuleEntry : public ZoneObject { |
+ const Scanner::Location location; |
+ const AstRawString* export_name; |
+ const AstRawString* local_name; |
+ const AstRawString* import_name; |
+ const AstRawString* module_request; |
+ |
+ explicit ModuleEntry(Scanner::Location loc) |
+ : location(loc), |
+ export_name(nullptr), |
+ local_name(nullptr), |
+ import_name(nullptr), |
+ module_request(nullptr) {} |
+ }; |
- ZoneHashMap* exports_; // Module exports and their types (allocated lazily) |
- ZoneList<const AstRawString*> requested_modules_; |
- int index_; |
+ ZoneList<const ModuleEntry*> exports_; |
+ ZoneList<const ModuleEntry*> imports_; |
}; |
} // namespace internal |