OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// A transformation to create a self-contained modular kernel without | 5 /// A transformation to create a self-contained modular kernel without |
6 /// unnecessary references to other libraries. | 6 /// unnecessary references to other libraries. |
7 library fasta.kernel.kernel_outline_shaker; | 7 library fasta.kernel.kernel_outline_shaker; |
8 | 8 |
9 import 'package:kernel/ast.dart'; | 9 import 'package:kernel/ast.dart'; |
10 import 'package:kernel/core_types.dart'; | 10 import 'package:kernel/core_types.dart'; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 155 } |
156 | 156 |
157 /// Determines the root APIs that need to be retained before running the | 157 /// Determines the root APIs that need to be retained before running the |
158 /// tree-shaker. | 158 /// tree-shaker. |
159 /// | 159 /// |
160 /// This is implemented using a visitor that walks through the sources that are | 160 /// This is implemented using a visitor that walks through the sources that are |
161 /// intended to be part of the kernel output. | 161 /// intended to be part of the kernel output. |
162 // TODO(sigmund): delete. We should collect this information while | 162 // TODO(sigmund): delete. We should collect this information while |
163 // building kernel without having to run a visitor afterwards. | 163 // building kernel without having to run a visitor afterwards. |
164 class RootsMarker extends RecursiveVisitor { | 164 class RootsMarker extends RecursiveVisitor { |
| 165 final CoreTypes coreTypes; |
165 final RetainedDataBuilder data; | 166 final RetainedDataBuilder data; |
166 RootsMarker(this.data); | 167 |
| 168 RootsMarker(this.coreTypes, this.data); |
167 | 169 |
168 void run(Program program, bool isIncluded(Uri uri)) { | 170 void run(Program program, bool isIncluded(Uri uri)) { |
169 markRequired(program); | 171 markRequired(program); |
170 data.markMember(program.mainMethod); | 172 data.markMember(program.mainMethod); |
171 for (var library in program.libraries) { | 173 for (var library in program.libraries) { |
172 if (isIncluded(library.importUri)) { | 174 if (isIncluded(library.importUri)) { |
173 library.accept(this); | 175 library.accept(this); |
174 } | 176 } |
175 } | 177 } |
176 } | 178 } |
177 | 179 |
178 /// Marks classes and members that are assumed to exist by fasta or by | 180 /// Marks classes and members that are assumed to exist by fasta or by |
179 /// transformers. | 181 /// transformers. |
180 // TODO(sigmund): consider being more fine-grained and only marking what is | 182 // TODO(sigmund): consider being more fine-grained and only marking what is |
181 // seen and used. | 183 // seen and used. |
182 void markRequired(Program program) { | 184 void markRequired(Program program) { |
183 var coreTypes = new CoreTypes(program); | |
184 coreTypes.objectClass.members.forEach(data.markMember); | 185 coreTypes.objectClass.members.forEach(data.markMember); |
185 | 186 |
186 // These are assumed to be available by fasta: | 187 // These are assumed to be available by fasta: |
187 data.markClass(coreTypes.objectClass); | 188 data.markClass(coreTypes.objectClass); |
188 data.markClass(coreTypes.nullClass); | 189 data.markClass(coreTypes.nullClass); |
189 data.markClass(coreTypes.boolClass); | 190 data.markClass(coreTypes.boolClass); |
190 data.markClass(coreTypes.intClass); | 191 data.markClass(coreTypes.intClass); |
191 data.markClass(coreTypes.numClass); | 192 data.markClass(coreTypes.numClass); |
192 data.markClass(coreTypes.doubleClass); | 193 data.markClass(coreTypes.doubleClass); |
193 data.markClass(coreTypes.stringClass); | 194 data.markClass(coreTypes.stringClass); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 /// Types appear to be encoded directly, so we have no need to preserve | 395 /// Types appear to be encoded directly, so we have no need to preserve |
395 /// typedefs. | 396 /// typedefs. |
396 // TODO(sigmund): revisit if this is not the case, the `inputError` in | 397 // TODO(sigmund): revisit if this is not the case, the `inputError` in |
397 // [RootsMarker] is meant to detect this. | 398 // [RootsMarker] is meant to detect this. |
398 Typedef visitTypedef(Typedef node) => null; | 399 Typedef visitTypedef(Typedef node) => null; |
399 | 400 |
400 TreeNode defaultTreeNode(TreeNode node) => node; | 401 TreeNode defaultTreeNode(TreeNode node) => node; |
401 } | 402 } |
402 | 403 |
403 typedef bool Filter(Uri uri); | 404 typedef bool Filter(Uri uri); |
OLD | NEW |