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

Side by Side Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 2030403002: Resynthesize constructors lazily. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: tweaks Created 4 years, 6 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/src/dart/element/element.dart ('k') | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 summary_resynthesizer; 5 library summary_resynthesizer;
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 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1476 UnitExplicitTopLevelAccessors buildTopLevelAccessors() { 1476 UnitExplicitTopLevelAccessors buildTopLevelAccessors() {
1477 return _unitResynthesizer.buildUnitExplicitTopLevelAccessors(); 1477 return _unitResynthesizer.buildUnitExplicitTopLevelAccessors();
1478 } 1478 }
1479 1479
1480 @override 1480 @override
1481 UnitExplicitTopLevelVariables buildTopLevelVariables() { 1481 UnitExplicitTopLevelVariables buildTopLevelVariables() {
1482 return _unitResynthesizer.buildUnitExplicitTopLevelVariables(); 1482 return _unitResynthesizer.buildUnitExplicitTopLevelVariables();
1483 } 1483 }
1484 1484
1485 @override 1485 @override
1486 bool isInConstCycle(int slot) {
1487 return _unitResynthesizer.constCycles.contains(slot);
1488 }
1489
1490 @override
1486 ConstructorElement resolveConstructorRef( 1491 ConstructorElement resolveConstructorRef(
1487 TypeParameterizedElementMixin typeParameterContext, EntityRef entry) { 1492 TypeParameterizedElementMixin typeParameterContext, EntityRef entry) {
1488 return _unitResynthesizer._getConstructorForEntry( 1493 return _unitResynthesizer._getConstructorForEntry(
1489 typeParameterContext, entry); 1494 typeParameterContext, entry);
1490 } 1495 }
1491 1496
1492 @override 1497 @override
1493 DartType resolveLinkedType( 1498 DartType resolveLinkedType(
1494 int slot, TypeParameterizedElementMixin typeParameterContext) { 1499 int slot, TypeParameterizedElementMixin typeParameterContext) {
1495 return _unitResynthesizer.buildLinkedType(slot, typeParameterContext); 1500 return _unitResynthesizer.buildLinkedType(slot, typeParameterContext);
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 1699
1695 /** 1700 /**
1696 * Fill the given [ClassElementImpl] with executable elements and fields. 1701 * Fill the given [ClassElementImpl] with executable elements and fields.
1697 */ 1702 */
1698 void buildClassExecutables( 1703 void buildClassExecutables(
1699 ClassElementImpl classElement, UnlinkedClass serializedClass) { 1704 ClassElementImpl classElement, UnlinkedClass serializedClass) {
1700 ElementHolder memberHolder = new ElementHolder(); 1705 ElementHolder memberHolder = new ElementHolder();
1701 for (UnlinkedVariable serializedVariable in serializedClass.fields) { 1706 for (UnlinkedVariable serializedVariable in serializedClass.fields) {
1702 buildField(classElement, serializedVariable, memberHolder); 1707 buildField(classElement, serializedVariable, memberHolder);
1703 } 1708 }
1704 bool constructorFound = false;
1705 for (UnlinkedExecutable serializedExecutable 1709 for (UnlinkedExecutable serializedExecutable
1706 in serializedClass.executables) { 1710 in serializedClass.executables) {
1707 switch (serializedExecutable.kind) { 1711 switch (serializedExecutable.kind) {
1708 case UnlinkedExecutableKind.constructor:
1709 constructorFound = true;
1710 buildConstructor(serializedExecutable, classElement, memberHolder);
1711 break;
1712 case UnlinkedExecutableKind.getter: 1712 case UnlinkedExecutableKind.getter:
1713 case UnlinkedExecutableKind.setter: 1713 case UnlinkedExecutableKind.setter:
1714 buildClassExecutable( 1714 buildClassExecutable(
1715 serializedExecutable, classElement, memberHolder); 1715 serializedExecutable, classElement, memberHolder);
1716 break; 1716 break;
1717 case UnlinkedExecutableKind.constructor:
1717 case UnlinkedExecutableKind.functionOrMethod: 1718 case UnlinkedExecutableKind.functionOrMethod:
1718 // Resynthesized lazily. 1719 // Resynthesized lazily.
1719 break; 1720 break;
1720 } 1721 }
1721 } 1722 }
1722 if (!serializedClass.isMixinApplication) {
1723 if (!constructorFound) {
1724 // Synthesize implicit constructors.
1725 ConstructorElementImpl constructor = new ConstructorElementImpl('', -1);
1726 constructor.synthetic = true;
1727 constructor.returnType = classElement.type;
1728 constructor.type = new FunctionTypeImpl.elementWithNameAndArgs(
1729 constructor, null, classElement.type.typeArguments, false);
1730 memberHolder.addConstructor(constructor);
1731 }
1732 classElement.constructors = memberHolder.constructors;
1733 }
1734 classElement.accessors = memberHolder.accessors; 1723 classElement.accessors = memberHolder.accessors;
1735 classElement.fields = memberHolder.fields; 1724 classElement.fields = memberHolder.fields;
1736 } 1725 }
1737 1726
1738 /** 1727 /**
1739 * Resynthesize a [ClassElementImpl]. If [handle] is not `null`, then 1728 * Resynthesize a [ClassElementImpl]. If [handle] is not `null`, then
1740 * executables are not resynthesized, and [InterfaceTypeImpl] is created 1729 * executables are not resynthesized, and [InterfaceTypeImpl] is created
1741 * around the [handle], so that executables are resynthesized lazily. 1730 * around the [handle], so that executables are resynthesized lazily.
1742 */ 1731 */
1743 ClassElementImpl buildClassImpl( 1732 ClassElementImpl buildClassImpl(
1744 UnlinkedClass serializedClass, ClassElementHandle handle) { 1733 UnlinkedClass serializedClass, ClassElementHandle handle) {
1745 ClassElementImpl classElement = 1734 ClassElementImpl classElement =
1746 new ClassElementImpl.forSerialized(serializedClass, unit); 1735 new ClassElementImpl.forSerialized(serializedClass, unit);
1747 classElement.hasBeenInferred = summaryResynthesizer.strongMode; 1736 classElement.hasBeenInferred = summaryResynthesizer.strongMode;
1748 InterfaceTypeImpl correspondingType = 1737 InterfaceTypeImpl correspondingType =
1749 new InterfaceTypeImpl(handle ?? classElement); 1738 new InterfaceTypeImpl(handle ?? classElement);
1750 // TODO(scheglov) move to ClassElementImpl 1739 // TODO(scheglov) move to ClassElementImpl
1751 correspondingType.typeArguments = classElement.typeParameterTypes; 1740 correspondingType.typeArguments = classElement.typeParameterTypes;
1752 classElement.type = correspondingType; 1741 classElement.type = correspondingType;
1753 // TODO(scheglov) Somehow Observatory shows too much time spent here 1742 // TODO(scheglov) Somehow Observatory shows too much time spent here
1754 // during DDC run on the large codebase. I would expect only Object here. 1743 // during DDC run on the large codebase. I would expect only Object here.
1755 if (handle == null) { 1744 if (handle == null) {
1756 buildClassExecutables(classElement, serializedClass); 1745 buildClassExecutables(classElement, serializedClass);
1757 } 1746 }
1758 return classElement; 1747 return classElement;
1759 } 1748 }
1760 1749
1761 /** 1750 /**
1762 * Resynthesize a [ConstructorElement] and place it in the given [holder].
1763 * [classElement] is the element of the class for which this element is a
1764 * constructor.
1765 */
1766 void buildConstructor(UnlinkedExecutable serializedExecutable,
1767 ClassElementImpl classElement, ElementHolder holder) {
1768 assert(serializedExecutable.kind == UnlinkedExecutableKind.constructor);
1769 ConstructorElementImpl constructor =
1770 new ConstructorElementImpl.forSerialized(
1771 serializedExecutable, constCycles, classElement);
1772 holder.addConstructor(constructor);
1773 }
1774
1775 /**
1776 * Build the documentation for the given [element]. Does nothing if 1751 * Build the documentation for the given [element]. Does nothing if
1777 * [serializedDocumentationComment] is `null`. 1752 * [serializedDocumentationComment] is `null`.
1778 */ 1753 */
1779 void buildDocumentation(ElementImpl element, 1754 void buildDocumentation(ElementImpl element,
1780 UnlinkedDocumentationComment serializedDocumentationComment) { 1755 UnlinkedDocumentationComment serializedDocumentationComment) {
1781 if (serializedDocumentationComment != null) { 1756 if (serializedDocumentationComment != null) {
1782 element.documentationComment = serializedDocumentationComment.text; 1757 element.documentationComment = serializedDocumentationComment.text;
1783 element.setDocRange(serializedDocumentationComment.offset, 1758 element.setDocRange(serializedDocumentationComment.offset,
1784 serializedDocumentationComment.length); 1759 serializedDocumentationComment.length);
1785 } 1760 }
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
2246 static String _getElementIdentifier(String name, ReferenceKind kind) { 2221 static String _getElementIdentifier(String name, ReferenceKind kind) {
2247 if (kind == ReferenceKind.topLevelPropertyAccessor || 2222 if (kind == ReferenceKind.topLevelPropertyAccessor ||
2248 kind == ReferenceKind.propertyAccessor) { 2223 kind == ReferenceKind.propertyAccessor) {
2249 if (!name.endsWith('=')) { 2224 if (!name.endsWith('=')) {
2250 return name + '?'; 2225 return name + '?';
2251 } 2226 }
2252 } 2227 }
2253 return name; 2228 return name;
2254 } 2229 }
2255 } 2230 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698