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

Side by Side Diff: pkg/kernel/lib/binary/limited_ast_to_binary.dart

Issue 2953703002: Tweak public APIs and use them in patch_sdk, dart2js, and kernel-service (Closed)
Patch Set: Created 3 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 (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:kernel/ast.dart'; 5 import 'package:kernel/ast.dart';
6 import 'package:kernel/binary/ast_to_binary.dart'; 6 import 'package:kernel/binary/ast_to_binary.dart';
7 7
8 /// Writes libraries that satisfy the [predicate]. 8 /// Writes libraries that satisfy the [predicate].
9 /// 9 ///
10 /// Only the referenced subset of canonical names is indexed and written, 10 /// Only the referenced subset of canonical names is indexed and written,
11 /// so we don't waste time indexing all libraries of a program, when only 11 /// so we don't waste time indexing all libraries of a program, when only
12 /// a tiny subset is used. 12 /// a tiny subset is used.
13 class LimitedBinaryPrinter extends BinaryPrinter { 13 class LimitedBinaryPrinter extends BinaryPrinter {
14 final LibraryFilter predicate; 14 final LibraryFilter predicate;
15 15
16 LimitedBinaryPrinter(Sink<List<int>> sink, this.predicate) 16 /// Excludes also all uriToSource information.
ahe 2017/07/06 13:12:22 "also" implies a context that's kinda missing here
Siggi Cherem (dart-lang) 2017/07/06 19:05:28 Done. The "what" was is basically everything this
17 // TODO(sigmund): provide a way to filter sources based on their
18 // corresponding libraries (or the filter specified above).
19 final bool excludeUriToSource;
20
21 LimitedBinaryPrinter(
22 Sink<List<int>> sink, this.predicate, this.excludeUriToSource)
17 : super(sink, stringIndexer: new ReferencesStringIndexer()); 23 : super(sink, stringIndexer: new ReferencesStringIndexer());
18 24
19 @override 25 @override
20 void computeCanonicalNames(Program program) { 26 void computeCanonicalNames(Program program) {
21 for (var library in program.libraries) { 27 for (var library in program.libraries) {
22 if (predicate(library)) { 28 if (predicate(library)) {
23 program.root 29 program.root
24 .getChildFromUri(library.importUri) 30 .getChildFromUri(library.importUri)
25 .bindTo(library.reference); 31 .bindTo(library.reference);
26 library.computeCanonicalNames(); 32 library.computeCanonicalNames();
(...skipping 28 matching lines...) Expand all
55 void writeLibraries(Program program) { 61 void writeLibraries(Program program) {
56 var librariesToWrite = program.libraries.where(predicate).toList(); 62 var librariesToWrite = program.libraries.where(predicate).toList();
57 writeList(librariesToWrite, writeNode); 63 writeList(librariesToWrite, writeNode);
58 } 64 }
59 65
60 @override 66 @override
61 void writeNode(Node node) { 67 void writeNode(Node node) {
62 if (node is Library && !predicate(node)) return; 68 if (node is Library && !predicate(node)) return;
63 node.accept(this); 69 node.accept(this);
64 } 70 }
71
72 @override
73 void writeUriToSource(Program program) {
74 if (!excludeUriToSource) {
75 super.writeUriToSource(program);
76 } else {
77 // Emit a practically empty uriToSrouce table.
78 writeStringTable(new StringIndexer());
79
80 // Add an entry for '', which is always included by default.
81 writeUtf8Bytes(const <int>[]);
82 writeUInt30(0);
83 }
84 }
65 } 85 }
66 86
67 /// Extension of [StringIndexer] that also indexes canonical names of 87 /// Extension of [StringIndexer] that also indexes canonical names of
68 /// referenced classes and members. 88 /// referenced classes and members.
69 class ReferencesStringIndexer extends StringIndexer { 89 class ReferencesStringIndexer extends StringIndexer {
70 final List<CanonicalName> referencedNames = <CanonicalName>[]; 90 final List<CanonicalName> referencedNames = <CanonicalName>[];
71 91
72 @override 92 @override
73 defaultMemberReference(Member node) { 93 defaultMemberReference(Member node) {
74 _handleReferencedName(node.canonicalName); 94 _handleReferencedName(node.canonicalName);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 136 }
117 137
118 void _handleReferencedName(CanonicalName name) { 138 void _handleReferencedName(CanonicalName name) {
119 if (name == null || name.parent == null) return; 139 if (name == null || name.parent == null) return;
120 _handleReferencedName(name.parent); 140 _handleReferencedName(name.parent);
121 referencedNames.add(name); 141 referencedNames.add(name);
122 name.index = -1; 142 name.index = -1;
123 put(name.name); 143 put(name.name);
124 } 144 }
125 } 145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698