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

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

Issue 2966313002: Remove ExecutableElement.localVariables altogether. (Closed)
Patch Set: Created 3 years, 5 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
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.element.element; 5 library analyzer.src.dart.element.element;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show min; 8 import 'dart:math' show min;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 2984 matching lines...) Expand 10 before | Expand all | Expand 10 after
2995 @override 2995 @override
2996 AstNode computeNode() => getNodeMatching((node) => node is AstNode); 2996 AstNode computeNode() => getNodeMatching((node) => node is AstNode);
2997 2997
2998 /** 2998 /**
2999 * Set this element as the enclosing element for given [element]. 2999 * Set this element as the enclosing element for given [element].
3000 */ 3000 */
3001 void encloseElement(ElementImpl element) { 3001 void encloseElement(ElementImpl element) {
3002 element.enclosingElement = this; 3002 element.enclosingElement = this;
3003 } 3003 }
3004 3004
3005 /**
3006 * Set this element as the enclosing element for given [elements].
3007 */
3008 void encloseElements(List<Element> elements) {
3009 for (Element element in elements) {
3010 (element as ElementImpl)._enclosingElement = this;
3011 }
3012 }
3013
3005 @override 3014 @override
3006 E getAncestor<E extends Element>(Predicate<Element> predicate) { 3015 E getAncestor<E extends Element>(Predicate<Element> predicate) {
3007 Element ancestor = _enclosingElement; 3016 Element ancestor = _enclosingElement;
3008 while (ancestor != null && !predicate(ancestor)) { 3017 while (ancestor != null && !predicate(ancestor)) {
3009 ancestor = ancestor.enclosingElement; 3018 ancestor = ancestor.enclosingElement;
3010 } 3019 }
3011 return ancestor as E; 3020 return ancestor as E;
3012 } 3021 }
3013 3022
3014 /** 3023 /**
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
3557 * element. 3566 * element.
3558 */ 3567 */
3559 List<FunctionElement> _functions; 3568 List<FunctionElement> _functions;
3560 3569
3561 /** 3570 /**
3562 * A list containing all of the labels defined within this executable element. 3571 * A list containing all of the labels defined within this executable element.
3563 */ 3572 */
3564 List<LabelElement> _labels; 3573 List<LabelElement> _labels;
3565 3574
3566 /** 3575 /**
3567 * A list containing all of the local variables defined within this executable
3568 * element.
3569 */
3570 List<LocalVariableElement> _localVariables;
3571
3572 /**
3573 * A list containing all of the parameters defined by this executable element. 3576 * A list containing all of the parameters defined by this executable element.
3574 */ 3577 */
3575 List<ParameterElement> _parameters; 3578 List<ParameterElement> _parameters;
3576 3579
3577 /** 3580 /**
3578 * The declared return type of this executable element. 3581 * The declared return type of this executable element.
3579 */ 3582 */
3580 DartType _declaredReturnType; 3583 DartType _declaredReturnType;
3581 3584
3582 /** 3585 /**
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
3763 */ 3766 */
3764 void set labels(List<LabelElement> labels) { 3767 void set labels(List<LabelElement> labels) {
3765 _assertNotResynthesized(serializedExecutable); 3768 _assertNotResynthesized(serializedExecutable);
3766 for (LabelElement label in labels) { 3769 for (LabelElement label in labels) {
3767 (label as LabelElementImpl).enclosingElement = this; 3770 (label as LabelElementImpl).enclosingElement = this;
3768 } 3771 }
3769 this._labels = labels; 3772 this._labels = labels;
3770 } 3773 }
3771 3774
3772 @override 3775 @override
3773 List<LocalVariableElement> get localVariables {
3774 if (serializedExecutable != null && _localVariables == null) {
3775 List<UnlinkedVariable> unlinkedVariables =
3776 serializedExecutable.localVariables;
3777 int length = unlinkedVariables.length;
3778 if (length != 0) {
3779 List<LocalVariableElementImpl> localVariables =
3780 new List<LocalVariableElementImpl>(length);
3781 for (int i = 0; i < length; i++) {
3782 localVariables[i] = new LocalVariableElementImpl.forSerializedFactory(
3783 unlinkedVariables[i], this);
3784 }
3785 _localVariables = localVariables;
3786 } else {
3787 _localVariables = const <LocalVariableElement>[];
3788 }
3789 }
3790 return _localVariables ?? const <LocalVariableElement>[];
3791 }
3792
3793 /**
3794 * Set the local variables defined within this executable element to the given
3795 * [variables].
3796 */
3797 void set localVariables(List<LocalVariableElement> variables) {
3798 _assertNotResynthesized(serializedExecutable);
3799 for (LocalVariableElement variable in variables) {
3800 (variable as LocalVariableElementImpl).enclosingElement = this;
3801 }
3802 this._localVariables = variables;
3803 }
3804
3805 @override
3806 List<ElementAnnotation> get metadata { 3776 List<ElementAnnotation> get metadata {
3807 if (serializedExecutable != null) { 3777 if (serializedExecutable != null) {
3808 return _metadata ??= 3778 return _metadata ??=
3809 _buildAnnotations(enclosingUnit, serializedExecutable.annotations); 3779 _buildAnnotations(enclosingUnit, serializedExecutable.annotations);
3810 } 3780 }
3811 return super.metadata; 3781 return super.metadata;
3812 } 3782 }
3813 3783
3814 @override 3784 @override
3815 String get name { 3785 String get name {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
3960 if (functionImpl.identifier == identifier) { 3930 if (functionImpl.identifier == identifier) {
3961 return functionImpl; 3931 return functionImpl;
3962 } 3932 }
3963 } 3933 }
3964 for (LabelElement label in _labels) { 3934 for (LabelElement label in _labels) {
3965 LabelElementImpl labelImpl = label; 3935 LabelElementImpl labelImpl = label;
3966 if (labelImpl.identifier == identifier) { 3936 if (labelImpl.identifier == identifier) {
3967 return labelImpl; 3937 return labelImpl;
3968 } 3938 }
3969 } 3939 }
3970 for (LocalVariableElement variable in _localVariables) {
3971 LocalVariableElementImpl variableImpl = variable;
3972 if (variableImpl.identifier == identifier) {
3973 return variableImpl;
3974 }
3975 }
3976 for (ParameterElement parameter in parameters) { 3940 for (ParameterElement parameter in parameters) {
3977 ParameterElementImpl parameterImpl = parameter; 3941 ParameterElementImpl parameterImpl = parameter;
3978 if (parameterImpl.identifier == identifier) { 3942 if (parameterImpl.identifier == identifier) {
3979 return parameterImpl; 3943 return parameterImpl;
3980 } 3944 }
3981 } 3945 }
3982 return null; 3946 return null;
3983 } 3947 }
3984 3948
3985 @override 3949 @override
3986 void visitChildren(ElementVisitor visitor) { 3950 void visitChildren(ElementVisitor visitor) {
3987 super.visitChildren(visitor); 3951 super.visitChildren(visitor);
3988 _safelyVisitPossibleChild(returnType, visitor); 3952 _safelyVisitPossibleChild(returnType, visitor);
3989 safelyVisitChildren(typeParameters, visitor); 3953 safelyVisitChildren(typeParameters, visitor);
3990 safelyVisitChildren(parameters, visitor); 3954 safelyVisitChildren(parameters, visitor);
3991 safelyVisitChildren(functions, visitor); 3955 safelyVisitChildren(functions, visitor);
3992 safelyVisitChildren(labels, visitor); 3956 safelyVisitChildren(labels, visitor);
3993 safelyVisitChildren(localVariables, visitor);
3994 } 3957 }
3995 } 3958 }
3996 3959
3997 /** 3960 /**
3998 * A concrete implementation of an [ExportElement]. 3961 * A concrete implementation of an [ExportElement].
3999 */ 3962 */
4000 class ExportElementImpl extends UriReferencedElementImpl 3963 class ExportElementImpl extends UriReferencedElementImpl
4001 implements ExportElement { 3964 implements ExportElement {
4002 /** 3965 /**
4003 * The unlinked representation of the export in the summary. 3966 * The unlinked representation of the export in the summary.
(...skipping 2443 matching lines...) Expand 10 before | Expand all | Expand 10 after
6447 return new ConstLocalVariableElementImpl.forSerialized( 6410 return new ConstLocalVariableElementImpl.forSerialized(
6448 unlinkedVariable, enclosingExecutable); 6411 unlinkedVariable, enclosingExecutable);
6449 } else { 6412 } else {
6450 return new LocalVariableElementImpl.forSerialized( 6413 return new LocalVariableElementImpl.forSerialized(
6451 unlinkedVariable, enclosingExecutable); 6414 unlinkedVariable, enclosingExecutable);
6452 } 6415 }
6453 } 6416 }
6454 6417
6455 @override 6418 @override
6456 String get identifier { 6419 String get identifier {
6457 String identifier = super.identifier; 6420 return '$name$nameOffset';
6458 Element enclosing = this.enclosingElement;
6459 if (enclosing is ExecutableElement) {
6460 int id = ElementImpl.findElementIndexUsingIdentical(
6461 enclosing.localVariables, this);
6462 identifier += "@$id";
6463 }
6464 return identifier;
6465 } 6421 }
6466 6422
6467 @override 6423 @override
6468 bool get isPotentiallyMutatedInClosure => true; 6424 bool get isPotentiallyMutatedInClosure => true;
6469 6425
6470 @override 6426 @override
6471 bool get isPotentiallyMutatedInScope => true; 6427 bool get isPotentiallyMutatedInScope => true;
6472 6428
6473 @override 6429 @override
6474 ElementKind get kind => ElementKind.LOCAL_VARIABLE; 6430 ElementKind get kind => ElementKind.LOCAL_VARIABLE;
(...skipping 2566 matching lines...) Expand 10 before | Expand all | Expand 10 after
9041 8997
9042 @override 8998 @override
9043 DartObject computeConstantValue() => null; 8999 DartObject computeConstantValue() => null;
9044 9000
9045 @override 9001 @override
9046 void visitChildren(ElementVisitor visitor) { 9002 void visitChildren(ElementVisitor visitor) {
9047 super.visitChildren(visitor); 9003 super.visitChildren(visitor);
9048 _initializer?.accept(visitor); 9004 _initializer?.accept(visitor);
9049 } 9005 }
9050 } 9006 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/builder.dart ('k') | pkg/analyzer/lib/src/dart/element/handle.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698