| 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 summary_resynthesizer; | 5 library summary_resynthesizer; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| (...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 // TODO(paulberry): figure out how to handle this case (which should | 1290 // TODO(paulberry): figure out how to handle this case (which should |
| 1291 // only occur in the event of erroneous code). | 1291 // only occur in the event of erroneous code). |
| 1292 throw new UnimplementedError(); | 1292 throw new UnimplementedError(); |
| 1293 } | 1293 } |
| 1294 return result; | 1294 return result; |
| 1295 } | 1295 } |
| 1296 | 1296 |
| 1297 /** | 1297 /** |
| 1298 * If this reference refers to a type, build a [DartType]. Otherwise return | 1298 * If this reference refers to a type, build a [DartType]. Otherwise return |
| 1299 * `null`. If [numTypeArguments] is the same as the [numTypeParameters], | 1299 * `null`. If [numTypeArguments] is the same as the [numTypeParameters], |
| 1300 * the type in instantiated with type arguments returned by [getTypeArgument], | 1300 * the type is instantiated with type arguments returned by [getTypeArgument], |
| 1301 * otherwise it is instantiated with type parameter bounds (if strong mode), | 1301 * otherwise it is instantiated with type parameter bounds (if strong mode), |
| 1302 * or with `dynamic` type arguments. | 1302 * or with `dynamic` type arguments. |
| 1303 * | 1303 * |
| 1304 * If [implicitFunctionTypeIndices] is not null, a [DartType] should be | 1304 * If [implicitFunctionTypeIndices] is not null, a [DartType] should be |
| 1305 * created which refers to a function type implicitly defined by one of the | 1305 * created which refers to a function type implicitly defined by one of the |
| 1306 * element's parameters. [implicitFunctionTypeIndices] is interpreted as in | 1306 * element's parameters. [implicitFunctionTypeIndices] is interpreted as in |
| 1307 * [EntityRef.implicitFunctionTypeIndices]. | 1307 * [EntityRef.implicitFunctionTypeIndices]. |
| 1308 */ | 1308 */ |
| 1309 DartType _buildType(bool instantiateToBoundsAllowed, int numTypeArguments, | 1309 DartType _buildType(bool instantiateToBoundsAllowed, int numTypeArguments, |
| 1310 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) { | 1310 DartType getTypeArgument(int i), List<int> implicitFunctionTypeIndices) { |
| 1311 ElementHandle element = this.element; // To allow type promotion | 1311 ElementHandle element = this.element; // To allow type promotion |
| 1312 if (element is ClassElementHandle) { | 1312 if (element is ClassElementHandle) { |
| 1313 List<DartType> typeArguments = null; | 1313 List<DartType> typeArguments = null; |
| 1314 // If type arguments are specified, use them. | 1314 // If type arguments are specified, use them. |
| 1315 // Otherwise, delay until they are requested. | 1315 // Otherwise, delay until they are requested. |
| 1316 if (numTypeParameters == 0) { | 1316 if (numTypeParameters == 0) { |
| 1317 return element.type; | 1317 return element.type; |
| 1318 } else if (numTypeArguments == numTypeParameters) { | 1318 } else if (numTypeArguments == numTypeParameters) { |
| 1319 typeArguments = new List<DartType>(numTypeParameters); | 1319 typeArguments = new List<DartType>(numTypeParameters); |
| 1320 for (int i = 0; i < numTypeParameters; i++) { | 1320 for (int i = 0; i < numTypeParameters; i++) { |
| 1321 typeArguments[i] = getTypeArgument(i); | 1321 typeArguments[i] = getTypeArgument(i); |
| 1322 } | 1322 } |
| 1323 } | 1323 } |
| 1324 InterfaceTypeImpl type = | 1324 InterfaceTypeImpl type = |
| 1325 new InterfaceTypeImpl.elementWithNameAndArgs(element, name, () { | 1325 new InterfaceTypeImpl.elementWithNameAndArgs(element, name, () { |
| 1326 if (typeArguments == null) { | 1326 if (typeArguments == null) { |
| 1327 typeArguments = element.typeParameters | 1327 typeArguments = new List<DartType>.filled( |
| 1328 .map/*<DartType>*/((_) => DynamicTypeImpl.instance) | 1328 element.typeParameters.length, DynamicTypeImpl.instance); |
| 1329 .toList(); | |
| 1330 if (libraryResynthesizer.summaryResynthesizer.strongMode && | 1329 if (libraryResynthesizer.summaryResynthesizer.strongMode && |
| 1331 instantiateToBoundsAllowed) { | 1330 instantiateToBoundsAllowed) { |
| 1332 List<DartType> typeParameterTypes; | 1331 InterfaceType instantiatedToBounds = libraryResynthesizer |
| 1333 for (int i = 0; i < typeArguments.length; i++) { | 1332 .summaryResynthesizer.context.typeSystem |
| 1334 DartType bound = element.typeParameters[i].bound; | 1333 .instantiateToBounds(element.type) as InterfaceType; |
| 1335 if (bound != null) { | 1334 return instantiatedToBounds.typeArguments; |
| 1336 typeParameterTypes ??= element.typeParameters | |
| 1337 .map/*<DartType>*/((TypeParameterElement e) => e.type) | |
| 1338 .toList(); | |
| 1339 typeArguments[i] = | |
| 1340 bound.substitute2(typeArguments, typeParameterTypes); | |
| 1341 } | |
| 1342 } | |
| 1343 } | 1335 } |
| 1344 } | 1336 } |
| 1345 return typeArguments; | 1337 return typeArguments; |
| 1346 }); | 1338 }); |
| 1347 // Mark the type as having implicit type arguments, so that we don't | 1339 // Mark the type as having implicit type arguments, so that we don't |
| 1348 // attempt to request them during constant expression resynthesizing. | 1340 // attempt to request them during constant expression resynthesizing. |
| 1349 if (typeArguments == null) { | 1341 if (typeArguments == null) { |
| 1350 libraryResynthesizer.typesWithImplicitTypeArguments.add(type); | 1342 libraryResynthesizer.typesWithImplicitTypeArguments.add(type); |
| 1351 } | 1343 } |
| 1352 // Done. | 1344 // Done. |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1917 static String _getElementIdentifier(String name, ReferenceKind kind) { | 1909 static String _getElementIdentifier(String name, ReferenceKind kind) { |
| 1918 if (kind == ReferenceKind.topLevelPropertyAccessor || | 1910 if (kind == ReferenceKind.topLevelPropertyAccessor || |
| 1919 kind == ReferenceKind.propertyAccessor) { | 1911 kind == ReferenceKind.propertyAccessor) { |
| 1920 if (!name.endsWith('=')) { | 1912 if (!name.endsWith('=')) { |
| 1921 return name + '?'; | 1913 return name + '?'; |
| 1922 } | 1914 } |
| 1923 } | 1915 } |
| 1924 return name; | 1916 return name; |
| 1925 } | 1917 } |
| 1926 } | 1918 } |
| OLD | NEW |