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

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

Issue 2987883003: Resynthesize top-level accessors and variables from Kernel. (Closed)
Patch Set: Created 3 years, 4 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 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 String name) 1563 String name)
1564 : _kernelContext = null, 1564 : _kernelContext = null,
1565 super.forSerialized(null) { 1565 super.forSerialized(null) {
1566 _enclosingElement = enclosingLibrary; 1566 _enclosingElement = enclosingLibrary;
1567 _name = name; 1567 _name = name;
1568 _nameOffset = -1; 1568 _nameOffset = -1;
1569 } 1569 }
1570 1570
1571 @override 1571 @override
1572 List<PropertyAccessorElement> get accessors { 1572 List<PropertyAccessorElement> get accessors {
1573 if (_unlinkedUnit != null) { 1573 if (_accessors == null) {
1574 if (_accessors == null) { 1574 if (_kernelContext != null) {
1575 _explicitTopLevelAccessors ??=
1576 _kernelContext.buildTopLevelAccessors(this);
1577 _explicitTopLevelVariables ??=
1578 _kernelContext.buildTopLevelVariables(this);
1579 }
1580 if (_unlinkedUnit != null) {
1575 _explicitTopLevelAccessors ??= 1581 _explicitTopLevelAccessors ??=
1576 resynthesizerContext.buildTopLevelAccessors(); 1582 resynthesizerContext.buildTopLevelAccessors();
1577 _explicitTopLevelVariables ??= 1583 _explicitTopLevelVariables ??=
1578 resynthesizerContext.buildTopLevelVariables(); 1584 resynthesizerContext.buildTopLevelVariables();
1579 List<PropertyAccessorElementImpl> accessors = 1585 }
1580 <PropertyAccessorElementImpl>[]; 1586 if (_explicitTopLevelAccessors != null) {
1581 accessors.addAll(_explicitTopLevelAccessors.accessors); 1587 _accessors = <PropertyAccessorElementImpl>[]
1582 accessors.addAll(_explicitTopLevelVariables.implicitAccessors); 1588 ..addAll(_explicitTopLevelAccessors.accessors)
1583 _accessors = accessors; 1589 ..addAll(_explicitTopLevelVariables.implicitAccessors);
1584 } 1590 }
1585 } 1591 }
1586 return _accessors ?? PropertyAccessorElement.EMPTY_LIST; 1592 return _accessors ?? PropertyAccessorElement.EMPTY_LIST;
1587 } 1593 }
1588 1594
1589 /** 1595 /**
1590 * Set the top-level accessors (getters and setters) contained in this 1596 * Set the top-level accessors (getters and setters) contained in this
1591 * compilation unit to the given [accessors]. 1597 * compilation unit to the given [accessors].
1592 */ 1598 */
1593 void set accessors(List<PropertyAccessorElement> accessors) { 1599 void set accessors(List<PropertyAccessorElement> accessors) {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 if (_unlinkedPart != null) { 1716 if (_unlinkedPart != null) {
1711 return _metadata ??= _buildAnnotations( 1717 return _metadata ??= _buildAnnotations(
1712 library.definingCompilationUnit as CompilationUnitElementImpl, 1718 library.definingCompilationUnit as CompilationUnitElementImpl,
1713 _unlinkedPart.annotations); 1719 _unlinkedPart.annotations);
1714 } 1720 }
1715 return super.metadata; 1721 return super.metadata;
1716 } 1722 }
1717 1723
1718 @override 1724 @override
1719 List<TopLevelVariableElement> get topLevelVariables { 1725 List<TopLevelVariableElement> get topLevelVariables {
1720 if (_kernelContext != null) { 1726 if (_variables == null) {
1721 return _variables ??= _kernelContext.library.fields.map((k) { 1727 if (_kernelContext != null) {
1722 if (k.isConst && k.initializer != null) { 1728 _explicitTopLevelAccessors ??=
1723 return new ConstTopLevelVariableElementImpl.forKernel(this, k); 1729 _kernelContext.buildTopLevelAccessors(this);
1724 } else { 1730 _explicitTopLevelVariables ??=
1725 return new TopLevelVariableElementImpl.forKernel(this, k); 1731 _kernelContext.buildTopLevelVariables(this);
1726 } 1732 }
1727 }).toList(growable: false); 1733 if (_unlinkedUnit != null) {
1728 }
1729 if (_unlinkedUnit != null) {
1730 if (_variables == null) {
1731 _explicitTopLevelAccessors ??= 1734 _explicitTopLevelAccessors ??=
1732 resynthesizerContext.buildTopLevelAccessors(); 1735 resynthesizerContext.buildTopLevelAccessors();
1733 _explicitTopLevelVariables ??= 1736 _explicitTopLevelVariables ??=
1734 resynthesizerContext.buildTopLevelVariables(); 1737 resynthesizerContext.buildTopLevelVariables();
1735 List<TopLevelVariableElementImpl> variables = 1738 }
1736 <TopLevelVariableElementImpl>[]; 1739 if (_explicitTopLevelVariables != null) {
1737 variables.addAll(_explicitTopLevelVariables.variables); 1740 var variables = <TopLevelVariableElement>[]
1738 variables.addAll(_explicitTopLevelAccessors.implicitVariables); 1741 ..addAll(_explicitTopLevelVariables.variables)
1742 ..addAll(_explicitTopLevelAccessors.implicitVariables);
1743
1739 // Ensure that getters and setters in different units use 1744 // Ensure that getters and setters in different units use
1740 // the same top-level variables. 1745 // the same top-level variables.
1741 (enclosingElement as LibraryElementImpl) 1746 BuildLibraryElementUtils.patchTopLevelAccessors(library);
1742 .resynthesizerContext 1747
1743 .patchTopLevelAccessors(); 1748 // Apply recorded patches to variables.
1744 _variables = variables;
1745 _topLevelVariableReplaceMap?.forEach((from, to) { 1749 _topLevelVariableReplaceMap?.forEach((from, to) {
1746 int index = _variables.indexOf(from); 1750 int index = variables.indexOf(from);
1747 _variables[index] = to; 1751 variables[index] = to;
1748 }); 1752 });
1749 _topLevelVariableReplaceMap = null; 1753 _topLevelVariableReplaceMap = null;
1754
1755 _variables = variables;
1750 } 1756 }
1751 } 1757 }
1752 return _variables ?? TopLevelVariableElement.EMPTY_LIST; 1758 return _variables ?? TopLevelVariableElement.EMPTY_LIST;
1753 } 1759 }
1754 1760
1755 /** 1761 /**
1756 * Set the top-level variables contained in this compilation unit to the given 1762 * Set the top-level variables contained in this compilation unit to the given
1757 * [variables]. 1763 * [variables].
1758 */ 1764 */
1759 void set topLevelVariables(List<TopLevelVariableElement> variables) { 1765 void set topLevelVariables(List<TopLevelVariableElement> variables) {
(...skipping 4130 matching lines...) Expand 10 before | Expand all | Expand 10 after
5890 } 5896 }
5891 } 5897 }
5892 5898
5893 /** 5899 /**
5894 * The kernel context in which a library is resynthesized. 5900 * The kernel context in which a library is resynthesized.
5895 */ 5901 */
5896 abstract class KernelLibraryResynthesizerContext { 5902 abstract class KernelLibraryResynthesizerContext {
5897 kernel.Library get library; 5903 kernel.Library get library;
5898 5904
5899 /** 5905 /**
5906 * Build explicit top-level property accessors.
5907 */
5908 UnitExplicitTopLevelAccessors buildTopLevelAccessors(
5909 CompilationUnitElementImpl unit);
5910
5911 /**
5912 * Build explicit top-level variables.
5913 */
5914 UnitExplicitTopLevelVariables buildTopLevelVariables(
5915 CompilationUnitElementImpl unit);
5916
5917 /**
5900 * Return the resynthesized [ConstructorInitializer] for the given Kernel 5918 * Return the resynthesized [ConstructorInitializer] for the given Kernel
5901 * [initializer], or `null` if synthetic. 5919 * [initializer], or `null` if synthetic.
5902 */ 5920 */
5903 ConstructorInitializer getConstructorInitializer( 5921 ConstructorInitializer getConstructorInitializer(
5904 ConstructorElementImpl constructor, kernel.Initializer initializer); 5922 ConstructorElementImpl constructor, kernel.Initializer initializer);
5905 5923
5906 /** 5924 /**
5907 * Return the [Expression] for the given kernel. 5925 * Return the [Expression] for the given kernel.
5908 */ 5926 */
5909 Expression getExpression(kernel.Expression expression); 5927 Expression getExpression(kernel.Expression expression);
(...skipping 3722 matching lines...) Expand 10 before | Expand all | Expand 10 after
9632 9650
9633 @override 9651 @override
9634 DartObject computeConstantValue() => null; 9652 DartObject computeConstantValue() => null;
9635 9653
9636 @override 9654 @override
9637 void visitChildren(ElementVisitor visitor) { 9655 void visitChildren(ElementVisitor visitor) {
9638 super.visitChildren(visitor); 9656 super.visitChildren(visitor);
9639 _initializer?.accept(visitor); 9657 _initializer?.accept(visitor);
9640 } 9658 }
9641 } 9659 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/kernel/resynthesize.dart » ('j') | pkg/analyzer/lib/src/kernel/resynthesize.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698