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

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

Issue 1610043002: Add propagated types to summary files. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 * The [LinkedUnit] from which elements are currently being resynthesized. 255 * The [LinkedUnit] from which elements are currently being resynthesized.
256 */ 256 */
257 LinkedUnit linkedUnit; 257 LinkedUnit linkedUnit;
258 258
259 /** 259 /**
260 * The [UnlinkedUnit] from which elements are currently being resynthesized. 260 * The [UnlinkedUnit] from which elements are currently being resynthesized.
261 */ 261 */
262 UnlinkedUnit unlinkedUnit; 262 UnlinkedUnit unlinkedUnit;
263 263
264 /** 264 /**
265 * Map from slot id to the corresponding [TypeRef] object for linked types
266 * (i.e. propagated and inferred types).
267 */
268 Map<int, TypeRef> linkedTypeMap;
269
270 /**
265 * Map of top level elements that have been resynthesized so far. The first 271 * Map of top level elements that have been resynthesized so far. The first
266 * key is the URI of the compilation unit; the second is the name of the top 272 * key is the URI of the compilation unit; the second is the name of the top
267 * level element. 273 * level element.
268 */ 274 */
269 final Map<String, Map<String, Element>> resummarizedElements = 275 final Map<String, Map<String, Element>> resummarizedElements =
270 <String, Map<String, Element>>{}; 276 <String, Map<String, Element>>{};
271 277
272 /** 278 /**
273 * Type parameters for the generic class, typedef, or executable currently 279 * Type parameters for the generic class, typedef, or executable currently
274 * being resynthesized, if any. If multiple entities with type parameters 280 * being resynthesized, if any. If multiple entities with type parameters
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 // Dart SDK client to initialize TypeProvider and finish the dart:core and 859 // Dart SDK client to initialize TypeProvider and finish the dart:core and
854 // dart:async libraries creation. 860 // dart:async libraries creation.
855 if (library.name != 'dart.core' && library.name != 'dart.async') { 861 if (library.name != 'dart.core' && library.name != 'dart.async') {
856 library.createLoadLibraryFunction(summaryResynthesizer.typeProvider); 862 library.createLoadLibraryFunction(summaryResynthesizer.typeProvider);
857 } 863 }
858 // Done. 864 // Done.
859 return library; 865 return library;
860 } 866 }
861 867
862 /** 868 /**
869 * Build the appropriate [DartType] object corresponding to a slot id in the
870 * [LinkedUnit.types] table.
871 */
872 DartType buildLinkedType(int slot) {
873 if (slot == 0) {
874 // A slot id of 0 means there is no [DartType] object to build.
875 return null;
876 }
877 TypeRef type = linkedTypeMap[slot];
878 if (type == null) {
879 // A missing entry in [LinkedUnit.types] means there is no [DartType]
880 // stored in this slot.
881 return null;
882 }
883 return buildType(type);
884 }
885
886 /**
863 * Resynthesize a [ParameterElement]. 887 * Resynthesize a [ParameterElement].
864 */ 888 */
865 ParameterElement buildParameter(UnlinkedParam serializedParameter) { 889 ParameterElement buildParameter(UnlinkedParam serializedParameter) {
866 ParameterElementImpl parameterElement; 890 ParameterElementImpl parameterElement;
867 if (serializedParameter.isInitializingFormal) { 891 if (serializedParameter.isInitializingFormal) {
868 parameterElement = new FieldFormalParameterElementImpl.forNameAndOffset( 892 parameterElement = new FieldFormalParameterElementImpl.forNameAndOffset(
869 serializedParameter.name, serializedParameter.nameOffset) 893 serializedParameter.name, serializedParameter.nameOffset)
870 ..field = fields[serializedParameter.name]; 894 ..field = fields[serializedParameter.name];
871 } else { 895 } else {
872 parameterElement = new ParameterElementImpl( 896 parameterElement = new ParameterElementImpl(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 if (type.paramReference != 0) { 964 if (type.paramReference != 0) {
941 // TODO(paulberry): make this work for generic methods. 965 // TODO(paulberry): make this work for generic methods.
942 return currentTypeParameters[ 966 return currentTypeParameters[
943 currentTypeParameters.length - type.paramReference].type; 967 currentTypeParameters.length - type.paramReference].type;
944 } else { 968 } else {
945 // TODO(paulberry): handle references to things other than classes (note: 969 // TODO(paulberry): handle references to things other than classes (note:
946 // this should only occur in the case of erroneous code). 970 // this should only occur in the case of erroneous code).
947 // TODO(paulberry): test reference to something inside a part. 971 // TODO(paulberry): test reference to something inside a part.
948 // TODO(paulberry): test reference to something inside a part of the 972 // TODO(paulberry): test reference to something inside a part of the
949 // current lib. 973 // current lib.
950 UnlinkedReference reference = unlinkedUnit.references[type.reference];
951 LinkedReference referenceResolution = 974 LinkedReference referenceResolution =
952 linkedUnit.references[type.reference]; 975 linkedUnit.references[type.reference];
976 String name;
977 if (type.reference < unlinkedUnit.references.length) {
978 name = unlinkedUnit.references[type.reference].name;
979 } else {
980 name = referenceResolution.name;
981 }
953 ElementLocationImpl location; 982 ElementLocationImpl location;
954 if (referenceResolution.dependency != 0) { 983 if (referenceResolution.dependency != 0) {
955 location = getReferencedLocation( 984 location = getReferencedLocation(
956 linkedLibrary.dependencies[referenceResolution.dependency], 985 linkedLibrary.dependencies[referenceResolution.dependency],
957 referenceResolution.unit, 986 referenceResolution.unit,
958 reference.name); 987 name);
959 } else if (referenceResolution.kind == ReferenceKind.unresolved) { 988 } else if (referenceResolution.kind == ReferenceKind.unresolved) {
960 return summaryResynthesizer.typeProvider.undefinedType; 989 return summaryResynthesizer.typeProvider.undefinedType;
961 } else if (reference.name.isEmpty) { 990 } else if (name.isEmpty) {
962 return summaryResynthesizer.typeProvider.dynamicType; 991 return summaryResynthesizer.typeProvider.dynamicType;
963 } else { 992 } else {
964 String referencedLibraryUri = librarySource.uri.toString(); 993 String referencedLibraryUri = librarySource.uri.toString();
965 String partUri; 994 String partUri;
966 if (referenceResolution.unit != 0) { 995 if (referenceResolution.unit != 0) {
967 String uri = unlinkedUnits[0].publicNamespace.parts[ 996 String uri = unlinkedUnits[0].publicNamespace.parts[
968 referenceResolution.unit - 1]; 997 referenceResolution.unit - 1];
969 Source partSource = 998 Source partSource =
970 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri); 999 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri);
971 partUri = partSource.uri.toString(); 1000 partUri = partSource.uri.toString();
972 } else { 1001 } else {
973 partUri = referencedLibraryUri; 1002 partUri = referencedLibraryUri;
974 } 1003 }
975 location = new ElementLocationImpl.con3( 1004 location = new ElementLocationImpl.con3(
976 <String>[referencedLibraryUri, partUri, reference.name]); 1005 <String>[referencedLibraryUri, partUri, name]);
977 } 1006 }
978 List<DartType> typeArguments = const <DartType>[]; 1007 List<DartType> typeArguments = const <DartType>[];
979 if (referenceResolution.numTypeParameters != 0) { 1008 if (referenceResolution.numTypeParameters != 0) {
980 typeArguments = <DartType>[]; 1009 typeArguments = <DartType>[];
981 for (int i = 0; i < referenceResolution.numTypeParameters; i++) { 1010 for (int i = 0; i < referenceResolution.numTypeParameters; i++) {
982 if (i < type.typeArguments.length) { 1011 if (i < type.typeArguments.length) {
983 typeArguments.add(buildType(type.typeArguments[i])); 1012 typeArguments.add(buildType(type.typeArguments[i]));
984 } else { 1013 } else {
985 typeArguments.add(summaryResynthesizer.typeProvider.dynamicType); 1014 typeArguments.add(summaryResynthesizer.typeProvider.dynamicType);
986 } 1015 }
987 } 1016 }
988 } 1017 }
989 switch (referenceResolution.kind) { 1018 switch (referenceResolution.kind) {
990 case ReferenceKind.classOrEnum: 1019 case ReferenceKind.classOrEnum:
991 return new InterfaceTypeImpl.elementWithNameAndArgs( 1020 return new InterfaceTypeImpl.elementWithNameAndArgs(
992 new ClassElementHandle(summaryResynthesizer, location), 1021 new ClassElementHandle(summaryResynthesizer, location),
993 reference.name, 1022 name,
994 typeArguments); 1023 typeArguments);
995 case ReferenceKind.typedef: 1024 case ReferenceKind.typedef:
996 return new FunctionTypeImpl.elementWithNameAndArgs( 1025 return new FunctionTypeImpl.elementWithNameAndArgs(
997 new FunctionTypeAliasElementHandle( 1026 new FunctionTypeAliasElementHandle(
998 summaryResynthesizer, location), 1027 summaryResynthesizer, location),
999 reference.name, 1028 name,
1000 typeArguments, 1029 typeArguments,
1001 typeArguments.isNotEmpty); 1030 typeArguments.isNotEmpty);
1002 default: 1031 default:
1003 // TODO(paulberry): figure out how to handle this case (which should 1032 // TODO(paulberry): figure out how to handle this case (which should
1004 // only occur in the event of erroneous code). 1033 // only occur in the event of erroneous code).
1005 throw new UnimplementedError(); 1034 throw new UnimplementedError();
1006 } 1035 }
1007 } 1036 }
1008 } 1037 }
1009 1038
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 1111
1083 /** 1112 /**
1084 * Handle the parts that are common to top level variables and fields. 1113 * Handle the parts that are common to top level variables and fields.
1085 */ 1114 */
1086 void buildVariableCommonParts(PropertyInducingElementImpl element, 1115 void buildVariableCommonParts(PropertyInducingElementImpl element,
1087 UnlinkedVariable serializedVariable) { 1116 UnlinkedVariable serializedVariable) {
1088 element.type = buildType(serializedVariable.type); 1117 element.type = buildType(serializedVariable.type);
1089 element.const3 = serializedVariable.isConst; 1118 element.const3 = serializedVariable.isConst;
1090 element.final2 = serializedVariable.isFinal; 1119 element.final2 = serializedVariable.isFinal;
1091 element.hasImplicitType = serializedVariable.hasImplicitType; 1120 element.hasImplicitType = serializedVariable.hasImplicitType;
1121 element.propagatedType =
1122 buildLinkedType(serializedVariable.propagatedTypeSlot);
1092 buildDocumentation(element, serializedVariable.documentationComment); 1123 buildDocumentation(element, serializedVariable.documentationComment);
1093 } 1124 }
1094 1125
1095 /** 1126 /**
1096 * Finish creating a [TypeParameterElement] by deserializing its bound. 1127 * Finish creating a [TypeParameterElement] by deserializing its bound.
1097 */ 1128 */
1098 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter, 1129 void finishTypeParameter(UnlinkedTypeParam serializedTypeParameter,
1099 TypeParameterElementImpl typeParameterElement) { 1130 TypeParameterElementImpl typeParameterElement) {
1100 if (serializedTypeParameter.bound != null) { 1131 if (serializedTypeParameter.bound != null) {
1101 typeParameterElement.bound = buildType(serializedTypeParameter.bound); 1132 typeParameterElement.bound = buildType(serializedTypeParameter.bound);
(...skipping 28 matching lines...) Expand all
1130 <String>[referencedLibraryUri, partUri, name]); 1161 <String>[referencedLibraryUri, partUri, name]);
1131 } 1162 }
1132 1163
1133 /** 1164 /**
1134 * Populate a [CompilationUnitElement] by deserializing all the elements 1165 * Populate a [CompilationUnitElement] by deserializing all the elements
1135 * contained in it. 1166 * contained in it.
1136 */ 1167 */
1137 void populateUnit(CompilationUnitElementImpl unit, int unitNum) { 1168 void populateUnit(CompilationUnitElementImpl unit, int unitNum) {
1138 linkedUnit = linkedLibrary.units[unitNum]; 1169 linkedUnit = linkedLibrary.units[unitNum];
1139 unlinkedUnit = unlinkedUnits[unitNum]; 1170 unlinkedUnit = unlinkedUnits[unitNum];
1171 linkedTypeMap = <int, TypeRef>{};
1172 for (TypeRef t in linkedUnit.types) {
1173 linkedTypeMap[t.slot] = t;
1174 }
1140 unitHolder = new ElementHolder(); 1175 unitHolder = new ElementHolder();
1141 unlinkedUnit.classes.forEach(buildClass); 1176 unlinkedUnit.classes.forEach(buildClass);
1142 unlinkedUnit.enums.forEach(buildEnum); 1177 unlinkedUnit.enums.forEach(buildEnum);
1143 unlinkedUnit.executables.forEach(buildExecutable); 1178 unlinkedUnit.executables.forEach(buildExecutable);
1144 unlinkedUnit.typedefs.forEach(buildTypedef); 1179 unlinkedUnit.typedefs.forEach(buildTypedef);
1145 unlinkedUnit.variables.forEach(buildVariable); 1180 unlinkedUnit.variables.forEach(buildVariable);
1146 String absoluteUri = unit.source.uri.toString(); 1181 String absoluteUri = unit.source.uri.toString();
1147 unit.accessors = unitHolder.accessors; 1182 unit.accessors = unitHolder.accessors;
1148 unit.enums = unitHolder.enums; 1183 unit.enums = unitHolder.enums;
1149 unit.functions = unitHolder.functions; 1184 unit.functions = unitHolder.functions;
(...skipping 19 matching lines...) Expand all
1169 for (FunctionElement function in unit.functions) { 1204 for (FunctionElement function in unit.functions) {
1170 elementMap[function.name] = function; 1205 elementMap[function.name] = function;
1171 } 1206 }
1172 for (PropertyAccessorElementImpl accessor in unit.accessors) { 1207 for (PropertyAccessorElementImpl accessor in unit.accessors) {
1173 elementMap[accessor.identifier] = accessor; 1208 elementMap[accessor.identifier] = accessor;
1174 } 1209 }
1175 resummarizedElements[absoluteUri] = elementMap; 1210 resummarizedElements[absoluteUri] = elementMap;
1176 unitHolder = null; 1211 unitHolder = null;
1177 linkedUnit = null; 1212 linkedUnit = null;
1178 unlinkedUnit = null; 1213 unlinkedUnit = null;
1214 linkedTypeMap = null;
1179 } 1215 }
1180 } 1216 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/prelink.dart ('k') | pkg/analyzer/lib/src/summary/summarize_ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698