Chromium Code Reviews| 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 library kernel.class_hierarchy; | 4 library kernel.class_hierarchy; |
| 5 | 5 |
| 6 import 'ast.dart'; | 6 import 'ast.dart'; |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 import 'dart:typed_data'; | 8 import 'dart:typed_data'; |
| 9 import 'src/heap.dart'; | 9 import 'src/heap.dart'; |
| 10 import 'type_algebra.dart'; | 10 import 'type_algebra.dart'; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 /// This method will not report that a member overrides itself. A given pair | 113 /// This method will not report that a member overrides itself. A given pair |
| 114 /// may be reported multiple times when there are multiple inheritance paths | 114 /// may be reported multiple times when there are multiple inheritance paths |
| 115 /// to the overridden member. | 115 /// to the overridden member. |
| 116 /// | 116 /// |
| 117 /// It is possible for two methods to override one another in both directions. | 117 /// It is possible for two methods to override one another in both directions. |
| 118 /// | 118 /// |
| 119 /// Getters and setters are overridden separately. The [isSetter] callback | 119 /// Getters and setters are overridden separately. The [isSetter] callback |
| 120 /// parameter determines which type of access is being overridden. | 120 /// parameter determines which type of access is being overridden. |
| 121 void forEachOverridePair(Class class_, | 121 void forEachOverridePair(Class class_, |
| 122 callback(Member declaredMember, Member interfaceMember, bool isSetter)); | 122 callback(Member declaredMember, Member interfaceMember, bool isSetter)); |
| 123 | |
| 124 /// This method is invoked by the client after it changed the [changed] | |
| 125 /// classes, and some of the information that this hierarchy might have | |
| 126 /// cached, is not valid anymore. The hierarchy may perform required | |
| 127 /// updates and return the same instance, or return a new instance. | |
| 128 ClassHierarchy applyChanges(Iterable<Class> changed); | |
|
ahe
2017/06/08 20:18:10
I suggest that you rename this parameter to classe
scheglov
2017/06/08 21:00:25
Done.
| |
| 123 } | 129 } |
| 124 | 130 |
| 125 /// Implementation of [ClassHierarchy] for closed world. | 131 /// Implementation of [ClassHierarchy] for closed world. |
| 126 class ClosedWorldClassHierarchy implements ClassHierarchy { | 132 class ClosedWorldClassHierarchy implements ClassHierarchy { |
| 133 /// The [Program] that this class hierarchy represents. | |
| 134 final Program program; | |
|
ahe
2017/06/08 20:18:10
Private?
scheglov
2017/06/08 21:00:24
Done.
| |
| 135 | |
| 127 /// All classes in the program. | 136 /// All classes in the program. |
| 128 /// | 137 /// |
| 129 /// The list is ordered so that classes occur after their super classes. | 138 /// The list is ordered so that classes occur after their super classes. |
| 130 final List<Class> classes; | 139 final List<Class> classes; |
| 131 | 140 |
| 132 final Map<Class, _ClassInfo> _infoFor = <Class, _ClassInfo>{}; | 141 final Map<Class, _ClassInfo> _infoFor = <Class, _ClassInfo>{}; |
| 133 | 142 |
| 134 ClosedWorldClassHierarchy(Program program) | 143 ClosedWorldClassHierarchy(Program program) |
| 135 : this._internal(program, _countClasses(program)); | 144 : this._internal(program, _countClasses(program)); |
| 136 | 145 |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 /// Returns the subtypes of [class_] as an interval list. | 449 /// Returns the subtypes of [class_] as an interval list. |
| 441 ClassSet getSubtypesOf(Class class_) { | 450 ClassSet getSubtypesOf(Class class_) { |
| 442 return new ClassSet(this, _infoFor[class_].subtypeIntervalList); | 451 return new ClassSet(this, _infoFor[class_].subtypeIntervalList); |
| 443 } | 452 } |
| 444 | 453 |
| 445 /// Returns the subclasses of [class_] as an interval list. | 454 /// Returns the subclasses of [class_] as an interval list. |
| 446 ClassSet getSubclassesOf(Class class_) { | 455 ClassSet getSubclassesOf(Class class_) { |
| 447 return new ClassSet(this, _infoFor[class_].subclassIntervalList); | 456 return new ClassSet(this, _infoFor[class_].subclassIntervalList); |
| 448 } | 457 } |
| 449 | 458 |
| 450 ClosedWorldClassHierarchy._internal(Program program, int numberOfClasses) | 459 @override |
| 460 ClassHierarchy applyChanges(Iterable<Class> changed) { | |
| 461 if (changed.isEmpty) return this; | |
| 462 return new ClosedWorldClassHierarchy(program); | |
| 463 } | |
| 464 | |
| 465 ClosedWorldClassHierarchy._internal(this.program, int numberOfClasses) | |
| 451 : classes = new List<Class>(numberOfClasses) { | 466 : classes = new List<Class>(numberOfClasses) { |
| 452 // Build the class ordering based on a topological sort. | 467 // Build the class ordering based on a topological sort. |
| 453 for (var library in program.libraries) { | 468 for (var library in program.libraries) { |
| 454 for (var classNode in library.classes) { | 469 for (var classNode in library.classes) { |
| 455 _topologicalSortVisit(classNode); | 470 _topologicalSortVisit(classNode); |
| 456 } | 471 } |
| 457 } | 472 } |
| 458 | 473 |
| 459 // Build index of direct children. Do this after the topological sort so | 474 // Build index of direct children. Do this after the topological sort so |
| 460 // that super types always occur before subtypes. | 475 // that super types always occur before subtypes. |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1118 class _LubHeap extends Heap<_ClassInfo> { | 1133 class _LubHeap extends Heap<_ClassInfo> { |
| 1119 @override | 1134 @override |
| 1120 bool sortsBefore(_ClassInfo a, _ClassInfo b) => sortsBeforeStatic(a, b); | 1135 bool sortsBefore(_ClassInfo a, _ClassInfo b) => sortsBeforeStatic(a, b); |
| 1121 | 1136 |
| 1122 static bool sortsBeforeStatic(_ClassInfo a, _ClassInfo b) { | 1137 static bool sortsBeforeStatic(_ClassInfo a, _ClassInfo b) { |
| 1123 if (a.depth > b.depth) return true; | 1138 if (a.depth > b.depth) return true; |
| 1124 if (a.depth < b.depth) return false; | 1139 if (a.depth < b.depth) return false; |
| 1125 return a.topologicalIndex < b.topologicalIndex; | 1140 return a.topologicalIndex < b.topologicalIndex; |
| 1126 } | 1141 } |
| 1127 } | 1142 } |
| OLD | NEW |