| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 | 4 |
| 5 library related_types; | 5 library related_types; |
| 6 | 6 |
| 7 import 'package:compiler/src/commandline_options.dart'; | 7 import 'package:compiler/src/commandline_options.dart'; |
| 8 import 'package:compiler/src/compiler.dart'; | 8 import 'package:compiler/src/compiler.dart'; |
| 9 import 'package:compiler/src/core_types.dart'; | 9 import 'package:compiler/src/core_types.dart'; |
| 10 import 'package:compiler/src/dart_types.dart'; | 10 import 'package:compiler/src/dart_types.dart'; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 class RelatedTypesChecker extends TraversalVisitor<DartType, dynamic> { | 71 class RelatedTypesChecker extends TraversalVisitor<DartType, dynamic> { |
| 72 final Compiler compiler; | 72 final Compiler compiler; |
| 73 final ResolvedAst resolvedAst; | 73 final ResolvedAst resolvedAst; |
| 74 | 74 |
| 75 RelatedTypesChecker(this.compiler, ResolvedAst resolvedAst) | 75 RelatedTypesChecker(this.compiler, ResolvedAst resolvedAst) |
| 76 : this.resolvedAst = resolvedAst, | 76 : this.resolvedAst = resolvedAst, |
| 77 super(resolvedAst.elements); | 77 super(resolvedAst.elements); |
| 78 | 78 |
| 79 ClassWorld get world => compiler.world; | 79 ClassWorld get world => compiler.world; |
| 80 | 80 |
| 81 CoreClasses get coreClasses => compiler.coreClasses; |
| 82 |
| 81 CoreTypes get coreTypes => compiler.coreTypes; | 83 CoreTypes get coreTypes => compiler.coreTypes; |
| 82 | 84 |
| 83 DiagnosticReporter get reporter => compiler.reporter; | 85 DiagnosticReporter get reporter => compiler.reporter; |
| 84 | 86 |
| 85 InterfaceType get thisType => resolvedAst.element.enclosingClass.thisType; | 87 InterfaceType get thisType => resolvedAst.element.enclosingClass.thisType; |
| 86 | 88 |
| 87 /// Returns `true` if there exists no common subtype of [left] and [right]. | 89 /// Returns `true` if there exists no common subtype of [left] and [right]. |
| 88 bool hasEmptyIntersection(DartType left, DartType right) { | 90 bool hasEmptyIntersection(DartType left, DartType right) { |
| 89 if (left == right) return false; | 91 if (left == right) return false; |
| 90 if (left == null || right == null) return false; | 92 if (left == null || right == null) return false; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 InterfaceType findClassType(DartType receiver, ClassElement cls) { | 162 InterfaceType findClassType(DartType receiver, ClassElement cls) { |
| 161 InterfaceType interfaceType = findInterfaceType(receiver); | 163 InterfaceType interfaceType = findInterfaceType(receiver); |
| 162 if (interfaceType == null) return null; | 164 if (interfaceType == null) return null; |
| 163 InterfaceType mapType = interfaceType.asInstanceOf(cls); | 165 InterfaceType mapType = interfaceType.asInstanceOf(cls); |
| 164 if (mapType == null) return null; | 166 if (mapType == null) return null; |
| 165 return mapType; | 167 return mapType; |
| 166 } | 168 } |
| 167 | 169 |
| 168 /// Returns the supertype of [receiver] that implements `Iterable`, if any. | 170 /// Returns the supertype of [receiver] that implements `Iterable`, if any. |
| 169 InterfaceType findIterableType(DartType receiver) { | 171 InterfaceType findIterableType(DartType receiver) { |
| 170 return findClassType(receiver, compiler.iterableClass); | 172 return findClassType(receiver, coreClasses.iterableClass); |
| 171 } | 173 } |
| 172 | 174 |
| 173 /// Returns the element type of the supertype of [receiver] that implements | 175 /// Returns the element type of the supertype of [receiver] that implements |
| 174 /// `Iterable`, if any. | 176 /// `Iterable`, if any. |
| 175 DartType findIterableElementType(InterfaceType iterableType) { | 177 DartType findIterableElementType(InterfaceType iterableType) { |
| 176 if (iterableType == null) return null; | 178 if (iterableType == null) return null; |
| 177 return iterableType.typeArguments[0]; | 179 return iterableType.typeArguments[0]; |
| 178 } | 180 } |
| 179 | 181 |
| 180 /// Returns the supertype of [receiver] that implements `Map`, if any. | 182 /// Returns the supertype of [receiver] that implements `Map`, if any. |
| 181 InterfaceType findMapType(DartType receiver) { | 183 InterfaceType findMapType(DartType receiver) { |
| 182 return findClassType(receiver, compiler.mapClass); | 184 return findClassType(receiver, coreClasses.mapClass); |
| 183 } | 185 } |
| 184 | 186 |
| 185 /// Returns the key type of the supertype of [receiver] that implements | 187 /// Returns the key type of the supertype of [receiver] that implements |
| 186 /// `Map`, if any. | 188 /// `Map`, if any. |
| 187 DartType findMapKeyType(InterfaceType mapType) { | 189 DartType findMapKeyType(InterfaceType mapType) { |
| 188 if (mapType == null) return null; | 190 if (mapType == null) return null; |
| 189 return mapType.typeArguments[0]; | 191 return mapType.typeArguments[0]; |
| 190 } | 192 } |
| 191 | 193 |
| 192 /// Returns the value type of the supertype of [receiver] that implements | 194 /// Returns the value type of the supertype of [receiver] that implements |
| 193 /// `Map`, if any. | 195 /// `Map`, if any. |
| 194 DartType findMapValueType(InterfaceType mapType) { | 196 DartType findMapValueType(InterfaceType mapType) { |
| 195 if (mapType == null) return null; | 197 if (mapType == null) return null; |
| 196 return mapType.typeArguments[1]; | 198 return mapType.typeArguments[1]; |
| 197 } | 199 } |
| 198 | 200 |
| 199 /// Returns the supertype of [receiver] that implements `List`, if any. | 201 /// Returns the supertype of [receiver] that implements `List`, if any. |
| 200 InterfaceType findListType(DartType receiver) { | 202 InterfaceType findListType(DartType receiver) { |
| 201 return findClassType(receiver, compiler.listClass); | 203 return findClassType(receiver, coreClasses.listClass); |
| 202 } | 204 } |
| 203 | 205 |
| 204 /// Returns the element type of the supertype of [receiver] that implements | 206 /// Returns the element type of the supertype of [receiver] that implements |
| 205 /// `List`, if any. | 207 /// `List`, if any. |
| 206 DartType findListElementType(InterfaceType listType) { | 208 DartType findListElementType(InterfaceType listType) { |
| 207 if (listType == null) return null; | 209 if (listType == null) return null; |
| 208 return listType.typeArguments[0]; | 210 return listType.typeArguments[0]; |
| 209 } | 211 } |
| 210 | 212 |
| 211 /// Returns the implied return type of [type] or `dynamic` if no return type | 213 /// Returns the implied return type of [type] or `dynamic` if no return type |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 ClassElement findClass(DartType type) => type.accept(this, null); | 429 ClassElement findClass(DartType type) => type.accept(this, null); |
| 428 | 430 |
| 429 @override | 431 @override |
| 430 ClassElement visitType(DartType type, _) => null; | 432 ClassElement visitType(DartType type, _) => null; |
| 431 | 433 |
| 432 @override | 434 @override |
| 433 ClassElement visitInterfaceType(InterfaceType type, _) { | 435 ClassElement visitInterfaceType(InterfaceType type, _) { |
| 434 return type.element; | 436 return type.element; |
| 435 } | 437 } |
| 436 } | 438 } |
| OLD | NEW |