| Index: pkg/compiler/lib/src/elements/types.dart
|
| diff --git a/pkg/compiler/lib/src/elements/types.dart b/pkg/compiler/lib/src/elements/types.dart
|
| index 3d564b3190c827efd6071d6bbce05bd363a29769..d3f68833485e7a8b3d9b3bff99b7d8632f8d7edf 100644
|
| --- a/pkg/compiler/lib/src/elements/types.dart
|
| +++ b/pkg/compiler/lib/src/elements/types.dart
|
| @@ -3,6 +3,7 @@
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| import 'entities.dart';
|
| +import '../util/util.dart' show equalElements;
|
|
|
| /// Hierarchy to describe types in Dart.
|
| ///
|
| @@ -20,6 +21,8 @@ import 'entities.dart';
|
| /// on kernel ir without the need for [Element].
|
|
|
| abstract class DartType {
|
| + const DartType();
|
| +
|
| /// Returns the unaliased type of this type.
|
| ///
|
| /// The unaliased type of a typedef'd type is the unaliased type to which its
|
| @@ -28,61 +31,209 @@ abstract class DartType {
|
| /// For example, the unaliased type of `typedef A Func<A,B>(B b)` is the
|
| /// function type `(B) -> A` and the unaliased type of `Func<int,String>`
|
| /// is the function type `(String) -> int`.
|
| - DartType get unaliased;
|
| + DartType get unaliased => this;
|
|
|
| /// Is `true` if this type has no non-dynamic type arguments.
|
| - bool get treatAsRaw;
|
| + bool get treatAsRaw => true;
|
|
|
| /// Is `true` if this type should be treated as the dynamic type.
|
| - bool get treatAsDynamic;
|
| + bool get treatAsDynamic => false;
|
|
|
| /// Is `true` if this type is the dynamic type.
|
| - bool get isDynamic;
|
| + bool get isDynamic => false;
|
|
|
| /// Is `true` if this type is the void type.
|
| - bool get isVoid;
|
| -
|
| - /// Is `true` if this is the type of `Object` from dart:core.
|
| - bool get isObject;
|
| + bool get isVoid => false;
|
|
|
| /// Is `true` if this type is an interface type.
|
| - bool get isInterfaceType;
|
| + bool get isInterfaceType => false;
|
|
|
| /// Is `true` if this type is a typedef.
|
| - bool get isTypedef;
|
| + bool get isTypedef => false;
|
|
|
| /// Is `true` if this type is a function type.
|
| - bool get isFunctionType;
|
| + bool get isFunctionType => false;
|
|
|
| /// Is `true` if this type is a type variable.
|
| - bool get isTypeVariable;
|
| + bool get isTypeVariable => false;
|
|
|
| /// Is `true` if this type is a malformed type.
|
| - bool get isMalformed;
|
| + bool get isMalformed => false;
|
| +}
|
| +
|
| +class InterfaceType extends DartType {
|
| + final ClassEntity element;
|
| + final List<DartType> typeArguments;
|
| +
|
| + InterfaceType(this.element, this.typeArguments);
|
| +
|
| + int get hashCode {
|
| + int hash = element.hashCode;
|
| + for (DartType argument in typeArguments) {
|
| + int argumentHash = argument != null ? argument.hashCode : 0;
|
| + hash = 17 * hash + 3 * argumentHash;
|
| + }
|
| + return hash;
|
| + }
|
| +
|
| + bool operator ==(other) {
|
| + if (other is! InterfaceType) return false;
|
| + return identical(element, other.element) &&
|
| + equalElements(typeArguments, other.typeArguments);
|
| + }
|
| +
|
| + String toString() {
|
| + StringBuffer sb = new StringBuffer();
|
| + sb.write(element.name);
|
| + if (typeArguments.isNotEmpty) {
|
| + sb.write('<');
|
| + bool needsComma = false;
|
| + for (DartType typeArgument in typeArguments) {
|
| + if (needsComma) {
|
| + sb.write(',');
|
| + }
|
| + sb.write(typeArgument);
|
| + needsComma = true;
|
| + }
|
| + sb.write('>');
|
| + }
|
| + return sb.toString();
|
| + }
|
| }
|
|
|
| -abstract class InterfaceType extends DartType {
|
| - ClassEntity get element;
|
| - List<DartType> get typeArguments;
|
| +class TypeVariableType extends DartType {
|
| + final TypeVariableEntity element;
|
| +
|
| + TypeVariableType(this.element);
|
| +
|
| + bool get isTypeVariable => true;
|
| +
|
| + int get hashCode => 17 * element.hashCode;
|
| +
|
| + bool operator ==(other) {
|
| + if (other is! TypeVariableType) return false;
|
| + return identical(other.element, element);
|
| + }
|
| +
|
| + String toString() => '${element.typeDeclaration.name}.${element.name}';
|
| }
|
|
|
| -abstract class TypeVariableType extends DartType {
|
| - TypeVariableEntity get element;
|
| +class VoidType extends DartType {
|
| + const VoidType();
|
| +
|
| + bool get isVoid => true;
|
| +
|
| + int get hashCode => 6007;
|
| +
|
| + String toString() => 'void';
|
| }
|
|
|
| -abstract class VoidType extends DartType {}
|
| +class DynamicType extends DartType {
|
| + const DynamicType();
|
|
|
| -abstract class DynamicType extends DartType {}
|
| + @override
|
| + bool get isDynamic => true;
|
| +
|
| + @override
|
| + bool get treatAsDynamic => true;
|
| +
|
| + int get hashCode => 91;
|
| +
|
| + String toString() => 'dynamic';
|
| +}
|
|
|
| -abstract class FunctionType extends DartType {
|
| - DartType get returnType;
|
| - List<DartType> get parameterTypes;
|
| - List<DartType> get optionalParameterTypes;
|
| +class FunctionType extends DartType {
|
| + final DartType returnType;
|
| + final List<DartType> parameterTypes;
|
| + final List<DartType> optionalParameterTypes;
|
|
|
| /// The names of the named parameters ordered lexicographically.
|
| - List<String> get namedParameters;
|
| + final List<String> namedParameters;
|
|
|
| /// The types of the named parameters in the order corresponding to the
|
| /// [namedParameters].
|
| - List<DartType> get namedParameterTypes;
|
| + final List<DartType> namedParameterTypes;
|
| +
|
| + FunctionType(
|
| + this.returnType,
|
| + this.parameterTypes,
|
| + this.optionalParameterTypes,
|
| + this.namedParameters,
|
| + this.namedParameterTypes);
|
| +
|
| + bool get isFunctionType => true;
|
| +
|
| + int get hashCode {
|
| + int hash = 3 * returnType.hashCode;
|
| + for (DartType parameter in parameterTypes) {
|
| + hash = 17 * hash + 5 * parameter.hashCode;
|
| + }
|
| + for (DartType parameter in optionalParameterTypes) {
|
| + hash = 19 * hash + 7 * parameter.hashCode;
|
| + }
|
| + for (String name in namedParameters) {
|
| + hash = 23 * hash + 11 * name.hashCode;
|
| + }
|
| + for (DartType parameter in namedParameterTypes) {
|
| + hash = 29 * hash + 13 * parameter.hashCode;
|
| + }
|
| + return hash;
|
| + }
|
| +
|
| + bool operator ==(other) {
|
| + if (other is! FunctionType) return false;
|
| + return returnType == other.returnType &&
|
| + equalElements(parameterTypes, other.parameterTypes) &&
|
| + equalElements(optionalParameterTypes, other.optionalParameterTypes) &&
|
| + equalElements(namedParameters, other.namedParameters) &&
|
| + equalElements(namedParameterTypes, other.namedParameterTypes);
|
| + }
|
| +
|
| + String toString() {
|
| + StringBuffer sb = new StringBuffer();
|
| + sb.write(returnType);
|
| + sb.write(' Function(');
|
| + bool needsComma = false;
|
| + for (DartType parameterType in parameterTypes) {
|
| + if (needsComma) {
|
| + sb.write(',');
|
| + }
|
| + sb.write(parameterType);
|
| + needsComma = true;
|
| + }
|
| + if (optionalParameterTypes.isNotEmpty) {
|
| + if (needsComma) {
|
| + sb.write(',');
|
| + }
|
| + sb.write('[');
|
| + bool needsOptionalComma = false;
|
| + for (DartType typeArgument in optionalParameterTypes) {
|
| + if (needsOptionalComma) {
|
| + sb.write(',');
|
| + }
|
| + sb.write(typeArgument);
|
| + needsOptionalComma = true;
|
| + }
|
| + sb.write(']');
|
| + needsComma = true;
|
| + }
|
| + if (namedParameters.isNotEmpty) {
|
| + if (needsComma) {
|
| + sb.write(',');
|
| + }
|
| + sb.write('{');
|
| + bool needsNamedComma = false;
|
| + for (int index = 0; index < namedParameters.length; index++) {
|
| + if (needsNamedComma) {
|
| + sb.write(',');
|
| + }
|
| + sb.write(namedParameterTypes[index]);
|
| + sb.write(' ');
|
| + sb.write(namedParameters[index]);
|
| + needsNamedComma = true;
|
| + }
|
| + sb.write('}');
|
| + }
|
| + return sb.toString();
|
| + }
|
| }
|
|
|