Chromium Code Reviews| 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 '../dart_types.dart' show | 7 import '../dart_types.dart' show |
| 8 DartType, | 8 DartType, |
| 9 InterfaceType; | 9 InterfaceType; |
| 10 import '../elements/elements.dart' show | 10 import '../elements/elements.dart' show |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 Iterable<StaticUse> get staticUses => const <StaticUse>[]; | 28 Iterable<StaticUse> get staticUses => const <StaticUse>[]; |
| 29 | 29 |
| 30 // TODO(johnniwinther): Replace this by called constructors with type | 30 // TODO(johnniwinther): Replace this by called constructors with type |
| 31 // arguments. | 31 // arguments. |
| 32 // TODO(johnniwinther): Collect all checked types for checked mode separately | 32 // TODO(johnniwinther): Collect all checked types for checked mode separately |
| 33 // to support serialization. | 33 // to support serialization. |
| 34 | 34 |
| 35 Iterable<TypeUse> get typeUses => const <TypeUse>[]; | 35 Iterable<TypeUse> get typeUses => const <TypeUse>[]; |
| 36 | 36 |
| 37 void apply(WorldImpactVisitor visitor) { | |
| 38 staticUses.forEach(visitor.visitStaticUse); | |
| 39 dynamicUses.forEach(visitor.visitDynamicUse); | |
| 40 typeUses.forEach(visitor.visitTypeUse); | |
| 41 } | |
| 42 | |
| 37 String toString() => dump(this); | 43 String toString() => dump(this); |
| 38 | 44 |
| 39 static String dump(WorldImpact worldImpact) { | 45 static String dump(WorldImpact worldImpact) { |
| 40 StringBuffer sb = new StringBuffer(); | 46 StringBuffer sb = new StringBuffer(); |
| 41 printOn(sb, worldImpact); | 47 printOn(sb, worldImpact); |
| 42 return sb.toString(); | 48 return sb.toString(); |
| 43 } | 49 } |
| 44 | 50 |
| 45 static void printOn(StringBuffer sb, WorldImpact worldImpact) { | 51 static void printOn(StringBuffer sb, WorldImpact worldImpact) { |
| 46 void add(String title, Iterable iterable) { | 52 void add(String title, Iterable iterable) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 _staticUses.addAll(worldImpact.staticUses); | 153 _staticUses.addAll(worldImpact.staticUses); |
| 148 } | 154 } |
| 149 _staticUses.add(staticUse); | 155 _staticUses.add(staticUse); |
| 150 } | 156 } |
| 151 | 157 |
| 152 @override | 158 @override |
| 153 Iterable<StaticUse> get staticUses { | 159 Iterable<StaticUse> get staticUses { |
| 154 return _staticUses != null ? _staticUses : worldImpact.staticUses; | 160 return _staticUses != null ? _staticUses : worldImpact.staticUses; |
| 155 } | 161 } |
| 156 | 162 |
| 163 void apply(WorldImpactVisitor visitor) { | |
| 164 staticUses.forEach(visitor.visitStaticUse); | |
| 165 dynamicUses.forEach(visitor.visitDynamicUse); | |
| 166 typeUses.forEach(visitor.visitTypeUse); | |
| 167 } | |
| 168 | |
| 157 String toString() { | 169 String toString() { |
| 158 StringBuffer sb = new StringBuffer(); | 170 StringBuffer sb = new StringBuffer(); |
| 159 sb.write('TransformedWorldImpact($worldImpact)'); | 171 sb.write('TransformedWorldImpact($worldImpact)'); |
| 160 WorldImpact.printOn(sb, this); | 172 WorldImpact.printOn(sb, this); |
| 161 return sb.toString(); | 173 return sb.toString(); |
| 162 } | 174 } |
| 163 } | 175 } |
| 176 | |
| 177 class ImpactUse { | |
|
sigurdm
2015/11/20 12:13:19
dartdoc
Johnni Winther
2015/11/20 13:49:36
Done + Renamed to ImpactUseCase.
| |
| 178 final String name; | |
| 179 | |
| 180 const ImpactUse(this.name); | |
| 181 | |
| 182 String toString() => 'ImpactUse($name)'; | |
| 183 } | |
| 184 | |
| 185 class ImpactStrategy { | |
|
sigurdm
2015/11/20 12:13:19
Consider if this can be named more descriptively.
sigurdm
2015/11/20 12:13:19
dartdoc
Johnni Winther
2015/11/20 13:49:36
Acknowledged.
Johnni Winther
2015/11/20 13:49:36
Done.
| |
| 186 const ImpactStrategy(); | |
| 187 | |
| 188 /// Applies [impact] to [visitor] for the [impactUse] of [element]. | |
| 189 void visitImpact(Element element, | |
| 190 WorldImpact impact, | |
| 191 WorldImpactVisitor visitor, | |
| 192 ImpactUse impactUse) { | |
| 193 // Apply unconditionally. | |
| 194 impact.apply(visitor); | |
| 195 } | |
| 196 } | |
| 197 | |
| 198 abstract class WorldImpactVisitor { | |
|
sigurdm
2015/11/20 12:13:19
dartdoc
Johnni Winther
2015/11/20 13:49:36
Done.
| |
| 199 void visitStaticUse(StaticUse staticUse); | |
| 200 void visitDynamicUse(DynamicUse dynamicUse); | |
| 201 void visitTypeUse(TypeUse typeUse); | |
| 202 } | |
| 203 | |
| 204 // TODO(johnniwinther): Remove these when we get anonymous local classes. | |
|
sigurdm
2015/11/20 12:13:19
Don't hold your breath though ;)
Johnni Winther
2015/11/20 13:49:36
Acknowledged.
| |
| 205 typedef void VisitUse<U>(U use); | |
| 206 | |
| 207 class WorldImpactVisitorImpl implements WorldImpactVisitor { | |
| 208 final VisitUse<StaticUse> _visitStaticUse; | |
| 209 final VisitUse<DynamicUse> _visitDynamicUse; | |
| 210 final VisitUse<TypeUse> _visitTypeUse; | |
| 211 | |
| 212 WorldImpactVisitorImpl( | |
| 213 {VisitUse<StaticUse> visitStaticUse, | |
| 214 VisitUse<DynamicUse> visitDynamicUse, | |
| 215 VisitUse<TypeUse> visitTypeUse}) | |
| 216 : _visitStaticUse = visitStaticUse, | |
| 217 _visitDynamicUse = visitDynamicUse, | |
| 218 _visitTypeUse = visitTypeUse; | |
| 219 | |
| 220 @override | |
| 221 void visitStaticUse(StaticUse use) { | |
| 222 if (_visitStaticUse != null) { | |
| 223 _visitStaticUse(use); | |
| 224 } | |
| 225 } | |
| 226 | |
| 227 @override | |
| 228 void visitDynamicUse(DynamicUse use) { | |
| 229 if (_visitDynamicUse != null) { | |
| 230 _visitDynamicUse(use); | |
| 231 } | |
| 232 } | |
| 233 | |
| 234 @override | |
| 235 void visitTypeUse(TypeUse use) { | |
| 236 if (_visitTypeUse != null) { | |
| 237 _visitTypeUse(use); | |
| 238 } | |
| 239 } | |
| 240 } | |
| 241 | |
| OLD | NEW |