Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: pkg/kernel/lib/class_hierarchy.dart

Issue 2924333002: Use ClassHierarchy.applyChanges() in MixinFullResolution. (Closed)
Patch Set: Changes for review comments. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 [classes], and
125 /// some of the information that this hierarchy might have cached, is not
126 /// valid anymore. The hierarchy may perform required updates and return the
127 /// same instance, or return a new instance.
128 ClassHierarchy applyChanges(Iterable<Class> classes);
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;
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
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> classes) {
461 if (classes.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.
461 for (int i = 0; i < classes.length; ++i) { 476 for (int i = 0; i < classes.length; ++i) {
462 var class_ = classes[i]; 477 var class_ = classes[i];
463 var info = _infoFor[class_]; 478 var info = _infoFor[class_];
(...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/fasta/analyzer_loader.dart ('k') | pkg/kernel/lib/src/incremental_class_hierarchy.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698