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

Side by Side 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: . 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 unified diff | Download patch
OLDNEW
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"
adamk 2016/07/13 18:38:21 This is just for Scanner::Location, right? Can you
neis 2016/07/14 10:28:23 Yes. Done.
9 #include "src/pending-compilation-error-handler.h"
8 #include "src/zone.h" 10 #include "src/zone.h"
9 11
10 namespace v8 { 12 namespace v8 {
11 namespace internal { 13 namespace internal {
12 14
13 15
14 class AstRawString; 16 class AstRawString;
15 17
16 18
17 class ModuleDescriptor : public ZoneObject { 19 class ModuleDescriptor : public ZoneObject {
18 public: 20 public:
19 // --------------------------------------------------------------------------- 21 // ---------------------------------------------------------------------------
20 // Factory methods. 22 // Factory methods.
21 23
22 static ModuleDescriptor* New(Zone* zone) { 24 static ModuleDescriptor* New(Zone* zone) {
23 return new (zone) ModuleDescriptor(zone); 25 return new (zone) ModuleDescriptor(zone);
24 } 26 }
25 27
28
26 // --------------------------------------------------------------------------- 29 // ---------------------------------------------------------------------------
27 // Mutators. 30 // Mutators.
28 31
29 // Add a name to the list of exports. If it already exists, that's an error. 32 // import "foo.js";
30 void AddLocalExport(const AstRawString* export_name, 33 // import {} from "foo.js";
31 const AstRawString* local_name, Zone* zone, bool* ok); 34 // export {} from "foo.js";
35 void AddEmptyImport(
36 const AstRawString* module_request, const Scanner::Location loc,
37 Zone* zone);
32 38
33 // Add module_specifier to the list of requested modules, 39 // import x from "foo.js";
34 // if not already present. 40 // import {x} from "foo.js";
35 void AddModuleRequest(const AstRawString* module_specifier, Zone* zone); 41 // import {x as y} from "foo.js";
42 void AddNonStarImport(
adamk 2016/07/13 18:38:21 This seems like the "common" case, how about "AddI
neis 2016/07/14 10:28:23 Done.
43 const AstRawString* import_name, const AstRawString* local_name,
44 const AstRawString* module_request, const Scanner::Location loc,
45 Zone* zone);
36 46
37 // Assign an index. 47 // import * as x from "foo.js";
38 void Allocate(int index) { 48 void AddStarImport(
39 DCHECK_EQ(-1, index_); 49 const AstRawString* local_name, const AstRawString* module_request,
40 index_ = index; 50 const Scanner::Location loc, Zone* zone);
41 } 51
52 // export {x};
53 // export {x as y};
54 // export VariableStatement
55 // export Declaration
56 // export default ...
57 void AddNonStarExport(
adamk 2016/07/13 18:38:21 Same here and below, just "AddExport" and let "Add
neis 2016/07/14 10:28:23 Done.
58 const AstRawString* local_name, const AstRawString* export_name,
59 const Scanner::Location loc, Zone* zone);
60
61 // export {x} from "foo.js";
62 // export {x as y} from "foo.js";
63 void AddNonStarExport(
64 const AstRawString* export_name, const AstRawString* import_name,
65 const AstRawString* module_request, const Scanner::Location loc,
66 Zone* zone);
67
68 // export * from "foo.js";
69 void AddStarExport(
70 const AstRawString* module_request, const Scanner::Location loc,
71 Zone* zone);
72
42 73
43 // --------------------------------------------------------------------------- 74 // ---------------------------------------------------------------------------
44 // Accessors. 75 // Accessors.
adamk 2016/07/13 18:38:21 Don't think this comment is terribly useful or acc
neis 2016/07/14 10:28:23 Removed this and the others.
45 76
46 int Length() { 77 bool Validate(
adamk 2016/07/13 18:38:21 Add a comment here too?
neis 2016/07/14 10:28:23 Done.
47 ZoneHashMap* exports = exports_; 78 Scope* module_scope, PendingCompilationErrorHandler* error_handler,
48 return exports ? exports->occupancy() : 0; 79 Zone* zone) const;
49 }
50 80
51 // The context slot in the hosting script context pointing to this module.
52 int Index() {
53 return index_;
54 }
55
56 const AstRawString* LookupLocalExport(const AstRawString* export_name,
57 Zone* zone);
58
59 const ZoneList<const AstRawString*>& requested_modules() const {
60 return requested_modules_;
61 }
62
63 // ---------------------------------------------------------------------------
64 // Iterators.
65
66 // Use like:
67 // for (auto it = descriptor->iterator(); !it.done(); it.Advance()) {
68 // ... it.name() ...
69 // }
70 class Iterator {
71 public:
72 bool done() const { return entry_ == NULL; }
73 const AstRawString* export_name() const {
74 DCHECK(!done());
75 return static_cast<const AstRawString*>(entry_->key);
76 }
77 const AstRawString* local_name() const {
78 DCHECK(!done());
79 return static_cast<const AstRawString*>(entry_->value);
80 }
81 void Advance() { entry_ = exports_->Next(entry_); }
82
83 private:
84 friend class ModuleDescriptor;
85 explicit Iterator(const ZoneHashMap* exports)
86 : exports_(exports), entry_(exports ? exports->Start() : NULL) {}
87
88 const ZoneHashMap* exports_;
89 ZoneHashMap::Entry* entry_;
90 };
91
92 Iterator iterator() const { return Iterator(this->exports_); }
93 81
94 // --------------------------------------------------------------------------- 82 // ---------------------------------------------------------------------------
95 // Implementation. 83 // Implementation.
84
96 private: 85 private:
97 explicit ModuleDescriptor(Zone* zone) 86 explicit ModuleDescriptor(Zone* zone)
98 : exports_(NULL), requested_modules_(1, zone), index_(-1) {} 87 : exports_(1, zone), imports_(1, zone) {}
99 88
100 ZoneHashMap* exports_; // Module exports and their types (allocated lazily) 89 struct ModuleEntry {
adamk 2016/07/13 18:38:21 Any reason not to have this extend ZoneObject?
neis 2016/07/14 10:28:23 No, thans for the suggestion. Done.
101 ZoneList<const AstRawString*> requested_modules_; 90 const Scanner::Location location;
102 int index_; 91 const AstRawString* export_name;
92 const AstRawString* local_name;
93 const AstRawString* import_name;
94 const AstRawString* module_request;
95
96 explicit ModuleEntry(const Scanner::Location loc)
adamk 2016/07/13 18:38:21 No need for "const" here.
neis 2016/07/14 10:28:23 Done.
97 : location(loc),
98 export_name(nullptr),
99 local_name(nullptr),
100 import_name(nullptr),
101 module_request(nullptr) {}
102 };
103
104 ZoneList<const ModuleEntry*> exports_;
105 ZoneList<const ModuleEntry*> imports_;
103 }; 106 };
104 107
105 } // namespace internal 108 } // namespace internal
106 } // namespace v8 109 } // namespace v8
107 110
108 #endif // V8_AST_MODULES_H_ 111 #endif // V8_AST_MODULES_H_
OLDNEW
« no previous file with comments | « src/ast/ast-numbering.cc ('k') | src/ast/modules.cc » ('j') | src/ast/modules.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698