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

Side by Side Diff: src/ast/modules.h

Issue 2277273002: [modules] Partial support for (de-)serializing module descriptor entries. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 3 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
« no previous file with comments | « no previous file | src/ast/modules.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" // 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"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace internal { 13 namespace internal {
14 14
15 15
16 class AstRawString; 16 class AstRawString;
17 17
18 18
19 class ModuleDescriptor : public ZoneObject { 19 class ModuleDescriptor : public ZoneObject {
20 public: 20 public:
21 explicit ModuleDescriptor(Zone* zone) 21 explicit ModuleDescriptor(Zone* zone)
22 : special_exports_(1, zone), 22 : special_exports_(1, zone),
23 special_imports_(1, zone), 23 special_imports_(1, zone),
24 regular_exports_(zone), 24 regular_exports_(zone),
25 regular_imports_(zone) {} 25 regular_imports_(zone) {}
26 26
27 // The following Add* methods are high-level convenience functions for use by
28 // the parser.
29
27 // import x from "foo.js"; 30 // import x from "foo.js";
28 // import {x} from "foo.js"; 31 // import {x} from "foo.js";
29 // import {x as y} from "foo.js"; 32 // import {x as y} from "foo.js";
30 void AddImport( 33 void AddImport(
31 const AstRawString* import_name, const AstRawString* local_name, 34 const AstRawString* import_name, const AstRawString* local_name,
32 const AstRawString* module_request, const Scanner::Location loc, 35 const AstRawString* module_request, const Scanner::Location loc,
33 Zone* zone); 36 Zone* zone);
34 37
35 // import * as x from "foo.js"; 38 // import * as x from "foo.js";
36 void AddStarImport( 39 void AddStarImport(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 const AstRawString* local_name; 79 const AstRawString* local_name;
77 const AstRawString* import_name; 80 const AstRawString* import_name;
78 const AstRawString* module_request; 81 const AstRawString* module_request;
79 82
80 explicit Entry(Scanner::Location loc) 83 explicit Entry(Scanner::Location loc)
81 : location(loc), 84 : location(loc),
82 export_name(nullptr), 85 export_name(nullptr),
83 local_name(nullptr), 86 local_name(nullptr),
84 import_name(nullptr), 87 import_name(nullptr),
85 module_request(nullptr) {} 88 module_request(nullptr) {}
89
90 Handle<FixedArray> Serialize(Isolate* isolate) const;
91 static Entry* Deserialize(Isolate* isolate, AstValueFactory* avfactory,
92 Handle<FixedArray> data);
86 }; 93 };
87 94
88 // Empty imports and namespace imports. 95 // Empty imports and namespace imports.
89 const ZoneList<const Entry*>& special_imports() const { 96 const ZoneList<const Entry*>& special_imports() const {
90 return special_imports_; 97 return special_imports_;
91 } 98 }
92 99
93 // All the remaining imports, indexed by local name. 100 // All the remaining imports, indexed by local name.
94 const ZoneMap<const AstRawString*, const Entry*>& regular_imports() const { 101 const ZoneMap<const AstRawString*, const Entry*>& regular_imports() const {
95 return regular_imports_; 102 return regular_imports_;
96 } 103 }
97 104
98 // Star exports and explicitly indirect exports. 105 // Star exports and explicitly indirect exports.
99 const ZoneList<const Entry*>& special_exports() const { 106 const ZoneList<const Entry*>& special_exports() const {
100 return special_exports_; 107 return special_exports_;
101 } 108 }
102 109
103 // All the remaining exports, indexed by local name. 110 // All the remaining exports, indexed by local name.
104 const ZoneMultimap<const AstRawString*, Entry*>& regular_exports() const { 111 const ZoneMultimap<const AstRawString*, Entry*>& regular_exports() const {
105 return regular_exports_; 112 return regular_exports_;
106 } 113 }
107 114
115 void AddRegularExport(Entry* entry) {
116 DCHECK_NOT_NULL(entry->export_name);
117 DCHECK_NOT_NULL(entry->local_name);
118 DCHECK_NULL(entry->import_name);
119 regular_exports_.insert(std::make_pair(entry->local_name, entry));
120 }
121
122 void AddSpecialExport(const Entry* entry, Zone* zone) {
123 DCHECK_NOT_NULL(entry->module_request);
124 special_exports_.Add(entry, zone);
125 }
126
127 void AddRegularImport(const Entry* entry) {
128 DCHECK_NOT_NULL(entry->import_name);
129 DCHECK_NOT_NULL(entry->local_name);
130 DCHECK_NOT_NULL(entry->module_request);
131 DCHECK_NULL(entry->export_name);
132 regular_imports_.insert(std::make_pair(entry->local_name, entry));
133 // We don't care if there's already an entry for this local name, as in that
134 // case we will report an error when declaring the variable.
135 }
136
137 void AddSpecialImport(const Entry* entry, Zone* zone) {
138 DCHECK_NOT_NULL(entry->module_request);
139 DCHECK_NULL(entry->export_name);
140 special_imports_.Add(entry, zone);
141 }
142
108 private: 143 private:
109 // TODO(neis): Use STL datastructure instead of ZoneList? 144 // TODO(neis): Use STL datastructure instead of ZoneList?
110 ZoneList<const Entry*> special_exports_; 145 ZoneList<const Entry*> special_exports_;
111 ZoneList<const Entry*> special_imports_; 146 ZoneList<const Entry*> special_imports_;
112 ZoneMultimap<const AstRawString*, Entry*> regular_exports_; 147 ZoneMultimap<const AstRawString*, Entry*> regular_exports_;
113 ZoneMap<const AstRawString*, const Entry*> regular_imports_; 148 ZoneMap<const AstRawString*, const Entry*> regular_imports_;
114 149
115 // If there are multiple export entries with the same export name, return one 150 // If there are multiple export entries with the same export name, return one
116 // of them. Otherwise return nullptr. 151 // of them. Otherwise return nullptr.
117 const Entry* FindDuplicateExport(Zone* zone) const; 152 const Entry* FindDuplicateExport(Zone* zone) const;
(...skipping 14 matching lines...) Expand all
132 // into: 167 // into:
133 // import {a as b} from "X"; export {a as c} from "X"; 168 // import {a as b} from "X"; export {a as c} from "X";
134 // (The import entry is never deleted.) 169 // (The import entry is never deleted.)
135 void MakeIndirectExportsExplicit(Zone* zone); 170 void MakeIndirectExportsExplicit(Zone* zone);
136 }; 171 };
137 172
138 } // namespace internal 173 } // namespace internal
139 } // namespace v8 174 } // namespace v8
140 175
141 #endif // V8_AST_MODULES_H_ 176 #endif // V8_AST_MODULES_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast/modules.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698