| 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.world.class_set; | 5 library dart2js.world.class_set; |
| 6 | 6 |
| 7 import 'dart:collection' show IterableBase; | 7 import 'dart:collection' show IterableBase; |
| 8 import '../elements/elements.dart' show ClassElement; | 8 import '../elements/elements.dart' show ClassElement; |
| 9 import '../util/util.dart' show Link; | 9 import '../util/util.dart' show Link; |
| 10 | 10 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 bool includeUninstantiated: true, | 94 bool includeUninstantiated: true, |
| 95 bool strict: false}) { | 95 bool strict: false}) { |
| 96 return new ClassHierarchyNodeIterable( | 96 return new ClassHierarchyNodeIterable( |
| 97 this, | 97 this, |
| 98 includeRoot: !strict, | 98 includeRoot: !strict, |
| 99 includeDirectlyInstantiated: includeDirectlyInstantiated, | 99 includeDirectlyInstantiated: includeDirectlyInstantiated, |
| 100 includeIndirectlyInstantiated: includeIndirectlyInstantiated, | 100 includeIndirectlyInstantiated: includeIndirectlyInstantiated, |
| 101 includeUninstantiated: includeUninstantiated); | 101 includeUninstantiated: includeUninstantiated); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void printOn(StringBuffer sb, String indentation, | 104 void dump(StringBuffer sb, String indentation) { |
| 105 {bool instantiatedOnly: false}) { | 105 sb.write('$indentation$cls:['); |
| 106 sb.write('$indentation$cls'); | |
| 107 if (isDirectlyInstantiated) { | |
| 108 sb.write(' directly'); | |
| 109 } | |
| 110 if (isIndirectlyInstantiated) { | |
| 111 sb.write(' indirectly'); | |
| 112 } | |
| 113 sb.write(' ['); | |
| 114 if (_directSubclasses.isEmpty) { | 106 if (_directSubclasses.isEmpty) { |
| 115 sb.write(']'); | 107 sb.write(']'); |
| 116 } else { | 108 } else { |
| 109 sb.write('\n'); |
| 117 bool needsComma = false; | 110 bool needsComma = false; |
| 118 for (Link<ClassHierarchyNode> link = _directSubclasses; | 111 for (Link<ClassHierarchyNode> link = _directSubclasses; |
| 119 !link.isEmpty; | 112 !link.isEmpty; |
| 120 link = link.tail) { | 113 link = link.tail) { |
| 121 if (instantiatedOnly && !link.head.isInstantiated) { | |
| 122 continue; | |
| 123 } | |
| 124 if (needsComma) { | 114 if (needsComma) { |
| 125 sb.write(',\n'); | 115 sb.write(',\n'); |
| 126 } else { | |
| 127 sb.write('\n'); | |
| 128 } | 116 } |
| 129 link.head.printOn( | 117 link.head.dump(sb, '$indentation '); |
| 130 sb, '$indentation ', instantiatedOnly: instantiatedOnly); | |
| 131 needsComma = true; | 118 needsComma = true; |
| 132 } | 119 } |
| 133 if (needsComma) { | 120 sb.write('\n'); |
| 134 sb.write('\n'); | 121 sb.write('$indentation]'); |
| 135 sb.write('$indentation]'); | |
| 136 } else { | |
| 137 sb.write(']'); | |
| 138 } | |
| 139 } | 122 } |
| 140 } | 123 } |
| 141 | 124 |
| 142 String dump({String indentation: '', bool instantiatedOnly: false}) { | |
| 143 StringBuffer sb = new StringBuffer(); | |
| 144 printOn(sb, indentation, instantiatedOnly: instantiatedOnly); | |
| 145 return sb.toString(); | |
| 146 } | |
| 147 | |
| 148 String toString() => cls.toString(); | 125 String toString() => cls.toString(); |
| 149 } | 126 } |
| 150 | 127 |
| 151 /// Object holding the subclass and subtype relation for a single | 128 /// Object holding the subclass and subtype relation for a single |
| 152 /// [ClassElement]. | 129 /// [ClassElement]. |
| 153 /// | 130 /// |
| 154 /// The subclass relation for a class `C` is modelled through a reference to | 131 /// The subclass relation for a class `C` is modelled through a reference to |
| 155 /// the [ClassHierarchyNode] for `C` in the global [ClassHierarchyNode] tree | 132 /// the [ClassHierarchyNode] for `C` in the global [ClassHierarchyNode] tree |
| 156 /// computed in [World]. | 133 /// computed in [World]. |
| 157 /// | 134 /// |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 if (!added) { | 267 if (!added) { |
| 291 newSubtypes.add(subtype); | 268 newSubtypes.add(subtype); |
| 292 } | 269 } |
| 293 _directSubtypes = newSubtypes; | 270 _directSubtypes = newSubtypes; |
| 294 } | 271 } |
| 295 } | 272 } |
| 296 | 273 |
| 297 String toString() { | 274 String toString() { |
| 298 StringBuffer sb = new StringBuffer(); | 275 StringBuffer sb = new StringBuffer(); |
| 299 sb.write('[\n'); | 276 sb.write('[\n'); |
| 300 node.printOn(sb, ' '); | 277 node.dump(sb, ' '); |
| 301 sb.write('\n'); | 278 sb.write('\n'); |
| 302 if (_directSubtypes != null) { | 279 if (_directSubtypes != null) { |
| 303 for (ClassHierarchyNode node in _directSubtypes) { | 280 for (ClassHierarchyNode node in _directSubtypes) { |
| 304 node.printOn(sb, ' '); | 281 node.dump(sb, ' '); |
| 305 sb.write('\n'); | 282 sb.write('\n'); |
| 306 } | 283 } |
| 307 } | 284 } |
| 308 sb.write(']'); | 285 sb.write(']'); |
| 309 return sb.toString(); | 286 return sb.toString(); |
| 310 } | 287 } |
| 311 } | 288 } |
| 312 | 289 |
| 313 /// Iterable for subclasses of a [ClassHierarchyNode]. | 290 /// Iterable for subclasses of a [ClassHierarchyNode]. |
| 314 class ClassHierarchyNodeIterable extends IterableBase<ClassElement> { | 291 class ClassHierarchyNodeIterable extends IterableBase<ClassElement> { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 includeDirectlyInstantiated: includeDirectlyInstantiated, | 469 includeDirectlyInstantiated: includeDirectlyInstantiated, |
| 493 includeIndirectlyInstantiated: includeIndirectlyInstantiated, | 470 includeIndirectlyInstantiated: includeIndirectlyInstantiated, |
| 494 includeUninstantiated: includeUninstantiated).iterator; | 471 includeUninstantiated: includeUninstantiated).iterator; |
| 495 if (elements.moveNext()) { | 472 if (elements.moveNext()) { |
| 496 return true; | 473 return true; |
| 497 } | 474 } |
| 498 } | 475 } |
| 499 return false; | 476 return false; |
| 500 } | 477 } |
| 501 } | 478 } |
| OLD | NEW |