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

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

Issue 2815713003: Issue 29109. Resynthesize PrefixElement(s) to fix constants evaluation. (Closed)
Patch Set: Created 3 years, 8 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/standard_ast_factory.dart'; 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 TypeProvider get typeProvider => _typeProvider; 90 TypeProvider get typeProvider => _typeProvider;
91 91
92 @override 92 @override
93 Element getElement(ElementLocation location) { 93 Element getElement(ElementLocation location) {
94 List<String> components = location.components; 94 List<String> components = location.components;
95 String libraryUri = components[0]; 95 String libraryUri = components[0];
96 // Resynthesize locally. 96 // Resynthesize locally.
97 if (components.length == 1) { 97 if (components.length == 1) {
98 return getLibraryElement(libraryUri); 98 return getLibraryElement(libraryUri);
99 } else if (components.length == 2) { 99 } else if (components.length == 2) {
100 Map<String, CompilationUnitElement> libraryMap = 100 LibraryElement libraryElement = getLibraryElement(libraryUri);
101 _resynthesizedUnits[libraryUri]; 101 // Try to find the unit element.
102 if (libraryMap == null) { 102 {
103 getLibraryElement(libraryUri); 103 Map<String, CompilationUnitElement> libraryMap =
104 libraryMap = _resynthesizedUnits[libraryUri]; 104 _resynthesizedUnits[libraryUri];
105 assert(libraryMap != null); 105 assert(libraryMap != null);
106 String unitUri = components[1];
107 CompilationUnitElement unitElement = libraryMap[unitUri];
108 if (unitElement != null) {
109 return unitElement;
110 }
106 } 111 }
107 String unitUri = components[1]; 112 // Try to find the prefix element.
108 CompilationUnitElement element = libraryMap[unitUri]; 113 {
109 if (element == null) { 114 String name = components[1];
110 throw new Exception('Unit element not found in summary: $location'); 115 for (PrefixElement prefix in libraryElement.prefixes) {
116 if (prefix.name == name) {
117 return prefix;
118 }
119 }
111 } 120 }
112 return element; 121 // Fail.
122 throw new Exception('The element not found in summary: $location');
113 } else if (components.length == 3 || components.length == 4) { 123 } else if (components.length == 3 || components.length == 4) {
114 String unitUri = components[1]; 124 String unitUri = components[1];
115 // Prepare elements-in-units in the library. 125 // Prepare elements-in-units in the library.
116 Map<String, Map<String, Element>> unitsInLibrary = 126 Map<String, Map<String, Element>> unitsInLibrary =
117 _resynthesizedElements[libraryUri]; 127 _resynthesizedElements[libraryUri];
118 if (unitsInLibrary == null) { 128 if (unitsInLibrary == null) {
119 unitsInLibrary = new HashMap<String, Map<String, Element>>(); 129 unitsInLibrary = new HashMap<String, Map<String, Element>>();
120 _resynthesizedElements[libraryUri] = unitsInLibrary; 130 _resynthesizedElements[libraryUri] = unitsInLibrary;
121 } 131 }
122 // Prepare elements in the unit. 132 // Prepare elements in the unit.
(...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 if (enclosingInfo != null && enclosingInfo.element is ClassElement) { 1805 if (enclosingInfo != null && enclosingInfo.element is ClassElement) {
1796 String identifier = _getElementIdentifier(name, linkedReference.kind); 1806 String identifier = _getElementIdentifier(name, linkedReference.kind);
1797 locationComponents = 1807 locationComponents =
1798 enclosingInfo.element.location.components.toList(); 1808 enclosingInfo.element.location.components.toList();
1799 locationComponents.add(identifier); 1809 locationComponents.add(identifier);
1800 } else { 1810 } else {
1801 String identifier = _getElementIdentifier(name, linkedReference.kind); 1811 String identifier = _getElementIdentifier(name, linkedReference.kind);
1802 locationComponents = 1812 locationComponents =
1803 libraryResynthesizer.getReferencedLocationComponents( 1813 libraryResynthesizer.getReferencedLocationComponents(
1804 linkedReference.dependency, linkedReference.unit, identifier); 1814 linkedReference.dependency, linkedReference.unit, identifier);
1815 if (linkedReference.kind == ReferenceKind.prefix) {
1816 locationComponents = <String>[
1817 locationComponents[0],
1818 locationComponents[2]
1819 ];
1820 }
1805 } 1821 }
1806 if (!_resynthesizerContext.isStrongMode && 1822 if (!_resynthesizerContext.isStrongMode &&
1807 locationComponents.length == 3 && 1823 locationComponents.length == 3 &&
1808 locationComponents[0] == 'dart:async' && 1824 locationComponents[0] == 'dart:async' &&
1809 locationComponents[2] == 'FutureOr') { 1825 locationComponents[2] == 'FutureOr') {
1810 type = typeProvider.dynamicType; 1826 type = typeProvider.dynamicType;
1811 numTypeParameters = 0; 1827 numTypeParameters = 0;
1812 } 1828 }
1813 ElementLocation location = 1829 ElementLocation location =
1814 new ElementLocationImpl.con3(locationComponents); 1830 new ElementLocationImpl.con3(locationComponents);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 element = new _DeferredInitializerElement(enclosingElement); 1884 element = new _DeferredInitializerElement(enclosingElement);
1869 } else if (enclosingElement is ExecutableElement) { 1885 } else if (enclosingElement is ExecutableElement) {
1870 element = new _DeferredLocalFunctionElement( 1886 element = new _DeferredLocalFunctionElement(
1871 enclosingElement, linkedReference.localIndex); 1887 enclosingElement, linkedReference.localIndex);
1872 } else { 1888 } else {
1873 throw new StateError('Unexpected element enclosing function:' 1889 throw new StateError('Unexpected element enclosing function:'
1874 ' ${enclosingElement.runtimeType}'); 1890 ' ${enclosingElement.runtimeType}');
1875 } 1891 }
1876 break; 1892 break;
1877 case ReferenceKind.prefix: 1893 case ReferenceKind.prefix:
1894 element = new PrefixElementHandle(summaryResynthesizer, location);
1895 break;
1878 case ReferenceKind.unresolved: 1896 case ReferenceKind.unresolved:
1879 break; 1897 break;
1880 } 1898 }
1881 } 1899 }
1882 result = new _ReferenceInfo(libraryResynthesizer, enclosingInfo, name, 1900 result = new _ReferenceInfo(libraryResynthesizer, enclosingInfo, name,
1883 isDeclarableType, element, type, numTypeParameters); 1901 isDeclarableType, element, type, numTypeParameters);
1884 referenceInfos[index] = result; 1902 referenceInfos[index] = result;
1885 } 1903 }
1886 return result; 1904 return result;
1887 } 1905 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 static String _getElementIdentifier(String name, ReferenceKind kind) { 1993 static String _getElementIdentifier(String name, ReferenceKind kind) {
1976 if (kind == ReferenceKind.topLevelPropertyAccessor || 1994 if (kind == ReferenceKind.topLevelPropertyAccessor ||
1977 kind == ReferenceKind.propertyAccessor) { 1995 kind == ReferenceKind.propertyAccessor) {
1978 if (!name.endsWith('=')) { 1996 if (!name.endsWith('=')) {
1979 return name + '?'; 1997 return name + '?';
1980 } 1998 }
1981 } 1999 }
1982 return name; 2000 return name;
1983 } 2001 }
1984 } 2002 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698