| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 analyzer.src.generated.resolver; | 5 library analyzer.src.generated.resolver; |
| 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_resolution_map.dart'; | 10 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 /** | 93 /** |
| 94 * Create a new instance of the [BestPracticesVerifier]. | 94 * Create a new instance of the [BestPracticesVerifier]. |
| 95 * | 95 * |
| 96 * @param errorReporter the error reporter | 96 * @param errorReporter the error reporter |
| 97 */ | 97 */ |
| 98 BestPracticesVerifier(this._errorReporter, TypeProvider typeProvider, | 98 BestPracticesVerifier(this._errorReporter, TypeProvider typeProvider, |
| 99 this._currentLibrary, this._manager, | 99 this._currentLibrary, this._manager, |
| 100 {TypeSystem typeSystem}) | 100 {TypeSystem typeSystem}) |
| 101 : _nullType = typeProvider.nullType, | 101 : _nullType = typeProvider.nullType, |
| 102 _futureNullType = typeProvider.futureNullType, | 102 _futureNullType = typeProvider.futureNullType, |
| 103 _typeSystem = typeSystem ?? new TypeSystemImpl() { | 103 _typeSystem = typeSystem ?? new TypeSystemImpl(typeProvider) { |
| 104 inDeprecatedMember = _currentLibrary.isDeprecated; | 104 inDeprecatedMember = _currentLibrary.isDeprecated; |
| 105 } | 105 } |
| 106 | 106 |
| 107 @override | 107 @override |
| 108 Object visitAnnotation(Annotation node) { | 108 Object visitAnnotation(Annotation node) { |
| 109 if (resolutionMap.elementAnnotationForAnnotation(node)?.isFactory == true) { | 109 if (resolutionMap.elementAnnotationForAnnotation(node)?.isFactory == true) { |
| 110 AstNode parent = node.parent; | 110 AstNode parent = node.parent; |
| 111 if (parent is MethodDeclaration) { | 111 if (parent is MethodDeclaration) { |
| 112 _checkForInvalidFactory(parent); | 112 _checkForInvalidFactory(parent); |
| 113 } else { | 113 } else { |
| (...skipping 1777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1891 * The type system for this visitor | 1891 * The type system for this visitor |
| 1892 */ | 1892 */ |
| 1893 final TypeSystem _typeSystem; | 1893 final TypeSystem _typeSystem; |
| 1894 | 1894 |
| 1895 /** | 1895 /** |
| 1896 * Create a new instance of the [DeadCodeVerifier]. | 1896 * Create a new instance of the [DeadCodeVerifier]. |
| 1897 * | 1897 * |
| 1898 * @param errorReporter the error reporter | 1898 * @param errorReporter the error reporter |
| 1899 */ | 1899 */ |
| 1900 DeadCodeVerifier(this._errorReporter, {TypeSystem typeSystem}) | 1900 DeadCodeVerifier(this._errorReporter, {TypeSystem typeSystem}) |
| 1901 : this._typeSystem = typeSystem ?? new TypeSystemImpl(); | 1901 : this._typeSystem = typeSystem ?? new TypeSystemImpl(null); |
| 1902 | 1902 |
| 1903 @override | 1903 @override |
| 1904 Object visitBinaryExpression(BinaryExpression node) { | 1904 Object visitBinaryExpression(BinaryExpression node) { |
| 1905 Token operator = node.operator; | 1905 Token operator = node.operator; |
| 1906 bool isAmpAmp = operator.type == TokenType.AMPERSAND_AMPERSAND; | 1906 bool isAmpAmp = operator.type == TokenType.AMPERSAND_AMPERSAND; |
| 1907 bool isBarBar = operator.type == TokenType.BAR_BAR; | 1907 bool isBarBar = operator.type == TokenType.BAR_BAR; |
| 1908 if (isAmpAmp || isBarBar) { | 1908 if (isAmpAmp || isBarBar) { |
| 1909 Expression lhsCondition = node.leftOperand; | 1909 Expression lhsCondition = node.leftOperand; |
| 1910 if (!_isDebugConstant(lhsCondition)) { | 1910 if (!_isDebugConstant(lhsCondition)) { |
| 1911 EvaluationResultImpl lhsResult = _getConstantBooleanValue(lhsCondition); | 1911 EvaluationResultImpl lhsResult = _getConstantBooleanValue(lhsCondition); |
| (...skipping 2195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4107 * | 4107 * |
| 4108 * This will be used for inferring a block bodied lambda, if no context | 4108 * This will be used for inferring a block bodied lambda, if no context |
| 4109 * type was available. | 4109 * type was available. |
| 4110 */ | 4110 */ |
| 4111 void addReturnOrYieldType(DartType type) { | 4111 void addReturnOrYieldType(DartType type) { |
| 4112 if (_returnStack.isEmpty) { | 4112 if (_returnStack.isEmpty) { |
| 4113 return; | 4113 return; |
| 4114 } | 4114 } |
| 4115 | 4115 |
| 4116 DartType inferred = _inferredReturn.last; | 4116 DartType inferred = _inferredReturn.last; |
| 4117 inferred = _typeSystem.getLeastUpperBound(_typeProvider, type, inferred); | 4117 inferred = _typeSystem.getLeastUpperBound(type, inferred); |
| 4118 _inferredReturn[_inferredReturn.length - 1] = inferred; | 4118 _inferredReturn[_inferredReturn.length - 1] = inferred; |
| 4119 } | 4119 } |
| 4120 | 4120 |
| 4121 /** | 4121 /** |
| 4122 * Match type [t1] against type [t2] as follows. | 4122 * Match type [t1] against type [t2] as follows. |
| 4123 * If `t1 = I<dynamic, ..., dynamic>`, then look for a supertype | 4123 * If `t1 = I<dynamic, ..., dynamic>`, then look for a supertype |
| 4124 * of t1 of the form `K<S0, ..., Sm>` where `t2 = K<S0', ..., Sm'>` | 4124 * of t1 of the form `K<S0, ..., Sm>` where `t2 = K<S0', ..., Sm'>` |
| 4125 * If the supertype exists, use the constraints `S0 <: S0', ... Sm <: Sm'` | 4125 * If the supertype exists, use the constraints `S0 <: S0', ... Sm <: Sm'` |
| 4126 * to derive a concrete instantation for I of the form `<T0, ..., Tn>`, | 4126 * to derive a concrete instantation for I of the form `<T0, ..., Tn>`, |
| 4127 * such that `I<T0, .., Tn> <: t2` | 4127 * such that `I<T0, .., Tn> <: t2` |
| (...skipping 2574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6702 if (contextType is FunctionType) { | 6702 if (contextType is FunctionType) { |
| 6703 DartType originalType = node.function.staticType; | 6703 DartType originalType = node.function.staticType; |
| 6704 DartType returnContextType = InferenceContext.getContext(node); | 6704 DartType returnContextType = InferenceContext.getContext(node); |
| 6705 TypeSystem ts = typeSystem; | 6705 TypeSystem ts = typeSystem; |
| 6706 if (returnContextType != null && | 6706 if (returnContextType != null && |
| 6707 node.typeArguments == null && | 6707 node.typeArguments == null && |
| 6708 originalType is FunctionType && | 6708 originalType is FunctionType && |
| 6709 originalType.typeFormals.isNotEmpty && | 6709 originalType.typeFormals.isNotEmpty && |
| 6710 ts is StrongTypeSystemImpl) { | 6710 ts is StrongTypeSystemImpl) { |
| 6711 contextType = ts.inferGenericFunctionCall( | 6711 contextType = ts.inferGenericFunctionCall( |
| 6712 typeProvider, | |
| 6713 originalType, | 6712 originalType, |
| 6714 DartType.EMPTY_LIST, | 6713 DartType.EMPTY_LIST, |
| 6715 DartType.EMPTY_LIST, | 6714 DartType.EMPTY_LIST, |
| 6716 originalType.returnType, | 6715 originalType.returnType, |
| 6717 returnContextType); | 6716 returnContextType); |
| 6718 } | 6717 } |
| 6719 | 6718 |
| 6720 InferenceContext.setType(node.argumentList, contextType); | 6719 InferenceContext.setType(node.argumentList, contextType); |
| 6721 } | 6720 } |
| 6722 } | 6721 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6762 // If the expectedClosureType is not more specific than the static type, | 6761 // If the expectedClosureType is not more specific than the static type, |
| 6763 // return. | 6762 // return. |
| 6764 DartType staticClosureType = | 6763 DartType staticClosureType = |
| 6765 resolutionMap.elementDeclaredByFunctionExpression(closure)?.type; | 6764 resolutionMap.elementDeclaredByFunctionExpression(closure)?.type; |
| 6766 if (staticClosureType != null && | 6765 if (staticClosureType != null && |
| 6767 !FunctionTypeImpl.relate( | 6766 !FunctionTypeImpl.relate( |
| 6768 expectedClosureType, | 6767 expectedClosureType, |
| 6769 staticClosureType, | 6768 staticClosureType, |
| 6770 (DartType t, DartType s, _, __) => | 6769 (DartType t, DartType s, _, __) => |
| 6771 (t as TypeImpl).isMoreSpecificThan(s), | 6770 (t as TypeImpl).isMoreSpecificThan(s), |
| 6772 new TypeSystemImpl().instantiateToBounds, | 6771 new TypeSystemImpl(typeProvider).instantiateToBounds, |
| 6773 returnRelation: (s, t) => true)) { | 6772 returnRelation: (s, t) => true)) { |
| 6774 return; | 6773 return; |
| 6775 } | 6774 } |
| 6776 // set propagated type for the closure | 6775 // set propagated type for the closure |
| 6777 if (!strongMode) { | 6776 if (!strongMode) { |
| 6778 closure.propagatedType = expectedClosureType; | 6777 closure.propagatedType = expectedClosureType; |
| 6779 } | 6778 } |
| 6780 // set inferred types for parameters | 6779 // set inferred types for parameters |
| 6781 NodeList<FormalParameter> parameters = closure.parameters.parameters; | 6780 NodeList<FormalParameter> parameters = closure.parameters.parameters; |
| 6782 List<ParameterElement> expectedParameters = expectedClosureType.parameters; | 6781 List<ParameterElement> expectedParameters = expectedClosureType.parameters; |
| (...skipping 2032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8815 TypeName bound = typeParameter.bound; | 8814 TypeName bound = typeParameter.bound; |
| 8816 if (bound != null) { | 8815 if (bound != null) { |
| 8817 Element typeParameterElement = typeParameter.name.staticElement; | 8816 Element typeParameterElement = typeParameter.name.staticElement; |
| 8818 if (typeParameterElement is TypeParameterElementImpl) { | 8817 if (typeParameterElement is TypeParameterElementImpl) { |
| 8819 if (LibraryElementImpl.hasResolutionCapability( | 8818 if (LibraryElementImpl.hasResolutionCapability( |
| 8820 library, LibraryResolutionCapability.resolvedTypeNames)) { | 8819 library, LibraryResolutionCapability.resolvedTypeNames)) { |
| 8821 bound.type = typeParameterElement.bound; | 8820 bound.type = typeParameterElement.bound; |
| 8822 } else { | 8821 } else { |
| 8823 libraryScope ??= new LibraryScope(library); | 8822 libraryScope ??= new LibraryScope(library); |
| 8824 typeParametersScope ??= createTypeParametersScope(); | 8823 typeParametersScope ??= createTypeParametersScope(); |
| 8825 typeNameResolver ??= new TypeNameResolver(new TypeSystemImpl(), | 8824 typeNameResolver ??= new TypeNameResolver( |
| 8826 typeProvider, library, source, errorListener); | 8825 new TypeSystemImpl(typeProvider), |
| 8826 typeProvider, |
| 8827 library, |
| 8828 source, |
| 8829 errorListener); |
| 8827 typeNameResolver.nameScope = typeParametersScope; | 8830 typeNameResolver.nameScope = typeParametersScope; |
| 8828 _resolveTypeName(bound); | 8831 _resolveTypeName(bound); |
| 8829 typeParameterElement.bound = bound.type; | 8832 typeParameterElement.bound = bound.type; |
| 8830 } | 8833 } |
| 8831 } | 8834 } |
| 8832 } | 8835 } |
| 8833 } | 8836 } |
| 8834 } | 8837 } |
| 8835 } | 8838 } |
| 8836 } | 8839 } |
| (...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10689 | 10692 |
| 10690 TypeSystem _typeSystem; | 10693 TypeSystem _typeSystem; |
| 10691 | 10694 |
| 10692 _ConstantVerifier_validateInitializerExpression( | 10695 _ConstantVerifier_validateInitializerExpression( |
| 10693 TypeProvider typeProvider, | 10696 TypeProvider typeProvider, |
| 10694 ErrorReporter errorReporter, | 10697 ErrorReporter errorReporter, |
| 10695 this.verifier, | 10698 this.verifier, |
| 10696 this.parameterElements, | 10699 this.parameterElements, |
| 10697 DeclaredVariables declaredVariables, | 10700 DeclaredVariables declaredVariables, |
| 10698 {TypeSystem typeSystem}) | 10701 {TypeSystem typeSystem}) |
| 10699 : _typeSystem = typeSystem ?? new TypeSystemImpl(), | 10702 : _typeSystem = typeSystem ?? new TypeSystemImpl(typeProvider), |
| 10700 super( | 10703 super( |
| 10701 new ConstantEvaluationEngine(typeProvider, declaredVariables, | 10704 new ConstantEvaluationEngine(typeProvider, declaredVariables, |
| 10702 typeSystem: typeSystem), | 10705 typeSystem: typeSystem), |
| 10703 errorReporter); | 10706 errorReporter); |
| 10704 | 10707 |
| 10705 @override | 10708 @override |
| 10706 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) { | 10709 DartObjectImpl visitSimpleIdentifier(SimpleIdentifier node) { |
| 10707 Element element = node.staticElement; | 10710 Element element = node.staticElement; |
| 10708 int length = parameterElements.length; | 10711 int length = parameterElements.length; |
| 10709 for (int i = 0; i < length; i++) { | 10712 for (int i = 0; i < length; i++) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10795 return null; | 10798 return null; |
| 10796 } | 10799 } |
| 10797 if (identical(node.staticElement, variable)) { | 10800 if (identical(node.staticElement, variable)) { |
| 10798 if (node.inSetterContext()) { | 10801 if (node.inSetterContext()) { |
| 10799 result = true; | 10802 result = true; |
| 10800 } | 10803 } |
| 10801 } | 10804 } |
| 10802 return null; | 10805 return null; |
| 10803 } | 10806 } |
| 10804 } | 10807 } |
| OLD | NEW |