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

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

Issue 1650873002: Fix memory leak in incremental resolver (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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
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 1688 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 * or `null` if this element does not have a documentation comment. 1699 * or `null` if this element does not have a documentation comment.
1700 */ 1700 */
1701 int _docRangeOffset; 1701 int _docRangeOffset;
1702 1702
1703 /** 1703 /**
1704 * The length of the documentation comment range for this element. 1704 * The length of the documentation comment range for this element.
1705 */ 1705 */
1706 int _docRangeLength; 1706 int _docRangeLength;
1707 1707
1708 /** 1708 /**
1709 * If true, the element is being used as a map key.
1710 * Mutations that change operator== (and hashCode)
1711 * will throw an exception.
1712 */
1713 bool frozen = false;
Brian Wilkerson 2016/02/01 14:58:16 This would be better implemented as a Modifier bec
skybrian 2016/02/02 02:12:19 Hmm. That apparently makes it part of the public A
Brian Wilkerson 2016/02/02 16:32:06 I'm not sure why. The class Modifier isn't part of
1714
1715 /**
1709 * Initialize a newly created element to have the given [name] at the given 1716 * Initialize a newly created element to have the given [name] at the given
1710 * [_nameOffset]. 1717 * [_nameOffset].
1711 */ 1718 */
1712 ElementImpl(String name, this._nameOffset) { 1719 ElementImpl(String name, this._nameOffset) {
1713 this._name = StringUtilities.intern(name); 1720 this._name = StringUtilities.intern(name);
1714 } 1721 }
1715 1722
1716 /** 1723 /**
1717 * Initialize a newly created element to have the given [name]. 1724 * Initialize a newly created element to have the given [name].
1718 */ 1725 */
(...skipping 29 matching lines...) Expand all
1748 _docComment = doc?.replaceAll('\r\n', '\n'); 1755 _docComment = doc?.replaceAll('\r\n', '\n');
1749 } 1756 }
1750 1757
1751 @override 1758 @override
1752 Element get enclosingElement => _enclosingElement; 1759 Element get enclosingElement => _enclosingElement;
1753 1760
1754 /** 1761 /**
1755 * Set the enclosing element of this element to the given [element]. 1762 * Set the enclosing element of this element to the given [element].
1756 */ 1763 */
1757 void set enclosingElement(Element element) { 1764 void set enclosingElement(Element element) {
1765 _checkNotFrozen();
1758 _enclosingElement = element as ElementImpl; 1766 _enclosingElement = element as ElementImpl;
1759 _cachedLocation = null; 1767 _cachedLocation = null;
1760 _cachedHashCode = null; 1768 _cachedHashCode = null;
1761 } 1769 }
1762 1770
1763 @override 1771 @override
1764 int get hashCode { 1772 int get hashCode {
1765 // TODO: We might want to re-visit this optimization in the future. 1773 // TODO: We might want to re-visit this optimization in the future.
1766 // We cache the hash code value as this is a very frequently called method. 1774 // We cache the hash code value as this is a very frequently called method.
1767 if (_cachedHashCode == null) { 1775 if (_cachedHashCode == null) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 } 1837 }
1830 _cachedLocation = new ElementLocationImpl.con1(this); 1838 _cachedLocation = new ElementLocationImpl.con1(this);
1831 } 1839 }
1832 return _cachedLocation; 1840 return _cachedLocation;
1833 } 1841 }
1834 1842
1835 @override 1843 @override
1836 String get name => _name; 1844 String get name => _name;
1837 1845
1838 void set name(String name) { 1846 void set name(String name) {
1847 _checkNotFrozen();
scheglov 2016/02/01 16:01:25 The location of an Element consists of identifiers
Brian Wilkerson 2016/02/01 16:11:58 Good point! If we went with the method on CachePa
Brian Wilkerson 2016/02/02 16:32:06 It seems to me that the consequences are that we'r
1839 this._name = name; 1848 this._name = name;
1840 _cachedLocation = null; 1849 _cachedLocation = null;
1841 _cachedHashCode = null; 1850 _cachedHashCode = null;
1842 } 1851 }
1843 1852
1844 @override 1853 @override
1845 int get nameLength => displayName != null ? displayName.length : 0; 1854 int get nameLength => displayName != null ? displayName.length : 0;
1846 1855
1847 @override 1856 @override
1848 int get nameOffset => _nameOffset; 1857 int get nameOffset => _nameOffset;
1849 1858
1850 /** 1859 /**
1851 * Sets the offset of the name of this element in the file that contains the 1860 * Sets the offset of the name of this element in the file that contains the
1852 * declaration of this element. 1861 * declaration of this element.
1853 */ 1862 */
1854 void set nameOffset(int offset) { 1863 void set nameOffset(int offset) {
1864 _checkNotFrozen();
1855 _nameOffset = offset; 1865 _nameOffset = offset;
1856 _cachedHashCode = null; 1866 _cachedHashCode = null;
1857 _cachedLocation = null; 1867 _cachedLocation = null;
1858 } 1868 }
1859 1869
1860 @override 1870 @override
1861 Source get source { 1871 Source get source {
1862 if (_enclosingElement == null) { 1872 if (_enclosingElement == null) {
1863 return null; 1873 return null;
1864 } 1874 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2008 String toString() { 2018 String toString() {
2009 StringBuffer buffer = new StringBuffer(); 2019 StringBuffer buffer = new StringBuffer();
2010 appendTo(buffer); 2020 appendTo(buffer);
2011 return buffer.toString(); 2021 return buffer.toString();
2012 } 2022 }
2013 2023
2014 @override 2024 @override
2015 void visitChildren(ElementVisitor visitor) { 2025 void visitChildren(ElementVisitor visitor) {
2016 // There are no children to visit 2026 // There are no children to visit
2017 } 2027 }
2028
2029 void _checkNotFrozen() {
2030 if (frozen) {
2031 //print("$this at $location is frozen and can't be mutated");
Brian Wilkerson 2016/02/01 14:58:16 Remove debugging code.
skybrian 2016/02/02 01:16:54 I've seen other commented out debugging code check
skybrian 2016/02/02 02:12:19 Done.
Brian Wilkerson 2016/02/02 16:32:06 It's a judgement call. Commented out code tends to
2032 throw new StateError("$this at $location is frozen and can't be mutated");
2033 }
2034 }
2018 } 2035 }
2019 2036
2020 /** 2037 /**
2021 * A concrete implementation of an [ElementLocation]. 2038 * A concrete implementation of an [ElementLocation].
2022 */ 2039 */
2023 class ElementLocationImpl implements ElementLocation { 2040 class ElementLocationImpl implements ElementLocation {
2024 /** 2041 /**
2025 * The character used to separate components in the encoded form. 2042 * The character used to separate components in the encoded form.
2026 */ 2043 */
2027 static int _SEPARATOR_CHAR = 0x3B; 2044 static int _SEPARATOR_CHAR = 0x3B;
(...skipping 2072 matching lines...) Expand 10 before | Expand all | Expand 10 after
4100 ParameterElementImpl(String name, int nameOffset) : super(name, nameOffset); 4117 ParameterElementImpl(String name, int nameOffset) : super(name, nameOffset);
4101 4118
4102 /** 4119 /**
4103 * Initialize a newly created parameter element to have the given [name]. 4120 * Initialize a newly created parameter element to have the given [name].
4104 */ 4121 */
4105 ParameterElementImpl.forNode(Identifier name) : super.forNode(name); 4122 ParameterElementImpl.forNode(Identifier name) : super.forNode(name);
4106 4123
4107 /** 4124 /**
4108 * Creates a synthetic parameter with [name], [type] and [kind]. 4125 * Creates a synthetic parameter with [name], [type] and [kind].
4109 */ 4126 */
4110 factory ParameterElementImpl.synthetic(String name, DartType type, 4127 factory ParameterElementImpl.synthetic(
4111 ParameterKind kind) { 4128 String name, DartType type, ParameterKind kind) {
4112 ParameterElementImpl element = new ParameterElementImpl(name, -1); 4129 ParameterElementImpl element = new ParameterElementImpl(name, -1);
4113 element.type = type; 4130 element.type = type;
4114 element.synthetic = true; 4131 element.synthetic = true;
4115 element.parameterKind = kind; 4132 element.parameterKind = kind;
4116 return element; 4133 return element;
4117 } 4134 }
4118 4135
4119 @override 4136 @override
4120 String get defaultValueCode => _defaultValueCode; 4137 String get defaultValueCode => _defaultValueCode;
4121 4138
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
4768 4785
4769 @override 4786 @override
4770 void visitElement(Element element) { 4787 void visitElement(Element element) {
4771 int offset = element.nameOffset; 4788 int offset = element.nameOffset;
4772 if (offset != -1) { 4789 if (offset != -1) {
4773 map[offset] = element; 4790 map[offset] = element;
4774 } 4791 }
4775 super.visitElement(element); 4792 super.visitElement(element);
4776 } 4793 }
4777 } 4794 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698