OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 library kernel.incremental_class_hierarchy; | |
5 | |
6 import 'dart:math'; | |
7 | |
8 import 'package:kernel/ast.dart'; | |
9 import 'package:kernel/class_hierarchy.dart'; | |
10 | |
11 /// Lazy and incremental implementation of [ClassHierarchy]. | |
12 class IncrementalClassHierarchy implements ClassHierarchy { | |
13 /// The mapping from [Class]es to the corresponding [_ClassInfo]s. | |
14 /// It is filled lazily as the client requests information about classes. | |
ahe
2017/06/02 11:34:48
What are your plans for the incremental part of th
scheglov
2017/06/02 15:36:07
I think we can use single instance of IncrementalC
ahe
2017/06/02 15:43:46
Thank you for explaining.
| |
15 final Map<Class, _ClassInfo> _info = {}; | |
16 | |
17 @override | |
18 Iterable<Class> get classes { | |
19 // TODO(scheglov): implement classes | |
20 throw new UnimplementedError(); | |
21 } | |
22 | |
23 @override | |
24 void forEachOverridePair(Class class_, | |
25 callback(Member declaredMember, Member interfaceMember, bool isSetter)) { | |
26 // TODO(scheglov): implement forEachOverridePair | |
27 throw new UnimplementedError(); | |
28 } | |
29 | |
30 @override | |
31 Supertype getClassAsInstanceOf(Class class_, Class superclass) { | |
32 // TODO(scheglov): implement getClassAsInstanceOf | |
33 throw new UnimplementedError(); | |
34 } | |
35 | |
36 @override | |
37 int getClassDepth(Class node) { | |
38 var info = _getInfo(node); | |
39 if (info.depth < 0) { | |
40 int superDepth = -1; | |
41 if (node.supertype != null) { | |
42 superDepth = max(superDepth, getClassDepth(node.supertype.classNode)); | |
ahe
2017/06/02 11:34:48
Any concerns about recursion here?
Paul Berry
2017/06/02 12:25:48
FWIW the topological sort in ClosedWorldClassHiera
ahe
2017/06/02 12:29:03
This situation might be slightly different. Howeve
| |
43 } | |
44 if (node.mixedInType != null) { | |
45 superDepth = max(superDepth, getClassDepth(node.mixedInType.classNode)); | |
46 } | |
47 for (var supertype in node.implementedTypes) { | |
48 superDepth = max(superDepth, getClassDepth(supertype.classNode)); | |
49 } | |
50 info.depth = superDepth + 1; | |
51 } | |
52 | |
53 return info.depth; | |
54 } | |
55 | |
56 @override | |
57 InterfaceType getClassicLeastUpperBound( | |
58 InterfaceType type1, InterfaceType type2) { | |
59 // TODO(scheglov): implement getClassicLeastUpperBound | |
60 throw new UnimplementedError(); | |
61 } | |
62 | |
63 @override | |
64 int getClassIndex(Class class_) { | |
65 // TODO(scheglov): implement getClassIndex | |
66 throw new UnimplementedError(); | |
67 } | |
68 | |
69 @override | |
70 Member getDispatchTarget(Class class_, Name name, {bool setter: false}) { | |
71 // TODO(scheglov): implement getDispatchTarget | |
72 throw new UnimplementedError(); | |
73 } | |
74 | |
75 @override | |
76 Member getInterfaceMember(Class class_, Name name, {bool setter: false}) { | |
77 // TODO(scheglov): implement getInterfaceMember | |
78 throw new UnimplementedError(); | |
79 } | |
80 | |
81 @override | |
82 List<Class> getRankedSuperclasses(Class class_) { | |
83 // TODO(scheglov): implement getRankedSuperclasses | |
84 throw new UnimplementedError(); | |
85 } | |
86 | |
87 @override | |
88 InterfaceType getTypeAsInstanceOf(InterfaceType type, Class superclass) { | |
89 // TODO(scheglov): implement getTypeAsInstanceOf | |
90 throw new UnimplementedError(); | |
91 } | |
92 | |
93 @override | |
94 bool hasProperSubtypes(Class class_) { | |
95 // TODO(scheglov): implement hasProperSubtypes | |
96 throw new UnimplementedError(); | |
97 } | |
98 | |
99 /// Return the [_ClassInfo] for the [node]. | |
100 _ClassInfo _getInfo(Class node) { | |
101 return _info.putIfAbsent(node, () => new _ClassInfo(node)); | |
102 } | |
103 } | |
104 | |
105 /// Information about a [Class]. | |
106 class _ClassInfo { | |
107 final Class node; | |
108 | |
109 /// The number of steps in the longest inheritance path from the class | |
110 /// to [Object], or -1 if the depth has not been computed yet. | |
111 int depth = -1; | |
112 | |
113 _ClassInfo(this.node); | |
114 } | |
OLD | NEW |