OLD | NEW |
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 LimitedBinaryPrinter(Sink<List<int>> sink, this.predicate) |
17 : super(sink, stringIndexer: new ReferencesStringIndexer()); | 17 : super(sink, stringIndexer: new ReferencesStringIndexer()); |
18 | 18 |
19 @override | 19 @override |
| 20 void computeCanonicalNames(Program program) { |
| 21 for (var library in program.libraries) { |
| 22 if (predicate(library)) { |
| 23 program.root |
| 24 .getChildFromUri(library.importUri) |
| 25 .bindTo(library.reference); |
| 26 library.computeCanonicalNames(); |
| 27 } |
| 28 } |
| 29 } |
| 30 |
| 31 @override |
20 void addCanonicalNamesForLinkTable(List<CanonicalName> list) { | 32 void addCanonicalNamesForLinkTable(List<CanonicalName> list) { |
21 ReferencesStringIndexer stringIndexer = this.stringIndexer; | 33 ReferencesStringIndexer stringIndexer = this.stringIndexer; |
22 stringIndexer.referencedNames.forEach((name) { | 34 stringIndexer.referencedNames.forEach((name) { |
23 if (name.index != -1) return; | 35 if (name.index != -1) return; |
24 name.index = list.length; | 36 name.index = list.length; |
25 list.add(name); | 37 list.add(name); |
26 }); | 38 }); |
27 } | 39 } |
28 | 40 |
29 @override | 41 @override |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 116 } |
105 | 117 |
106 void _handleReferencedName(CanonicalName name) { | 118 void _handleReferencedName(CanonicalName name) { |
107 if (name == null || name.parent == null) return; | 119 if (name == null || name.parent == null) return; |
108 _handleReferencedName(name.parent); | 120 _handleReferencedName(name.parent); |
109 referencedNames.add(name); | 121 referencedNames.add(name); |
110 name.index = -1; | 122 name.index = -1; |
111 put(name.name); | 123 put(name.name); |
112 } | 124 } |
113 } | 125 } |
OLD | NEW |