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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/resynthesize.dart
diff --git a/pkg/analyzer/lib/src/summary/resynthesize.dart b/pkg/analyzer/lib/src/summary/resynthesize.dart
index 3e4d121ea1297beceff4263a0baeb96e7dcecdae..098ec1e97a4a844e81d30defc5084a3f8a182f87 100644
--- a/pkg/analyzer/lib/src/summary/resynthesize.dart
+++ b/pkg/analyzer/lib/src/summary/resynthesize.dart
@@ -262,6 +262,12 @@ class _LibraryResynthesizer {
UnlinkedUnit unlinkedUnit;
/**
+ * Map from slot id to the corresponding [TypeRef] object for linked types
+ * (i.e. propagated and inferred types).
+ */
+ Map<int, TypeRef> linkedTypeMap;
+
+ /**
* Map of top level elements that have been resynthesized so far. The first
* key is the URI of the compilation unit; the second is the name of the top
* level element.
@@ -860,6 +866,24 @@ class _LibraryResynthesizer {
}
/**
+ * Build the appropriate [DartType] object corresponding to a slot id in the
+ * [LinkedUnit.types] table.
+ */
+ DartType buildLinkedType(int slot) {
+ if (slot == 0) {
+ // A slot id of 0 means there is no [DartType] object to build.
+ return null;
+ }
+ TypeRef type = linkedTypeMap[slot];
+ if (type == null) {
+ // A missing entry in [LinkedUnit.types] means there is no [DartType]
+ // stored in this slot.
+ return null;
+ }
+ return buildType(type);
+ }
+
+ /**
* Resynthesize a [ParameterElement].
*/
ParameterElement buildParameter(UnlinkedParam serializedParameter) {
@@ -947,18 +971,23 @@ class _LibraryResynthesizer {
// TODO(paulberry): test reference to something inside a part.
// TODO(paulberry): test reference to something inside a part of the
// current lib.
- UnlinkedReference reference = unlinkedUnit.references[type.reference];
LinkedReference referenceResolution =
linkedUnit.references[type.reference];
+ String name;
+ if (type.reference < unlinkedUnit.references.length) {
+ name = unlinkedUnit.references[type.reference].name;
+ } else {
+ name = referenceResolution.name;
+ }
ElementLocationImpl location;
if (referenceResolution.dependency != 0) {
location = getReferencedLocation(
linkedLibrary.dependencies[referenceResolution.dependency],
referenceResolution.unit,
- reference.name);
+ name);
} else if (referenceResolution.kind == ReferenceKind.unresolved) {
return summaryResynthesizer.typeProvider.undefinedType;
- } else if (reference.name.isEmpty) {
+ } else if (name.isEmpty) {
return summaryResynthesizer.typeProvider.dynamicType;
} else {
String referencedLibraryUri = librarySource.uri.toString();
@@ -973,7 +1002,7 @@ class _LibraryResynthesizer {
partUri = referencedLibraryUri;
}
location = new ElementLocationImpl.con3(
- <String>[referencedLibraryUri, partUri, reference.name]);
+ <String>[referencedLibraryUri, partUri, name]);
}
List<DartType> typeArguments = const <DartType>[];
if (referenceResolution.numTypeParameters != 0) {
@@ -990,13 +1019,13 @@ class _LibraryResynthesizer {
case ReferenceKind.classOrEnum:
return new InterfaceTypeImpl.elementWithNameAndArgs(
new ClassElementHandle(summaryResynthesizer, location),
- reference.name,
+ name,
typeArguments);
case ReferenceKind.typedef:
return new FunctionTypeImpl.elementWithNameAndArgs(
new FunctionTypeAliasElementHandle(
summaryResynthesizer, location),
- reference.name,
+ name,
typeArguments,
typeArguments.isNotEmpty);
default:
@@ -1089,6 +1118,8 @@ class _LibraryResynthesizer {
element.const3 = serializedVariable.isConst;
element.final2 = serializedVariable.isFinal;
element.hasImplicitType = serializedVariable.hasImplicitType;
+ element.propagatedType =
+ buildLinkedType(serializedVariable.propagatedTypeSlot);
buildDocumentation(element, serializedVariable.documentationComment);
}
@@ -1137,6 +1168,10 @@ class _LibraryResynthesizer {
void populateUnit(CompilationUnitElementImpl unit, int unitNum) {
linkedUnit = linkedLibrary.units[unitNum];
unlinkedUnit = unlinkedUnits[unitNum];
+ linkedTypeMap = <int, TypeRef>{};
+ for (TypeRef t in linkedUnit.types) {
+ linkedTypeMap[t.slot] = t;
+ }
unitHolder = new ElementHolder();
unlinkedUnit.classes.forEach(buildClass);
unlinkedUnit.enums.forEach(buildEnum);
@@ -1176,5 +1211,6 @@ class _LibraryResynthesizer {
unitHolder = null;
linkedUnit = null;
unlinkedUnit = null;
+ linkedTypeMap = null;
}
}
« 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