OLD | NEW |
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 '../constants/constructors.dart'; | 9 import '../constants/constructors.dart'; |
9 import '../constants/expressions.dart'; | 10 import '../constants/expressions.dart'; |
10 import '../dart_types.dart'; | 11 import '../dart_types.dart'; |
11 import '../diagnostics/messages.dart'; | 12 import '../diagnostics/messages.dart'; |
12 import '../elements/elements.dart'; | 13 import '../elements/elements.dart'; |
13 import '../elements/modelx.dart' show ErroneousElementX; | 14 import '../elements/modelx.dart' |
| 15 show DeferredLoaderGetterElementX, ErroneousElementX; |
14 import 'constant_serialization.dart'; | 16 import 'constant_serialization.dart'; |
15 import 'keys.dart'; | 17 import 'keys.dart'; |
16 import 'modelz.dart'; | 18 import 'modelz.dart'; |
17 import 'serialization.dart'; | 19 import 'serialization.dart'; |
18 import 'serialization_util.dart'; | 20 import 'serialization_util.dart'; |
19 | 21 |
20 /// Enum kinds used for encoding [Element]s. | 22 /// Enum kinds used for encoding [Element]s. |
21 enum SerializedElementKind { | 23 enum SerializedElementKind { |
22 ERROR, | 24 ERROR, |
23 LIBRARY, | 25 LIBRARY, |
(...skipping 20 matching lines...) Expand all Loading... |
44 INSTANCE_GETTER, | 46 INSTANCE_GETTER, |
45 INSTANCE_SETTER, | 47 INSTANCE_SETTER, |
46 LOCAL_FUNCTION, | 48 LOCAL_FUNCTION, |
47 TYPEDEF, | 49 TYPEDEF, |
48 TYPEVARIABLE, | 50 TYPEVARIABLE, |
49 PARAMETER, | 51 PARAMETER, |
50 INITIALIZING_FORMAL, | 52 INITIALIZING_FORMAL, |
51 IMPORT, | 53 IMPORT, |
52 EXPORT, | 54 EXPORT, |
53 PREFIX, | 55 PREFIX, |
| 56 DEFERRED_LOAD_LIBRARY, |
54 LOCAL_VARIABLE, | 57 LOCAL_VARIABLE, |
55 EXTERNAL_LIBRARY, | 58 EXTERNAL_LIBRARY, |
56 EXTERNAL_LIBRARY_MEMBER, | 59 EXTERNAL_LIBRARY_MEMBER, |
57 EXTERNAL_CLASS_MEMBER, | 60 EXTERNAL_CLASS_MEMBER, |
58 EXTERNAL_CONSTRUCTOR, | 61 EXTERNAL_CONSTRUCTOR, |
59 } | 62 } |
60 | 63 |
61 /// Set of serializers used to serialize different kinds of elements by | 64 /// Set of serializers used to serialize different kinds of elements by |
62 /// encoding into them into [ObjectEncoder]s. | 65 /// encoding into them into [ObjectEncoder]s. |
63 /// | 66 /// |
64 /// This class is called from the [Serializer] when an [Element] needs | 67 /// This class is called from the [Serializer] when an [Element] needs |
65 /// serialization. The [ObjectEncoder] ensures that any [Element], [DartType], | 68 /// serialization. The [ObjectEncoder] ensures that any [Element], [DartType], |
66 /// and [ConstantExpression] that the serialized [Element] depends upon are also | 69 /// and [ConstantExpression] that the serialized [Element] depends upon are also |
67 /// serialized. | 70 /// serialized. |
68 const List<ElementSerializer> ELEMENT_SERIALIZERS = const [ | 71 const List<ElementSerializer> ELEMENT_SERIALIZERS = const [ |
69 const ErrorSerializer(), | 72 const ErrorSerializer(), |
70 const LibrarySerializer(), | 73 const LibrarySerializer(), |
71 const CompilationUnitSerializer(), | 74 const CompilationUnitSerializer(), |
| 75 const PrefixSerializer(), |
| 76 const DeferredLoadLibrarySerializer(), |
72 const ClassSerializer(), | 77 const ClassSerializer(), |
73 const ConstructorSerializer(), | 78 const ConstructorSerializer(), |
74 const FieldSerializer(), | 79 const FieldSerializer(), |
75 const FunctionSerializer(), | 80 const FunctionSerializer(), |
76 const TypedefSerializer(), | 81 const TypedefSerializer(), |
77 const TypeVariableSerializer(), | 82 const TypeVariableSerializer(), |
78 const ParameterSerializer(), | 83 const ParameterSerializer(), |
79 const ImportSerializer(), | 84 const ImportSerializer(), |
80 const ExportSerializer(), | 85 const ExportSerializer(), |
81 const PrefixSerializer(), | |
82 const LocalVariableSerializer(), | 86 const LocalVariableSerializer(), |
83 ]; | 87 ]; |
84 | 88 |
85 /// Interface for a function that can serialize a set of element kinds. | 89 /// Interface for a function that can serialize a set of element kinds. |
86 abstract class ElementSerializer { | 90 abstract class ElementSerializer { |
87 /// Returns the [SerializedElementKind] for [element] if this serializer | 91 /// Returns the [SerializedElementKind] for [element] if this serializer |
88 /// supports serialization of [element] or `null` otherwise. | 92 /// supports serialization of [element] or `null` otherwise. |
89 SerializedElementKind getSerializedKind(Element element); | 93 SerializedElementKind getSerializedKind(Element element); |
90 | 94 |
91 /// Serializes [element] into the [encoder] using the [kind] computed | 95 /// Serializes [element] into the [encoder] using the [kind] computed |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 EnumConstantElement enumConstant = element; | 497 EnumConstantElement enumConstant = element; |
494 encoder.setInt(Key.INDEX, enumConstant.index); | 498 encoder.setInt(Key.INDEX, enumConstant.index); |
495 } | 499 } |
496 } | 500 } |
497 } | 501 } |
498 | 502 |
499 class FunctionSerializer implements ElementSerializer { | 503 class FunctionSerializer implements ElementSerializer { |
500 const FunctionSerializer(); | 504 const FunctionSerializer(); |
501 | 505 |
502 SerializedElementKind getSerializedKind(Element element) { | 506 SerializedElementKind getSerializedKind(Element element) { |
| 507 if (element.isDeferredLoaderGetter) { |
| 508 return null; |
| 509 } |
503 if (element.isFunction) { | 510 if (element.isFunction) { |
504 if (element.isTopLevel) return SerializedElementKind.TOPLEVEL_FUNCTION; | 511 if (element.isTopLevel) return SerializedElementKind.TOPLEVEL_FUNCTION; |
505 if (element.isStatic) return SerializedElementKind.STATIC_FUNCTION; | 512 if (element.isStatic) return SerializedElementKind.STATIC_FUNCTION; |
506 if (element.isInstanceMember) { | 513 if (element.isInstanceMember) { |
507 return SerializedElementKind.INSTANCE_FUNCTION; | 514 return SerializedElementKind.INSTANCE_FUNCTION; |
508 } | 515 } |
509 if (element.isLocal) { | 516 if (element.isLocal) { |
510 return SerializedElementKind.LOCAL_FUNCTION; | 517 return SerializedElementKind.LOCAL_FUNCTION; |
511 } | 518 } |
512 } | 519 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 return SerializedElementKind.PREFIX; | 713 return SerializedElementKind.PREFIX; |
707 } | 714 } |
708 return null; | 715 return null; |
709 } | 716 } |
710 | 717 |
711 void serialize(PrefixElement element, ObjectEncoder encoder, | 718 void serialize(PrefixElement element, ObjectEncoder encoder, |
712 SerializedElementKind kind) { | 719 SerializedElementKind kind) { |
713 encoder.setString(Key.NAME, element.name); | 720 encoder.setString(Key.NAME, element.name); |
714 encoder.setElement(Key.LIBRARY, element.library); | 721 encoder.setElement(Key.LIBRARY, element.library); |
715 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit); | 722 encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit); |
716 if (element.deferredImport != null) { | 723 encoder.setBool(Key.IS_DEFERRED, element.isDeferred); |
| 724 if (element.isDeferred) { |
717 encoder.setElement(Key.IMPORT, element.deferredImport); | 725 encoder.setElement(Key.IMPORT, element.deferredImport); |
| 726 encoder.setElement(Key.GETTER, element.loadLibrary); |
718 } | 727 } |
719 encoder.setBool(Key.IS_DEFERRED, element.isDeferred); | |
720 } | 728 } |
721 } | 729 } |
722 | 730 |
| 731 class DeferredLoadLibrarySerializer implements ElementSerializer { |
| 732 const DeferredLoadLibrarySerializer(); |
| 733 |
| 734 SerializedElementKind getSerializedKind(Element element) { |
| 735 if (element.isDeferredLoaderGetter) { |
| 736 return SerializedElementKind.DEFERRED_LOAD_LIBRARY; |
| 737 } |
| 738 return null; |
| 739 } |
| 740 |
| 741 void serialize(GetterElement element, ObjectEncoder encoder, |
| 742 SerializedElementKind kind) { |
| 743 encoder.setElement(Key.PREFIX, element.enclosingElement); |
| 744 } |
| 745 } |
| 746 |
723 /// Utility class for deserializing [Element]s. | 747 /// Utility class for deserializing [Element]s. |
724 /// | 748 /// |
725 /// This is used by the [Deserializer]. | 749 /// This is used by the [Deserializer]. |
726 class ElementDeserializer { | 750 class ElementDeserializer { |
727 /// Deserializes an [Element] from an [ObjectDecoder]. | 751 /// Deserializes an [Element] from an [ObjectDecoder]. |
728 /// | 752 /// |
729 /// The class is called from the [Deserializer] when an [Element] | 753 /// The class is called from the [Deserializer] when an [Element] |
730 /// needs deserialization. The [ObjectDecoder] ensures that any [Element], | 754 /// needs deserialization. The [ObjectDecoder] ensures that any [Element], |
731 /// [DartType], and [ConstantExpression] that the deserialized [Element] | 755 /// [DartType], and [ConstantExpression] that the deserialized [Element] |
732 /// depends upon are available. | 756 /// depends upon are available. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 case SerializedElementKind.PARAMETER: | 826 case SerializedElementKind.PARAMETER: |
803 return new LocalParameterElementZ(decoder); | 827 return new LocalParameterElementZ(decoder); |
804 case SerializedElementKind.INITIALIZING_FORMAL: | 828 case SerializedElementKind.INITIALIZING_FORMAL: |
805 return new InitializingFormalElementZ(decoder); | 829 return new InitializingFormalElementZ(decoder); |
806 case SerializedElementKind.IMPORT: | 830 case SerializedElementKind.IMPORT: |
807 return new ImportElementZ(decoder); | 831 return new ImportElementZ(decoder); |
808 case SerializedElementKind.EXPORT: | 832 case SerializedElementKind.EXPORT: |
809 return new ExportElementZ(decoder); | 833 return new ExportElementZ(decoder); |
810 case SerializedElementKind.PREFIX: | 834 case SerializedElementKind.PREFIX: |
811 return new PrefixElementZ(decoder); | 835 return new PrefixElementZ(decoder); |
| 836 case SerializedElementKind.DEFERRED_LOAD_LIBRARY: |
| 837 return new DeferredLoaderGetterElementX(decoder.getElement(Key.PREFIX)); |
812 case SerializedElementKind.LOCAL_VARIABLE: | 838 case SerializedElementKind.LOCAL_VARIABLE: |
813 return new LocalVariableElementZ(decoder); | 839 return new LocalVariableElementZ(decoder); |
814 case SerializedElementKind.EXTERNAL_LIBRARY: | 840 case SerializedElementKind.EXTERNAL_LIBRARY: |
815 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: | 841 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: |
816 case SerializedElementKind.EXTERNAL_CLASS_MEMBER: | 842 case SerializedElementKind.EXTERNAL_CLASS_MEMBER: |
817 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: | 843 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: |
818 break; | 844 break; |
819 } | 845 } |
820 throw new UnsupportedError("Unexpected element kind '${elementKind}."); | 846 throw new UnsupportedError("Unexpected element kind '${elementKind}."); |
821 } | 847 } |
822 } | 848 } |
OLD | NEW |