| 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 '../constants/constructors.dart'; | 8 import '../constants/constructors.dart'; |
| 9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| 11 import '../diagnostics/messages.dart'; | 11 import '../diagnostics/messages.dart'; |
| 12 import '../elements/elements.dart'; | 12 import '../elements/elements.dart'; |
| 13 import '../elements/modelx.dart' | 13 import '../elements/modelx.dart' |
| 14 show | 14 show |
| 15 AmbiguousImportX, |
| 15 DeferredLoaderGetterElementX, | 16 DeferredLoaderGetterElementX, |
| 16 ErroneousElementX, | 17 ErroneousElementX, |
| 17 WarnOnUseElementX, | 18 WarnOnUseElementX, |
| 18 WrappedMessage; | 19 WrappedMessage; |
| 19 import 'constant_serialization.dart'; | 20 import 'constant_serialization.dart'; |
| 20 import 'keys.dart'; | 21 import 'keys.dart'; |
| 21 import 'modelz.dart'; | 22 import 'modelz.dart'; |
| 22 import 'serialization.dart'; | 23 import 'serialization.dart'; |
| 23 import 'serialization_util.dart'; | 24 import 'serialization_util.dart'; |
| 24 | 25 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 52 TYPEDEF, | 53 TYPEDEF, |
| 53 TYPEVARIABLE, | 54 TYPEVARIABLE, |
| 54 PARAMETER, | 55 PARAMETER, |
| 55 INITIALIZING_FORMAL, | 56 INITIALIZING_FORMAL, |
| 56 IMPORT, | 57 IMPORT, |
| 57 EXPORT, | 58 EXPORT, |
| 58 PREFIX, | 59 PREFIX, |
| 59 DEFERRED_LOAD_LIBRARY, | 60 DEFERRED_LOAD_LIBRARY, |
| 60 LOCAL_VARIABLE, | 61 LOCAL_VARIABLE, |
| 61 WARN_ON_USE, | 62 WARN_ON_USE, |
| 63 AMBIGUOUS, |
| 62 EXTERNAL_LIBRARY, | 64 EXTERNAL_LIBRARY, |
| 63 EXTERNAL_LIBRARY_MEMBER, | 65 EXTERNAL_LIBRARY_MEMBER, |
| 64 EXTERNAL_CLASS_MEMBER, | 66 EXTERNAL_CLASS_MEMBER, |
| 65 EXTERNAL_CONSTRUCTOR, | 67 EXTERNAL_CONSTRUCTOR, |
| 66 } | 68 } |
| 67 | 69 |
| 68 /// Set of serializers used to serialize different kinds of elements by | 70 /// Set of serializers used to serialize different kinds of elements by |
| 69 /// encoding into them into [ObjectEncoder]s. | 71 /// encoding into them into [ObjectEncoder]s. |
| 70 /// | 72 /// |
| 71 /// This class is called from the [Serializer] when an [Element] needs | 73 /// This class is called from the [Serializer] when an [Element] needs |
| (...skipping 10 matching lines...) Expand all Loading... |
| 82 const ConstructorSerializer(), | 84 const ConstructorSerializer(), |
| 83 const FieldSerializer(), | 85 const FieldSerializer(), |
| 84 const FunctionSerializer(), | 86 const FunctionSerializer(), |
| 85 const TypedefSerializer(), | 87 const TypedefSerializer(), |
| 86 const TypeVariableSerializer(), | 88 const TypeVariableSerializer(), |
| 87 const ParameterSerializer(), | 89 const ParameterSerializer(), |
| 88 const ImportSerializer(), | 90 const ImportSerializer(), |
| 89 const ExportSerializer(), | 91 const ExportSerializer(), |
| 90 const LocalVariableSerializer(), | 92 const LocalVariableSerializer(), |
| 91 const WarnOnUseSerializer(), | 93 const WarnOnUseSerializer(), |
| 94 const AmbiguousSerializer(), |
| 92 ]; | 95 ]; |
| 93 | 96 |
| 94 /// Interface for a function that can serialize a set of element kinds. | 97 /// Interface for a function that can serialize a set of element kinds. |
| 95 abstract class ElementSerializer { | 98 abstract class ElementSerializer { |
| 96 /// Returns the [SerializedElementKind] for [element] if this serializer | 99 /// Returns the [SerializedElementKind] for [element] if this serializer |
| 97 /// supports serialization of [element] or `null` otherwise. | 100 /// supports serialization of [element] or `null` otherwise. |
| 98 SerializedElementKind getSerializedKind(Element element); | 101 SerializedElementKind getSerializedKind(Element element); |
| 99 | 102 |
| 100 /// Serializes [element] into the [encoder] using the [kind] computed | 103 /// Serializes [element] into the [encoder] using the [kind] computed |
| 101 /// by [getSerializedKind]. | 104 /// by [getSerializedKind]. |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 | 811 |
| 809 void serialize(WarnOnUseElementX element, ObjectEncoder encoder, | 812 void serialize(WarnOnUseElementX element, ObjectEncoder encoder, |
| 810 SerializedElementKind kind) { | 813 SerializedElementKind kind) { |
| 811 encoder.setElement(Key.ENCLOSING, element.enclosingElement); | 814 encoder.setElement(Key.ENCLOSING, element.enclosingElement); |
| 812 encoder.setElement(Key.ELEMENT, element.wrappedElement); | 815 encoder.setElement(Key.ELEMENT, element.wrappedElement); |
| 813 serializeWrappedMessage(encoder, Key.WARNING, element.warning); | 816 serializeWrappedMessage(encoder, Key.WARNING, element.warning); |
| 814 serializeWrappedMessage(encoder, Key.INFO, element.info); | 817 serializeWrappedMessage(encoder, Key.INFO, element.info); |
| 815 } | 818 } |
| 816 } | 819 } |
| 817 | 820 |
| 821 class AmbiguousSerializer implements ElementSerializer { |
| 822 const AmbiguousSerializer(); |
| 823 |
| 824 SerializedElementKind getSerializedKind(Element element) { |
| 825 if (element.isAmbiguous) { |
| 826 return SerializedElementKind.AMBIGUOUS; |
| 827 } |
| 828 return null; |
| 829 } |
| 830 |
| 831 void serialize(AmbiguousImportX element, ObjectEncoder encoder, |
| 832 SerializedElementKind kind) { |
| 833 // TODO(johnniwinther): Also support [DuplicateElementX] if serialization |
| 834 // of code with compile-time errors is supported. |
| 835 encoder.setElement(Key.ENCLOSING, element.enclosingElement); |
| 836 encoder.setElement(Key.EXISTING, element.existingElement); |
| 837 encoder.setElement(Key.NEW, element.newElement); |
| 838 encoder.setEnum(Key.MESSAGE_KIND, element.messageKind); |
| 839 serializeMessageArguments(encoder, Key.ARGUMENTS, element.messageArguments); |
| 840 } |
| 841 } |
| 842 |
| 818 /// Utility class for deserializing [Element]s. | 843 /// Utility class for deserializing [Element]s. |
| 819 /// | 844 /// |
| 820 /// This is used by the [Deserializer]. | 845 /// This is used by the [Deserializer]. |
| 821 class ElementDeserializer { | 846 class ElementDeserializer { |
| 822 /// Deserializes an [Element] from an [ObjectDecoder]. | 847 /// Deserializes an [Element] from an [ObjectDecoder]. |
| 823 /// | 848 /// |
| 824 /// The class is called from the [Deserializer] when an [Element] | 849 /// The class is called from the [Deserializer] when an [Element] |
| 825 /// needs deserialization. The [ObjectDecoder] ensures that any [Element], | 850 /// needs deserialization. The [ObjectDecoder] ensures that any [Element], |
| 826 /// [DartType], and [ConstantExpression] that the deserialized [Element] | 851 /// [DartType], and [ConstantExpression] that the deserialized [Element] |
| 827 /// depends upon are available. | 852 /// depends upon are available. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 return new DeferredLoaderGetterElementX(decoder.getElement(Key.PREFIX)); | 930 return new DeferredLoaderGetterElementX(decoder.getElement(Key.PREFIX)); |
| 906 case SerializedElementKind.LOCAL_VARIABLE: | 931 case SerializedElementKind.LOCAL_VARIABLE: |
| 907 return new LocalVariableElementZ(decoder); | 932 return new LocalVariableElementZ(decoder); |
| 908 case SerializedElementKind.WARN_ON_USE: | 933 case SerializedElementKind.WARN_ON_USE: |
| 909 Element enclosing = decoder.getElement(Key.ENCLOSING); | 934 Element enclosing = decoder.getElement(Key.ENCLOSING); |
| 910 Element element = decoder.getElement(Key.ELEMENT); | 935 Element element = decoder.getElement(Key.ELEMENT); |
| 911 WrappedMessage warning = | 936 WrappedMessage warning = |
| 912 deserializeWrappedMessage(decoder, Key.WARNING); | 937 deserializeWrappedMessage(decoder, Key.WARNING); |
| 913 WrappedMessage info = deserializeWrappedMessage(decoder, Key.INFO); | 938 WrappedMessage info = deserializeWrappedMessage(decoder, Key.INFO); |
| 914 return new WarnOnUseElementX(warning, info, enclosing, element); | 939 return new WarnOnUseElementX(warning, info, enclosing, element); |
| 915 case SerializedElementKind.EXTERNAL_LIBRARY: | 940 case SerializedElementKind.AMBIGUOUS: |
| 941 Element enclosingElement = decoder.getElement(Key.ENCLOSING); |
| 942 Element existingElement = decoder.getElement(Key.EXISTING); |
| 943 Element newElement = decoder.getElement(Key.NEW); |
| 944 MessageKind messageKind = |
| 945 decoder.getEnum(Key.MESSAGE_KIND, MessageKind.values); |
| 946 Map messageArguments = |
| 947 deserializeMessageArguments(decoder, Key.ARGUMENTS); |
| 948 return new AmbiguousImportX( |
| 949 messageKind, messageArguments, |
| 950 enclosingElement, existingElement, newElement); |
| 951 case SerializedElementKind.EXTERNAL_LIBRARY: |
| 916 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: | 952 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: |
| 917 case SerializedElementKind.EXTERNAL_CLASS_MEMBER: | 953 case SerializedElementKind.EXTERNAL_CLASS_MEMBER: |
| 918 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: | 954 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: |
| 919 break; | 955 break; |
| 920 } | 956 } |
| 921 throw new UnsupportedError("Unexpected element kind '${elementKind}."); | 957 throw new UnsupportedError("Unexpected element kind '${elementKind}."); |
| 922 } | 958 } |
| 923 } | 959 } |
| OLD | NEW |