| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dart2js.universe.world_impact; | 5 library dart2js.universe.world_impact; |
| 6 | 6 |
| 7 import '../elements/elements.dart' show Element; | 7 import '../elements/elements.dart' show Element; |
| 8 import '../util/util.dart' show Setlet; | 8 import '../util/util.dart' show Setlet; |
| 9 import 'use.dart' show DynamicUse, StaticUse, TypeUse; | 9 import 'use.dart' show DynamicUse, StaticUse, TypeUse; |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 Iterable<StaticUse> get staticUses => const <StaticUse>[]; | 27 Iterable<StaticUse> get staticUses => const <StaticUse>[]; |
| 28 | 28 |
| 29 // TODO(johnniwinther): Replace this by called constructors with type | 29 // TODO(johnniwinther): Replace this by called constructors with type |
| 30 // arguments. | 30 // arguments. |
| 31 // TODO(johnniwinther): Collect all checked types for checked mode separately | 31 // TODO(johnniwinther): Collect all checked types for checked mode separately |
| 32 // to support serialization. | 32 // to support serialization. |
| 33 | 33 |
| 34 Iterable<TypeUse> get typeUses => const <TypeUse>[]; | 34 Iterable<TypeUse> get typeUses => const <TypeUse>[]; |
| 35 | 35 |
| 36 bool get isEmpty => true; |
| 37 |
| 36 void apply(WorldImpactVisitor visitor) { | 38 void apply(WorldImpactVisitor visitor) { |
| 37 staticUses.forEach(visitor.visitStaticUse); | 39 staticUses.forEach(visitor.visitStaticUse); |
| 38 dynamicUses.forEach(visitor.visitDynamicUse); | 40 dynamicUses.forEach(visitor.visitDynamicUse); |
| 39 typeUses.forEach(visitor.visitTypeUse); | 41 typeUses.forEach(visitor.visitTypeUse); |
| 40 } | 42 } |
| 41 | 43 |
| 42 String toString() => dump(this); | 44 String toString() => dump(this); |
| 43 | 45 |
| 44 static String dump(WorldImpact worldImpact) { | 46 static String dump(WorldImpact worldImpact) { |
| 45 StringBuffer sb = new StringBuffer(); | 47 StringBuffer sb = new StringBuffer(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 67 void registerStaticUse(StaticUse staticUse); | 69 void registerStaticUse(StaticUse staticUse); |
| 68 } | 70 } |
| 69 | 71 |
| 70 class WorldImpactBuilderImpl extends WorldImpact implements WorldImpactBuilder { | 72 class WorldImpactBuilderImpl extends WorldImpact implements WorldImpactBuilder { |
| 71 // TODO(johnniwinther): Do we benefit from lazy initialization of the | 73 // TODO(johnniwinther): Do we benefit from lazy initialization of the |
| 72 // [Setlet]s? | 74 // [Setlet]s? |
| 73 Set<DynamicUse> _dynamicUses; | 75 Set<DynamicUse> _dynamicUses; |
| 74 Set<StaticUse> _staticUses; | 76 Set<StaticUse> _staticUses; |
| 75 Set<TypeUse> _typeUses; | 77 Set<TypeUse> _typeUses; |
| 76 | 78 |
| 79 @override |
| 80 bool get isEmpty => |
| 81 _dynamicUses == null && _staticUses == null && _typeUses == null; |
| 82 |
| 83 /// Copy uses in [impact] to this impact builder. |
| 84 void addImpact(WorldImpact impact) { |
| 85 if (impact.isEmpty) return; |
| 86 impact.dynamicUses.forEach(registerDynamicUse); |
| 87 impact.staticUses.forEach(registerStaticUse); |
| 88 impact.typeUses.forEach(registerTypeUse); |
| 89 } |
| 90 |
| 77 void registerDynamicUse(DynamicUse dynamicUse) { | 91 void registerDynamicUse(DynamicUse dynamicUse) { |
| 78 assert(dynamicUse != null); | 92 assert(dynamicUse != null); |
| 79 if (_dynamicUses == null) { | 93 if (_dynamicUses == null) { |
| 80 _dynamicUses = new Setlet<DynamicUse>(); | 94 _dynamicUses = new Setlet<DynamicUse>(); |
| 81 } | 95 } |
| 82 _dynamicUses.add(dynamicUse); | 96 _dynamicUses.add(dynamicUse); |
| 83 } | 97 } |
| 84 | 98 |
| 85 Iterable<DynamicUse> get dynamicUses { | 99 Iterable<DynamicUse> get dynamicUses { |
| 86 return _dynamicUses != null ? _dynamicUses : const <DynamicUse>[]; | 100 return _dynamicUses != null ? _dynamicUses : const <DynamicUse>[]; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 class TransformedWorldImpact implements WorldImpact, WorldImpactBuilder { | 181 class TransformedWorldImpact implements WorldImpact, WorldImpactBuilder { |
| 168 final WorldImpact worldImpact; | 182 final WorldImpact worldImpact; |
| 169 | 183 |
| 170 Setlet<StaticUse> _staticUses; | 184 Setlet<StaticUse> _staticUses; |
| 171 Setlet<TypeUse> _typeUses; | 185 Setlet<TypeUse> _typeUses; |
| 172 Setlet<DynamicUse> _dynamicUses; | 186 Setlet<DynamicUse> _dynamicUses; |
| 173 | 187 |
| 174 TransformedWorldImpact(this.worldImpact); | 188 TransformedWorldImpact(this.worldImpact); |
| 175 | 189 |
| 176 @override | 190 @override |
| 191 bool get isEmpty { |
| 192 return worldImpact.isEmpty && |
| 193 _staticUses == null && |
| 194 _typeUses == null && |
| 195 _dynamicUses == null; |
| 196 } |
| 197 |
| 198 @override |
| 177 Iterable<DynamicUse> get dynamicUses { | 199 Iterable<DynamicUse> get dynamicUses { |
| 178 return _dynamicUses != null ? _dynamicUses : worldImpact.dynamicUses; | 200 return _dynamicUses != null ? _dynamicUses : worldImpact.dynamicUses; |
| 179 } | 201 } |
| 180 | 202 |
| 181 void registerDynamicUse(DynamicUse dynamicUse) { | 203 void registerDynamicUse(DynamicUse dynamicUse) { |
| 182 if (_dynamicUses == null) { | 204 if (_dynamicUses == null) { |
| 183 _dynamicUses = new Setlet<DynamicUse>(); | 205 _dynamicUses = new Setlet<DynamicUse>(); |
| 184 _dynamicUses.addAll(worldImpact.dynamicUses); | 206 _dynamicUses.addAll(worldImpact.dynamicUses); |
| 185 } | 207 } |
| 186 _dynamicUses.add(dynamicUse); | 208 _dynamicUses.add(dynamicUse); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 312 } |
| 291 } | 313 } |
| 292 | 314 |
| 293 @override | 315 @override |
| 294 void visitTypeUse(TypeUse use) { | 316 void visitTypeUse(TypeUse use) { |
| 295 if (_visitTypeUse != null) { | 317 if (_visitTypeUse != null) { |
| 296 _visitTypeUse(use); | 318 _visitTypeUse(use); |
| 297 } | 319 } |
| 298 } | 320 } |
| 299 } | 321 } |
| OLD | NEW |