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

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

Issue 2034473002: Delay 'supertype' for ClassElementImpl and EnumElementImpl. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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
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 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 * Indicates whether [librarySource] is the `dart:core` library. 1025 * Indicates whether [librarySource] is the `dart:core` library.
1026 */ 1026 */
1027 bool isCoreLibrary; 1027 bool isCoreLibrary;
1028 1028
1029 /** 1029 /**
1030 * The resynthesized library. 1030 * The resynthesized library.
1031 */ 1031 */
1032 LibraryElementImpl library; 1032 LibraryElementImpl library;
1033 1033
1034 /** 1034 /**
1035 * Classes which should have their supertype set to "object" once
1036 * resynthesis is complete. Only used if [isCoreLibrary] is `true`.
1037 */
1038 List<ClassElementImpl> delayedObjectSubclasses = <ClassElementImpl>[];
1039
1040 /**
1041 * Map of compilation unit elements that have been resynthesized so far. The 1035 * Map of compilation unit elements that have been resynthesized so far. The
1042 * key is the URI of the compilation unit. 1036 * key is the URI of the compilation unit.
1043 */ 1037 */
1044 final Map<String, CompilationUnitElementImpl> resynthesizedUnits = 1038 final Map<String, CompilationUnitElementImpl> resynthesizedUnits =
1045 <String, CompilationUnitElementImpl>{}; 1039 <String, CompilationUnitElementImpl>{};
1046 1040
1047 /** 1041 /**
1048 * Types with implicit type arguments, which are the same as type parameter 1042 * Types with implicit type arguments, which are the same as type parameter
1049 * bounds (in strong mode), or `dynamic` (in spec mode). 1043 * bounds (in strong mode), or `dynamic` (in spec mode).
1050 */ 1044 */
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 unlinkedDefiningUnit.parts[i - 1], 1150 unlinkedDefiningUnit.parts[i - 1],
1157 i); 1151 i);
1158 partResynthesizers.add(partResynthesizer); 1152 partResynthesizers.add(partResynthesizer);
1159 } 1153 }
1160 library.parts = partResynthesizers.map((r) => r.unit).toList(); 1154 library.parts = partResynthesizers.map((r) => r.unit).toList();
1161 // Populate units. 1155 // Populate units.
1162 populateUnit(definingUnitResynthesizer); 1156 populateUnit(definingUnitResynthesizer);
1163 for (_UnitResynthesizer partResynthesizer in partResynthesizers) { 1157 for (_UnitResynthesizer partResynthesizer in partResynthesizers) {
1164 populateUnit(partResynthesizer); 1158 populateUnit(partResynthesizer);
1165 } 1159 }
1166 // Update delayed Object class references.
1167 if (isCoreLibrary) {
1168 ClassElement objectElement = library.getType('Object');
1169 assert(objectElement != null);
1170 for (ClassElementImpl classElement in delayedObjectSubclasses) {
1171 classElement.supertype = objectElement.type;
1172 }
1173 }
1174 // Create the synthetic element for `loadLibrary`. 1160 // Create the synthetic element for `loadLibrary`.
1175 // Until the client received dart:core and dart:async, we cannot do this, 1161 // Until the client received dart:core and dart:async, we cannot do this,
1176 // because the TypeProvider is not fully initialized. So, it is up to the 1162 // because the TypeProvider is not fully initialized. So, it is up to the
1177 // Dart SDK client to initialize TypeProvider and finish the dart:core and 1163 // Dart SDK client to initialize TypeProvider and finish the dart:core and
1178 // dart:async libraries creation. 1164 // dart:async libraries creation.
1179 if (library.name != 'dart.core' && library.name != 'dart.async') { 1165 if (library.name != 'dart.core' && library.name != 'dart.async') {
1180 library.createLoadLibraryFunction(summaryResynthesizer.typeProvider); 1166 library.createLoadLibraryFunction(summaryResynthesizer.typeProvider);
1181 } 1167 }
1182 // Done. 1168 // Done.
1183 return library; 1169 return library;
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 } 1668 }
1683 1669
1684 /** 1670 /**
1685 * Resynthesize a [ClassElement] and place it in [unitHolder]. 1671 * Resynthesize a [ClassElement] and place it in [unitHolder].
1686 */ 1672 */
1687 void buildClass(UnlinkedClass serializedClass) { 1673 void buildClass(UnlinkedClass serializedClass) {
1688 ClassElement classElement; 1674 ClassElement classElement;
1689 if (libraryResynthesizer.isCoreLibrary && 1675 if (libraryResynthesizer.isCoreLibrary &&
1690 serializedClass.supertype == null) { 1676 serializedClass.supertype == null) {
1691 classElement = buildClassImpl(serializedClass, null); 1677 classElement = buildClassImpl(serializedClass, null);
1692 if (!serializedClass.hasNoSupertype) {
1693 libraryResynthesizer.delayedObjectSubclasses.add(classElement);
1694 }
1695 } else { 1678 } else {
1696 classElement = new _DeferredClassElement(this, unit, serializedClass); 1679 classElement = new _DeferredClassElement(this, unit, serializedClass);
1697 } 1680 }
1698 unitHolder.addType(classElement); 1681 unitHolder.addType(classElement);
1699 } 1682 }
1700 1683
1701 /** 1684 /**
1702 * Fill the given [ClassElementImpl] with executable elements and fields. 1685 * Fill the given [ClassElementImpl] with executable elements and fields.
1703 */ 1686 */
1704 void buildClassExecutables( 1687 void buildClassExecutables(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 * executables are not resynthesized, and [InterfaceTypeImpl] is created 1729 * executables are not resynthesized, and [InterfaceTypeImpl] is created
1747 * around the [handle], so that executables are resynthesized lazily. 1730 * around the [handle], so that executables are resynthesized lazily.
1748 */ 1731 */
1749 ClassElementImpl buildClassImpl( 1732 ClassElementImpl buildClassImpl(
1750 UnlinkedClass serializedClass, ClassElementHandle handle) { 1733 UnlinkedClass serializedClass, ClassElementHandle handle) {
1751 ClassElementImpl classElement = 1734 ClassElementImpl classElement =
1752 new ClassElementImpl.forSerialized(serializedClass, unit); 1735 new ClassElementImpl.forSerialized(serializedClass, unit);
1753 classElement.hasBeenInferred = summaryResynthesizer.strongMode; 1736 classElement.hasBeenInferred = summaryResynthesizer.strongMode;
1754 InterfaceTypeImpl correspondingType = 1737 InterfaceTypeImpl correspondingType =
1755 new InterfaceTypeImpl(handle ?? classElement); 1738 new InterfaceTypeImpl(handle ?? classElement);
1756 if (serializedClass.supertype != null) {
1757 classElement.supertype =
1758 buildType(serializedClass.supertype, classElement);
1759 } else if (!libraryResynthesizer.isCoreLibrary) {
1760 classElement.supertype = typeProvider.objectType;
1761 }
1762 // TODO(scheglov) move to ClassElementImpl 1739 // TODO(scheglov) move to ClassElementImpl
1763 correspondingType.typeArguments = classElement.typeParameterTypes; 1740 correspondingType.typeArguments = classElement.typeParameterTypes;
1764 classElement.type = correspondingType; 1741 classElement.type = correspondingType;
1765 // TODO(scheglov) Somehow Observatory shows too much time spent here 1742 // TODO(scheglov) Somehow Observatory shows too much time spent here
1766 // 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.
1767 if (handle == null) { 1744 if (handle == null) {
1768 buildClassExecutables(classElement, serializedClass); 1745 buildClassExecutables(classElement, serializedClass);
1769 } 1746 }
1770 constructors = null; 1747 constructors = null;
1771 return classElement; 1748 return classElement;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 /** 1840 /**
1864 * Resynthesize the [ClassElement] corresponding to an enum, along with the 1841 * Resynthesize the [ClassElement] corresponding to an enum, along with the
1865 * associated fields and implicit accessors. 1842 * associated fields and implicit accessors.
1866 */ 1843 */
1867 void buildEnum(UnlinkedEnum serializedEnum) { 1844 void buildEnum(UnlinkedEnum serializedEnum) {
1868 assert(!libraryResynthesizer.isCoreLibrary); 1845 assert(!libraryResynthesizer.isCoreLibrary);
1869 EnumElementImpl classElement = 1846 EnumElementImpl classElement =
1870 new EnumElementImpl.forSerialized(serializedEnum, unit); 1847 new EnumElementImpl.forSerialized(serializedEnum, unit);
1871 InterfaceType enumType = new InterfaceTypeImpl(classElement); 1848 InterfaceType enumType = new InterfaceTypeImpl(classElement);
1872 classElement.type = enumType; 1849 classElement.type = enumType;
1873 classElement.supertype = typeProvider.objectType;
1874 ElementHolder memberHolder = new ElementHolder(); 1850 ElementHolder memberHolder = new ElementHolder();
1875 // Build the 'index' field. 1851 // Build the 'index' field.
1876 FieldElementImpl indexField = new FieldElementImpl('index', -1); 1852 FieldElementImpl indexField = new FieldElementImpl('index', -1);
1877 indexField.final2 = true; 1853 indexField.final2 = true;
1878 indexField.synthetic = true; 1854 indexField.synthetic = true;
1879 indexField.type = typeProvider.intType; 1855 indexField.type = typeProvider.intType;
1880 memberHolder.addField(indexField); 1856 memberHolder.addField(indexField);
1881 buildImplicitAccessors(indexField, memberHolder); 1857 buildImplicitAccessors(indexField, memberHolder);
1882 // Build the 'values' field. 1858 // Build the 'values' field.
1883 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); 1859 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1);
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
2396 static String _getElementIdentifier(String name, ReferenceKind kind) { 2372 static String _getElementIdentifier(String name, ReferenceKind kind) {
2397 if (kind == ReferenceKind.topLevelPropertyAccessor || 2373 if (kind == ReferenceKind.topLevelPropertyAccessor ||
2398 kind == ReferenceKind.propertyAccessor) { 2374 kind == ReferenceKind.propertyAccessor) {
2399 if (!name.endsWith('=')) { 2375 if (!name.endsWith('=')) {
2400 return name + '?'; 2376 return name + '?';
2401 } 2377 }
2402 } 2378 }
2403 return name; 2379 return name;
2404 } 2380 }
2405 } 2381 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698