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

Side by Side Diff: pkg/kernel/lib/src/incremental_class_hierarchy.dart

Issue 2920323002: Fix the test and implement forEachOverridePair() for IncrementalClassHierarchy. (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | pkg/kernel/test/class_hierarchy_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 /// It is filled lazily as the client requests information about classes. 77 /// It is filled lazily as the client requests information about classes.
78 final Map<Class, _ClassInfo> _info = {}; 78 final Map<Class, _ClassInfo> _info = {};
79 79
80 @override 80 @override
81 Iterable<Class> get classes { 81 Iterable<Class> get classes {
82 // TODO(scheglov): implement classes 82 // TODO(scheglov): implement classes
83 throw new UnimplementedError(); 83 throw new UnimplementedError();
84 } 84 }
85 85
86 @override 86 @override
87 void forEachOverridePair(Class class_, 87 void forEachOverridePair(Class node,
88 callback(Member declaredMember, Member interfaceMember, bool isSetter)) { 88 callback(Member declaredMember, Member interfaceMember, bool isSetter)) {
89 // TODO(scheglov): implement forEachOverridePair 89 _ClassInfo info = _getInfo(node);
90 throw new UnimplementedError(); 90 for (var supertype in node.supers) {
91 var superNode = supertype.classNode;
92 var superInfo = _getInfo(superNode);
93
94 var superGetters = superInfo.interfaceGettersAndCalls;
95 _reportOverrides(info.implementedGettersAndCalls, superGetters, callback);
96 _reportOverrides(info.declaredGettersAndCalls, superGetters, callback,
97 onlyAbstract: true);
98
99 var superSetters = superInfo.interfaceSetters;
100 _reportOverrides(info.implementedSetters, superSetters, callback,
101 isSetter: true);
102 _reportOverrides(info.declaredSetters, superSetters, callback,
103 isSetter: true, onlyAbstract: true);
104 }
105 if (!node.isAbstract) {
106 // If a non-abstract class declares an abstract method M whose
107 // implementation M' is inherited from the superclass, then the inherited
108 // method M' overrides the declared method M.
109 // This flies in the face of conventional override logic, but is necessary
110 // because an instance of the class will contain the method M' which can
111 // be invoked through the interface of M.
112 // Note that [_reportOverrides] does not report self-overrides, so in
113 // most cases these calls will just scan both lists and report nothing.
114 _reportOverrides(info.implementedGettersAndCalls,
115 info.declaredGettersAndCalls, callback);
116 _reportOverrides(info.implementedSetters, info.declaredSetters, callback,
117 isSetter: true);
118 }
91 } 119 }
92 120
93 @override 121 @override
94 Supertype getClassAsInstanceOf(Class node, Class superclass) { 122 Supertype getClassAsInstanceOf(Class node, Class superclass) {
95 if (identical(node, superclass)) return node.asThisSupertype; 123 if (identical(node, superclass)) return node.asThisSupertype;
96 _ClassInfo info = _getInfo(node); 124 _ClassInfo info = _getInfo(node);
97 _ClassInfo superInfo = _getInfo(superclass); 125 _ClassInfo superInfo = _getInfo(superclass);
98 if (!info.isSubtypeOf(superInfo)) return null; 126 if (!info.isSubtypeOf(superInfo)) return null;
99 if (superclass.typeParameters.isEmpty) return superclass.asRawSupertype; 127 if (superclass.typeParameters.isEmpty) return superclass.asRawSupertype;
100 return info.genericSuperTypes[superclass]; 128 return info.genericSuperTypes[superclass];
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 } 576 }
549 while (i < first.length) { 577 while (i < first.length) {
550 result[storeIndex++] = first[i++]; 578 result[storeIndex++] = first[i++];
551 } 579 }
552 while (j < second.length) { 580 while (j < second.length) {
553 result[storeIndex++] = second[j++]; 581 result[storeIndex++] = second[j++];
554 } 582 }
555 result.length = storeIndex; 583 result.length = storeIndex;
556 return result; 584 return result;
557 } 585 }
586
587 static void _reportOverrides(
588 List<Member> declaredList,
589 List<Member> inheritedList,
590 callback(Member declaredMember, Member interfaceMember, bool isSetter),
591 {bool isSetter: false,
592 bool onlyAbstract: false}) {
593 int i = 0, j = 0;
594 while (i < declaredList.length && j < inheritedList.length) {
595 Member declared = declaredList[i];
596 if (onlyAbstract && !declared.isAbstract) {
597 ++i;
598 continue;
599 }
600 Member inherited = inheritedList[j];
601 int comparison = _compareMembers(declared, inherited);
602 if (comparison < 0) {
603 ++i;
604 } else if (comparison > 0) {
605 ++j;
606 } else {
607 if (!identical(declared, inherited)) {
608 callback(declared, inherited, isSetter);
609 }
610 // A given declared member may override multiple interface members,
611 // so only move past the interface member.
612 ++j;
613 }
614 }
615 }
558 } 616 }
559 617
560 /// Information about a [Class]. 618 /// Information about a [Class].
561 class _ClassInfo { 619 class _ClassInfo {
562 /// The unique identifier of the [_ClassInfo]. 620 /// The unique identifier of the [_ClassInfo].
563 final int id; 621 final int id;
564 622
565 /// The [Class] node described by this [_ClassInfo]. 623 /// The [Class] node described by this [_ClassInfo].
566 final Class node; 624 final Class node;
567 625
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 class _LubHeap extends Heap<_ClassInfo> { 709 class _LubHeap extends Heap<_ClassInfo> {
652 @override 710 @override
653 bool sortsBefore(_ClassInfo a, _ClassInfo b) => sortsBeforeStatic(a, b); 711 bool sortsBefore(_ClassInfo a, _ClassInfo b) => sortsBeforeStatic(a, b);
654 712
655 static bool sortsBeforeStatic(_ClassInfo a, _ClassInfo b) { 713 static bool sortsBeforeStatic(_ClassInfo a, _ClassInfo b) {
656 if (a.depth > b.depth) return true; 714 if (a.depth > b.depth) return true;
657 if (a.depth < b.depth) return false; 715 if (a.depth < b.depth) return false;
658 return a.id < b.id; 716 return a.id < b.id;
659 } 717 }
660 } 718 }
OLDNEW
« no previous file with comments | « no previous file | pkg/kernel/test/class_hierarchy_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698