| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /** | 5 /** |
| 6 * This library is capable of producing linked summaries from unlinked | 6 * This library is capable of producing linked summaries from unlinked |
| 7 * ones (or prelinked ones). It functions by building a miniature | 7 * ones (or prelinked ones). It functions by building a miniature |
| 8 * element model to represent the contents of the summaries, and then | 8 * element model to represent the contents of the summaries, and then |
| 9 * scanning the element model to gather linked information and adding | 9 * scanning the element model to gather linked information and adding |
| 10 * it to the summary data structures. | 10 * it to the summary data structures. |
| (...skipping 1833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1844 stack.add(DynamicTypeImpl.instance); | 1844 stack.add(DynamicTypeImpl.instance); |
| 1845 } else { | 1845 } else { |
| 1846 stack.removeLast(); | 1846 stack.removeLast(); |
| 1847 // TODO(scheglov) implement | 1847 // TODO(scheglov) implement |
| 1848 stack.add(DynamicTypeImpl.instance); | 1848 stack.add(DynamicTypeImpl.instance); |
| 1849 } | 1849 } |
| 1850 } | 1850 } |
| 1851 | 1851 |
| 1852 void _doAssignToProperty() { | 1852 void _doAssignToProperty() { |
| 1853 DartType targetType = stack.removeLast(); | 1853 DartType targetType = stack.removeLast(); |
| 1854 String propertyName = unlinkedConst.strings[strPtr++]; | 1854 String propertyName = _getNextString(); |
| 1855 UnlinkedExprAssignOperator assignOperator = | 1855 UnlinkedExprAssignOperator assignOperator = |
| 1856 unlinkedConst.assignmentOperators[assignmentOperatorPtr++]; | 1856 unlinkedConst.assignmentOperators[assignmentOperatorPtr++]; |
| 1857 if (assignOperator == UnlinkedExprAssignOperator.assign) { | 1857 if (assignOperator == UnlinkedExprAssignOperator.assign) { |
| 1858 // The type of the assignment is the type of the value, | 1858 // The type of the assignment is the type of the value, |
| 1859 // which is already in the stack. | 1859 // which is already in the stack. |
| 1860 } else if (assignOperator == UnlinkedExprAssignOperator.postfixDecrement || | 1860 } else if (assignOperator == UnlinkedExprAssignOperator.postfixDecrement || |
| 1861 assignOperator == UnlinkedExprAssignOperator.postfixIncrement) { | 1861 assignOperator == UnlinkedExprAssignOperator.postfixIncrement) { |
| 1862 DartType propertyType = _getPropertyType(targetType, propertyName); | 1862 DartType propertyType = _getPropertyType(targetType, propertyName); |
| 1863 stack.add(propertyType); | 1863 stack.add(propertyType); |
| 1864 } else if (assignOperator == UnlinkedExprAssignOperator.prefixDecrement) { | 1864 } else if (assignOperator == UnlinkedExprAssignOperator.prefixDecrement) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1897 DartType elseType = stack.removeLast(); | 1897 DartType elseType = stack.removeLast(); |
| 1898 DartType thenType = stack.removeLast(); | 1898 DartType thenType = stack.removeLast(); |
| 1899 stack.removeLast(); | 1899 stack.removeLast(); |
| 1900 DartType type = _leastUpperBound(thenType, elseType); | 1900 DartType type = _leastUpperBound(thenType, elseType); |
| 1901 type = _dynamicIfNull(type); | 1901 type = _dynamicIfNull(type); |
| 1902 stack.add(type); | 1902 stack.add(type); |
| 1903 } | 1903 } |
| 1904 | 1904 |
| 1905 void _doExtractProperty() { | 1905 void _doExtractProperty() { |
| 1906 DartType target = stack.removeLast(); | 1906 DartType target = stack.removeLast(); |
| 1907 String propertyName = unlinkedConst.strings[strPtr++]; | 1907 String propertyName = _getNextString(); |
| 1908 stack.add(() { | 1908 stack.add(() { |
| 1909 if (target is InterfaceType) { | 1909 if (target is InterfaceType) { |
| 1910 PropertyAccessorElement getter = | 1910 PropertyAccessorElement getter = |
| 1911 target.lookUpGetter(propertyName, library); | 1911 target.lookUpGetter(propertyName, library); |
| 1912 if (getter != null) { | 1912 if (getter != null) { |
| 1913 return getter.returnType; | 1913 return getter.returnType; |
| 1914 } | 1914 } |
| 1915 MethodElement method = target.lookUpMethod(propertyName, library); | 1915 MethodElement method = target.lookUpMethod(propertyName, library); |
| 1916 if (method != null) { | 1916 if (method != null) { |
| 1917 return method.type; | 1917 return method.type; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1937 ? DynamicTypeImpl.instance | 1937 ? DynamicTypeImpl.instance |
| 1938 : unit._resolveTypeRef( | 1938 : unit._resolveTypeRef( |
| 1939 ref.typeArguments[i], variable._typeParameterContext), | 1939 ref.typeArguments[i], variable._typeParameterContext), |
| 1940 const [])); | 1940 const [])); |
| 1941 } else { | 1941 } else { |
| 1942 stack.add(DynamicTypeImpl.instance); | 1942 stack.add(DynamicTypeImpl.instance); |
| 1943 } | 1943 } |
| 1944 } | 1944 } |
| 1945 | 1945 |
| 1946 void _doInvokeMethod() { | 1946 void _doInvokeMethod() { |
| 1947 strPtr++; | 1947 int numNamed = unlinkedConst.ints[intPtr++]; |
| 1948 int numNamed = _getNextInt(); | 1948 int numPositional = unlinkedConst.ints[intPtr++]; |
| 1949 int numPositional = _getNextInt(); | 1949 List<String> namedArgNames = _getNextStrings(numNamed); |
| 1950 // TODO(paulberry): don't just pop the args; use their types | 1950 List<DartType> namedArgTypeList = _popList(numNamed); |
| 1951 // to infer the type of type arguments. | 1951 List<DartType> positionalArgTypes = _popList(numPositional); |
| 1952 stack.length -= numNamed + numPositional; | 1952 String methodName = _getNextString(); |
| 1953 strPtr += numNamed; | 1953 DartType target = stack.removeLast(); |
| 1954 stack.removeLast(); | 1954 stack.add(() { |
| 1955 // TODO(paulberry): implement. | 1955 if (target is InterfaceType) { |
| 1956 stack.add(DynamicTypeImpl.instance); | 1956 MethodElement method = target.lookUpMethod(methodName, library); |
| 1957 DartType rawMethodType = method?.type; |
| 1958 TypeSystem ts = linker.typeSystem; |
| 1959 if (rawMethodType is FunctionType) { |
| 1960 if (rawMethodType.typeFormals.isNotEmpty && |
| 1961 ts is StrongTypeSystemImpl) { |
| 1962 List<DartType> paramTypes = <DartType>[]; |
| 1963 List<DartType> argTypes = <DartType>[]; |
| 1964 // Add positional parameter and argument types. |
| 1965 for (int i = 0; i < numPositional; i++) { |
| 1966 ParameterElement parameter = rawMethodType.parameters[i]; |
| 1967 if (parameter != null) { |
| 1968 paramTypes.add(parameter.type); |
| 1969 argTypes.add(positionalArgTypes[i]); |
| 1970 } |
| 1971 } |
| 1972 // Prepare named argument types map. |
| 1973 Map<String, DartType> namedArgTypes = <String, DartType>{}; |
| 1974 for (int i = 0; i < numNamed; i++) { |
| 1975 String name = namedArgNames[i]; |
| 1976 DartType type = namedArgTypeList[i]; |
| 1977 namedArgTypes[name] = type; |
| 1978 } |
| 1979 // Add named parameter and argument types. |
| 1980 Map<String, DartType> namedParameterTypes = |
| 1981 rawMethodType.namedParameterTypes; |
| 1982 namedArgTypes.forEach((String name, DartType argType) { |
| 1983 DartType parameterType = namedParameterTypes[name]; |
| 1984 if (parameterType != null) { |
| 1985 paramTypes.add(parameterType); |
| 1986 argTypes.add(argType); |
| 1987 } |
| 1988 }); |
| 1989 // Perform inference. |
| 1990 FunctionType inferred = ts.inferGenericFunctionCall( |
| 1991 typeProvider, rawMethodType, paramTypes, argTypes, null); |
| 1992 return inferred.returnType; |
| 1993 } |
| 1994 // Not a generic method, use the raw return type. |
| 1995 return rawMethodType.returnType; |
| 1996 } |
| 1997 } |
| 1998 return DynamicTypeImpl.instance; |
| 1999 }()); |
| 1957 } | 2000 } |
| 1958 | 2001 |
| 1959 void _doInvokeMethodRef() { | 2002 void _doInvokeMethodRef() { |
| 1960 int numNamed = _getNextInt(); | 2003 int numNamed = _getNextInt(); |
| 1961 int numPositional = _getNextInt(); | 2004 int numPositional = _getNextInt(); |
| 1962 // TODO(paulberry): don't just pop the args; use their types | 2005 // TODO(paulberry): don't just pop the args; use their types |
| 1963 // to infer the type of type arguments. | 2006 // to infer the type of type arguments. |
| 1964 stack.length -= numNamed + numPositional; | 2007 stack.length -= numNamed + numPositional; |
| 1965 strPtr += numNamed; | 2008 strPtr += numNamed; |
| 1966 refPtr++; | 2009 refPtr++; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2027 } else { | 2070 } else { |
| 2028 stack.add(element.asStaticType); | 2071 stack.add(element.asStaticType); |
| 2029 } | 2072 } |
| 2030 } | 2073 } |
| 2031 } | 2074 } |
| 2032 | 2075 |
| 2033 int _getNextInt() { | 2076 int _getNextInt() { |
| 2034 return unlinkedConst.ints[intPtr++]; | 2077 return unlinkedConst.ints[intPtr++]; |
| 2035 } | 2078 } |
| 2036 | 2079 |
| 2080 String _getNextString() { |
| 2081 return unlinkedConst.strings[strPtr++]; |
| 2082 } |
| 2083 |
| 2084 List<String> _getNextStrings(int n) { |
| 2085 List<String> result = new List<String>(n); |
| 2086 for (int i = 0; i < n; i++) { |
| 2087 result[i] = _getNextString(); |
| 2088 } |
| 2089 return result; |
| 2090 } |
| 2091 |
| 2037 DartType _getNextTypeRef() { | 2092 DartType _getNextTypeRef() { |
| 2038 EntityRef ref = unlinkedConst.references[refPtr++]; | 2093 EntityRef ref = unlinkedConst.references[refPtr++]; |
| 2039 return unit._resolveTypeRef(ref, variable._typeParameterContext); | 2094 return unit._resolveTypeRef(ref, variable._typeParameterContext); |
| 2040 } | 2095 } |
| 2041 | 2096 |
| 2042 /** | 2097 /** |
| 2043 * Return the type of the property with the given [propertyName] in the | 2098 * Return the type of the property with the given [propertyName] in the |
| 2044 * given [targetType]. May return `dynamic` if the property cannot be | 2099 * given [targetType]. May return `dynamic` if the property cannot be |
| 2045 * resolved. | 2100 * resolved. |
| 2046 */ | 2101 */ |
| (...skipping 1753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3800 List<int> implicitFunctionTypeIndices) => | 3855 List<int> implicitFunctionTypeIndices) => |
| 3801 DynamicTypeImpl.instance; | 3856 DynamicTypeImpl.instance; |
| 3802 | 3857 |
| 3803 ReferenceableElementForLink getContainedName(String name) { | 3858 ReferenceableElementForLink getContainedName(String name) { |
| 3804 return new NonstaticMemberElementForLink(_constNode); | 3859 return new NonstaticMemberElementForLink(_constNode); |
| 3805 } | 3860 } |
| 3806 | 3861 |
| 3807 @override | 3862 @override |
| 3808 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 3863 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 3809 } | 3864 } |
| OLD | NEW |