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

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

Issue 2088233003: Serialize erroneous element and more (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. 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
« no previous file with comments | « pkg/compiler/lib/src/library_loader.dart ('k') | pkg/compiler/lib/src/serialization/keys.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 '../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 '../elements/elements.dart'; 11 import '../elements/elements.dart';
12 import '../elements/modelx.dart' show ErroneousElementX;
12 import 'constant_serialization.dart'; 13 import 'constant_serialization.dart';
13 import 'keys.dart'; 14 import 'keys.dart';
14 import 'modelz.dart'; 15 import 'modelz.dart';
15 import 'serialization.dart'; 16 import 'serialization.dart';
16 import 'serialization_util.dart'; 17 import 'serialization_util.dart';
17 18
18 /// Enum kinds used for encoding [Element]s. 19 /// Enum kinds used for encoding [Element]s.
19 enum SerializedElementKind { 20 enum SerializedElementKind {
21 ERROR,
20 LIBRARY, 22 LIBRARY,
21 COMPILATION_UNIT, 23 COMPILATION_UNIT,
22 CLASS, 24 CLASS,
23 ENUM, 25 ENUM,
24 NAMED_MIXIN_APPLICATION, 26 NAMED_MIXIN_APPLICATION,
25 GENERATIVE_CONSTRUCTOR, 27 GENERATIVE_CONSTRUCTOR,
26 DEFAULT_CONSTRUCTOR, 28 DEFAULT_CONSTRUCTOR,
27 FACTORY_CONSTRUCTOR, 29 FACTORY_CONSTRUCTOR,
28 REDIRECTING_FACTORY_CONSTRUCTOR, 30 REDIRECTING_FACTORY_CONSTRUCTOR,
29 FORWARDING_CONSTRUCTOR, 31 FORWARDING_CONSTRUCTOR,
(...skipping 26 matching lines...) Expand all
56 } 58 }
57 59
58 /// Set of serializers used to serialize different kinds of elements by 60 /// Set of serializers used to serialize different kinds of elements by
59 /// encoding into them into [ObjectEncoder]s. 61 /// encoding into them into [ObjectEncoder]s.
60 /// 62 ///
61 /// This class is called from the [Serializer] when an [Element] needs 63 /// This class is called from the [Serializer] when an [Element] needs
62 /// serialization. The [ObjectEncoder] ensures that any [Element], [DartType], 64 /// serialization. The [ObjectEncoder] ensures that any [Element], [DartType],
63 /// and [ConstantExpression] that the serialized [Element] depends upon are also 65 /// and [ConstantExpression] that the serialized [Element] depends upon are also
64 /// serialized. 66 /// serialized.
65 const List<ElementSerializer> ELEMENT_SERIALIZERS = const [ 67 const List<ElementSerializer> ELEMENT_SERIALIZERS = const [
68 const ErrorSerializer(),
66 const LibrarySerializer(), 69 const LibrarySerializer(),
67 const CompilationUnitSerializer(), 70 const CompilationUnitSerializer(),
68 const ClassSerializer(), 71 const ClassSerializer(),
69 const ConstructorSerializer(), 72 const ConstructorSerializer(),
70 const FieldSerializer(), 73 const FieldSerializer(),
71 const FunctionSerializer(), 74 const FunctionSerializer(),
72 const TypedefSerializer(), 75 const TypedefSerializer(),
73 const TypeVariableSerializer(), 76 const TypeVariableSerializer(),
74 const ParameterSerializer(), 77 const ParameterSerializer(),
75 const ImportSerializer(), 78 const ImportSerializer(),
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 if (abstractField.setter != null) { 189 if (abstractField.setter != null) {
187 set.add(abstractField.setter); 190 set.add(abstractField.setter);
188 } 191 }
189 } else { 192 } else {
190 set.add(element); 193 set.add(element);
191 } 194 }
192 }; 195 };
193 } 196 }
194 } 197 }
195 198
199 class ErrorSerializer implements ElementSerializer {
200 const ErrorSerializer();
201
202 SerializedElementKind getSerializedKind(Element element) {
203 if (element.isError) {
204 return SerializedElementKind.ERROR;
205 }
206 return null;
207 }
208
209 void serialize(ErroneousElement element, ObjectEncoder encoder,
210 SerializedElementKind kind) {
211 encoder.setElement(Key.ENCLOSING, element.enclosingElement);
212 encoder.setString(Key.NAME, element.name);
213 encoder.setEnum(Key.MESSAGE_KIND, element.messageKind);
214 if (element.messageArguments.isNotEmpty) {
215 MapEncoder mapEncoder = encoder.createMap(Key.ARGUMENTS);
216 element.messageArguments.forEach((String key, String value) {
217 mapEncoder.setString(key, value);
218 });
219 }
220 }
221 }
222
196 class LibrarySerializer implements ElementSerializer { 223 class LibrarySerializer implements ElementSerializer {
197 const LibrarySerializer(); 224 const LibrarySerializer();
198 225
199 SerializedElementKind getSerializedKind(Element element) { 226 SerializedElementKind getSerializedKind(Element element) {
200 if (element.isLibrary) { 227 if (element.isLibrary) {
201 return SerializedElementKind.LIBRARY; 228 return SerializedElementKind.LIBRARY;
202 } 229 }
203 return null; 230 return null;
204 } 231 }
205 232
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 class ElementDeserializer { 725 class ElementDeserializer {
699 /// Deserializes an [Element] from an [ObjectDecoder]. 726 /// Deserializes an [Element] from an [ObjectDecoder].
700 /// 727 ///
701 /// The class is called from the [Deserializer] when an [Element] 728 /// The class is called from the [Deserializer] when an [Element]
702 /// needs deserialization. The [ObjectDecoder] ensures that any [Element], 729 /// needs deserialization. The [ObjectDecoder] ensures that any [Element],
703 /// [DartType], and [ConstantExpression] that the deserialized [Element] 730 /// [DartType], and [ConstantExpression] that the deserialized [Element]
704 /// depends upon are available. 731 /// depends upon are available.
705 static Element deserialize( 732 static Element deserialize(
706 ObjectDecoder decoder, SerializedElementKind elementKind) { 733 ObjectDecoder decoder, SerializedElementKind elementKind) {
707 switch (elementKind) { 734 switch (elementKind) {
735 case SerializedElementKind.ERROR:
736 Element enclosing = decoder.getElement(Key.ENCLOSING);
737 String name = decoder.getString(Key.NAME);
738 MessageKind messageKind =
739 decoder.getEnum(Key.MESSAGE_KIND, MessageKind.values);
740 Map<String, String> arguments = <String, String>{};
741 MapDecoder mapDecoder = decoder.getMap(Key.ARGUMENTS, isOptional: true);
742 if (mapDecoder != null) {
743 mapDecoder.forEachKey((String key) {
744 arguments[key] = mapDecoder.getString(key);
745 });
746 }
747 return new ErroneousElementX(messageKind, arguments, name, enclosing);
708 case SerializedElementKind.LIBRARY: 748 case SerializedElementKind.LIBRARY:
709 return new LibraryElementZ(decoder); 749 return new LibraryElementZ(decoder);
710 case SerializedElementKind.COMPILATION_UNIT: 750 case SerializedElementKind.COMPILATION_UNIT:
711 return new CompilationUnitElementZ(decoder); 751 return new CompilationUnitElementZ(decoder);
712 case SerializedElementKind.CLASS: 752 case SerializedElementKind.CLASS:
713 return new ClassElementZ(decoder); 753 return new ClassElementZ(decoder);
714 case SerializedElementKind.ENUM: 754 case SerializedElementKind.ENUM:
715 return new EnumClassElementZ(decoder); 755 return new EnumClassElementZ(decoder);
716 case SerializedElementKind.NAMED_MIXIN_APPLICATION: 756 case SerializedElementKind.NAMED_MIXIN_APPLICATION:
717 return new NamedMixinApplicationElementZ(decoder); 757 return new NamedMixinApplicationElementZ(decoder);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 return new LocalVariableElementZ(decoder); 812 return new LocalVariableElementZ(decoder);
773 case SerializedElementKind.EXTERNAL_LIBRARY: 813 case SerializedElementKind.EXTERNAL_LIBRARY:
774 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: 814 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER:
775 case SerializedElementKind.EXTERNAL_CLASS_MEMBER: 815 case SerializedElementKind.EXTERNAL_CLASS_MEMBER:
776 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: 816 case SerializedElementKind.EXTERNAL_CONSTRUCTOR:
777 break; 817 break;
778 } 818 }
779 throw new UnsupportedError("Unexpected element kind '${elementKind}."); 819 throw new UnsupportedError("Unexpected element kind '${elementKind}.");
780 } 820 }
781 } 821 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/library_loader.dart ('k') | pkg/compiler/lib/src/serialization/keys.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698