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

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

Issue 1762193002: Resynthesize codeOffset/codeLength properties. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 } 1013 }
1014 classElement.constructors = memberHolder.constructors; 1014 classElement.constructors = memberHolder.constructors;
1015 } 1015 }
1016 classElement.accessors = memberHolder.accessors; 1016 classElement.accessors = memberHolder.accessors;
1017 classElement.fields = memberHolder.fields; 1017 classElement.fields = memberHolder.fields;
1018 classElement.methods = memberHolder.methods; 1018 classElement.methods = memberHolder.methods;
1019 correspondingType.typeArguments = getCurrentTypeArguments(); 1019 correspondingType.typeArguments = getCurrentTypeArguments();
1020 classElement.type = correspondingType; 1020 classElement.type = correspondingType;
1021 buildDocumentation(classElement, serializedClass.documentationComment); 1021 buildDocumentation(classElement, serializedClass.documentationComment);
1022 buildAnnotations(classElement, serializedClass.annotations); 1022 buildAnnotations(classElement, serializedClass.annotations);
1023 buildCodeRange(classElement, serializedClass);
1023 resolveConstructorInitializers(classElement); 1024 resolveConstructorInitializers(classElement);
1024 unitHolder.addType(classElement); 1025 unitHolder.addType(classElement);
1025 currentTypeParameters.removeLast(); 1026 currentTypeParameters.removeLast();
1026 assert(currentTypeParameters.isEmpty); 1027 assert(currentTypeParameters.isEmpty);
1027 fields = null; 1028 fields = null;
1028 constructors = null; 1029 constructors = null;
1029 } 1030 }
1030 1031
1032 void buildCodeRange(ElementImpl element, Object summary) {
1033 int offset;
1034 int length;
1035 if (summary is UnlinkedClass) {
1036 if (summary.hasCodeRange) {
1037 offset = summary.codeOffset;
1038 length = summary.codeLength;
1039 }
1040 } else if (summary is UnlinkedEnum) {
1041 if (summary.hasCodeRange) {
1042 offset = summary.codeOffset;
1043 length = summary.codeLength;
1044 }
1045 } else if (summary is UnlinkedExecutable) {
1046 if (summary.hasCodeRange) {
1047 offset = summary.codeOffset;
1048 length = summary.codeLength;
1049 }
1050 } else if (summary is UnlinkedParam) {
1051 if (summary.hasCodeRange) {
1052 offset = summary.codeOffset;
1053 length = summary.codeLength;
1054 }
1055 } else if (summary is UnlinkedTypedef) {
1056 if (summary.hasCodeRange) {
1057 offset = summary.codeOffset;
1058 length = summary.codeLength;
1059 }
1060 } else if (summary is UnlinkedTypeParam) {
1061 if (summary.hasCodeRange) {
1062 offset = summary.codeOffset;
1063 length = summary.codeLength;
1064 }
1065 } else if (summary is UnlinkedUnit) {
1066 if (summary.hasCodeRange) {
1067 offset = summary.codeOffset;
1068 length = summary.codeLength;
1069 }
1070 } else if (summary is UnlinkedVariable) {
1071 if (summary.hasCodeRange) {
1072 offset = summary.codeOffset;
1073 length = summary.codeLength;
1074 }
1075 }
1076 if (offset != null) {
1077 element.setCodeRange(offset, length);
1078 }
1079 }
1080
1031 /** 1081 /**
1032 * Resynthesize a [NamespaceCombinator]. 1082 * Resynthesize a [NamespaceCombinator].
1033 */ 1083 */
1034 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) { 1084 NamespaceCombinator buildCombinator(UnlinkedCombinator serializedCombinator) {
1035 if (serializedCombinator.shows.isNotEmpty) { 1085 if (serializedCombinator.shows.isNotEmpty) {
1036 ShowElementCombinatorImpl combinator = new ShowElementCombinatorImpl(); 1086 ShowElementCombinatorImpl combinator = new ShowElementCombinatorImpl();
1037 // Note: we call toList() so that we don't retain a reference to the 1087 // Note: we call toList() so that we don't retain a reference to the
1038 // deserialized data structure. 1088 // deserialized data structure.
1039 combinator.shownNames = serializedCombinator.shows.toList(); 1089 combinator.shownNames = serializedCombinator.shows.toList();
1040 combinator.offset = serializedCombinator.offset; 1090 combinator.offset = serializedCombinator.offset;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 void buildEnum(UnlinkedEnum serializedEnum) { 1194 void buildEnum(UnlinkedEnum serializedEnum) {
1145 assert(!isCoreLibrary); 1195 assert(!isCoreLibrary);
1146 ClassElementImpl classElement = 1196 ClassElementImpl classElement =
1147 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset); 1197 new ClassElementImpl(serializedEnum.name, serializedEnum.nameOffset);
1148 classElement.enum2 = true; 1198 classElement.enum2 = true;
1149 InterfaceType enumType = new InterfaceTypeImpl(classElement); 1199 InterfaceType enumType = new InterfaceTypeImpl(classElement);
1150 classElement.type = enumType; 1200 classElement.type = enumType;
1151 classElement.supertype = summaryResynthesizer.typeProvider.objectType; 1201 classElement.supertype = summaryResynthesizer.typeProvider.objectType;
1152 buildDocumentation(classElement, serializedEnum.documentationComment); 1202 buildDocumentation(classElement, serializedEnum.documentationComment);
1153 buildAnnotations(classElement, serializedEnum.annotations); 1203 buildAnnotations(classElement, serializedEnum.annotations);
1204 buildCodeRange(classElement, serializedEnum);
1154 ElementHolder memberHolder = new ElementHolder(); 1205 ElementHolder memberHolder = new ElementHolder();
1155 // Build the 'index' field. 1206 // Build the 'index' field.
1156 FieldElementImpl indexField = new FieldElementImpl('index', -1); 1207 FieldElementImpl indexField = new FieldElementImpl('index', -1);
1157 indexField.final2 = true; 1208 indexField.final2 = true;
1158 indexField.synthetic = true; 1209 indexField.synthetic = true;
1159 indexField.type = summaryResynthesizer.typeProvider.intType; 1210 indexField.type = summaryResynthesizer.typeProvider.intType;
1160 memberHolder.addField(indexField); 1211 memberHolder.addField(indexField);
1161 buildImplicitAccessors(indexField, memberHolder); 1212 buildImplicitAccessors(indexField, memberHolder);
1162 // Build the 'values' field. 1213 // Build the 'values' field.
1163 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1); 1214 FieldElementImpl valuesField = new ConstFieldElementImpl('values', -1);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 defaultVoid: isSetter && summaryResynthesizer.strongMode); 1350 defaultVoid: isSetter && summaryResynthesizer.strongMode);
1300 executableElement.hasImplicitReturnType = 1351 executableElement.hasImplicitReturnType =
1301 serializedExecutable.returnType == null; 1352 serializedExecutable.returnType == null;
1302 } 1353 }
1303 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs( 1354 executableElement.type = new FunctionTypeImpl.elementWithNameAndArgs(
1304 executableElement, null, getCurrentTypeArguments(skipLevels: 1), false); 1355 executableElement, null, getCurrentTypeArguments(skipLevels: 1), false);
1305 executableElement.external = serializedExecutable.isExternal; 1356 executableElement.external = serializedExecutable.isExternal;
1306 buildDocumentation( 1357 buildDocumentation(
1307 executableElement, serializedExecutable.documentationComment); 1358 executableElement, serializedExecutable.documentationComment);
1308 buildAnnotations(executableElement, serializedExecutable.annotations); 1359 buildAnnotations(executableElement, serializedExecutable.annotations);
1360 buildCodeRange(executableElement, serializedExecutable);
1309 executableElement.functions = 1361 executableElement.functions =
1310 serializedExecutable.localFunctions.map(buildLocalFunction).toList(); 1362 serializedExecutable.localFunctions.map(buildLocalFunction).toList();
1311 executableElement.labels = 1363 executableElement.labels =
1312 serializedExecutable.localLabels.map(buildLocalLabel).toList(); 1364 serializedExecutable.localLabels.map(buildLocalLabel).toList();
1313 executableElement.localVariables = 1365 executableElement.localVariables =
1314 serializedExecutable.localVariables.map(buildLocalVariable).toList(); 1366 serializedExecutable.localVariables.map(buildLocalVariable).toList();
1315 currentTypeParameters.removeLast(); 1367 currentTypeParameters.removeLast();
1316 } 1368 }
1317 1369
1318 /** 1370 /**
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 if (serializedParameter.defaultValue != null) { 1752 if (serializedParameter.defaultValue != null) {
1701 defaultParameter.constantInitializer = 1753 defaultParameter.constantInitializer =
1702 _buildConstExpression(serializedParameter.defaultValue); 1754 _buildConstExpression(serializedParameter.defaultValue);
1703 defaultParameter.defaultValueCode = 1755 defaultParameter.defaultValueCode =
1704 serializedParameter.defaultValueCode; 1756 serializedParameter.defaultValueCode;
1705 } 1757 }
1706 } 1758 }
1707 } 1759 }
1708 parameterElement.synthetic = synthetic; 1760 parameterElement.synthetic = synthetic;
1709 buildAnnotations(parameterElement, serializedParameter.annotations); 1761 buildAnnotations(parameterElement, serializedParameter.annotations);
1762 buildCodeRange(parameterElement, serializedParameter);
1710 if (serializedParameter.isFunctionTyped) { 1763 if (serializedParameter.isFunctionTyped) {
1711 FunctionElementImpl parameterTypeElement = 1764 FunctionElementImpl parameterTypeElement =
1712 new FunctionElementImpl('', -1); 1765 new FunctionElementImpl('', -1);
1713 parameterTypeElement.synthetic = true; 1766 parameterTypeElement.synthetic = true;
1714 parameterElement.parameters = 1767 parameterElement.parameters =
1715 serializedParameter.parameters.map(buildParameter).toList(); 1768 serializedParameter.parameters.map(buildParameter).toList();
1716 parameterTypeElement.enclosingElement = parameterElement; 1769 parameterTypeElement.enclosingElement = parameterElement;
1717 parameterTypeElement.shareParameters(parameterElement.parameters); 1770 parameterTypeElement.shareParameters(parameterElement.parameters);
1718 parameterTypeElement.returnType = buildType(serializedParameter.type); 1771 parameterTypeElement.returnType = buildType(serializedParameter.type);
1719 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs( 1772 parameterElement.type = new FunctionTypeImpl.elementWithNameAndArgs(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1833 buildTypeParameters(serializedTypedef.typeParameters); 1886 buildTypeParameters(serializedTypedef.typeParameters);
1834 functionTypeAliasElement.parameters = 1887 functionTypeAliasElement.parameters =
1835 serializedTypedef.parameters.map(buildParameter).toList(); 1888 serializedTypedef.parameters.map(buildParameter).toList();
1836 functionTypeAliasElement.returnType = 1889 functionTypeAliasElement.returnType =
1837 buildType(serializedTypedef.returnType); 1890 buildType(serializedTypedef.returnType);
1838 functionTypeAliasElement.type = 1891 functionTypeAliasElement.type =
1839 new FunctionTypeImpl.forTypedef(functionTypeAliasElement); 1892 new FunctionTypeImpl.forTypedef(functionTypeAliasElement);
1840 buildDocumentation( 1893 buildDocumentation(
1841 functionTypeAliasElement, serializedTypedef.documentationComment); 1894 functionTypeAliasElement, serializedTypedef.documentationComment);
1842 buildAnnotations(functionTypeAliasElement, serializedTypedef.annotations); 1895 buildAnnotations(functionTypeAliasElement, serializedTypedef.annotations);
1896 buildCodeRange(functionTypeAliasElement, serializedTypedef);
1843 unitHolder.addTypeAlias(functionTypeAliasElement); 1897 unitHolder.addTypeAlias(functionTypeAliasElement);
1844 currentTypeParameters.removeLast(); 1898 currentTypeParameters.removeLast();
1845 assert(currentTypeParameters.isEmpty); 1899 assert(currentTypeParameters.isEmpty);
1846 } 1900 }
1847 1901
1848 /** 1902 /**
1849 * Resynthesize a [TypeParameterElement], handling all parts of its except 1903 * Resynthesize a [TypeParameterElement], handling all parts of its except
1850 * its bound. 1904 * its bound.
1851 * 1905 *
1852 * The bound is deferred until later since it may refer to other type 1906 * The bound is deferred until later since it may refer to other type
1853 * parameters that have not been resynthesized yet. To handle the bound, 1907 * parameters that have not been resynthesized yet. To handle the bound,
1854 * call [finishTypeParameter]. 1908 * call [finishTypeParameter].
1855 */ 1909 */
1856 TypeParameterElement buildTypeParameter( 1910 TypeParameterElement buildTypeParameter(
1857 UnlinkedTypeParam serializedTypeParameter) { 1911 UnlinkedTypeParam serializedTypeParameter) {
1858 TypeParameterElementImpl typeParameterElement = 1912 TypeParameterElementImpl typeParameterElement =
1859 new TypeParameterElementImpl( 1913 new TypeParameterElementImpl(
1860 serializedTypeParameter.name, serializedTypeParameter.nameOffset); 1914 serializedTypeParameter.name, serializedTypeParameter.nameOffset);
1861 typeParameterElement.type = new TypeParameterTypeImpl(typeParameterElement); 1915 typeParameterElement.type = new TypeParameterTypeImpl(typeParameterElement);
1862 buildAnnotations(typeParameterElement, serializedTypeParameter.annotations); 1916 buildAnnotations(typeParameterElement, serializedTypeParameter.annotations);
1917 buildCodeRange(typeParameterElement, serializedTypeParameter);
1863 return typeParameterElement; 1918 return typeParameterElement;
1864 } 1919 }
1865 1920
1866 /** 1921 /**
1867 * Build [TypeParameterElement]s corresponding to the type parameters in 1922 * Build [TypeParameterElement]s corresponding to the type parameters in
1868 * [serializedTypeParameters] and store them in [currentTypeParameters]. 1923 * [serializedTypeParameters] and store them in [currentTypeParameters].
1869 * Also return them. 1924 * Also return them.
1870 */ 1925 */
1871 List<TypeParameterElement> buildTypeParameters( 1926 List<TypeParameterElement> buildTypeParameters(
1872 List<UnlinkedTypeParam> serializedTypeParameters) { 1927 List<UnlinkedTypeParam> serializedTypeParameters) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1926 void buildVariableCommonParts( 1981 void buildVariableCommonParts(
1927 VariableElementImpl element, UnlinkedVariable serializedVariable) { 1982 VariableElementImpl element, UnlinkedVariable serializedVariable) {
1928 element.type = buildLinkedType(serializedVariable.inferredTypeSlot) ?? 1983 element.type = buildLinkedType(serializedVariable.inferredTypeSlot) ??
1929 buildType(serializedVariable.type); 1984 buildType(serializedVariable.type);
1930 element.const3 = serializedVariable.isConst; 1985 element.const3 = serializedVariable.isConst;
1931 element.final2 = serializedVariable.isFinal; 1986 element.final2 = serializedVariable.isFinal;
1932 element.hasImplicitType = serializedVariable.type == null; 1987 element.hasImplicitType = serializedVariable.type == null;
1933 buildVariableInitializer(element, serializedVariable.initializer); 1988 buildVariableInitializer(element, serializedVariable.initializer);
1934 buildDocumentation(element, serializedVariable.documentationComment); 1989 buildDocumentation(element, serializedVariable.documentationComment);
1935 buildAnnotations(element, serializedVariable.annotations); 1990 buildAnnotations(element, serializedVariable.annotations);
1991 buildCodeRange(element, serializedVariable);
1936 } 1992 }
1937 1993
1938 /** 1994 /**
1939 * If the given [serializedInitializer] is not `null`, create the 1995 * If the given [serializedInitializer] is not `null`, create the
1940 * corresponding [FunctionElementImpl] and set it for the [variable]. 1996 * corresponding [FunctionElementImpl] and set it for the [variable].
1941 */ 1997 */
1942 void buildVariableInitializer( 1998 void buildVariableInitializer(
1943 VariableElementImpl variable, UnlinkedExecutable serializedInitializer) { 1999 VariableElementImpl variable, UnlinkedExecutable serializedInitializer) {
1944 if (serializedInitializer == null) { 2000 if (serializedInitializer == null) {
1945 return null; 2001 return null;
1946 } 2002 }
1947 FunctionElementImpl initializerElement = 2003 FunctionElementImpl initializerElement =
1948 buildLocalFunction(serializedInitializer); 2004 buildLocalFunction(serializedInitializer);
1949 initializerElement.synthetic = true; 2005 initializerElement.synthetic = true;
2006 initializerElement.setCodeRange(null, null);
1950 variable.initializer = initializerElement; 2007 variable.initializer = initializerElement;
1951 } 2008 }
1952 2009
1953 /** 2010 /**
1954 * Finish creating a [TypeParameterElement] by deserializing its bound. 2011 * Finish creating a [TypeParameterElement] by deserializing its bound.
1955 */ 2012 */
1956 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, 2013 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter,
1957 TypeParameterElementImpl typeParameterElement) { 2014 TypeParameterElementImpl typeParameterElement) {
1958 if (serializedTypeParameter.bound != null) { 2015 if (serializedTypeParameter.bound != null) {
1959 typeParameterElement.bound = buildType(serializedTypeParameter.bound); 2016 typeParameterElement.bound = buildType(serializedTypeParameter.bound);
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
2197 } 2254 }
2198 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) { 2255 for (FunctionTypeAliasElement typeAlias in unit.functionTypeAliases) {
2199 elementMap[typeAlias.name] = typeAlias; 2256 elementMap[typeAlias.name] = typeAlias;
2200 } 2257 }
2201 for (FunctionElement function in unit.functions) { 2258 for (FunctionElement function in unit.functions) {
2202 elementMap[function.name] = function; 2259 elementMap[function.name] = function;
2203 } 2260 }
2204 for (PropertyAccessorElementImpl accessor in unit.accessors) { 2261 for (PropertyAccessorElementImpl accessor in unit.accessors) {
2205 elementMap[accessor.identifier] = accessor; 2262 elementMap[accessor.identifier] = accessor;
2206 } 2263 }
2264 buildCodeRange(unit, unlinkedUnit);
2207 resynthesizedUnits[absoluteUri] = unit; 2265 resynthesizedUnits[absoluteUri] = unit;
2208 resynthesizedElements[absoluteUri] = elementMap; 2266 resynthesizedElements[absoluteUri] = elementMap;
2209 assert(currentTypeParameters.isEmpty); 2267 assert(currentTypeParameters.isEmpty);
2210 } 2268 }
2211 2269
2212 /** 2270 /**
2213 * Set up data structures for deserializing a compilation unit. 2271 * Set up data structures for deserializing a compilation unit.
2214 */ 2272 */
2215 void prepareUnit(CompilationUnitElementImpl unit, int unitNum) { 2273 void prepareUnit(CompilationUnitElementImpl unit, int unitNum) {
2216 linkedUnit = linkedLibrary.units[unitNum]; 2274 linkedUnit = linkedLibrary.units[unitNum];
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
2457 List<DartType> typeArguments = const <DartType>[]; 2515 List<DartType> typeArguments = const <DartType>[];
2458 if (numTypeArguments != 0) { 2516 if (numTypeArguments != 0) {
2459 typeArguments = <DartType>[]; 2517 typeArguments = <DartType>[];
2460 for (int i = 0; i < numTypeArguments; i++) { 2518 for (int i = 0; i < numTypeArguments; i++) {
2461 typeArguments.add(getTypeArgument(i)); 2519 typeArguments.add(getTypeArgument(i));
2462 } 2520 }
2463 } 2521 }
2464 return typeArguments; 2522 return typeArguments;
2465 } 2523 }
2466 } 2524 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698