| 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 5004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5015 * A comment before a function should be resolved in the context of the | 5015 * A comment before a function should be resolved in the context of the |
| 5016 * function. But when we incrementally resolve a comment, we don't want to | 5016 * function. But when we incrementally resolve a comment, we don't want to |
| 5017 * resolve the whole function. | 5017 * resolve the whole function. |
| 5018 * | 5018 * |
| 5019 * So, this flag is set to `true`, when just context of the function should | 5019 * So, this flag is set to `true`, when just context of the function should |
| 5020 * be built and the comment resolved. | 5020 * be built and the comment resolved. |
| 5021 */ | 5021 */ |
| 5022 bool resolveOnlyCommentInFunctionBody = false; | 5022 bool resolveOnlyCommentInFunctionBody = false; |
| 5023 | 5023 |
| 5024 /** | 5024 /** |
| 5025 * This flag is set to `true` while the type of a top-level variable or a |
| 5026 * class field is being inferred using its initializer. |
| 5027 */ |
| 5028 bool isTopLevelInference; |
| 5029 |
| 5030 /** |
| 5025 * Body of the function currently being analyzed, if any. | 5031 * Body of the function currently being analyzed, if any. |
| 5026 */ | 5032 */ |
| 5027 FunctionBody _currentFunctionBody; | 5033 FunctionBody _currentFunctionBody; |
| 5028 | 5034 |
| 5029 /** | 5035 /** |
| 5030 * Are we running in strong mode or not. | 5036 * Are we running in strong mode or not. |
| 5031 */ | 5037 */ |
| 5032 bool strongMode; | 5038 bool strongMode; |
| 5033 | 5039 |
| 5034 /** | 5040 /** |
| 5035 * Initialize a newly created visitor to resolve the nodes in an AST node. | 5041 * Initialize a newly created visitor to resolve the nodes in an AST node. |
| 5036 * | 5042 * |
| 5037 * The [definingLibrary] is the element for the library containing the node | 5043 * The [definingLibrary] is the element for the library containing the node |
| 5038 * being visited. The [source] is the source representing the compilation unit | 5044 * being visited. The [source] is the source representing the compilation unit |
| 5039 * containing the node being visited. The [typeProvider] is the object used to | 5045 * containing the node being visited. The [typeProvider] is the object used to |
| 5040 * access the types from the core library. The [errorListener] is the error | 5046 * access the types from the core library. The [errorListener] is the error |
| 5041 * listener that will be informed of any errors that are found during | 5047 * listener that will be informed of any errors that are found during |
| 5042 * resolution. The [nameScope] is the scope used to resolve identifiers in the | 5048 * resolution. The [nameScope] is the scope used to resolve identifiers in the |
| 5043 * node that will first be visited. If `null` or unspecified, a new | 5049 * node that will first be visited. If `null` or unspecified, a new |
| 5044 * [LibraryScope] will be created based on [definingLibrary] and | 5050 * [LibraryScope] will be created based on [definingLibrary] and |
| 5045 * [typeProvider]. The [inheritanceManager] is used to perform inheritance | 5051 * [typeProvider]. The [inheritanceManager] is used to perform inheritance |
| 5046 * lookups. If `null` or unspecified, a new [InheritanceManager] will be | 5052 * lookups. If `null` or unspecified, a new [InheritanceManager] will be |
| 5047 * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to | 5053 * created based on [definingLibrary]. The [typeAnalyzerFactory] is used to |
| 5048 * create the type analyzer. If `null` or unspecified, a type analyzer of | 5054 * create the type analyzer. If `null` or unspecified, a type analyzer of |
| 5049 * type [StaticTypeAnalyzer] will be created. | 5055 * type [StaticTypeAnalyzer] will be created. |
| 5050 */ | 5056 */ |
| 5051 ResolverVisitor(LibraryElement definingLibrary, Source source, | 5057 ResolverVisitor(LibraryElement definingLibrary, Source source, |
| 5052 TypeProvider typeProvider, AnalysisErrorListener errorListener, | 5058 TypeProvider typeProvider, AnalysisErrorListener errorListener, |
| 5053 {Scope nameScope}) | 5059 {Scope nameScope, this.isTopLevelInference: false}) |
| 5054 : super(definingLibrary, source, typeProvider, errorListener, | 5060 : super(definingLibrary, source, typeProvider, errorListener, |
| 5055 nameScope: nameScope) { | 5061 nameScope: nameScope) { |
| 5056 AnalysisOptions options = definingLibrary.context.analysisOptions; | 5062 AnalysisOptions options = definingLibrary.context.analysisOptions; |
| 5057 this.strongMode = options.strongMode; | 5063 this.strongMode = options.strongMode; |
| 5058 this.elementResolver = new ElementResolver(this); | 5064 this.elementResolver = new ElementResolver(this); |
| 5059 this.typeSystem = definingLibrary.context.typeSystem; | 5065 this.typeSystem = definingLibrary.context.typeSystem; |
| 5060 bool strongModeHints = false; | 5066 bool strongModeHints = false; |
| 5061 if (options is AnalysisOptionsImpl) { | 5067 if (options is AnalysisOptionsImpl) { |
| 5062 strongModeHints = options.strongModeHints; | 5068 strongModeHints = options.strongModeHints; |
| 5063 } | 5069 } |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5543 } | 5549 } |
| 5544 rightOperand?.accept(this); | 5550 rightOperand?.accept(this); |
| 5545 } | 5551 } |
| 5546 node.accept(elementResolver); | 5552 node.accept(elementResolver); |
| 5547 node.accept(typeAnalyzer); | 5553 node.accept(typeAnalyzer); |
| 5548 return null; | 5554 return null; |
| 5549 } | 5555 } |
| 5550 | 5556 |
| 5551 @override | 5557 @override |
| 5552 Object visitBlockFunctionBody(BlockFunctionBody node) { | 5558 Object visitBlockFunctionBody(BlockFunctionBody node) { |
| 5559 bool wasTopLevelInference = isTopLevelInference; |
| 5560 isTopLevelInference = false; |
| 5553 _overrideManager.enterScope(); | 5561 _overrideManager.enterScope(); |
| 5554 try { | 5562 try { |
| 5555 inferenceContext.pushReturnContext(node); | 5563 inferenceContext.pushReturnContext(node); |
| 5556 super.visitBlockFunctionBody(node); | 5564 super.visitBlockFunctionBody(node); |
| 5557 } finally { | 5565 } finally { |
| 5566 isTopLevelInference = wasTopLevelInference; |
| 5558 _overrideManager.exitScope(); | 5567 _overrideManager.exitScope(); |
| 5559 inferenceContext.popReturnContext(node); | 5568 inferenceContext.popReturnContext(node); |
| 5560 } | 5569 } |
| 5561 return null; | 5570 return null; |
| 5562 } | 5571 } |
| 5563 | 5572 |
| 5564 @override | 5573 @override |
| 5565 Object visitBreakStatement(BreakStatement node) { | 5574 Object visitBreakStatement(BreakStatement node) { |
| 5566 // | 5575 // |
| 5567 // We do not visit the label because it needs to be visited in the context | 5576 // We do not visit the label because it needs to be visited in the context |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5866 InferenceContext.setTypeFromNode(node.expression, node); | 5875 InferenceContext.setTypeFromNode(node.expression, node); |
| 5867 super.visitExpressionFunctionBody(node); | 5876 super.visitExpressionFunctionBody(node); |
| 5868 } finally { | 5877 } finally { |
| 5869 _overrideManager.exitScope(); | 5878 _overrideManager.exitScope(); |
| 5870 } | 5879 } |
| 5871 return null; | 5880 return null; |
| 5872 } | 5881 } |
| 5873 | 5882 |
| 5874 @override | 5883 @override |
| 5875 Object visitFieldDeclaration(FieldDeclaration node) { | 5884 Object visitFieldDeclaration(FieldDeclaration node) { |
| 5885 bool wasTopLevelInference = isTopLevelInference; |
| 5886 isTopLevelInference = node.fields.type == null; |
| 5876 _overrideManager.enterScope(); | 5887 _overrideManager.enterScope(); |
| 5877 try { | 5888 try { |
| 5878 super.visitFieldDeclaration(node); | 5889 super.visitFieldDeclaration(node); |
| 5879 } finally { | 5890 } finally { |
| 5891 isTopLevelInference = wasTopLevelInference; |
| 5880 Map<VariableElement, DartType> overrides = | 5892 Map<VariableElement, DartType> overrides = |
| 5881 _overrideManager.captureOverrides(node.fields); | 5893 _overrideManager.captureOverrides(node.fields); |
| 5882 _overrideManager.exitScope(); | 5894 _overrideManager.exitScope(); |
| 5883 _overrideManager.applyOverrides(overrides); | 5895 _overrideManager.applyOverrides(overrides); |
| 5884 } | 5896 } |
| 5885 return null; | 5897 return null; |
| 5886 } | 5898 } |
| 5887 | 5899 |
| 5888 @override | 5900 @override |
| 5889 Object visitForEachStatement(ForEachStatement node) { | 5901 Object visitForEachStatement(ForEachStatement node) { |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6372 try { | 6384 try { |
| 6373 super.visitSwitchDefault(node); | 6385 super.visitSwitchDefault(node); |
| 6374 } finally { | 6386 } finally { |
| 6375 _overrideManager.exitScope(); | 6387 _overrideManager.exitScope(); |
| 6376 } | 6388 } |
| 6377 return null; | 6389 return null; |
| 6378 } | 6390 } |
| 6379 | 6391 |
| 6380 @override | 6392 @override |
| 6381 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | 6393 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 6394 bool wasTopLevelInference = isTopLevelInference; |
| 6395 isTopLevelInference = node.variables.type == null; |
| 6382 _overrideManager.enterScope(); | 6396 _overrideManager.enterScope(); |
| 6383 try { | 6397 try { |
| 6384 super.visitTopLevelVariableDeclaration(node); | 6398 super.visitTopLevelVariableDeclaration(node); |
| 6385 } finally { | 6399 } finally { |
| 6400 isTopLevelInference = wasTopLevelInference; |
| 6386 Map<VariableElement, DartType> overrides = | 6401 Map<VariableElement, DartType> overrides = |
| 6387 _overrideManager.captureOverrides(node.variables); | 6402 _overrideManager.captureOverrides(node.variables); |
| 6388 _overrideManager.exitScope(); | 6403 _overrideManager.exitScope(); |
| 6389 _overrideManager.applyOverrides(overrides); | 6404 _overrideManager.applyOverrides(overrides); |
| 6390 } | 6405 } |
| 6391 return null; | 6406 return null; |
| 6392 } | 6407 } |
| 6393 | 6408 |
| 6394 @override | 6409 @override |
| 6395 Object visitTypeName(TypeName node) => null; | 6410 Object visitTypeName(TypeName node) => null; |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6654 | 6669 |
| 6655 FunctionType _inferArgumentTypesForGeneric(AstNode inferenceNode, | 6670 FunctionType _inferArgumentTypesForGeneric(AstNode inferenceNode, |
| 6656 DartType uninstantiatedType, TypeArgumentList typeArguments, | 6671 DartType uninstantiatedType, TypeArgumentList typeArguments, |
| 6657 {AstNode errorNode}) { | 6672 {AstNode errorNode}) { |
| 6658 errorNode ??= inferenceNode; | 6673 errorNode ??= inferenceNode; |
| 6659 TypeSystem ts = typeSystem; | 6674 TypeSystem ts = typeSystem; |
| 6660 if (typeArguments == null && | 6675 if (typeArguments == null && |
| 6661 uninstantiatedType is FunctionType && | 6676 uninstantiatedType is FunctionType && |
| 6662 uninstantiatedType.typeFormals.isNotEmpty && | 6677 uninstantiatedType.typeFormals.isNotEmpty && |
| 6663 ts is StrongTypeSystemImpl) { | 6678 ts is StrongTypeSystemImpl) { |
| 6679 if (isTopLevelInference) { |
| 6680 if (uninstantiatedType.typeFormals.isNotEmpty) { |
| 6681 return null; |
| 6682 } |
| 6683 } |
| 6664 return ts.inferGenericFunctionOrType/*<FunctionType>*/( | 6684 return ts.inferGenericFunctionOrType/*<FunctionType>*/( |
| 6665 uninstantiatedType, | 6685 uninstantiatedType, |
| 6666 ParameterElement.EMPTY_LIST, | 6686 ParameterElement.EMPTY_LIST, |
| 6667 DartType.EMPTY_LIST, | 6687 DartType.EMPTY_LIST, |
| 6668 InferenceContext.getContext(inferenceNode), | 6688 InferenceContext.getContext(inferenceNode), |
| 6669 downwards: true, | 6689 downwards: true, |
| 6670 errorReporter: errorReporter, | 6690 errorReporter: errorReporter, |
| 6671 errorNode: errorNode); | 6691 errorNode: errorNode); |
| 6672 } | 6692 } |
| 6673 return null; | 6693 return null; |
| (...skipping 4222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10896 return null; | 10916 return null; |
| 10897 } | 10917 } |
| 10898 if (identical(node.staticElement, variable)) { | 10918 if (identical(node.staticElement, variable)) { |
| 10899 if (node.inSetterContext()) { | 10919 if (node.inSetterContext()) { |
| 10900 result = true; | 10920 result = true; |
| 10901 } | 10921 } |
| 10902 } | 10922 } |
| 10903 return null; | 10923 return null; |
| 10904 } | 10924 } |
| 10905 } | 10925 } |
| OLD | NEW |