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'; |
11 | 11 |
12 import '../deprecated_problems.dart' show deprecated_internalProblem; | 12 import '../problems.dart' show unimplemented, unsupported; |
13 | 13 |
14 /// Removes unnecessary libraries, classes, and members from [program]. | 14 /// Removes unnecessary libraries, classes, and members from [program]. |
15 /// | 15 /// |
16 /// This applies a simple "tree-shaking" technique: the full body of libraries | 16 /// This applies a simple "tree-shaking" technique: the full body of libraries |
17 /// whose URI match [isIncluded] is preserved, and so is the outline of the | 17 /// whose URI match [isIncluded] is preserved, and so is the outline of the |
18 /// members and classes which are transitively visible from the | 18 /// members and classes which are transitively visible from the |
19 /// included libraries. | 19 /// included libraries. |
20 /// | 20 /// |
21 /// The intent is that the resulting program has the entire code that is meant | 21 /// The intent is that the resulting program has the entire code that is meant |
22 /// to be included and the minimum required to prevent dangling references and | 22 /// to be included and the minimum required to prevent dangling references and |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 256 |
257 @override | 257 @override |
258 visitStaticInvocation(StaticInvocation node) { | 258 visitStaticInvocation(StaticInvocation node) { |
259 data.markMember(node.target); | 259 data.markMember(node.target); |
260 node.visitChildren(this); | 260 node.visitChildren(this); |
261 } | 261 } |
262 | 262 |
263 @override | 263 @override |
264 visitDirectMethodInvocation(DirectMethodInvocation node) { | 264 visitDirectMethodInvocation(DirectMethodInvocation node) { |
265 if (node.receiver is! ThisExpression) { | 265 if (node.receiver is! ThisExpression) { |
266 return deprecated_internalProblem( | 266 return unsupported("direct call not on this", node.fileOffset, null); |
267 'Direct calls are only supported on "this"'); | |
268 } | 267 } |
269 data.markMember(node.target); | 268 data.markMember(node.target); |
270 node.visitChildren(this); | 269 node.visitChildren(this); |
271 } | 270 } |
272 | 271 |
273 @override | 272 @override |
274 visitMethodInvocation(MethodInvocation node) { | 273 visitMethodInvocation(MethodInvocation node) { |
275 data.markMember(node.interfaceTarget); | 274 data.markMember(node.interfaceTarget); |
276 node.visitChildren(this); | 275 node.visitChildren(this); |
277 } | 276 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } | 330 } |
332 | 331 |
333 @override | 332 @override |
334 visitSupertype(Supertype node) { | 333 visitSupertype(Supertype node) { |
335 data.markClass(node.classNode); | 334 data.markClass(node.classNode); |
336 node.visitChildren(this); | 335 node.visitChildren(this); |
337 } | 336 } |
338 | 337 |
339 @override | 338 @override |
340 visitTypedefReference(Typedef node) { | 339 visitTypedefReference(Typedef node) { |
341 return deprecated_internalProblem('not implemented'); | 340 return unimplemented("visitTypedefReference", -1, null); |
342 } | 341 } |
343 } | 342 } |
344 | 343 |
345 /// Transformer that trims everything in the excluded libraries that is not | 344 /// Transformer that trims everything in the excluded libraries that is not |
346 /// marked as preserved by the given [RetainedData]. For every member in these | 345 /// marked as preserved by the given [RetainedData]. For every member in these |
347 /// excluded libraries, this transformer also removes function bodies and | 346 /// excluded libraries, this transformer also removes function bodies and |
348 /// initializers. | 347 /// initializers. |
349 class KernelOutlineShaker extends Transformer { | 348 class KernelOutlineShaker extends Transformer { |
350 final RetainedData data; | 349 final RetainedData data; |
351 final Filter isIncluded; | 350 final Filter isIncluded; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 /// Types appear to be encoded directly, so we have no need to preserve | 396 /// Types appear to be encoded directly, so we have no need to preserve |
398 /// typedefs. | 397 /// typedefs. |
399 // TODO(sigmund): revisit if this is not the case, the `inputError` in | 398 // TODO(sigmund): revisit if this is not the case, the `inputError` in |
400 // [RootsMarker] is meant to detect this. | 399 // [RootsMarker] is meant to detect this. |
401 Typedef visitTypedef(Typedef node) => null; | 400 Typedef visitTypedef(Typedef node) => null; |
402 | 401 |
403 TreeNode defaultTreeNode(TreeNode node) => node; | 402 TreeNode defaultTreeNode(TreeNode node) => node; |
404 } | 403 } |
405 | 404 |
406 typedef bool Filter(Uri uri); | 405 typedef bool Filter(Uri uri); |
OLD | NEW |