Chromium Code Reviews| Index: pkg/kernel/lib/src/incremental_class_hierarchy.dart |
| diff --git a/pkg/kernel/lib/src/incremental_class_hierarchy.dart b/pkg/kernel/lib/src/incremental_class_hierarchy.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..eb913ca252fece7fb59ac849072e41eb4f6fdcf0 |
| --- /dev/null |
| +++ b/pkg/kernel/lib/src/incremental_class_hierarchy.dart |
| @@ -0,0 +1,125 @@ |
| +// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| +library kernel.incremental_class_hierarchy; |
| + |
| +import 'dart:math'; |
| + |
| +import 'package:kernel/ast.dart'; |
| +import 'package:kernel/class_hierarchy.dart'; |
| + |
| +/// Lazy and incremental implementation of [ClassHierarchy]. |
| +class IncrementalClassHierarchy implements ClassHierarchy { |
| + /// The mapping from [Class]es to the corresponding [_ClassInfo]s. |
| + /// It is filled lazily as the client requests information about classes. |
| + final Map<Class, _ClassInfo> _info = {}; |
| + |
| + @override |
| + Iterable<Class> get classes { |
| + // 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.
|
| + 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.
|
| + } |
| + |
| + @override |
| + Class get rootClass { |
| + // TODO: implement rootClass |
| + return null; |
| + } |
| + |
| + @override |
| + void forEachOverridePair(Class class_, |
| + callback(Member declaredMember, Member interfaceMember, bool isSetter)) { |
| + // TODO: implement forEachOverridePair |
| + throw new UnimplementedError(); |
| + } |
| + |
| + @override |
| + Supertype getClassAsInstanceOf(Class class_, Class superclass) { |
| + // TODO: implement getClassAsInstanceOf |
| + throw new UnimplementedError(); |
| + } |
| + |
| + @override |
| + int getClassDepth(Class node) { |
| + var info = _getInfo(node); |
| + if (info.depth < 0) { |
| + int superDepth = -1; |
| + if (node.supertype != null) { |
| + superDepth = max(superDepth, getClassDepth(node.supertype.classNode)); |
| + } |
| + if (node.mixedInType != null) { |
| + superDepth = max(superDepth, getClassDepth(node.mixedInType.classNode)); |
| + } |
| + for (var supertype in node.implementedTypes) { |
| + superDepth = max(superDepth, getClassDepth(supertype.classNode)); |
| + } |
| + info.depth = superDepth + 1; |
| + } |
| + |
| + return info.depth; |
| + } |
| + |
| + @override |
| + InterfaceType getClassicLeastUpperBound( |
| + InterfaceType type1, InterfaceType type2) { |
| + // TODO: implement getClassicLeastUpperBound |
| + throw new UnimplementedError(); |
| + } |
| + |
| + @override |
| + int getClassIndex(Class class_) { |
| + // TODO: implement getClassIndex |
| + throw new UnimplementedError(); |
| + } |
| + |
| + @override |
| + Member getDispatchTarget(Class class_, Name name, {bool setter: false}) { |
| + // TODO: implement getDispatchTarget |
| + throw new UnimplementedError(); |
| + } |
| + |
| + @override |
| + Member getInterfaceMember(Class class_, Name name, {bool setter: false}) { |
| + // TODO: implement getInterfaceMember |
| + throw new UnimplementedError(); |
| + } |
| + |
| + @override |
| + List<Class> getRankedSuperclasses(Class class_) { |
| + // TODO: implement getRankedSuperclasses |
| + throw new UnimplementedError(); |
| + } |
| + |
| + @override |
| + InterfaceType getTypeAsInstanceOf(InterfaceType type, Class superclass) { |
| + // TODO: implement getTypeAsInstanceOf |
| + throw new UnimplementedError(); |
| + } |
| + |
| + @override |
| + bool hasProperSubtypes(Class class_) { |
| + // TODO: implement hasProperSubtypes |
| + throw new UnimplementedError(); |
| + } |
| + |
| + /// Return the [_ClassInfo] for the [node]. |
| + _ClassInfo _getInfo(Class node) { |
| + 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.
|
| + if (info == null) { |
| + info = new _ClassInfo(node); |
| + _info[node] = info; |
| + } |
| + return info; |
| + } |
| +} |
| + |
| +/// Information about a [Class]. |
| +class _ClassInfo { |
| + final Class node; |
| + |
| + /// The number of steps in the longest inheritance path from the class |
| + /// 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.
|
| + int depth = -1; |
| + |
| + _ClassInfo(this.node); |
| +} |