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

Side by Side Diff: pkg/analyzer/lib/src/dart/ast/ast.dart

Issue 1700263002: Add data structures to AST to indicate potentially mutated variables. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Follow Brian's suggestion Created 4 years, 10 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 | « pkg/analyzer/lib/dart/ast/ast.dart ('k') | pkg/analyzer/lib/src/generated/resolver.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 analyzer.src.dart.ast.ast; 5 library analyzer.src.dart.ast.ast;
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 4704 matching lines...) Expand 10 before | Expand all | Expand 10 after
4715 /** 4715 /**
4716 * A node representing the body of a function or method. 4716 * A node representing the body of a function or method.
4717 * 4717 *
4718 * > functionBody ::= 4718 * > functionBody ::=
4719 * > [BlockFunctionBody] 4719 * > [BlockFunctionBody]
4720 * > | [EmptyFunctionBody] 4720 * > | [EmptyFunctionBody]
4721 * > | [ExpressionFunctionBody] 4721 * > | [ExpressionFunctionBody]
4722 */ 4722 */
4723 abstract class FunctionBodyImpl extends AstNodeImpl implements FunctionBody { 4723 abstract class FunctionBodyImpl extends AstNodeImpl implements FunctionBody {
4724 /** 4724 /**
4725 * Additional information about local variables and parameters that are
4726 * declared within this function body or any enclosing function body. `null`
4727 * if resolution has not yet been performed.
4728 */
4729 LocalVariableInfo localVariableInfo;
4730
4731 /**
4725 * Return `true` if this function body is asynchronous. 4732 * Return `true` if this function body is asynchronous.
4726 */ 4733 */
4727 bool get isAsynchronous => false; 4734 bool get isAsynchronous => false;
4728 4735
4729 /** 4736 /**
4730 * Return `true` if this function body is a generator. 4737 * Return `true` if this function body is a generator.
4731 */ 4738 */
4732 bool get isGenerator => false; 4739 bool get isGenerator => false;
4733 4740
4734 /** 4741 /**
4735 * Return `true` if this function body is synchronous. 4742 * Return `true` if this function body is synchronous.
4736 */ 4743 */
4737 bool get isSynchronous => true; 4744 bool get isSynchronous => true;
4738 4745
4739 /** 4746 /**
4740 * Return the token representing the 'async' or 'sync' keyword, or `null` if 4747 * Return the token representing the 'async' or 'sync' keyword, or `null` if
4741 * there is no such keyword. 4748 * there is no such keyword.
4742 */ 4749 */
4743 Token get keyword => null; 4750 Token get keyword => null;
4744 4751
4745 /** 4752 /**
4746 * Return the star following the 'async' or 'sync' keyword, or `null` if there 4753 * Return the star following the 'async' or 'sync' keyword, or `null` if there
4747 * is no star. 4754 * is no star.
4748 */ 4755 */
4749 Token get star => null; 4756 Token get star => null;
4757
4758 @override
4759 bool isPotentiallyMutatedInClosure(VariableElement variable) {
4760 if (localVariableInfo == null) {
4761 throw new StateError('Resolution has not yet been performed');
4762 }
4763 return localVariableInfo.potentiallyMutatedInClosure.contains(variable);
4764 }
4765
4766 @override
4767 bool isPotentiallyMutatedInScope(VariableElement variable) {
4768 if (localVariableInfo == null) {
4769 throw new StateError('Resolution has not yet been performed');
4770 }
4771 return localVariableInfo.potentiallyMutatedInScope.contains(variable);
4772 }
4750 } 4773 }
4751 4774
4752 /** 4775 /**
4753 * A top-level declaration. 4776 * A top-level declaration.
4754 * 4777 *
4755 * > functionDeclaration ::= 4778 * > functionDeclaration ::=
4756 * > 'external' functionSignature 4779 * > 'external' functionSignature
4757 * > | functionSignature [FunctionBody] 4780 * > | functionSignature [FunctionBody]
4758 * > 4781 * >
4759 * > functionSignature ::= 4782 * > functionSignature ::=
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after
6550 * > | [MapLiteral] 6573 * > | [MapLiteral]
6551 * > | [NullLiteral] 6574 * > | [NullLiteral]
6552 * > | [StringLiteral] 6575 * > | [StringLiteral]
6553 */ 6576 */
6554 abstract class LiteralImpl extends ExpressionImpl implements Literal { 6577 abstract class LiteralImpl extends ExpressionImpl implements Literal {
6555 @override 6578 @override
6556 int get precedence => 16; 6579 int get precedence => 16;
6557 } 6580 }
6558 6581
6559 /** 6582 /**
6583 * Additional information about local variables within a function or method
6584 * produced at resolution time.
6585 */
6586 class LocalVariableInfo {
6587 /**
6588 * The set of local variables and parameters that are potentially mutated
6589 * within a local function other than the function in which they are declared.
6590 */
6591 final Set<VariableElement> potentiallyMutatedInClosure =
6592 new Set<VariableElement>();
6593
6594 /**
6595 * The set of local variables and parameters that are potentiall mutated
6596 * within the scope of their declarations.
6597 */
6598 final Set<VariableElement> potentiallyMutatedInScope =
6599 new Set<VariableElement>();
6600 }
6601
6602 /**
6560 * A single key/value pair in a map literal. 6603 * A single key/value pair in a map literal.
6561 * 6604 *
6562 * > mapLiteralEntry ::= 6605 * > mapLiteralEntry ::=
6563 * > [Expression] ':' [Expression] 6606 * > [Expression] ':' [Expression]
6564 */ 6607 */
6565 class MapLiteralEntryImpl extends AstNodeImpl implements MapLiteralEntry { 6608 class MapLiteralEntryImpl extends AstNodeImpl implements MapLiteralEntry {
6566 /** 6609 /**
6567 * The expression computing the key with which the value will be associated. 6610 * The expression computing the key with which the value will be associated.
6568 */ 6611 */
6569 Expression _key; 6612 Expression _key;
(...skipping 4235 matching lines...) Expand 10 before | Expand all | Expand 10 after
10805 } 10848 }
10806 10849
10807 @override 10850 @override
10808 accept(AstVisitor visitor) => visitor.visitYieldStatement(this); 10851 accept(AstVisitor visitor) => visitor.visitYieldStatement(this);
10809 10852
10810 @override 10853 @override
10811 void visitChildren(AstVisitor visitor) { 10854 void visitChildren(AstVisitor visitor) {
10812 _safelyVisitChild(_expression, visitor); 10855 _safelyVisitChild(_expression, visitor);
10813 } 10856 }
10814 } 10857 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/dart/ast/ast.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698