Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: src/ast/modules.h

Issue 2108193003: [modules] AST and parser rework. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@anonymous-declarations
Patch Set: Rebase. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ast/ast-numbering.cc ('k') | src/ast/modules.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « src/ast/ast-numbering.cc ('k') | src/ast/modules.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698