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

Unified Diff: pkg/compiler/lib/src/serialization/type_serialization.dart

Issue 1192103002: Support serialization of the compiler backbone. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/serialization/type_serialization.dart
diff --git a/pkg/compiler/lib/src/serialization/type_serialization.dart b/pkg/compiler/lib/src/serialization/type_serialization.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cf3bfa71de8b3c7a01affe938525675bb42f64a5
--- /dev/null
+++ b/pkg/compiler/lib/src/serialization/type_serialization.dart
@@ -0,0 +1,93 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library dart2js.serialization.types;
+
+import '../dart_types.dart';
+import 'serialization.dart';
+import 'keys.dart';
+
+class TypeSerializer extends DartTypeVisitor<dynamic, ObjectSerializer> {
+ const TypeSerializer();
+
+ void apply(DartType type, ObjectSerializer serializer) {
+ type.accept(this, serializer);
+ }
+
+ void visitType(DartType type, ObjectSerializer serializer) {
+ throw new UnsupportedError('Unsupported type: $type');
+ }
+
+ void visitVoidType(VoidType type, ObjectSerializer serializer) {}
+
+ void visitTypeVariableType(TypeVariableType type,
+ ObjectSerializer serializer) {
+ serializer.setElement(Key.ELEMENT, type.element);
+ }
+
+ void visitFunctionType(FunctionType type,
+ ObjectSerializer serializer) {
+ // TODO(johnniwinther): Support encoding of `type.element`.
+ serializer.setType(Key.RETURN_TYPE, type.returnType);
+ serializer.setTypes(Key.PARAMETER_TYPES, type.parameterTypes);
+ serializer.setTypes(
+ Key.OPTIONAL_PARAMETER_TYPES, type.optionalParameterTypes);
+ serializer.setStrings(Key.NAMED_PARAMETERS, type.namedParameters);
+ serializer.setTypes(Key.NAMED_PARAMETER_TYPES, type.namedParameterTypes);
+ }
+
+ void visitMalformedType(MalformedType type, ObjectSerializer serializer) {
+
+ }
+
+ void visitInterfaceType(InterfaceType type, ObjectSerializer serializer) {
+ serializer.setElement(Key.ELEMENT, type.element);
+ serializer.setTypes(Key.TYPE_ARGUMENTS, type.typeArguments);
+ }
+
+ void visitTypedefType(TypedefType type, ObjectSerializer serializer) {
+ serializer.setElement(Key.ELEMENT, type.element);
+ serializer.setTypes(Key.TYPE_ARGUMENTS, type.typeArguments);
+ }
+
+ void visitDynamicType(DynamicType type, ObjectSerializer serializer) {}
+}
+
+class TypeDeserializer {
+ static DartType deserialize(ObjectDeserializer deserializer) {
+ TypeKind typeKind = deserializer.getEnum(Key.KIND, TypeKind.values);
+ switch (typeKind) {
+ case TypeKind.INTERFACE:
+ return new InterfaceType(
+ deserializer.getElement(Key.ELEMENT),
+ deserializer.getTypes(Key.TYPE_ARGUMENTS, isOptional: true));
+ case TypeKind.FUNCTION:
+ // TODO(johnniwinther): Support decoding of `type.element`.
+ return new FunctionType.synthesized(
+ deserializer.getType(Key.RETURN_TYPE),
+ deserializer.getTypes(Key.PARAMETER_TYPES, isOptional: true),
+ deserializer.getTypes(
+ Key.OPTIONAL_PARAMETER_TYPES, isOptional: true),
+ deserializer.getStrings(
+ Key.NAMED_PARAMETERS, isOptional: true),
+ deserializer.getTypes(
+ Key.NAMED_PARAMETER_TYPES, isOptional: true));
+ case TypeKind.TYPE_VARIABLE:
+ return new TypeVariableType(
+ deserializer.getElement(Key.ELEMENT));
+ case TypeKind.TYPEDEF:
+ return new TypedefType(
+ deserializer.getElement(Key.ELEMENT),
+ deserializer.getTypes(Key.TYPE_ARGUMENTS, isOptional: true));
+ case TypeKind.STATEMENT:
+ case TypeKind.MALFORMED_TYPE:
+ throw new UnsupportedError("Unexpected type kind '${typeKind}.");
+ case TypeKind.DYNAMIC:
+ return const DynamicType();
+ case TypeKind.VOID:
+ return const VoidType();
+ }
+ }
+}
+

Powered by Google App Engine
This is Rietveld 408576698