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

Side by Side Diff: pkg/compiler/lib/src/serialization/serialization.dart

Issue 1811173003: Support per-library serialization. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 4 years, 8 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; 5 library dart2js.serialization;
6 6
7 import '../common/backend_api.dart';
8 import '../elements/elements.dart'; 7 import '../elements/elements.dart';
9 import '../constants/expressions.dart'; 8 import '../constants/expressions.dart';
10 import '../dart_types.dart'; 9 import '../dart_types.dart';
11 import '../universe/world_impact.dart';
12 10
13 import 'constant_serialization.dart'; 11 import 'constant_serialization.dart';
14 import 'element_serialization.dart'; 12 import 'element_serialization.dart';
15 import 'impact_serialization.dart';
16 import 'json_serializer.dart'; 13 import 'json_serializer.dart';
17 import 'keys.dart'; 14 import 'keys.dart';
18 import 'type_serialization.dart'; 15 import 'type_serialization.dart';
19 import 'values.dart'; 16 import 'values.dart';
20 17
21 /// An object that supports the encoding an [ObjectValue] for serialization. 18 /// An object that supports the encoding an [ObjectValue] for serialization.
22 /// 19 ///
23 /// The [ObjectEncoder] ensures that nominality and circularities of 20 /// The [ObjectEncoder] ensures that nominality and circularities of
24 /// non-primitive values like [Element], [DartType] and [ConstantExpression] are 21 /// non-primitive values like [Element], [DartType] and [ConstantExpression] are
25 /// handled. 22 /// handled.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 81
85 /// The name of the encoder kind. Use for error reporting. 82 /// The name of the encoder kind. Use for error reporting.
86 String get _name; 83 String get _name;
87 84
88 void _checkKey(K key) { 85 void _checkKey(K key) {
89 if (_map.containsKey(key)) { 86 if (_map.containsKey(key)) {
90 throw new StateError("$_name value '$key' already in $_map."); 87 throw new StateError("$_name value '$key' already in $_map.");
91 } 88 }
92 } 89 }
93 90
91 /// Maps the [key] entry to the [value] in the encoded object.
92 void setValue(K key, Value value) {
93 _checkKey(key);
94 _map[key] = value;
95 }
96
97
94 /// Maps the [key] entry to the enum [value] in the encoded object. 98 /// Maps the [key] entry to the enum [value] in the encoded object.
95 void setEnum(K key, var value) { 99 void setEnum(K key, var value) {
96 _checkKey(key); 100 _checkKey(key);
97 _map[key] = new EnumValue(value); 101 _map[key] = new EnumValue(value);
98 } 102 }
99 103
100 /// Maps the [key] entry to the [element] in the encoded object. 104 /// Maps the [key] entry to the [element] in the encoded object.
101 void setElement(K key, Element element) { 105 void setElement(K key, Element element) {
102 _checkKey(key); 106 _checkKey(key);
103 _map[key] = _serializer.createElementValue(element); 107 _map[key] = _serializer.createElementValue(element);
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 final ObjectValue objectValue; 578 final ObjectValue objectValue;
575 579
576 DataObject(Value id, EnumValue kind) 580 DataObject(Value id, EnumValue kind)
577 : this.id = id, 581 : this.id = id,
578 this.objectValue = 582 this.objectValue =
579 new ObjectValue(<Key, Value>{Key.ID: id, Key.KIND: kind}); 583 new ObjectValue(<Key, Value>{Key.ID: id, Key.KIND: kind});
580 584
581 Map<Key, Value> get map => objectValue.map; 585 Map<Key, Value> get map => objectValue.map;
582 } 586 }
583 587
588 /// Function used to filter which element serialized.
589 typedef bool ElementMatcher(Element element);
590
591 bool includeAllElements(Element element) => true;
592
584 /// Serializer for the transitive closure of a collection of libraries. 593 /// Serializer for the transitive closure of a collection of libraries.
585 /// 594 ///
586 /// The serializer creates an [ObjectValue] model of the [Element], [DartType] 595 /// The serializer creates an [ObjectValue] model of the [Element], [DartType]
587 /// and [ConstantExpression] values in the transitive closure of the serialized 596 /// and [ConstantExpression] values in the transitive closure of the serialized
588 /// libraries. 597 /// libraries.
589 /// 598 ///
590 /// The model layout of the produced [objectValue] is: 599 /// The model layout of the produced [objectValue] is:
591 /// 600 ///
592 /// { // Header object 601 /// { // Header object
593 /// Key.ELEMENTS: [ 602 /// Key.ELEMENTS: [
594 /// {...}, // [ObjectValue] of the 0th [Element]. 603 /// {...}, // [ObjectValue] of the 0th [Element].
595 /// ... 604 /// ...
596 /// {...}, // [ObjectValue] of the n-th [Element]. 605 /// {...}, // [ObjectValue] of the n-th [Element].
597 /// ], 606 /// ],
598 /// Key.TYPES: [ 607 /// Key.TYPES: [
599 /// {...}, // [ObjectValue] of the 0th [DartType]. 608 /// {...}, // [ObjectValue] of the 0th [DartType].
600 /// ... 609 /// ...
601 /// {...}, // [ObjectValue] of the n-th [DartType]. 610 /// {...}, // [ObjectValue] of the n-th [DartType].
602 /// ], 611 /// ],
603 /// Key.CONSTANTS: [ 612 /// Key.CONSTANTS: [
604 /// {...}, // [ObjectValue] of the 0th [ConstantExpression]. 613 /// {...}, // [ObjectValue] of the 0th [ConstantExpression].
605 /// ... 614 /// ...
606 /// {...}, // [ObjectValue] of the n-th [ConstantExpression]. 615 /// {...}, // [ObjectValue] of the n-th [ConstantExpression].
607 /// ], 616 /// ],
608 /// } 617 /// }
609 /// 618 ///
610 // TODO(johnniwinther): Support per-library serialization and dependencies 619 // TODO(johnniwinther): Support dependencies between serialized subcomponent.
611 // between serialized subcomponent.
612 class Serializer { 620 class Serializer {
613 final SerializationEncoder _encoder;
614 List<SerializerPlugin> plugins = <SerializerPlugin>[]; 621 List<SerializerPlugin> plugins = <SerializerPlugin>[];
615 622
623 Map<Uri, dynamic> _dependencyMap = <Uri, dynamic>{};
616 Map<Element, DataObject> _elementMap = <Element, DataObject>{}; 624 Map<Element, DataObject> _elementMap = <Element, DataObject>{};
617 Map<ConstantExpression, DataObject> _constantMap = 625 Map<ConstantExpression, DataObject> _constantMap =
618 <ConstantExpression, DataObject>{}; 626 <ConstantExpression, DataObject>{};
619 Map<DartType, DataObject> _typeMap = <DartType, DataObject>{}; 627 Map<DartType, DataObject> _typeMap = <DartType, DataObject>{};
620 List _pendingList = []; 628 List _pendingList = [];
629 ElementMatcher shouldInclude;
621 630
622 Serializer(this._encoder); 631 // TODO(johnniwinther): Replace [includeElement] with a general strategy.
632 Serializer({this.shouldInclude: includeAllElements});
623 633
624 /// Add the transitive closure of [library] to this serializer. 634 /// Add the transitive closure of [library] to this serializer.
625 void serialize(LibraryElement library) { 635 void serialize(LibraryElement library) {
626 // Call [_getElementDataObject] for its side-effect: To create a 636 // Call [_getElementId] for its side-effect: To create a
627 // [DataObject] for [library]. If not already created, this will 637 // [DataObject] for [library]. If not already created, this will
628 // put the serialization of [library] in the work queue. 638 // put the serialization of [library] in the work queue.
629 _getElementDataObject(library); 639 _getElementId(library);
630 } 640 }
631 641
632 void _emptyWorklist() { 642 void _emptyWorklist() {
633 while (_pendingList.isNotEmpty) { 643 while (_pendingList.isNotEmpty) {
634 _pendingList.removeLast()(); 644 _pendingList.removeLast()();
635 } 645 }
636 } 646 }
637 647
638 /// Returns the [DataObject] for [element]. 648 /// Returns the id [Value] for [element].
639 /// 649 ///
640 /// If [constant] has no [DataObject], a new [DataObject] is created and 650 /// If [element] has no [DataObject], a new [DataObject] is created and
641 /// encoding the [ObjectValue] for [constant] is put into the work queue of 651 /// encoding the [ObjectValue] for [element] is put into the work queue of
642 /// this serializer. 652 /// this serializer.
643 DataObject _getElementDataObject(Element element) { 653 Value _getElementId(Element element) {
644 if (element == null) { 654 if (element == null) {
645 throw new ArgumentError('Serializer._getElementDataObject(null)'); 655 throw new ArgumentError('Serializer._getElementDataObject(null)');
646 } 656 }
647 DataObject dataObject = _elementMap[element]; 657 DataObject dataObject = _elementMap[element];
648 if (dataObject == null) { 658 if (dataObject == null) {
649 // Run through [ELEMENT_SERIALIZERS] sequentially to find the one that 659 if (!shouldInclude(element)) {
650 // deals with [element]. 660 if (element.isLibrary) {
651 for (ElementSerializer serializer in ELEMENT_SERIALIZERS) { 661 LibraryElement library = element;
652 SerializedElementKind kind = serializer.getSerializedKind(element); 662 _elementMap[element] = dataObject = new DataObject(
653 if (kind != null) { 663 new IntValue(_elementMap.length),
654 dataObject = new DataObject( 664 new EnumValue(SerializedElementKind.EXTERNAL_LIBRARY));
655 new IntValue(_elementMap.length), new EnumValue(kind)); 665 ObjectEncoder encoder = new ObjectEncoder(this, dataObject.map);
656 _elementMap[element] = dataObject; 666 encoder.setUri(Key.URI, library.canonicalUri, library.canonicalUri);
657 // Delay the serialization of the element itself to avoid loops, and 667 } else if (element.isStatic) {
658 // to keep the call stack small. 668 Value classId =_getElementId(element.enclosingClass);
659 _pendingList.add(() { 669 _elementMap[element] = dataObject = new DataObject(
660 ObjectEncoder encoder = new ObjectEncoder(this, dataObject.map); 670 new IntValue(_elementMap.length),
661 serializer.serialize(element, encoder, kind); 671 new EnumValue(SerializedElementKind.EXTERNAL_STATIC_MEMBER));
672 ObjectEncoder encoder = new ObjectEncoder(this, dataObject.map);
673 encoder.setValue(Key.CLASS, classId);
674 encoder.setString(Key.NAME, element.name);
675 } else if (element.isConstructor) {
676 Value classId =_getElementId(element.enclosingClass);
677 _elementMap[element] = dataObject = new DataObject(
678 new IntValue(_elementMap.length),
679 new EnumValue(SerializedElementKind.EXTERNAL_CONSTRUCTOR));
680 ObjectEncoder encoder = new ObjectEncoder(this, dataObject.map);
681 encoder.setValue(Key.CLASS, classId);
682 encoder.setString(Key.NAME, element.name);
683 } else {
684 Value libraryId =_getElementId(element.library);
685 _elementMap[element] = dataObject = new DataObject(
686 new IntValue(_elementMap.length),
687 new EnumValue(SerializedElementKind.EXTERNAL_LIBRARY_MEMBER));
688 ObjectEncoder encoder = new ObjectEncoder(this, dataObject.map);
689 encoder.setValue(Key.LIBRARY, libraryId);
690 encoder.setString(Key.NAME, element.name);
691 }
692 } else {
693 // Run through [ELEMENT_SERIALIZERS] sequentially to find the one that
694 // deals with [element].
695 for (ElementSerializer serializer in ELEMENT_SERIALIZERS) {
696 SerializedElementKind kind = serializer.getSerializedKind(element);
697 if (kind != null) {
698 _elementMap[element] = dataObject = new DataObject(
699 new IntValue(_elementMap.length), new EnumValue(kind));
700 // Delay the serialization of the element itself to avoid loops, and
701 // to keep the call stack small.
702 _pendingList.add(() {
703 ObjectEncoder encoder = new ObjectEncoder(this, dataObject.map);
704 serializer.serialize(element, encoder, kind);
662 705
663 MapEncoder pluginData; 706 MapEncoder pluginData;
664 for (SerializerPlugin plugin in plugins) { 707 for (SerializerPlugin plugin in plugins) {
665 plugin.onElement(element, (String tag) { 708 plugin.onElement(element, (String tag) {
666 if (pluginData == null) { 709 if (pluginData == null) {
667 pluginData = encoder.createMap(Key.DATA); 710 pluginData = encoder.createMap(Key.DATA);
668 } 711 }
669 return pluginData.createObject(tag); 712 return pluginData.createObject(tag);
670 }); 713 });
671 } 714 }
672 }); 715 });
716 }
673 } 717 }
674 } 718 }
675 } 719 }
676 if (dataObject == null) { 720 if (dataObject == null) {
677 throw new UnsupportedError( 721 throw new UnsupportedError(
678 'Unsupported element: $element (${element.kind})'); 722 'Unsupported element: $element (${element.kind})');
679 } 723 }
680 return dataObject; 724 return dataObject.id;
681 } 725 }
682 726
683 /// Creates the [ElementValue] for [element]. 727 /// Creates the [ElementValue] for [element].
684 /// 728 ///
685 /// If [element] has not already been serialized, it is added to the work 729 /// If [element] has not already been serialized, it is added to the work
686 /// queue of this serializer. 730 /// queue of this serializer.
687 ElementValue createElementValue(Element element) { 731 ElementValue createElementValue(Element element) {
688 return new ElementValue(element, _getElementDataObject(element).id); 732 return new ElementValue(element, _getElementId(element));
689 } 733 }
690 734
691 /// Returns the [DataObject] for [constant]. 735 /// Returns the id [Value] for [constant].
692 /// 736 ///
693 /// If [constant] has no [DataObject], a new [DataObject] is created and 737 /// If [constant] has no [DataObject], a new [DataObject] is created and
694 /// encoding the [ObjectValue] for [constant] is put into the work queue of 738 /// encoding the [ObjectValue] for [constant] is put into the work queue of
695 /// this serializer. 739 /// this serializer.
696 DataObject _getConstantDataObject(ConstantExpression constant) { 740 Value _getConstantId(ConstantExpression constant) {
697 return _constantMap.putIfAbsent(constant, () { 741 return _constantMap.putIfAbsent(constant, () {
698 DataObject dataObject = new DataObject( 742 DataObject dataObject = new DataObject(
699 new IntValue(_constantMap.length), new EnumValue(constant.kind)); 743 new IntValue(_constantMap.length), new EnumValue(constant.kind));
700 // Delay the serialization of the constant itself to avoid loops, and to 744 // Delay the serialization of the constant itself to avoid loops, and to
701 // keep the call stack small. 745 // keep the call stack small.
702 _pendingList.add(() => _encodeConstant(constant, dataObject)); 746 _pendingList.add(() => _encodeConstant(constant, dataObject));
703 return dataObject; 747 return dataObject;
704 }); 748 }).id;
705 } 749 }
706 750
707 /// Encodes [constant] into the [ObjectValue] of [dataObject]. 751 /// Encodes [constant] into the [ObjectValue] of [dataObject].
708 void _encodeConstant(ConstantExpression constant, DataObject dataObject) { 752 void _encodeConstant(ConstantExpression constant, DataObject dataObject) {
709 const ConstantSerializer().visit(constant, 753 const ConstantSerializer().visit(constant,
710 new ObjectEncoder(this, dataObject.map)); 754 new ObjectEncoder(this, dataObject.map));
711 } 755 }
712 756
713 /// Creates the [ConstantValue] for [constant]. 757 /// Creates the [ConstantValue] for [constant].
714 /// 758 ///
715 /// If [constant] has not already been serialized, it is added to the work 759 /// If [constant] has not already been serialized, it is added to the work
716 /// queue of this serializer. 760 /// queue of this serializer.
717 ConstantValue createConstantValue(ConstantExpression constant) { 761 ConstantValue createConstantValue(ConstantExpression constant) {
718 return new ConstantValue(constant, _getConstantDataObject(constant).id); 762 return new ConstantValue(constant, _getConstantId(constant));
719 } 763 }
720 764
721 /// Returns the [DataObject] for [type]. 765 /// Returns the id [Value] for [type].
722 /// 766 ///
723 /// If [type] has no [DataObject], a new [DataObject] is created and 767 /// If [type] has no [DataObject], a new [DataObject] is created and
724 /// encoding the [ObjectValue] for [type] is put into the work queue of this 768 /// encoding the [ObjectValue] for [type] is put into the work queue of this
725 /// serializer. 769 /// serializer.
726 DataObject _getTypeDataObject(DartType type) { 770 Value _getTypeId(DartType type) {
727 return _typeMap.putIfAbsent(type, () { 771 DataObject dataObject = _typeMap[type];
728 DataObject dataObject = new DataObject( 772 if (dataObject == null) {
773 _typeMap[type] = dataObject = new DataObject(
729 new IntValue(_typeMap.length), new EnumValue(type.kind)); 774 new IntValue(_typeMap.length), new EnumValue(type.kind));
730 // Delay the serialization of the type itself to avoid loops, and to keep 775 // Delay the serialization of the type itself to avoid loops, and to keep
731 // the call stack small. 776 // the call stack small.
732 _pendingList.add(() => _encodeType(type, dataObject)); 777 _pendingList.add(() => _encodeType(type, dataObject));
733 return dataObject; 778 }
734 }); 779 return dataObject.id;
735 } 780 }
736 781
737 /// Encodes [type] into the [ObjectValue] of [dataObject]. 782 /// Encodes [type] into the [ObjectValue] of [dataObject].
738 void _encodeType(DartType type, DataObject dataObject) { 783 void _encodeType(DartType type, DataObject dataObject) {
739 const TypeSerializer().visit(type, new ObjectEncoder(this, dataObject.map)); 784 const TypeSerializer().visit(type, new ObjectEncoder(this, dataObject.map));
740 } 785 }
741 786
742 /// Creates the [TypeValue] for [type]. 787 /// Creates the [TypeValue] for [type].
743 /// 788 ///
744 /// If [type] has not already been serialized, it is added to the work 789 /// If [type] has not already been serialized, it is added to the work
745 /// queue of this serializer. 790 /// queue of this serializer.
746 TypeValue createTypeValue(DartType type) { 791 TypeValue createTypeValue(DartType type) {
747 return new TypeValue(type, _getTypeDataObject(type).id); 792 return new TypeValue(type, _getTypeId(type));
748 } 793 }
749 794
750 ObjectValue get objectValue { 795 ObjectValue get objectValue {
751 _emptyWorklist(); 796 _emptyWorklist();
752 797
753 Map<Key, Value> map = <Key, Value>{}; 798 Map<Key, Value> map = <Key, Value>{};
754 map[Key.ELEMENTS] = 799 map[Key.ELEMENTS] =
755 new ListValue(_elementMap.values.map((l) => l.objectValue).toList()); 800 new ListValue(_elementMap.values.map((l) => l.objectValue).toList());
756 if (_typeMap.isNotEmpty) { 801 if (_typeMap.isNotEmpty) {
757 map[Key.TYPES] = 802 map[Key.TYPES] =
758 new ListValue(_typeMap.values.map((l) => l.objectValue).toList()); 803 new ListValue(_typeMap.values.map((l) => l.objectValue).toList());
759 } 804 }
760 if (_constantMap.isNotEmpty) { 805 if (_constantMap.isNotEmpty) {
761 map[Key.CONSTANTS] = 806 map[Key.CONSTANTS] =
762 new ListValue(_constantMap.values.map((l) => l.objectValue).toList()); 807 new ListValue(_constantMap.values.map((l) => l.objectValue).toList());
763 } 808 }
764 return new ObjectValue(map); 809 return new ObjectValue(map);
765 } 810 }
766 811
767 String toText() { 812 String toText(SerializationEncoder encoder) {
768 return _encoder.encode(objectValue); 813 return encoder.encode(objectValue);
769 } 814 }
770 815
771 String prettyPrint() { 816 String prettyPrint() {
772 PrettyPrintEncoder encoder = new PrettyPrintEncoder(); 817 PrettyPrintEncoder encoder = new PrettyPrintEncoder();
773 return encoder.toText(objectValue); 818 return encoder.toText(objectValue);
774 } 819 }
775 } 820 }
776 821
777 /// Plugin for serializing additional data for an [Element]. 822 /// Plugin for serializing additional data for an [Element].
778 class SerializerPlugin { 823 class SerializerPlugin {
(...skipping 10 matching lines...) Expand all
789 class DeserializerPlugin { 834 class DeserializerPlugin {
790 const DeserializerPlugin(); 835 const DeserializerPlugin();
791 836
792 /// Called upon the deserialization of [element]. 837 /// Called upon the deserialization of [element].
793 /// 838 ///
794 /// Use [getDecoder] to retrieve the data object with id [tag] stored for 839 /// Use [getDecoder] to retrieve the data object with id [tag] stored for
795 /// [element]. If not object is stored for [tag], [getDecoder] returns `null`. 840 /// [element]. If not object is stored for [tag], [getDecoder] returns `null`.
796 void onElement(Element element, ObjectDecoder getDecoder(String tag)) {} 841 void onElement(Element element, ObjectDecoder getDecoder(String tag)) {}
797 } 842 }
798 843
844 /// Context for parallel deserialization.
845 class DeserializationContext {
846 Map<Uri, LibraryElement> _uriMap = <Uri, LibraryElement>{};
847 List<Deserializer> deserializers = <Deserializer>[];
848
849 LibraryElement lookupLibrary(Uri uri) {
850 return _uriMap.putIfAbsent(uri, () {
851 for (Deserializer deserializer in deserializers) {
852 LibraryElement library = deserializer.lookupLibrary(uri);
853 if (library != null) {
854 return library;
855 }
856 }
857 return null;
858 });
859 }
860 }
861
799 /// Deserializer for a closed collection of libraries. 862 /// Deserializer for a closed collection of libraries.
800 // TODO(johnniwinther): Support per-library deserialization and dependencies 863 // TODO(johnniwinther): Support per-library deserialization and dependencies
801 // between deserialized subcomponent. 864 // between deserialized subcomponent.
802 class Deserializer { 865 class Deserializer {
866 final DeserializationContext context;
803 final SerializationDecoder decoder; 867 final SerializationDecoder decoder;
804 List<DeserializerPlugin> plugins = <DeserializerPlugin>[]; 868 List<DeserializerPlugin> plugins = <DeserializerPlugin>[];
805 ObjectDecoder _headerObject; 869 ObjectDecoder _headerObject;
806 ListDecoder _elementList; 870 ListDecoder _elementList;
807 ListDecoder _typeList; 871 ListDecoder _typeList;
808 ListDecoder _constantList; 872 ListDecoder _constantList;
809 Map<int, Element> _elementMap = {}; 873 Map<int, Element> _elementMap = {};
810 Map<int, DartType> _typeMap = {}; 874 Map<int, DartType> _typeMap = {};
811 Map<int, ConstantExpression> _constantMap = {}; 875 Map<int, ConstantExpression> _constantMap = {};
812 876
813 Deserializer.fromText(String text, this.decoder) { 877 Deserializer.fromText(this.context, String text, this.decoder) {
814 _headerObject = new ObjectDecoder(this, decoder.decode(text)); 878 _headerObject = new ObjectDecoder(this, decoder.decode(text));
879 context.deserializers.add(this);
815 } 880 }
816 881
817 /// Returns the [ListDecoder] for the [Element]s in this deserializer. 882 /// Returns the [ListDecoder] for the [Element]s in this deserializer.
818 ListDecoder get elements { 883 ListDecoder get elements {
819 if (_elementList == null) { 884 if (_elementList == null) {
820 _elementList = _headerObject.getList(Key.ELEMENTS); 885 _elementList = _headerObject.getList(Key.ELEMENTS);
821 } 886 }
822 return _elementList; 887 return _elementList;
823 } 888 }
824 889
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 } 921 }
857 return null; 922 return null;
858 } 923 }
859 924
860 /// Returns the deserialized [Element] for [id]. 925 /// Returns the deserialized [Element] for [id].
861 Element deserializeElement(int id) { 926 Element deserializeElement(int id) {
862 if (id == null) throw new ArgumentError('Deserializer.getElement(null)'); 927 if (id == null) throw new ArgumentError('Deserializer.getElement(null)');
863 Element element = _elementMap[id]; 928 Element element = _elementMap[id];
864 if (element == null) { 929 if (element == null) {
865 ObjectDecoder decoder = elements.getObject(id); 930 ObjectDecoder decoder = elements.getObject(id);
866 element = ElementDeserializer.deserialize(decoder); 931 SerializedElementKind elementKind =
932 decoder.getEnum(Key.KIND, SerializedElementKind.values);
933 if (elementKind == SerializedElementKind.EXTERNAL_LIBRARY) {
934 Uri uri = decoder.getUri(Key.URI);
935 element = context.lookupLibrary(uri);
936 if (element == null) {
937 throw new StateError("Missing library for $uri.");
938 }
939 } else if (elementKind == SerializedElementKind.EXTERNAL_LIBRARY_MEMBER) {
940 LibraryElement library = decoder.getElement(Key.LIBRARY);
941 String name = decoder.getString(Key.NAME);
942 element = library.find(name);
943 if (element == null) {
944 throw new StateError("Missing library member for $name in $library.");
945 }
946 } else if (elementKind == SerializedElementKind.EXTERNAL_STATIC_MEMBER) {
947 ClassElement cls = decoder.getElement(Key.CLASS);
948 String name = decoder.getString(Key.NAME);
949 element = cls.lookupLocalMember(name);
950 if (element == null) {
951 throw new StateError("Missing static member for $name in $cls.");
952 }
953 } else if (elementKind == SerializedElementKind.EXTERNAL_CONSTRUCTOR) {
954 ClassElement cls = decoder.getElement(Key.CLASS);
955 String name = decoder.getString(Key.NAME);
956 element = cls.lookupConstructor(name);
957 if (element == null) {
958 throw new StateError("Missing constructor for $name in $cls.");
959 }
960 } else {
961 element = ElementDeserializer.deserialize(decoder, elementKind);
962 }
867 _elementMap[id] = element; 963 _elementMap[id] = element;
868 964
869 MapDecoder pluginData = decoder.getMap(Key.DATA, isOptional: true); 965 MapDecoder pluginData = decoder.getMap(Key.DATA, isOptional: true);
870 // Call plugins even when there is no data, so they can take action in 966 // Call plugins even when there is no data, so they can take action in
871 // this case. 967 // this case.
872 for (DeserializerPlugin plugin in plugins) { 968 for (DeserializerPlugin plugin in plugins) {
873 plugin.onElement(element, 969 plugin.onElement(element,
874 (String tag) => pluginData?.getObject(tag, isOptional: true)); 970 (String tag) => pluginData?.getObject(tag, isOptional: true));
875 } 971 }
876 } 972 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 1005
910 /// Returns the value used to store [key] as a property in the encoding an 1006 /// Returns the value used to store [key] as a property in the encoding an
911 /// [ObjectValue]. 1007 /// [ObjectValue].
912 /// 1008 ///
913 /// Different encodings have different restrictions and capabilities as how 1009 /// Different encodings have different restrictions and capabilities as how
914 /// to store a [Key] value. For instance: A JSON encoding needs to convert 1010 /// to store a [Key] value. For instance: A JSON encoding needs to convert
915 /// [Key] to a [String] to store it in a JSON object; a Dart encoding can 1011 /// [Key] to a [String] to store it in a JSON object; a Dart encoding can
916 /// choose to store a [Key] as an [int] or as the [Key] itself. 1012 /// choose to store a [Key] as an [int] or as the [Key] itself.
917 getObjectPropertyValue(Key key); 1013 getObjectPropertyValue(Key key);
918 } 1014 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/serialization/modelz.dart ('k') | tests/compiler/dart2js/serialization_analysis_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698