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

Side by Side Diff: src/modules.cc

Issue 1481613002: Create ast/ and parsing/ subdirectories and move appropriate files (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 years 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 | « src/modules.h ('k') | src/parameter-initializer-rewriter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/modules.h"
6
7 #include "src/ast-value-factory.h"
8
9 namespace v8 {
10 namespace internal {
11
12
13 void ModuleDescriptor::AddLocalExport(const AstRawString* export_name,
14 const AstRawString* local_name,
15 Zone* zone, bool* ok) {
16 DCHECK(!IsFrozen());
17 void* key = const_cast<AstRawString*>(export_name);
18
19 ZoneAllocationPolicy allocator(zone);
20
21 if (exports_ == nullptr) {
22 exports_ = new (zone->New(sizeof(ZoneHashMap)))
23 ZoneHashMap(ZoneHashMap::PointersMatch,
24 ZoneHashMap::kDefaultHashMapCapacity, allocator);
25 }
26
27 ZoneHashMap::Entry* p =
28 exports_->LookupOrInsert(key, export_name->hash(), allocator);
29 DCHECK_NOT_NULL(p);
30 if (p->value != nullptr) {
31 // Duplicate export.
32 *ok = false;
33 return;
34 }
35
36 p->value = const_cast<AstRawString*>(local_name);
37 }
38
39
40 void ModuleDescriptor::AddModuleRequest(const AstRawString* module_specifier,
41 Zone* zone) {
42 // TODO(adamk): Avoid this O(N) operation on each insert by storing
43 // a HashMap, or by de-duping after parsing.
44 if (requested_modules_.Contains(module_specifier)) return;
45 requested_modules_.Add(module_specifier, zone);
46 }
47
48
49 const AstRawString* ModuleDescriptor::LookupLocalExport(
50 const AstRawString* export_name, Zone* zone) {
51 if (exports_ == nullptr) return nullptr;
52 ZoneHashMap::Entry* entry = exports_->Lookup(
53 const_cast<AstRawString*>(export_name), export_name->hash());
54 if (entry == nullptr) return nullptr;
55 DCHECK_NOT_NULL(entry->value);
56 return static_cast<const AstRawString*>(entry->value);
57 }
58 } // namespace internal
59 } // namespace v8
OLDNEW
« no previous file with comments | « src/modules.h ('k') | src/parameter-initializer-rewriter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698