| 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'; |
| 11 import 'package:analyzer/dart/ast/token.dart'; | 11 import 'package:analyzer/dart/ast/token.dart'; |
| 12 import 'package:analyzer/dart/ast/visitor.dart'; | 12 import 'package:analyzer/dart/ast/visitor.dart'; |
| 13 import 'package:analyzer/dart/element/element.dart'; | 13 import 'package:analyzer/dart/element/element.dart'; |
| 14 import 'package:analyzer/dart/element/type.dart'; | 14 import 'package:analyzer/dart/element/type.dart'; |
| 15 import 'package:analyzer/dart/element/visitor.dart'; | 15 import 'package:analyzer/dart/element/visitor.dart'; |
| 16 import 'package:analyzer/error/error.dart'; | 16 import 'package:analyzer/error/error.dart'; |
| 17 import 'package:analyzer/error/listener.dart'; | 17 import 'package:analyzer/error/listener.dart'; |
| 18 import 'package:analyzer/exception/exception.dart'; | 18 import 'package:analyzer/exception/exception.dart'; |
| 19 import 'package:analyzer/src/dart/ast/ast.dart'; | 19 import 'package:analyzer/src/dart/ast/ast.dart'; |
| 20 import 'package:analyzer/src/dart/ast/utilities.dart'; | 20 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 21 import 'package:analyzer/src/dart/element/element.dart'; | 21 import 'package:analyzer/src/dart/element/element.dart'; |
| 22 import 'package:analyzer/src/dart/element/member.dart' show ConstructorMember; | 22 import 'package:analyzer/src/dart/element/member.dart' show ConstructorMember; |
| 23 import 'package:analyzer/src/dart/element/type.dart'; | 23 import 'package:analyzer/src/dart/element/type.dart'; |
| 24 import 'package:analyzer/src/dart/resolver/inheritance_manager.dart'; | 24 import 'package:analyzer/src/dart/resolver/inheritance_manager.dart'; |
| 25 import 'package:analyzer/src/dart/resolver/scope.dart'; | 25 import 'package:analyzer/src/dart/resolver/scope.dart'; |
| 26 import 'package:analyzer/src/error/codes.dart'; | 26 import 'package:analyzer/src/error/codes.dart'; |
| 27 import 'package:analyzer/src/fasta/uri_instrumentation.dart'; |
| 27 import 'package:analyzer/src/generated/constant.dart'; | 28 import 'package:analyzer/src/generated/constant.dart'; |
| 28 import 'package:analyzer/src/generated/element_resolver.dart'; | 29 import 'package:analyzer/src/generated/element_resolver.dart'; |
| 29 import 'package:analyzer/src/generated/engine.dart'; | 30 import 'package:analyzer/src/generated/engine.dart'; |
| 30 import 'package:analyzer/src/generated/error_verifier.dart'; | 31 import 'package:analyzer/src/generated/error_verifier.dart'; |
| 31 import 'package:analyzer/src/generated/source.dart'; | 32 import 'package:analyzer/src/generated/source.dart'; |
| 32 import 'package:analyzer/src/generated/static_type_analyzer.dart'; | 33 import 'package:analyzer/src/generated/static_type_analyzer.dart'; |
| 33 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 34 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 34 import 'package:analyzer/src/generated/type_system.dart'; | 35 import 'package:analyzer/src/generated/type_system.dart'; |
| 35 import 'package:analyzer/src/generated/utilities_dart.dart'; | 36 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 36 | 37 |
| (...skipping 4167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4204 // hash table help in an instance of this class. | 4205 // hash table help in an instance of this class. |
| 4205 static const String _typeProperty = | 4206 static const String _typeProperty = |
| 4206 'analyzer.src.generated.InferenceContext.contextType'; | 4207 'analyzer.src.generated.InferenceContext.contextType'; |
| 4207 | 4208 |
| 4208 /** | 4209 /** |
| 4209 * The error listener on which to record inference information. | 4210 * The error listener on which to record inference information. |
| 4210 */ | 4211 */ |
| 4211 final ErrorReporter _errorReporter; | 4212 final ErrorReporter _errorReporter; |
| 4212 | 4213 |
| 4213 /** | 4214 /** |
| 4215 * The instrumentation to report inference information. |
| 4216 */ |
| 4217 final UriInstrumentation _instrumentation; |
| 4218 |
| 4219 /** |
| 4214 * If true, emit hints when types are inferred | 4220 * If true, emit hints when types are inferred |
| 4215 */ | 4221 */ |
| 4216 final bool _inferenceHints; | 4222 final bool _inferenceHints; |
| 4217 | 4223 |
| 4218 /** | 4224 /** |
| 4219 * Type provider, needed for type matching. | 4225 * Type provider, needed for type matching. |
| 4220 */ | 4226 */ |
| 4221 final TypeProvider _typeProvider; | 4227 final TypeProvider _typeProvider; |
| 4222 | 4228 |
| 4223 /** | 4229 /** |
| 4224 * The type system in use. | 4230 * The type system in use. |
| 4225 */ | 4231 */ |
| 4226 final TypeSystem _typeSystem; | 4232 final TypeSystem _typeSystem; |
| 4227 | 4233 |
| 4228 /** | 4234 /** |
| 4229 * When no context type is available, this will track the least upper bound | 4235 * When no context type is available, this will track the least upper bound |
| 4230 * of all return statements in a lambda. | 4236 * of all return statements in a lambda. |
| 4231 * | 4237 * |
| 4232 * This will always be kept in sync with [_returnStack]. | 4238 * This will always be kept in sync with [_returnStack]. |
| 4233 */ | 4239 */ |
| 4234 final List<DartType> _inferredReturn = <DartType>[]; | 4240 final List<DartType> _inferredReturn = <DartType>[]; |
| 4235 | 4241 |
| 4236 /** | 4242 /** |
| 4237 * A stack of return types for all of the enclosing | 4243 * A stack of return types for all of the enclosing |
| 4238 * functions and methods. | 4244 * functions and methods. |
| 4239 */ | 4245 */ |
| 4240 final List<DartType> _returnStack = <DartType>[]; | 4246 final List<DartType> _returnStack = <DartType>[]; |
| 4241 | 4247 |
| 4242 InferenceContext._(this._errorReporter, TypeProvider typeProvider, | 4248 InferenceContext._(TypeProvider typeProvider, this._typeSystem, |
| 4243 this._typeSystem, this._inferenceHints) | 4249 this._inferenceHints, this._errorReporter, this._instrumentation) |
| 4244 : _typeProvider = typeProvider; | 4250 : _typeProvider = typeProvider; |
| 4245 | 4251 |
| 4246 /** | 4252 /** |
| 4247 * Get the return type of the current enclosing function, if any. | 4253 * Get the return type of the current enclosing function, if any. |
| 4248 * | 4254 * |
| 4249 * The type returned for a function is the type that is expected | 4255 * The type returned for a function is the type that is expected |
| 4250 * to be used in a return or yield context. For ordinary functions | 4256 * to be used in a return or yield context. For ordinary functions |
| 4251 * this is the same as the return type of the function. For async | 4257 * this is the same as the return type of the function. For async |
| 4252 * functions returning Future<T> and for generator functions | 4258 * functions returning Future<T> and for generator functions |
| 4253 * returning Stream<T> or Iterable<T>, this is T. | 4259 * returning Stream<T> or Iterable<T>, this is T. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4297 void pushReturnContext(BlockFunctionBody node) { | 4303 void pushReturnContext(BlockFunctionBody node) { |
| 4298 _returnStack.add(getContext(node)); | 4304 _returnStack.add(getContext(node)); |
| 4299 _inferredReturn.add(_typeProvider.nullType); | 4305 _inferredReturn.add(_typeProvider.nullType); |
| 4300 } | 4306 } |
| 4301 | 4307 |
| 4302 /** | 4308 /** |
| 4303 * Place an info node into the error stream indicating that a | 4309 * Place an info node into the error stream indicating that a |
| 4304 * [type] has been inferred as the type of [node]. | 4310 * [type] has been inferred as the type of [node]. |
| 4305 */ | 4311 */ |
| 4306 void recordInference(Expression node, DartType type) { | 4312 void recordInference(Expression node, DartType type) { |
| 4313 _instrumentation?.recordInference(node.offset, type); |
| 4314 |
| 4307 if (!_inferenceHints) { | 4315 if (!_inferenceHints) { |
| 4308 return; | 4316 return; |
| 4309 } | 4317 } |
| 4310 | 4318 |
| 4311 ErrorCode error; | 4319 ErrorCode error; |
| 4312 if (node is Literal) { | 4320 if (node is Literal) { |
| 4313 error = StrongModeCode.INFERRED_TYPE_LITERAL; | 4321 error = StrongModeCode.INFERRED_TYPE_LITERAL; |
| 4314 } else if (node is InstanceCreationExpression) { | 4322 } else if (node is InstanceCreationExpression) { |
| 4315 error = StrongModeCode.INFERRED_TYPE_ALLOCATION; | 4323 error = StrongModeCode.INFERRED_TYPE_ALLOCATION; |
| 4316 } else if (node is FunctionExpression) { | 4324 } else if (node is FunctionExpression) { |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4985 * The object used to compute the type associated with the current node. | 4993 * The object used to compute the type associated with the current node. |
| 4986 */ | 4994 */ |
| 4987 StaticTypeAnalyzer typeAnalyzer; | 4995 StaticTypeAnalyzer typeAnalyzer; |
| 4988 | 4996 |
| 4989 /** | 4997 /** |
| 4990 * The type system in use during resolution. | 4998 * The type system in use during resolution. |
| 4991 */ | 4999 */ |
| 4992 TypeSystem typeSystem; | 5000 TypeSystem typeSystem; |
| 4993 | 5001 |
| 4994 /** | 5002 /** |
| 5003 * The instrumentation to report inference information. |
| 5004 */ |
| 5005 final UriInstrumentation instrumentation; |
| 5006 |
| 5007 /** |
| 4995 * The class declaration representing the class containing the current node, o
r `null` if | 5008 * The class declaration representing the class containing the current node, o
r `null` if |
| 4996 * the current node is not contained in a class. | 5009 * the current node is not contained in a class. |
| 4997 */ | 5010 */ |
| 4998 ClassDeclaration _enclosingClassDeclaration = null; | 5011 ClassDeclaration _enclosingClassDeclaration = null; |
| 4999 | 5012 |
| 5000 /** | 5013 /** |
| 5001 * The function type alias representing the function type containing the curre
nt node, or | 5014 * The function type alias representing the function type containing the curre
nt node, or |
| 5002 * `null` if the current node is not contained in a function type alias. | 5015 * `null` if the current node is not contained in a function type alias. |
| 5003 */ | 5016 */ |
| 5004 FunctionTypeAlias _enclosingFunctionTypeAlias = null; | 5017 FunctionTypeAlias _enclosingFunctionTypeAlias = null; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5053 * node that will first be visited. If `null` or unspecified, a new | 5066 * node that will first be visited. If `null` or unspecified, a new |
| 5054 * [LibraryScope] will be created based on [definingLibrary] and | 5067 * [LibraryScope] will be created based on [definingLibrary] and |
| 5055 * [typeProvider]. The [inheritanceManager] is used to perform inheritance | 5068 * [typeProvider]. The [inheritanceManager] is used to perform inheritance |
| 5056 * lookups. If `null` or unspecified, a new [InheritanceManager] will be | 5069 * lookups. If `null` or unspecified, a new [InheritanceManager] will be |
| 5057 * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to | 5070 * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to |
| 5058 * create the type analyzer. If `null` or unspecified, a type analyzer of | 5071 * create the type analyzer. If `null` or unspecified, a type analyzer of |
| 5059 * type [StaticTypeAnalyzer] will be created. | 5072 * type [StaticTypeAnalyzer] will be created. |
| 5060 */ | 5073 */ |
| 5061 ResolverVisitor(LibraryElement definingLibrary, Source source, | 5074 ResolverVisitor(LibraryElement definingLibrary, Source source, |
| 5062 TypeProvider typeProvider, AnalysisErrorListener errorListener, | 5075 TypeProvider typeProvider, AnalysisErrorListener errorListener, |
| 5063 {Scope nameScope}) | 5076 {Scope nameScope, this.instrumentation}) |
| 5064 : super(definingLibrary, source, typeProvider, errorListener, | 5077 : super(definingLibrary, source, typeProvider, errorListener, |
| 5065 nameScope: nameScope) { | 5078 nameScope: nameScope) { |
| 5066 AnalysisOptions options = definingLibrary.context.analysisOptions; | 5079 AnalysisOptions options = definingLibrary.context.analysisOptions; |
| 5067 this.strongMode = options.strongMode; | 5080 this.strongMode = options.strongMode; |
| 5068 this.elementResolver = new ElementResolver(this); | 5081 this.elementResolver = new ElementResolver(this); |
| 5069 this.typeSystem = definingLibrary.context.typeSystem; | 5082 this.typeSystem = definingLibrary.context.typeSystem; |
| 5070 bool strongModeHints = false; | 5083 bool strongModeHints = false; |
| 5071 if (options is AnalysisOptionsImpl) { | 5084 if (options is AnalysisOptionsImpl) { |
| 5072 strongModeHints = options.strongModeHints; | 5085 strongModeHints = options.strongModeHints; |
| 5073 } | 5086 } |
| 5074 this.inferenceContext = new InferenceContext._( | 5087 this.inferenceContext = new InferenceContext._(typeProvider, typeSystem, |
| 5075 errorReporter, typeProvider, typeSystem, strongModeHints); | 5088 strongModeHints, errorReporter, instrumentation); |
| 5076 this.typeAnalyzer = new StaticTypeAnalyzer(this); | 5089 this.typeAnalyzer = new StaticTypeAnalyzer(this); |
| 5077 } | 5090 } |
| 5078 | 5091 |
| 5079 /** | 5092 /** |
| 5080 * Return the element representing the function containing the current node, o
r `null` if | 5093 * Return the element representing the function containing the current node, o
r `null` if |
| 5081 * the current node is not contained in a function. | 5094 * the current node is not contained in a function. |
| 5082 * | 5095 * |
| 5083 * @return the element representing the function containing the current node | 5096 * @return the element representing the function containing the current node |
| 5084 */ | 5097 */ |
| 5085 ExecutableElement get enclosingFunction => _enclosingFunction; | 5098 ExecutableElement get enclosingFunction => _enclosingFunction; |
| (...skipping 5852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10938 return null; | 10951 return null; |
| 10939 } | 10952 } |
| 10940 if (identical(node.staticElement, variable)) { | 10953 if (identical(node.staticElement, variable)) { |
| 10941 if (node.inSetterContext()) { | 10954 if (node.inSetterContext()) { |
| 10942 result = true; | 10955 result = true; |
| 10943 } | 10956 } |
| 10944 } | 10957 } |
| 10945 return null; | 10958 return null; |
| 10946 } | 10959 } |
| 10947 } | 10960 } |
| OLD | NEW |