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. | |
15 final Map<Class, _ClassInfo> _info = {}; | |
16 | |
17 @override | |
18 Iterable<Class> get classes { | |
19 // TODO: implement classes | |
Paul Berry
2017/06/01 21:39:03
Change the TODOs in this file to "TODO(scheglov)"
scheglov
2017/06/01 21:50:35
Done.
| |
20 return null; | |
Paul Berry
2017/06/01 21:39:03
I'd recommend replacing this line (and the other "
scheglov
2017/06/01 21:50:35
Done.
| |
21 } | |
22 | |
23 @override | |
24 Class get rootClass { | |
25 // TODO: implement rootClass | |
26 return null; | |
27 } | |
28 | |
29 @override | |
30 void forEachOverridePair(Class class_, | |
31 callback(Member declaredMember, Member interfaceMember, bool isSetter)) { | |
32 // TODO: implement forEachOverridePair | |
33 throw new UnimplementedError(); | |
34 } | |
35 | |
36 @override | |
37 Supertype getClassAsInstanceOf(Class class_, Class superclass) { | |
38 // TODO: implement getClassAsInstanceOf | |
39 throw new UnimplementedError(); | |
40 } | |
41 | |
42 @override | |
43 int getClassDepth(Class node) { | |
44 var info = _getInfo(node); | |
45 if (info.depth < 0) { | |
46 int superDepth = -1; | |
47 if (node.supertype != null) { | |
48 superDepth = max(superDepth, getClassDepth(node.supertype.classNode)); | |
49 } | |
50 if (node.mixedInType != null) { | |
51 superDepth = max(superDepth, getClassDepth(node.mixedInType.classNode)); | |
52 } | |
53 for (var supertype in node.implementedTypes) { | |
54 superDepth = max(superDepth, getClassDepth(supertype.classNode)); | |
55 } | |
56 info.depth = superDepth + 1; | |
57 } | |
58 | |
59 return info.depth; | |
60 } | |
61 | |
62 @override | |
63 InterfaceType getClassicLeastUpperBound( | |
64 InterfaceType type1, InterfaceType type2) { | |
65 // TODO: implement getClassicLeastUpperBound | |
66 throw new UnimplementedError(); | |
67 } | |
68 | |
69 @override | |
70 int getClassIndex(Class class_) { | |
71 // TODO: implement getClassIndex | |
72 throw new UnimplementedError(); | |
73 } | |
74 | |
75 @override | |
76 Member getDispatchTarget(Class class_, Name name, {bool setter: false}) { | |
77 // TODO: implement getDispatchTarget | |
78 throw new UnimplementedError(); | |
79 } | |
80 | |
81 @override | |
82 Member getInterfaceMember(Class class_, Name name, {bool setter: false}) { | |
83 // TODO: implement getInterfaceMember | |
84 throw new UnimplementedError(); | |
85 } | |
86 | |
87 @override | |
88 List<Class> getRankedSuperclasses(Class class_) { | |
89 // TODO: implement getRankedSuperclasses | |
90 throw new UnimplementedError(); | |
91 } | |
92 | |
93 @override | |
94 InterfaceType getTypeAsInstanceOf(InterfaceType type, Class superclass) { | |
95 // TODO: implement getTypeAsInstanceOf | |
96 throw new UnimplementedError(); | |
97 } | |
98 | |
99 @override | |
100 bool hasProperSubtypes(Class class_) { | |
101 // TODO: implement hasProperSubtypes | |
102 throw new UnimplementedError(); | |
103 } | |
104 | |
105 /// Return the [_ClassInfo] for the [node]. | |
106 _ClassInfo _getInfo(Class node) { | |
107 var info = _info[node]; | |
Paul Berry
2017/06/01 21:39:03
I think a more performant implementation of this f
scheglov
2017/06/01 21:50:35
Done.
| |
108 if (info == null) { | |
109 info = new _ClassInfo(node); | |
110 _info[node] = info; | |
111 } | |
112 return info; | |
113 } | |
114 } | |
115 | |
116 /// Information about a [Class]. | |
117 class _ClassInfo { | |
118 final Class node; | |
119 | |
120 /// The number of steps in the longest inheritance path from the class | |
121 /// to [Object]. | |
Paul Berry
2017/06/01 21:39:03
", or -1 if the depth has not been computed yet."
scheglov
2017/06/01 21:50:35
Done.
| |
122 int depth = -1; | |
123 | |
124 _ClassInfo(this.node); | |
125 } | |
OLD | NEW |