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

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

Issue 2979463002: Revert "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
« no previous file with comments | « pkg/kernel/lib/binary/ast_from_binary.dart ('k') | pkg/kernel/lib/target/targets.dart » ('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 (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 /// Excludes all uriToSource information. 16 LimitedBinaryPrinter(Sink<List<int>> sink, this.predicate)
17 ///
18 /// By default the [predicate] above will only exclude canonical names and
19 /// kernel libraries, but it will still emit the sources for all libraries.
20 /// filtered by libraries matching [predicate].
21 // TODO(sigmund): provide a way to filter sources directly based on
22 // [predicate]. That requires special logic to handle sources from part files.
23 final bool excludeUriToSource;
24
25 LimitedBinaryPrinter(
26 Sink<List<int>> sink, this.predicate, this.excludeUriToSource)
27 : super(sink, stringIndexer: new ReferencesStringIndexer()); 17 : super(sink, stringIndexer: new ReferencesStringIndexer());
28 18
29 @override 19 @override
30 void computeCanonicalNames(Program program) { 20 void computeCanonicalNames(Program program) {
31 for (var library in program.libraries) { 21 for (var library in program.libraries) {
32 if (predicate(library)) { 22 if (predicate(library)) {
33 program.root 23 program.root
34 .getChildFromUri(library.importUri) 24 .getChildFromUri(library.importUri)
35 .bindTo(library.reference); 25 .bindTo(library.reference);
36 library.computeCanonicalNames(); 26 library.computeCanonicalNames();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 void writeNode(Node node) { 61 void writeNode(Node node) {
72 if (node is Library && !predicate(node)) return; 62 if (node is Library && !predicate(node)) return;
73 node.accept(this); 63 node.accept(this);
74 } 64 }
75 65
76 @override 66 @override
77 void writeProgramIndex(Program program, List<Library> libraries) { 67 void writeProgramIndex(Program program, List<Library> libraries) {
78 var librariesToWrite = libraries.where(predicate).toList(); 68 var librariesToWrite = libraries.where(predicate).toList();
79 super.writeProgramIndex(program, librariesToWrite); 69 super.writeProgramIndex(program, librariesToWrite);
80 } 70 }
81
82 void writeUriToSource(Program program) {
83 if (!excludeUriToSource) {
84 super.writeUriToSource(program);
85 } else {
86 // Emit a practically empty uriToSrouce table.
87 writeStringTable(new StringIndexer());
88
89 // Add an entry for '', which is always included by default.
90 writeUtf8Bytes(const <int>[]);
91 writeUInt30(0);
92 }
93 }
94 } 71 }
95 72
96 /// Extension of [StringIndexer] that also indexes canonical names of 73 /// Extension of [StringIndexer] that also indexes canonical names of
97 /// referenced classes and members. 74 /// referenced classes and members.
98 class ReferencesStringIndexer extends StringIndexer { 75 class ReferencesStringIndexer extends StringIndexer {
99 final List<CanonicalName> referencedNames = <CanonicalName>[]; 76 final List<CanonicalName> referencedNames = <CanonicalName>[];
100 77
101 @override 78 @override
102 defaultMemberReference(Member node) { 79 defaultMemberReference(Member node) {
103 _handleReferencedName(node.canonicalName); 80 _handleReferencedName(node.canonicalName);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 } 122 }
146 123
147 void _handleReferencedName(CanonicalName name) { 124 void _handleReferencedName(CanonicalName name) {
148 if (name == null || name.parent == null) return; 125 if (name == null || name.parent == null) return;
149 _handleReferencedName(name.parent); 126 _handleReferencedName(name.parent);
150 referencedNames.add(name); 127 referencedNames.add(name);
151 name.index = -1; 128 name.index = -1;
152 put(name.name); 129 put(name.name);
153 } 130 }
154 } 131 }
OLDNEW
« no previous file with comments | « pkg/kernel/lib/binary/ast_from_binary.dart ('k') | pkg/kernel/lib/target/targets.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698