| 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 library kernel.tree_shaker; | 5 library kernel.tree_shaker; |
| 6 | 6 |
| 7 import '../ast.dart'; | 7 import '../ast.dart'; |
| 8 import '../class_hierarchy.dart'; | 8 import '../class_hierarchy.dart'; |
| 9 import '../core_types.dart'; | 9 import '../core_types.dart'; |
| 10 import '../type_environment.dart'; | 10 import '../type_environment.dart'; |
| 11 import '../library_index.dart'; | 11 import '../library_index.dart'; |
| 12 | 12 |
| 13 Program transformProgram(Program program, {List<ProgramRoot> programRoots}) { | 13 Program transformProgram(CoreTypes coreTypes, Program program, |
| 14 new TreeShaker(program, programRoots: programRoots).transform(program); | 14 {List<ProgramRoot> programRoots}) { |
| 15 new TreeShaker(coreTypes, program, programRoots: programRoots) |
| 16 .transform(program); |
| 15 return program; | 17 return program; |
| 16 } | 18 } |
| 17 | 19 |
| 18 enum ProgramRootKind { | 20 enum ProgramRootKind { |
| 19 /// The root is a class which will be instantiated by | 21 /// The root is a class which will be instantiated by |
| 20 /// external / non-Dart code. | 22 /// external / non-Dart code. |
| 21 ExternallyInstantiatedClass, | 23 ExternallyInstantiatedClass, |
| 22 | 24 |
| 23 /// The root is a setter function or a field. | 25 /// The root is a setter function or a field. |
| 24 Setter, | 26 Setter, |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 162 |
| 161 Library _mirrorsLibrary; | 163 Library _mirrorsLibrary; |
| 162 | 164 |
| 163 /// Set to true if any use of the `dart:mirrors` API is found. | 165 /// Set to true if any use of the `dart:mirrors` API is found. |
| 164 bool isUsingMirrors = false; | 166 bool isUsingMirrors = false; |
| 165 | 167 |
| 166 /// If we have roots, we will shake, even if we encounter some elements from | 168 /// If we have roots, we will shake, even if we encounter some elements from |
| 167 /// the mirrors library. | 169 /// the mirrors library. |
| 168 bool get forceShaking => programRoots != null && programRoots.isNotEmpty; | 170 bool get forceShaking => programRoots != null && programRoots.isNotEmpty; |
| 169 | 171 |
| 170 TreeShaker(Program program, | 172 TreeShaker(CoreTypes coreTypes, Program program, |
| 171 {ClassHierarchy hierarchy, | 173 {ClassHierarchy hierarchy, |
| 172 CoreTypes coreTypes, | |
| 173 bool strongMode: false, | 174 bool strongMode: false, |
| 174 List<ProgramRoot> programRoots}) | 175 List<ProgramRoot> programRoots}) |
| 175 : this._internal(program, hierarchy ?? new ClassHierarchy(program), | 176 : this._internal(program, hierarchy ?? new ClassHierarchy(program), |
| 176 coreTypes ?? new CoreTypes(program), strongMode, programRoots); | 177 coreTypes, strongMode, programRoots); |
| 177 | 178 |
| 178 bool isMemberBodyUsed(Member member) { | 179 bool isMemberBodyUsed(Member member) { |
| 179 return _usedMembers.containsKey(member); | 180 return _usedMembers.containsKey(member); |
| 180 } | 181 } |
| 181 | 182 |
| 182 bool isMemberOverridden(Member member) { | 183 bool isMemberOverridden(Member member) { |
| 183 return _overriddenMembers.contains(member); | 184 return _overriddenMembers.contains(member); |
| 184 } | 185 } |
| 185 | 186 |
| 186 bool isMemberUsed(Member member) { | 187 bool isMemberUsed(Member member) { |
| (...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 classNode == coreTypes.futureClass || | 1083 classNode == coreTypes.futureClass || |
| 1083 classNode == coreTypes.streamClass || | 1084 classNode == coreTypes.streamClass || |
| 1084 classNode == coreTypes.listClass || | 1085 classNode == coreTypes.listClass || |
| 1085 classNode == coreTypes.mapClass; | 1086 classNode == coreTypes.mapClass; |
| 1086 } | 1087 } |
| 1087 } | 1088 } |
| 1088 | 1089 |
| 1089 /// Exception that is thrown to stop the tree shaking analysis when a use | 1090 /// Exception that is thrown to stop the tree shaking analysis when a use |
| 1090 /// of `dart:mirrors` is found. | 1091 /// of `dart:mirrors` is found. |
| 1091 class _UsingMirrorsException {} | 1092 class _UsingMirrorsException {} |
| OLD | NEW |