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

Unified Diff: pkg/compiler/lib/src/serialization/element_serialization.dart

Issue 2150533002: Serialize data for LibraryElement.getImportsFor (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 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
Index: pkg/compiler/lib/src/serialization/element_serialization.dart
diff --git a/pkg/compiler/lib/src/serialization/element_serialization.dart b/pkg/compiler/lib/src/serialization/element_serialization.dart
index 8e57a3819a72b3a693ef4e6558883b3914e6316c..3a63bbc7e14b90f69ec2a5c426ae837555062f9d 100644
--- a/pkg/compiler/lib/src/serialization/element_serialization.dart
+++ b/pkg/compiler/lib/src/serialization/element_serialization.dart
@@ -293,8 +293,52 @@ class LibrarySerializer implements ElementSerializer {
encoder.setElements(Key.IMPORTS, getImports(element));
encoder.setElements(Key.EXPORTS, element.exports);
- encoder.setElements(Key.IMPORT_SCOPE, getImportedElements(element));
+ List<Element> importedElements = getImportedElements(element);
+ encoder.setElements(Key.IMPORT_SCOPE, importedElements);
encoder.setElements(Key.EXPORT_SCOPE, getExportedElements(element));
+
+ Map<Element, Iterable<ImportElement>> importsForMap =
+ <Element, Iterable<ImportElement>>{};
+
+ /// Map imports for [importedElement] in importsForMap.
+ ///
+ /// Imports are mapped to [AbstractFieldElement] which are not serialized
+ /// so we use getter (or setter if there is no getter) as the key.
+ void addImportsForElement(Element importedElement) {
+ Element key = importedElement;
+ if (importedElement.isDeferredLoaderGetter) {
+ // Use [importedElement].
+ } else if (importedElement.isGetter) {
+ GetterElement getter = importedElement;
+ importedElement = getter.abstractField;
+ } else if (importedElement.isSetter) {
+ SetterElement setter = importedElement;
+ if (setter.getter != null) {
+ return;
+ }
+ importedElement = setter.abstractField;
+ }
+ importsForMap.putIfAbsent(
+ key, () => element.getImportsFor(importedElement));
+ }
+
+ for (ImportElement import in getImports(element)) {
+ if (import.prefix != null) {
+ Set<Element> importedElements = new Set<Element>();
+ import.prefix.forEachLocalMember(
+ SerializerUtil.flattenElements(importedElements));
+ importedElements.forEach(addImportsForElement);
+ }
+ }
+ importedElements.forEach(addImportsForElement);
+
+ ListEncoder importsForEncoder = encoder.createList(Key.IMPORTS_FOR);
+ importsForMap
+ .forEach((Element importedElement, Iterable<ImportElement> imports) {
+ ObjectEncoder objectEncoder = importsForEncoder.createObject();
+ objectEncoder.setElement(Key.ELEMENT, importedElement);
+ objectEncoder.setElements(Key.IMPORTS, imports);
+ });
}
}

Powered by Google App Engine
This is Rietveld 408576698