Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1342903002: Fixes for the new task model (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 9548 matching lines...) Expand 10 before | Expand all | Expand 10 after
9559 9559
9560 /** 9560 /**
9561 * The static variables that have an initializer. These are the variables that 9561 * The static variables that have an initializer. These are the variables that
9562 * need to be re-resolved after static variables have their types inferred. A 9562 * need to be re-resolved after static variables have their types inferred. A
9563 * subset of these variables are those whose types should be inferred. The 9563 * subset of these variables are those whose types should be inferred. The
9564 * list will be empty unless the resolver is being run in strong mode. 9564 * list will be empty unless the resolver is being run in strong mode.
9565 */ 9565 */
9566 final List<VariableElement> staticVariables = <VariableElement>[]; 9566 final List<VariableElement> staticVariables = <VariableElement>[];
9567 9567
9568 /** 9568 /**
9569 * A flag indicating whether we are currently visiting a child of either a
9570 * field or a top-level variable.
9571 */
9572 bool inFieldOrTopLevelVariable = false;
9573
9574 /**
9575 * A flag indicating whether we should discard errors while resolving the 9569 * A flag indicating whether we should discard errors while resolving the
9576 * initializer for variable declarations. We do this for top-level variables 9570 * initializer for variable declarations. We do this for top-level variables
9577 * and fields because their initializer will be re-resolved at a later time. 9571 * and fields because their initializer will be re-resolved at a later time.
9578 */ 9572 */
9579 bool discardErrorsInInitializer = false; 9573 bool discardErrorsInInitializer = false;
9580 9574
9581 /** 9575 /**
9582 * Initialize a newly created visitor to resolve the nodes in an AST node. 9576 * Initialize a newly created visitor to resolve the nodes in an AST node.
9583 * 9577 *
9584 * The [definingLibrary] is the element for the library containing the node 9578 * The [definingLibrary] is the element for the library containing the node
(...skipping 14 matching lines...) Expand all
9599 TypeProvider typeProvider, AnalysisErrorListener errorListener, 9593 TypeProvider typeProvider, AnalysisErrorListener errorListener,
9600 {Scope nameScope, 9594 {Scope nameScope,
9601 InheritanceManager inheritanceManager, 9595 InheritanceManager inheritanceManager,
9602 StaticTypeAnalyzerFactory typeAnalyzerFactory}) 9596 StaticTypeAnalyzerFactory typeAnalyzerFactory})
9603 : strongMode = definingLibrary.context.analysisOptions.strongMode, 9597 : strongMode = definingLibrary.context.analysisOptions.strongMode,
9604 super(definingLibrary, source, typeProvider, 9598 super(definingLibrary, source, typeProvider,
9605 new DisablableErrorListener(errorListener)); 9599 new DisablableErrorListener(errorListener));
9606 9600
9607 @override 9601 @override
9608 Object visitBlockFunctionBody(BlockFunctionBody node) { 9602 Object visitBlockFunctionBody(BlockFunctionBody node) {
9609 if (inFieldOrTopLevelVariable) { 9603 if (_shouldBeSkipped(node)) {
9610 return super.visitBlockFunctionBody(node); 9604 return null;
9611 } 9605 }
9612 return null; 9606 return super.visitBlockFunctionBody(node);
9613 } 9607 }
9614 9608
9615 @override 9609 @override
9616 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { 9610 Object visitExpressionFunctionBody(ExpressionFunctionBody node) {
9617 if (inFieldOrTopLevelVariable) { 9611 if (_shouldBeSkipped(node)) {
9618 return super.visitExpressionFunctionBody(node); 9612 return null;
9619 } 9613 }
9620 return null; 9614 return super.visitExpressionFunctionBody(node);
9621 } 9615 }
9622 9616
9623 @override 9617 @override
9624 Object visitFieldDeclaration(FieldDeclaration node) { 9618 Object visitFieldDeclaration(FieldDeclaration node) {
9625 bool wasInFieldOrTopLevelVariable = inFieldOrTopLevelVariable; 9619 if (strongMode && node.isStatic) {
9626 try { 9620 _addStaticVariables(node.fields.variables);
9627 inFieldOrTopLevelVariable = true; 9621 bool wasDiscarding = discardErrorsInInitializer;
9628 if (strongMode && node.isStatic) { 9622 discardErrorsInInitializer = true;
9629 _addStaticVariables(node.fields.variables); 9623 try {
9630 bool wasDiscarding = discardErrorsInInitializer; 9624 return super.visitFieldDeclaration(node);
9631 discardErrorsInInitializer = true; 9625 } finally {
9632 try { 9626 discardErrorsInInitializer = wasDiscarding;
9633 return super.visitFieldDeclaration(node);
9634 } finally {
9635 discardErrorsInInitializer = wasDiscarding;
9636 }
9637 } 9627 }
9638 return super.visitFieldDeclaration(node);
9639 } finally {
9640 inFieldOrTopLevelVariable = wasInFieldOrTopLevelVariable;
9641 } 9628 }
9629 return super.visitFieldDeclaration(node);
9642 } 9630 }
9643 9631
9644 @override 9632 @override
9645 Object visitNode(AstNode node) { 9633 Object visitNode(AstNode node) {
9646 if (discardErrorsInInitializer) { 9634 if (discardErrorsInInitializer) {
9647 AstNode parent = node.parent; 9635 AstNode parent = node.parent;
9648 if (parent is VariableDeclaration && parent.initializer == node) { 9636 if (parent is VariableDeclaration && parent.initializer == node) {
9649 DisablableErrorListener listener = errorListener; 9637 DisablableErrorListener listener = errorListener;
9650 return listener.disableWhile(() => super.visitNode(node)); 9638 return listener.disableWhile(() => super.visitNode(node));
9651 } 9639 }
9652 } 9640 }
9653 return super.visitNode(node); 9641 return super.visitNode(node);
9654 } 9642 }
9655 9643
9656 @override 9644 @override
9657 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 9645 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
9658 bool wasInFieldOrTopLevelVariable = inFieldOrTopLevelVariable; 9646 if (strongMode) {
9659 try { 9647 _addStaticVariables(node.variables.variables);
9660 inFieldOrTopLevelVariable = true; 9648 bool wasDiscarding = discardErrorsInInitializer;
9661 if (strongMode) { 9649 discardErrorsInInitializer = true;
9662 _addStaticVariables(node.variables.variables); 9650 try {
9663 bool wasDiscarding = discardErrorsInInitializer; 9651 return super.visitTopLevelVariableDeclaration(node);
9664 discardErrorsInInitializer = true; 9652 } finally {
9665 try { 9653 discardErrorsInInitializer = wasDiscarding;
9666 return super.visitTopLevelVariableDeclaration(node);
9667 } finally {
9668 discardErrorsInInitializer = wasDiscarding;
9669 }
9670 } 9654 }
9671 return super.visitTopLevelVariableDeclaration(node);
9672 } finally {
9673 inFieldOrTopLevelVariable = wasInFieldOrTopLevelVariable;
9674 } 9655 }
9656 return super.visitTopLevelVariableDeclaration(node);
9675 } 9657 }
9676 9658
9677 /** 9659 /**
9678 * Add all of the [variables] with initializers to the list of variables whose 9660 * Add all of the [variables] with initializers to the list of variables whose
9679 * type can be inferred. Technically, we only infer the types of variables 9661 * type can be inferred. Technically, we only infer the types of variables
9680 * that do not have a static type, but all variables with initializers 9662 * that do not have a static type, but all variables with initializers
9681 * potentially need to be re-resolved after inference because they might 9663 * potentially need to be re-resolved after inference because they might
9682 * refer to a field whose type was inferred. 9664 * refer to a field whose type was inferred.
9683 */ 9665 */
9684 void _addStaticVariables(NodeList<VariableDeclaration> variables) { 9666 void _addStaticVariables(NodeList<VariableDeclaration> variables) {
9685 for (VariableDeclaration variable in variables) { 9667 for (VariableDeclaration variable in variables) {
9686 if (variable.initializer != null) { 9668 if (variable.initializer != null) {
9687 staticVariables.add(variable.element); 9669 staticVariables.add(variable.element);
9688 } 9670 }
9689 } 9671 }
9690 } 9672 }
9673
9674 /**
9675 * Return `true` if the given function body should be skipped because it is
9676 * the body of a top-level function, method or constructor.
9677 */
9678 bool _shouldBeSkipped(FunctionBody body) {
9679 AstNode parent = body.parent;
9680 if (parent is MethodDeclaration) {
9681 return parent.body == body;
9682 }
9683 if (parent is ConstructorDeclaration) {
9684 return parent.body == body;
9685 }
9686 if (parent is FunctionExpression) {
9687 AstNode parent2 = parent.parent;
9688 if (parent2 is FunctionDeclaration &&
9689 parent2.parent is! FunctionDeclarationStatement) {
9690 return parent.body == body;
9691 }
9692 }
9693 return false;
9694 }
9691 } 9695 }
9692 9696
9693 /** 9697 /**
9694 * Instances of the class `PubVerifier` traverse an AST structure looking for de viations from 9698 * Instances of the class `PubVerifier` traverse an AST structure looking for de viations from
9695 * pub best practices. 9699 * pub best practices.
9696 */ 9700 */
9697 class PubVerifier extends RecursiveAstVisitor<Object> { 9701 class PubVerifier extends RecursiveAstVisitor<Object> {
9698 // static String _PUBSPEC_YAML = "pubspec.yaml"; 9702 // static String _PUBSPEC_YAML = "pubspec.yaml";
9699 9703
9700 /** 9704 /**
(...skipping 5861 matching lines...) Expand 10 before | Expand all | Expand 10 after
15562 nonFields.add(node); 15566 nonFields.add(node);
15563 return null; 15567 return null;
15564 } 15568 }
15565 15569
15566 @override 15570 @override
15567 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 15571 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
15568 15572
15569 @override 15573 @override
15570 Object visitWithClause(WithClause node) => null; 15574 Object visitWithClause(WithClause node) => null;
15571 } 15575 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698