Chromium Code Reviews| Index: pkg/compiler/lib/src/kernel/types.dart |
| diff --git a/pkg/compiler/lib/src/kernel/types.dart b/pkg/compiler/lib/src/kernel/types.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..30bbb9c15b2accc4e7c85202823e3493a8fb17c9 |
| --- /dev/null |
| +++ b/pkg/compiler/lib/src/kernel/types.dart |
| @@ -0,0 +1,105 @@ |
| +// 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. |
| + |
| +part of dart2js.kernel.world_builder; |
| + |
| +class _KernelOrderedTypeSetBuilder extends OrderedTypeSetBuilderBase { |
| + final KernelWorldBuilder worldBuilder; |
| + |
| + _KernelOrderedTypeSetBuilder(this.worldBuilder, ClassEntity cls) |
| + : super(cls, |
| + reporter: worldBuilder.reporter, |
| + objectType: worldBuilder.commonElements.objectType); |
| + |
| + InterfaceType getThisType(ClassEntity cls) { |
| + return worldBuilder._getThisType(cls); |
| + } |
| + |
| + InterfaceType substByContext(InterfaceType type, InterfaceType context) { |
| + return worldBuilder._substByContext(type, context); |
| + } |
| + |
| + int getHierarchyDepth(ClassEntity cls) { |
| + return worldBuilder._getHierarchyDepth(cls); |
| + } |
| + |
| + OrderedTypeSet getOrderedTypeSet(ClassEntity cls) { |
| + return worldBuilder._getOrderedTypeSet(cls); |
| + } |
| +} |
| + |
| +class _KernelDartTypes implements DartTypes { |
|
Siggi Cherem (dart-lang)
2017/04/21 16:41:13
nits:
- move this to the top - it's likely the fi
Johnni Winther
2017/04/24 08:25:42
Done.
|
| + final KernelWorldBuilder worldBuilder; |
| + final SubtypeVisitor subtypeVisitor; |
| + final PotentialSubtypeVisitor potentialSubtypeVisitor; |
| + |
| + _KernelDartTypes(this.worldBuilder) |
| + : this.subtypeVisitor = new _KernelSubtypeVisitor(worldBuilder), |
| + this.potentialSubtypeVisitor = |
| + new _KernelPotentialSubtypeVisitor(worldBuilder); |
| + |
| + @override |
| + bool isPotentialSubtype(DartType t, DartType s) { |
| + return potentialSubtypeVisitor.isSubtype(t, s); |
| + } |
| + |
| + @override |
| + bool isAssignable(DartType t, DartType s) { |
| + return isSubtype(t, s) || isSubtype(s, t); |
| + } |
| + |
| + @override |
| + bool isSubtype(DartType t, DartType s) { |
| + return subtypeVisitor.isSubtype(t, s); |
| + } |
| + |
| + @override |
| + CommonElements get commonElements => worldBuilder.commonElements; |
| +} |
| + |
| +/// Abstract visitor for determining relations between types. |
| +abstract class _AbstractTypeRelationMixin implements AbstractTypeRelation { |
| + KernelWorldBuilder get worldBuilder; |
| + |
| + @override |
| + CommonElements get commonElements => worldBuilder.commonElements; |
| + |
| + @override |
| + DartType getTypeVariableBound(TypeVariableEntity element) { |
| + // TODO(johnniwinther): Compute the bound. |
| + return commonElements.objectType; |
| + } |
| + |
| + @override |
| + FunctionType getCallType(InterfaceType type) { |
| + // TODO(johnniwinther): Compute the call type. |
| + return null; |
|
Siggi Cherem (dart-lang)
2017/04/21 16:41:14
throw instead?
Johnni Winther
2017/04/24 08:25:42
We need this to pass for the closed world test.
|
| + } |
| + |
| + @override |
| + InterfaceType asInstanceOf(InterfaceType type, ClassEntity cls) { |
| + OrderedTypeSet orderedTypeSet = |
| + worldBuilder._getOrderedTypeSet(type.element); |
| + InterfaceType supertype = |
| + orderedTypeSet.asInstanceOf(cls, worldBuilder._getHierarchyDepth(cls)); |
| + if (supertype != null) { |
| + supertype = worldBuilder._substByContext(supertype, type); |
| + } |
| + return supertype; |
| + } |
| +} |
| + |
| +class _KernelSubtypeVisitor extends SubtypeVisitor |
| + with _AbstractTypeRelationMixin { |
| + final KernelWorldBuilder worldBuilder; |
| + |
| + _KernelSubtypeVisitor(this.worldBuilder); |
| +} |
| + |
| +class _KernelPotentialSubtypeVisitor extends PotentialSubtypeVisitor |
| + with _AbstractTypeRelationMixin { |
| + final KernelWorldBuilder worldBuilder; |
| + |
| + _KernelPotentialSubtypeVisitor(this.worldBuilder); |
| +} |