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

Side by Side 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 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 dart2js.serialization.elements; 5 library dart2js.serialization.elements;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/names.dart'; 8 import '../common/names.dart';
9 import '../constants/constructors.dart'; 9 import '../constants/constructors.dart';
10 import '../constants/expressions.dart'; 10 import '../constants/expressions.dart';
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 SerializerUtil.serializeMetadata(element, encoder); 286 SerializerUtil.serializeMetadata(element, encoder);
287 encoder.setUri( 287 encoder.setUri(
288 Key.CANONICAL_URI, element.canonicalUri, element.canonicalUri); 288 Key.CANONICAL_URI, element.canonicalUri, element.canonicalUri);
289 encoder.setString(Key.LIBRARY_NAME, element.libraryName); 289 encoder.setString(Key.LIBRARY_NAME, element.libraryName);
290 SerializerUtil.serializeMembers(getMembers(element), encoder); 290 SerializerUtil.serializeMembers(getMembers(element), encoder);
291 encoder.setElement(Key.COMPILATION_UNIT, element.entryCompilationUnit); 291 encoder.setElement(Key.COMPILATION_UNIT, element.entryCompilationUnit);
292 encoder.setElements(Key.COMPILATION_UNITS, getCompilationUnits(element)); 292 encoder.setElements(Key.COMPILATION_UNITS, getCompilationUnits(element));
293 encoder.setElements(Key.IMPORTS, getImports(element)); 293 encoder.setElements(Key.IMPORTS, getImports(element));
294 encoder.setElements(Key.EXPORTS, element.exports); 294 encoder.setElements(Key.EXPORTS, element.exports);
295 295
296 encoder.setElements(Key.IMPORT_SCOPE, getImportedElements(element)); 296 List<Element> importedElements = getImportedElements(element);
297 encoder.setElements(Key.IMPORT_SCOPE, importedElements);
297 encoder.setElements(Key.EXPORT_SCOPE, getExportedElements(element)); 298 encoder.setElements(Key.EXPORT_SCOPE, getExportedElements(element));
299
300 Map<Element, Iterable<ImportElement>> importsForMap =
301 <Element, Iterable<ImportElement>>{};
302
303 /// Map imports for [importedElement] in importsForMap.
304 ///
305 /// Imports are mapped to [AbstractFieldElement] which are not serialized
306 /// so we use getter (or setter if there is no getter) as the key.
307 void addImportsForElement(Element importedElement) {
308 Element key = importedElement;
309 if (importedElement.isDeferredLoaderGetter) {
310 // Use [importedElement].
311 } else if (importedElement.isGetter) {
312 GetterElement getter = importedElement;
313 importedElement = getter.abstractField;
314 } else if (importedElement.isSetter) {
315 SetterElement setter = importedElement;
316 if (setter.getter != null) {
317 return;
318 }
319 importedElement = setter.abstractField;
320 }
321 importsForMap.putIfAbsent(
322 key, () => element.getImportsFor(importedElement));
323 }
324
325 for (ImportElement import in getImports(element)) {
326 if (import.prefix != null) {
327 Set<Element> importedElements = new Set<Element>();
328 import.prefix.forEachLocalMember(
329 SerializerUtil.flattenElements(importedElements));
330 importedElements.forEach(addImportsForElement);
331 }
332 }
333 importedElements.forEach(addImportsForElement);
334
335 ListEncoder importsForEncoder = encoder.createList(Key.IMPORTS_FOR);
336 importsForMap
337 .forEach((Element importedElement, Iterable<ImportElement> imports) {
338 ObjectEncoder objectEncoder = importsForEncoder.createObject();
339 objectEncoder.setElement(Key.ELEMENT, importedElement);
340 objectEncoder.setElements(Key.IMPORTS, imports);
341 });
298 } 342 }
299 } 343 }
300 344
301 class CompilationUnitSerializer implements ElementSerializer { 345 class CompilationUnitSerializer implements ElementSerializer {
302 const CompilationUnitSerializer(); 346 const CompilationUnitSerializer();
303 347
304 SerializedElementKind getSerializedKind(Element element) { 348 SerializedElementKind getSerializedKind(Element element) {
305 if (element.isCompilationUnit) { 349 if (element.isCompilationUnit) {
306 return SerializedElementKind.COMPILATION_UNIT; 350 return SerializedElementKind.COMPILATION_UNIT;
307 } 351 }
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 return new WarnOnUseElementX(warning, info, enclosing, element); 915 return new WarnOnUseElementX(warning, info, enclosing, element);
872 case SerializedElementKind.EXTERNAL_LIBRARY: 916 case SerializedElementKind.EXTERNAL_LIBRARY:
873 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: 917 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER:
874 case SerializedElementKind.EXTERNAL_CLASS_MEMBER: 918 case SerializedElementKind.EXTERNAL_CLASS_MEMBER:
875 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: 919 case SerializedElementKind.EXTERNAL_CONSTRUCTOR:
876 break; 920 break;
877 } 921 }
878 throw new UnsupportedError("Unexpected element kind '${elementKind}."); 922 throw new UnsupportedError("Unexpected element kind '${elementKind}.");
879 } 923 }
880 } 924 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698