| 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 engine.resolver; | 5 library engine.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'ast.dart'; | 9 import 'ast.dart'; |
| 10 import 'constant.dart'; | 10 import 'constant.dart'; |
| (...skipping 9595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9606 * compilation unit. The nodes that are skipped are those that are within | 9606 * compilation unit. The nodes that are skipped are those that are within |
| 9607 * function bodies. | 9607 * function bodies. |
| 9608 */ | 9608 */ |
| 9609 class PartialResolverVisitor extends ResolverVisitor { | 9609 class PartialResolverVisitor extends ResolverVisitor { |
| 9610 /** | 9610 /** |
| 9611 * A flag indicating whether the resolver is being run in strong mode. | 9611 * A flag indicating whether the resolver is being run in strong mode. |
| 9612 */ | 9612 */ |
| 9613 final bool strongMode; | 9613 final bool strongMode; |
| 9614 | 9614 |
| 9615 /** | 9615 /** |
| 9616 * The static variables that have an initializer. These are the variables that | 9616 * The static variables and fields that have an initializer. These are the |
| 9617 * need to be re-resolved after static variables have their types inferred. A | 9617 * variables that need to be re-resolved after static variables have their |
| 9618 * subset of these variables are those whose types should be inferred. The | 9618 * types inferred. A subset of these variables are those whose types should |
| 9619 * list will be empty unless the resolver is being run in strong mode. | 9619 * be inferred. The list will be empty unless the resolver is being run in |
| 9620 * strong mode. |
| 9620 */ | 9621 */ |
| 9621 final List<VariableElement> staticVariables = <VariableElement>[]; | 9622 final List<VariableElement> variablesAndFields = <VariableElement>[]; |
| 9622 | 9623 |
| 9623 /** | 9624 /** |
| 9624 * A flag indicating whether we should discard errors while resolving the | 9625 * A flag indicating whether we should discard errors while resolving the |
| 9625 * initializer for variable declarations. We do this for top-level variables | 9626 * initializer for variable declarations. We do this for top-level variables |
| 9626 * and fields because their initializer will be re-resolved at a later time. | 9627 * and fields because their initializer will be re-resolved at a later time. |
| 9627 */ | 9628 */ |
| 9628 bool discardErrorsInInitializer = false; | 9629 bool discardErrorsInInitializer = false; |
| 9629 | 9630 |
| 9630 /** | 9631 /** |
| 9631 * Initialize a newly created visitor to resolve the nodes in an AST node. | 9632 * Initialize a newly created visitor to resolve the nodes in an AST node. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9664 @override | 9665 @override |
| 9665 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { | 9666 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { |
| 9666 if (_shouldBeSkipped(node)) { | 9667 if (_shouldBeSkipped(node)) { |
| 9667 return null; | 9668 return null; |
| 9668 } | 9669 } |
| 9669 return super.visitExpressionFunctionBody(node); | 9670 return super.visitExpressionFunctionBody(node); |
| 9670 } | 9671 } |
| 9671 | 9672 |
| 9672 @override | 9673 @override |
| 9673 Object visitFieldDeclaration(FieldDeclaration node) { | 9674 Object visitFieldDeclaration(FieldDeclaration node) { |
| 9674 if (strongMode && node.isStatic) { | 9675 if (strongMode) { |
| 9675 _addStaticVariables(node.fields.variables); | 9676 _addVariables(node.fields.variables); |
| 9676 bool wasDiscarding = discardErrorsInInitializer; | 9677 bool wasDiscarding = discardErrorsInInitializer; |
| 9677 discardErrorsInInitializer = true; | 9678 discardErrorsInInitializer = true; |
| 9678 try { | 9679 try { |
| 9679 return super.visitFieldDeclaration(node); | 9680 return super.visitFieldDeclaration(node); |
| 9680 } finally { | 9681 } finally { |
| 9681 discardErrorsInInitializer = wasDiscarding; | 9682 discardErrorsInInitializer = wasDiscarding; |
| 9682 } | 9683 } |
| 9683 } | 9684 } |
| 9684 return super.visitFieldDeclaration(node); | 9685 return super.visitFieldDeclaration(node); |
| 9685 } | 9686 } |
| 9686 | 9687 |
| 9687 @override | 9688 @override |
| 9688 Object visitNode(AstNode node) { | 9689 Object visitNode(AstNode node) { |
| 9689 if (discardErrorsInInitializer) { | 9690 if (discardErrorsInInitializer) { |
| 9690 AstNode parent = node.parent; | 9691 AstNode parent = node.parent; |
| 9691 if (parent is VariableDeclaration && parent.initializer == node) { | 9692 if (parent is VariableDeclaration && parent.initializer == node) { |
| 9692 DisablableErrorListener listener = errorListener; | 9693 DisablableErrorListener listener = errorListener; |
| 9693 return listener.disableWhile(() => super.visitNode(node)); | 9694 return listener.disableWhile(() => super.visitNode(node)); |
| 9694 } | 9695 } |
| 9695 } | 9696 } |
| 9696 return super.visitNode(node); | 9697 return super.visitNode(node); |
| 9697 } | 9698 } |
| 9698 | 9699 |
| 9699 @override | 9700 @override |
| 9700 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | 9701 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 9701 if (strongMode) { | 9702 if (strongMode) { |
| 9702 _addStaticVariables(node.variables.variables); | 9703 _addVariables(node.variables.variables); |
| 9703 bool wasDiscarding = discardErrorsInInitializer; | 9704 bool wasDiscarding = discardErrorsInInitializer; |
| 9704 discardErrorsInInitializer = true; | 9705 discardErrorsInInitializer = true; |
| 9705 try { | 9706 try { |
| 9706 return super.visitTopLevelVariableDeclaration(node); | 9707 return super.visitTopLevelVariableDeclaration(node); |
| 9707 } finally { | 9708 } finally { |
| 9708 discardErrorsInInitializer = wasDiscarding; | 9709 discardErrorsInInitializer = wasDiscarding; |
| 9709 } | 9710 } |
| 9710 } | 9711 } |
| 9711 return super.visitTopLevelVariableDeclaration(node); | 9712 return super.visitTopLevelVariableDeclaration(node); |
| 9712 } | 9713 } |
| 9713 | 9714 |
| 9714 /** | 9715 /** |
| 9715 * Add all of the [variables] with initializers to the list of variables whose | 9716 * Add all of the [variables] with initializers to the list of variables whose |
| 9716 * type can be inferred. Technically, we only infer the types of variables | 9717 * type can be inferred. Technically, we only infer the types of variables |
| 9717 * that do not have a static type, but all variables with initializers | 9718 * that do not have a static type, but all variables with initializers |
| 9718 * potentially need to be re-resolved after inference because they might | 9719 * potentially need to be re-resolved after inference because they might |
| 9719 * refer to a field whose type was inferred. | 9720 * refer to a field whose type was inferred. |
| 9720 */ | 9721 */ |
| 9721 void _addStaticVariables(NodeList<VariableDeclaration> variables) { | 9722 void _addVariables(NodeList<VariableDeclaration> variables) { |
| 9722 for (VariableDeclaration variable in variables) { | 9723 for (VariableDeclaration variable in variables) { |
| 9723 if (variable.initializer != null) { | 9724 if (variable.initializer != null) { |
| 9724 staticVariables.add(variable.element); | 9725 variablesAndFields.add(variable.element); |
| 9725 } | 9726 } |
| 9726 } | 9727 } |
| 9727 } | 9728 } |
| 9728 | 9729 |
| 9729 /** | 9730 /** |
| 9730 * Return `true` if the given function body should be skipped because it is | 9731 * Return `true` if the given function body should be skipped because it is |
| 9731 * the body of a top-level function, method or constructor. | 9732 * the body of a top-level function, method or constructor. |
| 9732 */ | 9733 */ |
| 9733 bool _shouldBeSkipped(FunctionBody body) { | 9734 bool _shouldBeSkipped(FunctionBody body) { |
| 9734 AstNode parent = body.parent; | 9735 AstNode parent = body.parent; |
| (...skipping 6212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15947 nonFields.add(node); | 15948 nonFields.add(node); |
| 15948 return null; | 15949 return null; |
| 15949 } | 15950 } |
| 15950 | 15951 |
| 15951 @override | 15952 @override |
| 15952 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15953 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15953 | 15954 |
| 15954 @override | 15955 @override |
| 15955 Object visitWithClause(WithClause node) => null; | 15956 Object visitWithClause(WithClause node) => null; |
| 15956 } | 15957 } |
| OLD | NEW |