| 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 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 } | 676 } |
| 677 | 677 |
| 678 @override | 678 @override |
| 679 String toString() => '$enclosingElement.$name'; | 679 String toString() => '$enclosingElement.$name'; |
| 680 | 680 |
| 681 /** | 681 /** |
| 682 * Convert [typeRef] into an [InterfaceType]. | 682 * Convert [typeRef] into an [InterfaceType]. |
| 683 */ | 683 */ |
| 684 InterfaceType _computeInterfaceType(EntityRef typeRef) { | 684 InterfaceType _computeInterfaceType(EntityRef typeRef) { |
| 685 if (typeRef != null) { | 685 if (typeRef != null) { |
| 686 DartType type = enclosingElement.resolveTypeRef(this, typeRef); | 686 DartType type = enclosingElement.resolveTypeRef(typeRef, this); |
| 687 if (type is InterfaceType && !type.element.isEnum) { | 687 if (type is InterfaceType && !type.element.isEnum) { |
| 688 return type; | 688 return type; |
| 689 } | 689 } |
| 690 // In the event that the `typeRef` isn't an interface type (which may | 690 // In the event that the `typeRef` isn't an interface type (which may |
| 691 // happen in the event of erroneous code) just fall through and pretend | 691 // happen in the event of erroneous code) just fall through and pretend |
| 692 // the supertype is `Object`. | 692 // the supertype is `Object`. |
| 693 } | 693 } |
| 694 return enclosingElement.enclosingElement._linker.typeProvider.objectType; | 694 return enclosingElement.enclosingElement._linker.typeProvider.objectType; |
| 695 } | 695 } |
| 696 } | 696 } |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 } else { | 1069 } else { |
| 1070 LibraryElementForLink dependency = | 1070 LibraryElementForLink dependency = |
| 1071 enclosingElement._getDependency(linkedReference.dependency); | 1071 enclosingElement._getDependency(linkedReference.dependency); |
| 1072 _references[index] = dependency.getContainedName(name); | 1072 _references[index] = dependency.getContainedName(name); |
| 1073 } | 1073 } |
| 1074 } | 1074 } |
| 1075 return _references[index]; | 1075 return _references[index]; |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 @override | 1078 @override |
| 1079 DartType resolveTypeRef(ElementImpl context, EntityRef type, | 1079 DartType resolveTypeRef( |
| 1080 EntityRef type, TypeParameterizedElementMixin typeParameterContext, |
| 1080 {bool defaultVoid: false, | 1081 {bool defaultVoid: false, |
| 1081 bool instantiateToBoundsAllowed: true, | 1082 bool instantiateToBoundsAllowed: true, |
| 1082 bool declaredType: false}) { | 1083 bool declaredType: false}) { |
| 1083 if (type == null) { | 1084 if (type == null) { |
| 1084 if (defaultVoid) { | 1085 if (defaultVoid) { |
| 1085 return VoidTypeImpl.instance; | 1086 return VoidTypeImpl.instance; |
| 1086 } else { | 1087 } else { |
| 1087 return DynamicTypeImpl.instance; | 1088 return DynamicTypeImpl.instance; |
| 1088 } | 1089 } |
| 1089 } | 1090 } |
| 1090 if (type.paramReference != 0) { | 1091 if (type.paramReference != 0) { |
| 1091 return context.typeParameterContext | 1092 return typeParameterContext.getTypeParameterType(type.paramReference); |
| 1092 .getTypeParameterType(type.paramReference); | |
| 1093 } else if (type.syntheticReturnType != null) { | 1093 } else if (type.syntheticReturnType != null) { |
| 1094 // TODO(paulberry): implement. | 1094 // TODO(paulberry): implement. |
| 1095 throw new UnimplementedError(); | 1095 throw new UnimplementedError(); |
| 1096 } else if (type.implicitFunctionTypeIndices.isNotEmpty) { | 1096 } else if (type.implicitFunctionTypeIndices.isNotEmpty) { |
| 1097 // TODO(paulberry): implement. | 1097 // TODO(paulberry): implement. |
| 1098 throw new UnimplementedError(); | 1098 throw new UnimplementedError(); |
| 1099 } else { | 1099 } else { |
| 1100 DartType getTypeArgument(int i) { | 1100 DartType getTypeArgument(int i) { |
| 1101 if (i < type.typeArguments.length) { | 1101 if (i < type.typeArguments.length) { |
| 1102 return resolveTypeRef(context, type.typeArguments[i]); | 1102 return resolveTypeRef(type.typeArguments[i], typeParameterContext); |
| 1103 } else if (!instantiateToBoundsAllowed) { | 1103 } else if (!instantiateToBoundsAllowed) { |
| 1104 // Do not allow buildType to instantiate the bounds; force dynamic. | 1104 // Do not allow buildType to instantiate the bounds; force dynamic. |
| 1105 return DynamicTypeImpl.instance; | 1105 return DynamicTypeImpl.instance; |
| 1106 } else { | 1106 } else { |
| 1107 return null; | 1107 return null; |
| 1108 } | 1108 } |
| 1109 } | 1109 } |
| 1110 | 1110 |
| 1111 ReferenceableElementForLink element = resolveRef(type.reference); | 1111 ReferenceableElementForLink element = resolveRef(type.reference); |
| 1112 return element.buildType( | 1112 return element.buildType( |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1402 } | 1402 } |
| 1403 } | 1403 } |
| 1404 | 1404 |
| 1405 @override | 1405 @override |
| 1406 bool get isInBuildUnit => false; | 1406 bool get isInBuildUnit => false; |
| 1407 | 1407 |
| 1408 @override | 1408 @override |
| 1409 DartType getLinkedType( | 1409 DartType getLinkedType( |
| 1410 int slot, TypeParameterizedElementMixin typeParameterContext) { | 1410 int slot, TypeParameterizedElementMixin typeParameterContext) { |
| 1411 if (slot < _linkedTypeRefs.length) { | 1411 if (slot < _linkedTypeRefs.length) { |
| 1412 return resolveTypeRef(this, _linkedTypeRefs[slot]); | 1412 return resolveTypeRef(_linkedTypeRefs[slot], typeParameterContext); |
| 1413 } else { | 1413 } else { |
| 1414 return DynamicTypeImpl.instance; | 1414 return DynamicTypeImpl.instance; |
| 1415 } | 1415 } |
| 1416 } | 1416 } |
| 1417 } | 1417 } |
| 1418 | 1418 |
| 1419 /** | 1419 /** |
| 1420 * Instance of [ConstNode] representing a constant constructor. | 1420 * Instance of [ConstNode] representing a constant constructor. |
| 1421 */ | 1421 */ |
| 1422 class ConstConstructorNode extends ConstNode { | 1422 class ConstConstructorNode extends ConstNode { |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1825 | 1825 |
| 1826 /** | 1826 /** |
| 1827 * If the executable element had an explicitly declared return type, return | 1827 * If the executable element had an explicitly declared return type, return |
| 1828 * it. Otherwise return `null`. | 1828 * it. Otherwise return `null`. |
| 1829 */ | 1829 */ |
| 1830 DartType get declaredReturnType { | 1830 DartType get declaredReturnType { |
| 1831 if (_unlinkedExecutable.returnType == null) { | 1831 if (_unlinkedExecutable.returnType == null) { |
| 1832 return null; | 1832 return null; |
| 1833 } else { | 1833 } else { |
| 1834 return _declaredReturnType ??= | 1834 return _declaredReturnType ??= |
| 1835 compilationUnit.resolveTypeRef(this, _unlinkedExecutable.returnType); | 1835 compilationUnit.resolveTypeRef(_unlinkedExecutable.returnType, this); |
| 1836 } | 1836 } |
| 1837 } | 1837 } |
| 1838 | 1838 |
| 1839 @override | 1839 @override |
| 1840 String get displayName { | 1840 String get displayName { |
| 1841 if (_displayName == null) { | 1841 if (_displayName == null) { |
| 1842 _displayName = _unlinkedExecutable.name; | 1842 _displayName = _unlinkedExecutable.name; |
| 1843 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { | 1843 if (_unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { |
| 1844 _displayName = _displayName.substring(0, _displayName.length - 1); | 1844 _displayName = _displayName.substring(0, _displayName.length - 1); |
| 1845 } | 1845 } |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2320 | 2320 |
| 2321 EntityRef ref = _getNextRef(); | 2321 EntityRef ref = _getNextRef(); |
| 2322 ReferenceableElementForLink refElement = unit.resolveRef(ref.reference); | 2322 ReferenceableElementForLink refElement = unit.resolveRef(ref.reference); |
| 2323 ConstructorElementForLink constructorElement = refElement.asConstructor; | 2323 ConstructorElementForLink constructorElement = refElement.asConstructor; |
| 2324 | 2324 |
| 2325 if (constructorElement != null) { | 2325 if (constructorElement != null) { |
| 2326 stack.add(() { | 2326 stack.add(() { |
| 2327 if (ref.typeArguments.isNotEmpty) { | 2327 if (ref.typeArguments.isNotEmpty) { |
| 2328 return constructorElement.enclosingClass.buildType((int i) { | 2328 return constructorElement.enclosingClass.buildType((int i) { |
| 2329 if (i < ref.typeArguments.length) { | 2329 if (i < ref.typeArguments.length) { |
| 2330 return unit.resolveTypeRef(function, ref.typeArguments[i]); | 2330 return unit.resolveTypeRef( |
| 2331 ref.typeArguments[i], function.typeParameterContext); |
| 2331 } else { | 2332 } else { |
| 2332 return null; | 2333 return null; |
| 2333 } | 2334 } |
| 2334 }, const <int>[]); | 2335 }, const <int>[]); |
| 2335 } else { | 2336 } else { |
| 2336 FunctionType rawType = StaticTypeAnalyzer | 2337 FunctionType rawType = StaticTypeAnalyzer |
| 2337 .constructorToGenericFunctionType(constructorElement); | 2338 .constructorToGenericFunctionType(constructorElement); |
| 2338 FunctionType inferredType = _inferExecutableType( | 2339 FunctionType inferredType = _inferExecutableType( |
| 2339 rawType, | 2340 rawType, |
| 2340 numNamed, | 2341 numNamed, |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2520 List<String> _getNextStrings(int n) { | 2521 List<String> _getNextStrings(int n) { |
| 2521 List<String> result = new List<String>(n); | 2522 List<String> result = new List<String>(n); |
| 2522 for (int i = 0; i < n; i++) { | 2523 for (int i = 0; i < n; i++) { |
| 2523 result[i] = _getNextString(); | 2524 result[i] = _getNextString(); |
| 2524 } | 2525 } |
| 2525 return result; | 2526 return result; |
| 2526 } | 2527 } |
| 2527 | 2528 |
| 2528 DartType _getNextTypeRef() { | 2529 DartType _getNextTypeRef() { |
| 2529 EntityRef ref = _getNextRef(); | 2530 EntityRef ref = _getNextRef(); |
| 2530 return unit.resolveTypeRef(function, ref); | 2531 return unit.resolveTypeRef(ref, function.typeParameterContext); |
| 2531 } | 2532 } |
| 2532 | 2533 |
| 2533 List<DartType> _getTypeArguments() { | 2534 List<DartType> _getTypeArguments() { |
| 2534 int numTypeArguments = _getNextInt(); | 2535 int numTypeArguments = _getNextInt(); |
| 2535 List<DartType> typeArguments = new List<DartType>(numTypeArguments); | 2536 List<DartType> typeArguments = new List<DartType>(numTypeArguments); |
| 2536 for (int i = 0; i < numTypeArguments; i++) { | 2537 for (int i = 0; i < numTypeArguments; i++) { |
| 2537 typeArguments[i] = _getNextTypeRef(); | 2538 typeArguments[i] = _getNextTypeRef(); |
| 2538 } | 2539 } |
| 2539 return typeArguments; | 2540 return typeArguments; |
| 2540 } | 2541 } |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2877 return _implicitFunctionTypeIndices; | 2878 return _implicitFunctionTypeIndices; |
| 2878 } | 2879 } |
| 2879 | 2880 |
| 2880 @override | 2881 @override |
| 2881 DartType get returnType { | 2882 DartType get returnType { |
| 2882 if (_returnType == null) { | 2883 if (_returnType == null) { |
| 2883 if (enclosingElement._unlinkedParam.type == null) { | 2884 if (enclosingElement._unlinkedParam.type == null) { |
| 2884 _returnType = DynamicTypeImpl.instance; | 2885 _returnType = DynamicTypeImpl.instance; |
| 2885 } else { | 2886 } else { |
| 2886 _returnType = enclosingElement.compilationUnit.resolveTypeRef( | 2887 _returnType = enclosingElement.compilationUnit.resolveTypeRef( |
| 2887 enclosingElement, enclosingElement._unlinkedParam.type); | 2888 enclosingElement._unlinkedParam.type, typeParameterContext); |
| 2888 } | 2889 } |
| 2889 } | 2890 } |
| 2890 return _returnType; | 2891 return _returnType; |
| 2891 } | 2892 } |
| 2892 | 2893 |
| 2893 @override | 2894 @override |
| 2894 List<TypeParameterElement> get typeParameters => const []; | 2895 List<TypeParameterElement> get typeParameters => const []; |
| 2895 | 2896 |
| 2896 @override | 2897 @override |
| 2897 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 2898 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3192 bool get isSynthetic => false; | 3193 bool get isSynthetic => false; |
| 3193 | 3194 |
| 3194 @override | 3195 @override |
| 3195 LibraryElementForLink get library => enclosingElement.library; | 3196 LibraryElementForLink get library => enclosingElement.library; |
| 3196 | 3197 |
| 3197 @override | 3198 @override |
| 3198 String get name => _unlinkedTypedef.name; | 3199 String get name => _unlinkedTypedef.name; |
| 3199 | 3200 |
| 3200 @override | 3201 @override |
| 3201 DartType get returnType => _returnType ??= | 3202 DartType get returnType => _returnType ??= |
| 3202 enclosingElement.resolveTypeRef(this, _unlinkedTypedef.returnType); | 3203 enclosingElement.resolveTypeRef(_unlinkedTypedef.returnType, this); |
| 3203 | 3204 |
| 3204 @override | 3205 @override |
| 3205 TypeParameterizedElementMixin get typeParameterContext => this; | 3206 TypeParameterizedElementMixin get typeParameterContext => this; |
| 3206 | 3207 |
| 3207 @override | 3208 @override |
| 3208 List<UnlinkedParam> get unlinkedParameters => _unlinkedTypedef.parameters; | 3209 List<UnlinkedParam> get unlinkedParameters => _unlinkedTypedef.parameters; |
| 3209 | 3210 |
| 3210 @override | 3211 @override |
| 3211 List<UnlinkedTypeParam> get unlinkedTypeParams => | 3212 List<UnlinkedTypeParam> get unlinkedTypeParams => |
| 3212 _unlinkedTypedef.typeParameters; | 3213 _unlinkedTypedef.typeParameters; |
| (...skipping 978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4191 this, _typeParameterContext, _unlinkedParam.parameters)); | 4192 this, _typeParameterContext, _unlinkedParam.parameters)); |
| 4192 } else if (_unlinkedParam.type == null) { | 4193 } else if (_unlinkedParam.type == null) { |
| 4193 if (!compilationUnit.isInBuildUnit) { | 4194 if (!compilationUnit.isInBuildUnit) { |
| 4194 _inferredType = compilationUnit.getLinkedType( | 4195 _inferredType = compilationUnit.getLinkedType( |
| 4195 _unlinkedParam.inferredTypeSlot, _typeParameterContext); | 4196 _unlinkedParam.inferredTypeSlot, _typeParameterContext); |
| 4196 return _inferredType; | 4197 return _inferredType; |
| 4197 } else { | 4198 } else { |
| 4198 _declaredType = DynamicTypeImpl.instance; | 4199 _declaredType = DynamicTypeImpl.instance; |
| 4199 } | 4200 } |
| 4200 } else { | 4201 } else { |
| 4201 _declaredType = | 4202 _declaredType = compilationUnit.resolveTypeRef( |
| 4202 compilationUnit.resolveTypeRef(this, _unlinkedParam.type); | 4203 _unlinkedParam.type, _typeParameterContext); |
| 4203 } | 4204 } |
| 4204 } | 4205 } |
| 4205 return _declaredType; | 4206 return _declaredType; |
| 4206 } | 4207 } |
| 4207 | 4208 |
| 4208 @override | 4209 @override |
| 4209 void set type(DartType inferredType) { | 4210 void set type(DartType inferredType) { |
| 4210 assert(_inferredType == null); | 4211 assert(_inferredType == null); |
| 4211 _inferredType = inferredType; | 4212 _inferredType = inferredType; |
| 4212 } | 4213 } |
| 4213 | 4214 |
| 4214 @override | |
| 4215 TypeParameterizedElementMixin get typeParameterContext { | |
| 4216 return _typeParameterContext; | |
| 4217 } | |
| 4218 | |
| 4219 /** | 4215 /** |
| 4220 * Store the results of type inference for this parameter in | 4216 * Store the results of type inference for this parameter in |
| 4221 * [compilationUnit]. | 4217 * [compilationUnit]. |
| 4222 */ | 4218 */ |
| 4223 void link(CompilationUnitElementInBuildUnit compilationUnit) { | 4219 void link(CompilationUnitElementInBuildUnit compilationUnit) { |
| 4224 compilationUnit._storeLinkedType( | 4220 compilationUnit._storeLinkedType( |
| 4225 _unlinkedParam.inferredTypeSlot, _inferredType, _typeParameterContext); | 4221 _unlinkedParam.inferredTypeSlot, _inferredType, _typeParameterContext); |
| 4226 compilationUnit._storeLinkedTypeError( | 4222 compilationUnit._storeLinkedTypeError( |
| 4227 _unlinkedParam.inferredTypeSlot, _inferenceError); | 4223 _unlinkedParam.inferredTypeSlot, _inferenceError); |
| 4228 if (inheritsCovariant) { | 4224 if (inheritsCovariant) { |
| (...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5183 } | 5179 } |
| 5184 | 5180 |
| 5185 /** | 5181 /** |
| 5186 * If the variable has an explicitly declared return type, return it. | 5182 * If the variable has an explicitly declared return type, return it. |
| 5187 * Otherwise return `null`. | 5183 * Otherwise return `null`. |
| 5188 */ | 5184 */ |
| 5189 DartType get declaredType { | 5185 DartType get declaredType { |
| 5190 if (unlinkedVariable.type == null) { | 5186 if (unlinkedVariable.type == null) { |
| 5191 return null; | 5187 return null; |
| 5192 } else { | 5188 } else { |
| 5193 return _declaredType ??= | 5189 return _declaredType ??= compilationUnit.resolveTypeRef( |
| 5194 compilationUnit.resolveTypeRef(this, unlinkedVariable.type); | 5190 unlinkedVariable.type, _typeParameterContext); |
| 5195 } | 5191 } |
| 5196 } | 5192 } |
| 5197 | 5193 |
| 5198 @override | 5194 @override |
| 5199 String get displayName => unlinkedVariable.name; | 5195 String get displayName => unlinkedVariable.name; |
| 5200 | 5196 |
| 5201 @override | 5197 @override |
| 5202 PropertyAccessorElementForLink_Variable get getter => | 5198 PropertyAccessorElementForLink_Variable get getter => |
| 5203 _getter ??= new PropertyAccessorElementForLink_Variable(this, false); | 5199 _getter ??= new PropertyAccessorElementForLink_Variable(this, false); |
| 5204 | 5200 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5282 } | 5278 } |
| 5283 | 5279 |
| 5284 @override | 5280 @override |
| 5285 DartType get type => declaredType ?? inferredType; | 5281 DartType get type => declaredType ?? inferredType; |
| 5286 | 5282 |
| 5287 @override | 5283 @override |
| 5288 void set type(DartType newType) { | 5284 void set type(DartType newType) { |
| 5289 // TODO(paulberry): store inferred type. | 5285 // TODO(paulberry): store inferred type. |
| 5290 } | 5286 } |
| 5291 | 5287 |
| 5292 @override | |
| 5293 TypeParameterizedElementMixin get typeParameterContext { | |
| 5294 return _typeParameterContext; | |
| 5295 } | |
| 5296 | |
| 5297 /** | 5288 /** |
| 5298 * The context in which type parameters should be interpreted, or `null` if | 5289 * The context in which type parameters should be interpreted, or `null` if |
| 5299 * there are no type parameters in scope. | 5290 * there are no type parameters in scope. |
| 5300 */ | 5291 */ |
| 5301 TypeParameterizedElementMixin get _typeParameterContext; | 5292 TypeParameterizedElementMixin get _typeParameterContext; |
| 5302 | 5293 |
| 5303 @override | 5294 @override |
| 5304 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 5295 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 5305 | 5296 |
| 5306 @override | 5297 @override |
| 5307 String toString() => '$enclosingElement.$name'; | 5298 String toString() => '$enclosingElement.$name'; |
| 5308 } | 5299 } |
| 5309 | 5300 |
| 5310 /** | 5301 /** |
| 5311 * This exception is thrown when [ExprTypeComputer] cannot inference the type. | 5302 * This exception is thrown when [ExprTypeComputer] cannot inference the type. |
| 5312 */ | 5303 */ |
| 5313 class _InferenceFailedError { | 5304 class _InferenceFailedError { |
| 5314 final String message; | 5305 final String message; |
| 5315 | 5306 |
| 5316 _InferenceFailedError(this.message); | 5307 _InferenceFailedError(this.message); |
| 5317 } | 5308 } |
| OLD | NEW |