Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: pkg/compiler/lib/src/elements/resolution_types.dart

Issue 2653203002: Use entities in CommonElements interface. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/core_types.dart ('k') | pkg/compiler/lib/src/inferrer/builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /// Implementation of the Dart types hierarchy in 'types.dart' specifically 5 /// Implementation of the Dart types hierarchy in 'types.dart' specifically
6 /// tailored to the resolution phase of the compiler. 6 /// tailored to the resolution phase of the compiler.
7 7
8 library resolution_types; 8 library resolution_types;
9 9
10 import 'dart:math' show min; 10 import 'dart:math' show min;
(...skipping 1649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 /// 1660 ///
1661 /// Otherwise, a function type is returned whose return type and 1661 /// Otherwise, a function type is returned whose return type and
1662 /// parameter types are the least upper bound of those of [a] and [b], 1662 /// parameter types are the least upper bound of those of [a] and [b],
1663 /// respectively. In addition, the optional parameters are the least upper 1663 /// respectively. In addition, the optional parameters are the least upper
1664 /// bound of the longest common prefix of the optional parameters of [a] and 1664 /// bound of the longest common prefix of the optional parameters of [a] and
1665 /// [b], and the named parameters are the least upper bound of those common to 1665 /// [b], and the named parameters are the least upper bound of those common to
1666 /// [a] and [b]. 1666 /// [a] and [b].
1667 ResolutionDartType computeLeastUpperBoundFunctionTypes( 1667 ResolutionDartType computeLeastUpperBoundFunctionTypes(
1668 ResolutionFunctionType a, ResolutionFunctionType b) { 1668 ResolutionFunctionType a, ResolutionFunctionType b) {
1669 if (a.parameterTypes.length != b.parameterTypes.length) { 1669 if (a.parameterTypes.length != b.parameterTypes.length) {
1670 return commonElements.functionType; 1670 ResolutionInterfaceType functionType = commonElements.functionType;
1671 return functionType;
1671 } 1672 }
1672 ResolutionDartType returnType = 1673 ResolutionDartType returnType =
1673 computeLeastUpperBound(a.returnType, b.returnType); 1674 computeLeastUpperBound(a.returnType, b.returnType);
1674 List<ResolutionDartType> parameterTypes = 1675 List<ResolutionDartType> parameterTypes =
1675 computeLeastUpperBoundsTypes(a.parameterTypes, b.parameterTypes); 1676 computeLeastUpperBoundsTypes(a.parameterTypes, b.parameterTypes);
1676 List<ResolutionDartType> optionalParameterTypes = 1677 List<ResolutionDartType> optionalParameterTypes =
1677 computeLeastUpperBoundsTypes( 1678 computeLeastUpperBoundsTypes(
1678 a.optionalParameterTypes, b.optionalParameterTypes); 1679 a.optionalParameterTypes, b.optionalParameterTypes);
1679 List<String> namedParameters = <String>[]; 1680 List<String> namedParameters = <String>[];
1680 List<String> aNamedParameters = a.namedParameters; 1681 List<String> aNamedParameters = a.namedParameters;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1742 1743
1743 if (a.treatAsDynamic || b.treatAsDynamic) 1744 if (a.treatAsDynamic || b.treatAsDynamic)
1744 return const ResolutionDynamicType(); 1745 return const ResolutionDynamicType();
1745 if (a.isVoid || b.isVoid) return const ResolutionVoidType(); 1746 if (a.isVoid || b.isVoid) return const ResolutionVoidType();
1746 1747
1747 if (a.isFunctionType && b.isFunctionType) { 1748 if (a.isFunctionType && b.isFunctionType) {
1748 return computeLeastUpperBoundFunctionTypes(a, b); 1749 return computeLeastUpperBoundFunctionTypes(a, b);
1749 } 1750 }
1750 1751
1751 if (a.isFunctionType) { 1752 if (a.isFunctionType) {
1752 a = commonElements.functionType; 1753 ResolutionInterfaceType functionType = commonElements.functionType;
1754 a = functionType;
1753 } 1755 }
1754 if (b.isFunctionType) { 1756 if (b.isFunctionType) {
1755 b = commonElements.functionType; 1757 ResolutionInterfaceType functionType = commonElements.functionType;
1758 b = functionType;
1756 } 1759 }
1757 1760
1758 if (a.isInterfaceType && b.isInterfaceType) { 1761 if (a.isInterfaceType && b.isInterfaceType) {
1759 return computeLeastUpperBoundInterfaces(a, b); 1762 return computeLeastUpperBoundInterfaces(a, b);
1760 } 1763 }
1761 return const ResolutionDynamicType(); 1764 return const ResolutionDynamicType();
1762 } 1765 }
1763 1766
1764 /// Computes the unaliased type of the first non type variable bound of 1767 /// Computes the unaliased type of the first non type variable bound of
1765 /// [type]. 1768 /// [type].
(...skipping 22 matching lines...) Expand all
1788 /// unaliasedBound(U) = unaliasedBound(Baz) = ()->dynamic 1791 /// unaliasedBound(U) = unaliasedBound(Baz) = ()->dynamic
1789 /// unaliasedBound(X) = unaliasedBound(Y) = `Object` 1792 /// unaliasedBound(X) = unaliasedBound(Y) = `Object`
1790 /// 1793 ///
1791 static ResolutionDartType computeUnaliasedBound( 1794 static ResolutionDartType computeUnaliasedBound(
1792 Resolution resolution, ResolutionDartType type) { 1795 Resolution resolution, ResolutionDartType type) {
1793 ResolutionDartType originalType = type; 1796 ResolutionDartType originalType = type;
1794 while (type.isTypeVariable) { 1797 while (type.isTypeVariable) {
1795 ResolutionTypeVariableType variable = type; 1798 ResolutionTypeVariableType variable = type;
1796 type = variable.element.bound; 1799 type = variable.element.bound;
1797 if (type == originalType) { 1800 if (type == originalType) {
1798 type = resolution.commonElements.objectType; 1801 ResolutionInterfaceType objectType =
1802 resolution.commonElements.objectType;
1803 type = objectType;
1799 } 1804 }
1800 } 1805 }
1801 if (type.isMalformed) { 1806 if (type.isMalformed) {
1802 return const ResolutionDynamicType(); 1807 return const ResolutionDynamicType();
1803 } 1808 }
1804 type.computeUnaliased(resolution); 1809 type.computeUnaliased(resolution);
1805 return type.unaliased; 1810 return type.unaliased;
1806 } 1811 }
1807 1812
1808 /// Computes the interface type of [type], which is the type that defines 1813 /// Computes the interface type of [type], which is the type that defines
(...skipping 23 matching lines...) Expand all
1832 /// When typechecking `o.foo` the interface type of the static type of `o` is 1837 /// When typechecking `o.foo` the interface type of the static type of `o` is
1833 /// used to lookup the existence and type of `foo`. 1838 /// used to lookup the existence and type of `foo`.
1834 /// 1839 ///
1835 static ResolutionInterfaceType computeInterfaceType( 1840 static ResolutionInterfaceType computeInterfaceType(
1836 Resolution resolution, ResolutionDartType type) { 1841 Resolution resolution, ResolutionDartType type) {
1837 type = computeUnaliasedBound(resolution, type); 1842 type = computeUnaliasedBound(resolution, type);
1838 if (type.treatAsDynamic) { 1843 if (type.treatAsDynamic) {
1839 return null; 1844 return null;
1840 } 1845 }
1841 if (type.isFunctionType) { 1846 if (type.isFunctionType) {
1842 type = resolution.commonElements.functionType; 1847 ResolutionInterfaceType functionType =
1848 resolution.commonElements.functionType;
1849 type = functionType;
1843 } 1850 }
1844 assert(invariant(NO_LOCATION_SPANNABLE, type.isInterfaceType, 1851 assert(invariant(NO_LOCATION_SPANNABLE, type.isInterfaceType,
1845 message: "unexpected type kind ${type.kind}.")); 1852 message: "unexpected type kind ${type.kind}."));
1846 return type; 1853 return type;
1847 } 1854 }
1848 } 1855 }
1849 1856
1850 /** 1857 /**
1851 * Type visitor that determines one type could a subtype of another given the 1858 * Type visitor that determines one type could a subtype of another given the
1852 * right type variable substitution. The computation is approximate and returns 1859 * right type variable substitution. The computation is approximate and returns
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 sb.write(', '); 2065 sb.write(', ');
2059 } 2066 }
2060 namedParameterTypes[index].accept(this, namedParameters[index]); 2067 namedParameterTypes[index].accept(this, namedParameters[index]);
2061 needsComma = true; 2068 needsComma = true;
2062 } 2069 }
2063 sb.write('}'); 2070 sb.write('}');
2064 } 2071 }
2065 sb.write(')'); 2072 sb.write(')');
2066 } 2073 }
2067 } 2074 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/core_types.dart ('k') | pkg/compiler/lib/src/inferrer/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698