OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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.incremental_class_hierarchy; | 4 library kernel.incremental_class_hierarchy; |
5 | 5 |
6 import 'dart:collection'; | 6 import 'dart:collection'; |
7 import 'dart:math'; | 7 import 'dart:math'; |
8 | 8 |
9 import 'package:kernel/ast.dart'; | 9 import 'package:kernel/ast.dart'; |
10 import 'package:kernel/class_hierarchy.dart'; | 10 import 'package:kernel/class_hierarchy.dart'; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 final Map<Class, _ClassInfo> _info = new LinkedHashMap<Class, _ClassInfo>(); | 79 final Map<Class, _ClassInfo> _info = new LinkedHashMap<Class, _ClassInfo>(); |
80 | 80 |
81 @override | 81 @override |
82 ClassHierarchy applyChanges(Iterable<Class> classes) { | 82 ClassHierarchy applyChanges(Iterable<Class> classes) { |
83 if (classes.isEmpty) return this; | 83 if (classes.isEmpty) return this; |
84 return new IncrementalClassHierarchy(); | 84 return new IncrementalClassHierarchy(); |
85 } | 85 } |
86 | 86 |
87 @override | 87 @override |
88 void forEachOverridePair(Class node, | 88 void forEachOverridePair(Class node, |
89 callback(Member declaredMember, Member interfaceMember, bool isSetter), | 89 callback(Member declaredMember, Member interfaceMember, bool isSetter)) { |
90 {bool crossGettersSetters: false}) { | |
91 _ClassInfo info = _getInfo(node); | 90 _ClassInfo info = _getInfo(node); |
92 for (var supertype in node.supers) { | 91 for (var supertype in node.supers) { |
93 var superNode = supertype.classNode; | 92 var superNode = supertype.classNode; |
94 var superInfo = _getInfo(superNode); | 93 var superInfo = _getInfo(superNode); |
95 | 94 |
96 var superGetters = superInfo.interfaceGettersAndCalls; | 95 var superGetters = superInfo.interfaceGettersAndCalls; |
97 var superSetters = superInfo.interfaceSetters; | 96 var superSetters = superInfo.interfaceSetters; |
98 | 97 |
99 _reportOverrides(info.implementedGettersAndCalls, superGetters, callback); | 98 _reportOverrides(info.implementedGettersAndCalls, superGetters, callback); |
100 _reportOverrides(info.declaredGettersAndCalls, superGetters, callback, | 99 _reportOverrides(info.declaredGettersAndCalls, superGetters, callback, |
101 onlyAbstract: true); | 100 onlyAbstract: true); |
102 | 101 |
103 _reportOverrides(info.implementedSetters, superSetters, callback, | 102 _reportOverrides(info.implementedSetters, superSetters, callback, |
104 isSetter: true); | 103 isSetter: true); |
105 _reportOverrides(info.declaredSetters, superSetters, callback, | 104 _reportOverrides(info.declaredSetters, superSetters, callback, |
106 isSetter: true, onlyAbstract: true); | 105 isSetter: true, onlyAbstract: true); |
107 | |
108 if (crossGettersSetters) { | |
109 _reportOverrides(info.declaredGettersAndCalls, superSetters, callback); | |
110 _reportOverrides(info.declaredSetters, superGetters, callback); | |
111 } | |
112 } | 106 } |
113 if (!node.isAbstract) { | 107 if (!node.isAbstract) { |
114 // If a non-abstract class declares an abstract method M whose | 108 // If a non-abstract class declares an abstract method M whose |
115 // implementation M' is inherited from the superclass, then the inherited | 109 // implementation M' is inherited from the superclass, then the inherited |
116 // method M' overrides the declared method M. | 110 // method M' overrides the declared method M. |
117 // This flies in the face of conventional override logic, but is necessary | 111 // This flies in the face of conventional override logic, but is necessary |
118 // because an instance of the class will contain the method M' which can | 112 // because an instance of the class will contain the method M' which can |
119 // be invoked through the interface of M. | 113 // be invoked through the interface of M. |
120 // Note that [_reportOverrides] does not report self-overrides, so in | 114 // Note that [_reportOverrides] does not report self-overrides, so in |
121 // most cases these calls will just scan both lists and report nothing. | 115 // most cases these calls will just scan both lists and report nothing. |
122 _reportOverrides(info.implementedGettersAndCalls, | 116 _reportOverrides(info.implementedGettersAndCalls, |
123 info.declaredGettersAndCalls, callback); | 117 info.declaredGettersAndCalls, callback); |
124 _reportOverrides(info.implementedSetters, info.declaredSetters, callback, | 118 _reportOverrides(info.implementedSetters, info.declaredSetters, callback, |
125 isSetter: true); | 119 isSetter: true); |
126 } | 120 } |
127 } | 121 } |
128 | 122 |
129 @override | 123 @override |
| 124 void forEachCrossOverridePair(Class node, |
| 125 callback(Member declaredMember, Member interfaceMember, bool isSetter), |
| 126 {bool crossGettersSetters: false}) { |
| 127 _ClassInfo info = _getInfo(node); |
| 128 for (var supertype in node.supers) { |
| 129 var superNode = supertype.classNode; |
| 130 var superInfo = _getInfo(superNode); |
| 131 |
| 132 var superGetters = superInfo.interfaceGettersAndCalls; |
| 133 var superSetters = superInfo.interfaceSetters; |
| 134 |
| 135 _reportOverrides(info.declaredGettersAndCalls, superSetters, callback); |
| 136 _reportOverrides(info.declaredSetters, superGetters, callback, |
| 137 isSetter: true); |
| 138 } |
| 139 } |
| 140 |
| 141 @override |
130 Supertype getClassAsInstanceOf(Class node, Class superclass) { | 142 Supertype getClassAsInstanceOf(Class node, Class superclass) { |
131 if (identical(node, superclass)) return node.asThisSupertype; | 143 if (identical(node, superclass)) return node.asThisSupertype; |
132 _ClassInfo info = _getInfo(node); | 144 _ClassInfo info = _getInfo(node); |
133 _ClassInfo superInfo = _getInfo(superclass); | 145 _ClassInfo superInfo = _getInfo(superclass); |
134 if (!info.isSubtypeOf(superInfo)) return null; | 146 if (!info.isSubtypeOf(superInfo)) return null; |
135 if (superclass.typeParameters.isEmpty) return superclass.asRawSupertype; | 147 if (superclass.typeParameters.isEmpty) return superclass.asRawSupertype; |
136 return info.genericSuperTypes[superclass]; | 148 return info.genericSuperTypes[superclass]; |
137 } | 149 } |
138 | 150 |
139 @override | 151 @override |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 class _LubHeap extends Heap<_ClassInfo> { | 737 class _LubHeap extends Heap<_ClassInfo> { |
726 @override | 738 @override |
727 bool sortsBefore(_ClassInfo a, _ClassInfo b) => sortsBeforeStatic(a, b); | 739 bool sortsBefore(_ClassInfo a, _ClassInfo b) => sortsBeforeStatic(a, b); |
728 | 740 |
729 static bool sortsBeforeStatic(_ClassInfo a, _ClassInfo b) { | 741 static bool sortsBeforeStatic(_ClassInfo a, _ClassInfo b) { |
730 if (a.depth > b.depth) return true; | 742 if (a.depth > b.depth) return true; |
731 if (a.depth < b.depth) return false; | 743 if (a.depth < b.depth) return false; |
732 return a.id < b.id; | 744 return a.id < b.id; |
733 } | 745 } |
734 } | 746 } |
OLD | NEW |