| OLD | NEW |
| 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 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1762 } | 1762 } |
| 1763 | 1763 |
| 1764 /** | 1764 /** |
| 1765 * Resynthesize a [ClassElementImpl]. If [handle] is not `null`, then | 1765 * Resynthesize a [ClassElementImpl]. If [handle] is not `null`, then |
| 1766 * executables are not resynthesized, and [InterfaceTypeImpl] is created | 1766 * executables are not resynthesized, and [InterfaceTypeImpl] is created |
| 1767 * around the [handle], so that executables are resynthesized lazily. | 1767 * around the [handle], so that executables are resynthesized lazily. |
| 1768 */ | 1768 */ |
| 1769 ClassElementImpl buildClassImpl( | 1769 ClassElementImpl buildClassImpl( |
| 1770 UnlinkedClass serializedClass, ClassElementHandle handle) { | 1770 UnlinkedClass serializedClass, ClassElementHandle handle) { |
| 1771 ClassElementImpl classElement = | 1771 ClassElementImpl classElement = |
| 1772 new ClassElementImpl.forSerialized(serializedClass, unit); | 1772 new ClassElementImpl_Class.forSerialized(serializedClass, unit); |
| 1773 classElement.hasBeenInferred = summaryResynthesizer.strongMode; | 1773 classElement.hasBeenInferred = summaryResynthesizer.strongMode; |
| 1774 InterfaceTypeImpl correspondingType = | 1774 InterfaceTypeImpl correspondingType = |
| 1775 new InterfaceTypeImpl(handle ?? classElement); | 1775 new InterfaceTypeImpl(handle ?? classElement); |
| 1776 if (serializedClass.supertype != null) { | 1776 if (serializedClass.supertype != null) { |
| 1777 classElement.supertype = | 1777 classElement.supertype = |
| 1778 buildType(serializedClass.supertype, classElement); | 1778 buildType(serializedClass.supertype, classElement); |
| 1779 } else if (!libraryResynthesizer.isCoreLibrary) { | 1779 } else if (!libraryResynthesizer.isCoreLibrary) { |
| 1780 classElement.supertype = typeProvider.objectType; | 1780 classElement.supertype = typeProvider.objectType; |
| 1781 } | 1781 } |
| 1782 // TODO(scheglov) move to ClassElementImpl | 1782 // TODO(scheglov) move to ClassElementImpl |
| 1783 correspondingType.typeArguments = classElement.typeParameterTypes; | 1783 correspondingType.typeArguments = classElement.typeParameterTypes; |
| 1784 classElement.type = correspondingType; | 1784 classElement.type = correspondingType; |
| 1785 // TODO(scheglov) Somehow Observatory shows too much time spent here | 1785 // TODO(scheglov) Somehow Observatory shows too much time spent here |
| 1786 // during DDC run on the large codebase. I would expect only Object here. | 1786 // during DDC run on the large codebase. I would expect only Object here. |
| 1787 if (handle == null) { | 1787 if (handle == null) { |
| 1788 buildClassExecutables(classElement, serializedClass); | 1788 buildClassExecutables(classElement, serializedClass); |
| 1789 } | 1789 } |
| 1790 fields = null; | 1790 fields = null; |
| 1791 constructors = null; | 1791 constructors = null; |
| 1792 return classElement; | 1792 return classElement; |
| 1793 } | 1793 } |
| 1794 | 1794 |
| 1795 void buildCodeRange(ElementImpl element, CodeRange codeRange) { | |
| 1796 if (codeRange != null) { | |
| 1797 element.setCodeRange(codeRange.offset, codeRange.length); | |
| 1798 } | |
| 1799 } | |
| 1800 | |
| 1801 /** | 1795 /** |
| 1802 * Resynthesize a [NamespaceCombinator]. | 1796 * Resynthesize a [NamespaceCombinator]. |
| 1803 */ | 1797 */ |
| 1804 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) { | 1798 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) { |
| 1805 if (serializedCombinator.shows.isNotEmpty) { | 1799 if (serializedCombinator.shows.isNotEmpty) { |
| 1806 ShowElementCombinatorImpl combinator = new ShowElementCombinatorImpl(); | 1800 ShowElementCombinatorImpl combinator = new ShowElementCombinatorImpl(); |
| 1807 // Note: we call toList() so that we don't retain a reference to the | 1801 // Note: we call toList() so that we don't retain a reference to the |
| 1808 // deserialized data structure. | 1802 // deserialized data structure. |
| 1809 combinator.shownNames = serializedCombinator.shows.toList(); | 1803 combinator.shownNames = serializedCombinator.shows.toList(); |
| 1810 combinator.offset = serializedCombinator.offset; | 1804 combinator.offset = serializedCombinator.offset; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1916 serializedDocumentationComment.length); | 1910 serializedDocumentationComment.length); |
| 1917 } | 1911 } |
| 1918 } | 1912 } |
| 1919 | 1913 |
| 1920 /** | 1914 /** |
| 1921 * Resynthesize the [ClassElement] corresponding to an enum, along with the | 1915 * Resynthesize the [ClassElement] corresponding to an enum, along with the |
| 1922 * associated fields and implicit accessors. | 1916 * associated fields and implicit accessors. |
| 1923 */ | 1917 */ |
| 1924 void buildEnum(UnlinkedEnum serializedEnum) { | 1918 void buildEnum(UnlinkedEnum serializedEnum) { |
| 1925 assert(!libraryResynthesizer.isCoreLibrary); | 1919 assert(!libraryResynthesizer.isCoreLibrary); |
| 1926 ClassElementImpl classElement = | 1920 ClassElementImpl_Enum classElement = |
| 1927 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset); | 1921 new ClassElementImpl_Enum.forSerialized(serializedEnum, unit); |
| 1928 classElement.enum2 = true; | |
| 1929 InterfaceType enumType = new InterfaceTypeImpl(classElement); | 1922 InterfaceType enumType = new InterfaceTypeImpl(classElement); |
| 1930 classElement.type = enumType; | 1923 classElement.type = enumType; |
| 1931 classElement.supertype = typeProvider.objectType; | 1924 classElement.supertype = typeProvider.objectType; |
| 1932 buildDocumentation(classElement, serializedEnum.documentationComment); | |
| 1933 buildAnnotations(classElement, serializedEnum.annotations); | |
| 1934 buildCodeRange(classElement, serializedEnum.codeRange); | |
| 1935 ElementHolder memberHolder = new ElementHolder(); | 1925 ElementHolder memberHolder = new ElementHolder(); |
| 1936 // Build the 'index' field. | 1926 // Build the 'index' field. |
| 1937 FieldElementImpl indexField = new FieldElementImpl('index', -1); | 1927 FieldElementImpl indexField = new FieldElementImpl('index', -1); |
| 1938 indexField.final2 = true; | 1928 indexField.final2 = true; |
| 1939 indexField.synthetic = true; | 1929 indexField.synthetic = true; |
| 1940 indexField.type = typeProvider.intType; | 1930 indexField.type = typeProvider.intType; |
| 1941 memberHolder.addField(indexField); | 1931 memberHolder.addField(indexField); |
| 1942 buildImplicitAccessors(indexField, memberHolder); | 1932 buildImplicitAccessors(indexField, memberHolder); |
| 1943 // Build the 'values' field. | 1933 // Build the 'values' field. |
| 1944 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); | 1934 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2495 static String _getElementIdentifier(String name, ReferenceKind kind) { | 2485 static String _getElementIdentifier(String name, ReferenceKind kind) { |
| 2496 if (kind == ReferenceKind.topLevelPropertyAccessor || | 2486 if (kind == ReferenceKind.topLevelPropertyAccessor || |
| 2497 kind == ReferenceKind.propertyAccessor) { | 2487 kind == ReferenceKind.propertyAccessor) { |
| 2498 if (!name.endsWith('=')) { | 2488 if (!name.endsWith('=')) { |
| 2499 return name + '?'; | 2489 return name + '?'; |
| 2500 } | 2490 } |
| 2501 } | 2491 } |
| 2502 return name; | 2492 return name; |
| 2503 } | 2493 } |
| 2504 } | 2494 } |
| OLD | NEW |