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/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 9377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9388 everything, | 9388 everything, |
9389 | 9389 |
9390 /** | 9390 /** |
9391 * Resolve only type names outside of function bodies, variable initializers, | 9391 * Resolve only type names outside of function bodies, variable initializers, |
9392 * and parameter default values. | 9392 * and parameter default values. |
9393 */ | 9393 */ |
9394 api, | 9394 api, |
9395 | 9395 |
9396 /** | 9396 /** |
9397 * Resolve only type names that would be skipped during [api]. | 9397 * Resolve only type names that would be skipped during [api]. |
9398 * | |
9399 * Resolution must start from a unit member or a class member. For example | |
9400 * it is not allowed to resolve types in a separate statement, or a function | |
9401 * body. | |
9398 */ | 9402 */ |
9399 local | 9403 local |
9400 } | 9404 } |
9401 | 9405 |
9402 /** | 9406 /** |
9403 * Instances of the class `TypeResolverVisitor` are used to resolve the types as sociated with | 9407 * Instances of the class `TypeResolverVisitor` are used to resolve the types as sociated with |
9404 * the elements in the element model. This includes the types of superclasses, m ixins, interfaces, | 9408 * the elements in the element model. This includes the types of superclasses, m ixins, interfaces, |
9405 * fields, methods, parameters, and local variables. As a side-effect, this also finishes building | 9409 * fields, methods, parameters, and local variables. As a side-effect, this also finishes building |
9406 * the type hierarchy. | 9410 * the type hierarchy. |
9407 */ | 9411 */ |
(...skipping 23 matching lines...) Expand all Loading... | |
9431 */ | 9435 */ |
9432 TypeSystem _typeSystem; | 9436 TypeSystem _typeSystem; |
9433 | 9437 |
9434 /** | 9438 /** |
9435 * The helper to resolve [TypeName]s. | 9439 * The helper to resolve [TypeName]s. |
9436 */ | 9440 */ |
9437 TypeNameResolver _typeNameResolver; | 9441 TypeNameResolver _typeNameResolver; |
9438 | 9442 |
9439 final TypeResolverMode mode; | 9443 final TypeResolverMode mode; |
9440 | 9444 |
9441 bool _visitAllInLocalMode = false; | 9445 /** |
9446 * Is `true` when we are visiting all nodes in [TypeResolverMode.local] mode. | |
9447 */ | |
9448 bool _localModeVisitAll = false; | |
9449 | |
9450 /** | |
9451 * Is `true` is we are in [TypeResolverMode.local] mode, and the initial | |
Brian Wilkerson
2016/10/19 21:00:36
"is we" --> "if we"
| |
9452 * [nameScope] was computed. | |
9453 */ | |
9454 bool _localModeScopeReady = false; | |
9442 | 9455 |
9443 /** | 9456 /** |
9444 * Initialize a newly created visitor to resolve the nodes in an AST node. | 9457 * Initialize a newly created visitor to resolve the nodes in an AST node. |
9445 * | 9458 * |
9446 * [definingLibrary] is the element for the library containing the node being | 9459 * [definingLibrary] is the element for the library containing the node being |
9447 * visited. | 9460 * visited. |
9448 * [source] is the source representing the compilation unit containing the | 9461 * [source] is the source representing the compilation unit containing the |
9449 * node being visited. | 9462 * node being visited. |
9450 * [typeProvider] is the object used to access the types from the core | 9463 * [typeProvider] is the object used to access the types from the core |
9451 * library. | 9464 * library. |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9787 | 9800 |
9788 // In local mode we need to resolve only: | 9801 // In local mode we need to resolve only: |
9789 // - function bodies; | 9802 // - function bodies; |
9790 // - default values of parameters; | 9803 // - default values of parameters; |
9791 // - initializers of top-level variables. | 9804 // - initializers of top-level variables. |
9792 // So, we carefully visit only nodes that are, or contain, these nodes. | 9805 // So, we carefully visit only nodes that are, or contain, these nodes. |
9793 // The client may choose to start visiting any node, but we still want to | 9806 // The client may choose to start visiting any node, but we still want to |
9794 // resolve only type names that are local. | 9807 // resolve only type names that are local. |
9795 if (mode == TypeResolverMode.local) { | 9808 if (mode == TypeResolverMode.local) { |
9796 // We are in the state of visiting all nodes. | 9809 // We are in the state of visiting all nodes. |
9797 if (_visitAllInLocalMode) { | 9810 if (_localModeVisitAll) { |
9798 return super.visitNode(node); | 9811 return super.visitNode(node); |
9799 } | 9812 } |
9800 | 9813 |
9814 // Ensure that the name scope is ready. | |
9815 if (!_localModeScopeReady) { | |
9816 void fillNameScope(AstNode node) { | |
9817 if (node is FunctionBody || | |
9818 node is FormalParameterList || | |
9819 node is VariableDeclaration) { | |
9820 throw new StateError( | |
9821 'Local type resolution must start from a class or unit member.') ; | |
9822 } | |
9823 // Create enclosing name scopes. | |
9824 AstNode parent = node.parent; | |
9825 if (parent != null) { | |
9826 fillNameScope(parent); | |
9827 } | |
9828 // Create the name scope for the node. | |
9829 if (node is ClassDeclaration) { | |
9830 ClassElement classElement = node.element; | |
9831 nameScope = new TypeParameterScope(nameScope, classElement); | |
9832 nameScope = new ClassScope(nameScope, classElement); | |
9833 } | |
9834 } | |
9835 | |
9836 fillNameScope(node); | |
9837 _localModeScopeReady = true; | |
9838 } | |
9839 | |
9801 /** | 9840 /** |
9802 * Visit the given [node] and all its children. | 9841 * Visit the given [node] and all its children. |
9803 */ | 9842 */ |
9804 void visitAllNodes(AstNode node) { | 9843 void visitAllNodes(AstNode node) { |
9805 if (node != null) { | 9844 if (node != null) { |
9806 bool wasVisitAllInLocalMode = _visitAllInLocalMode; | 9845 bool wasVisitAllInLocalMode = _localModeVisitAll; |
9807 try { | 9846 try { |
9808 _visitAllInLocalMode = true; | 9847 _localModeVisitAll = true; |
9809 node.accept(this); | 9848 node.accept(this); |
9810 } finally { | 9849 } finally { |
9811 _visitAllInLocalMode = wasVisitAllInLocalMode; | 9850 _localModeVisitAll = wasVisitAllInLocalMode; |
9812 } | 9851 } |
9813 } | 9852 } |
9814 } | 9853 } |
9815 | 9854 |
9816 // Visit only nodes that may contain type names to resolve. | 9855 // Visit only nodes that may contain type names to resolve. |
9817 if (node is CompilationUnit) { | 9856 if (node is CompilationUnit) { |
9818 node.declarations.forEach(visitNode); | 9857 node.declarations.forEach(visitNode); |
9819 } else if (node is ClassDeclaration) { | 9858 } else if (node is ClassDeclaration) { |
9820 node.members.forEach(visitNode); | 9859 node.members.forEach(visitNode); |
9821 } else if (node is DefaultFormalParameter) { | 9860 } else if (node is DefaultFormalParameter) { |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10681 return null; | 10720 return null; |
10682 } | 10721 } |
10683 if (identical(node.staticElement, variable)) { | 10722 if (identical(node.staticElement, variable)) { |
10684 if (node.inSetterContext()) { | 10723 if (node.inSetterContext()) { |
10685 result = true; | 10724 result = true; |
10686 } | 10725 } |
10687 } | 10726 } |
10688 return null; | 10727 return null; |
10689 } | 10728 } |
10690 } | 10729 } |
OLD | NEW |