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

Unified Diff: pkg/compiler/lib/src/js_backend/backend_serialization.dart

Issue 1896843002: Store and serialize NativeBehavior in TreeElements. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | pkg/compiler/lib/src/native/behavior.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_backend/backend_serialization.dart
diff --git a/pkg/compiler/lib/src/js_backend/backend_serialization.dart b/pkg/compiler/lib/src/js_backend/backend_serialization.dart
index c7c20395b55f8fc850a618043f6120d6da6e1732..ddd5c507ed898e0f403fb7e56be11724f735fdf4 100644
--- a/pkg/compiler/lib/src/js_backend/backend_serialization.dart
+++ b/pkg/compiler/lib/src/js_backend/backend_serialization.dart
@@ -5,13 +5,26 @@
library js_backend.serialization;
import '../common/backend_api.dart' show BackendSerialization;
+import '../dart_types.dart';
import '../elements/elements.dart';
+import '../js/js.dart' as js;
+import '../native/native.dart';
import '../serialization/serialization.dart'
show DeserializerPlugin, ObjectDecoder, ObjectEncoder, SerializerPlugin;
import '../serialization/keys.dart';
+import '../universe/side_effects.dart';
import 'js_backend.dart';
const String _BACKEND_DATA_TAG = 'jsBackendData';
+const Key DART_TYPES_RETURNED = const Key('dartTypesReturned');
+const Key SPECIAL_TYPES_RETURNED = const Key('specialTypesReturned');
+const Key DART_TYPES_INSTANTIATED = const Key('dartTypesInstantiated');
+const Key SPECIAL_TYPES_INSTANTIATED = const Key('specialTypesInstantiated');
+const Key CODE_TEMPLATE = const Key('codeTemplate');
+const Key SIDE_EFFECTS = const Key('sideEffects');
+const Key THROW_BEHAVIOR = const Key('throwBehavior');
+const Key IS_ALLOCATION = const Key('isAllocation');
+const Key USE_GVN = const Key('useGvn');
class JavaScriptBackendSerialization implements BackendSerialization {
final JavaScriptBackendSerializer serializer;
@@ -37,6 +50,41 @@ class JavaScriptBackendSerializer implements SerializerPlugin {
encoder.setString(Key.NAME, nativeName);
}
}
+
+ /// Returns a list of the [DartType]s in [types].
+ static List<DartType> filterDartTypes(List types) {
+ return types.where((type) => type is DartType).toList();
+ }
+
+ /// Returns a list of the names of the [SpecialType]s in [types].
+ static List<String> filterSpecialTypes(List types) {
+ return types
+ .where((type) => type is SpecialType)
+ .map((SpecialType type) => type.name)
+ .toList();
+ }
+
+ @override
+ void onData(NativeBehavior behavior, ObjectEncoder encoder) {
+ encoder.setTypes(
+ DART_TYPES_RETURNED, filterDartTypes(behavior.typesReturned));
+ encoder.setStrings(
+ SPECIAL_TYPES_RETURNED, filterSpecialTypes(behavior.typesReturned));
+
+ encoder.setTypes(
+ DART_TYPES_INSTANTIATED, filterDartTypes(behavior.typesInstantiated));
+ encoder.setStrings(SPECIAL_TYPES_INSTANTIATED,
+ filterSpecialTypes(behavior.typesInstantiated));
+
+ if (behavior.codeTemplateText != null) {
+ encoder.setString(CODE_TEMPLATE, behavior.codeTemplateText);
+ }
+
+ encoder.setInt(SIDE_EFFECTS, behavior.sideEffects.flags);
+ encoder.setEnum(THROW_BEHAVIOR, behavior.throwBehavior);
+ encoder.setBool(IS_ALLOCATION, behavior.isAllocation);
+ encoder.setBool(USE_GVN, behavior.useGvn);
+ }
}
class JavaScriptBackendDeserializer implements DeserializerPlugin {
@@ -52,4 +100,35 @@ class JavaScriptBackendDeserializer implements DeserializerPlugin {
backend.nativeData.nativeMemberName[element] = nativeName;
}
}
+
+ @override
+ NativeBehavior onData(ObjectDecoder decoder) {
+ SideEffects sideEffects =
+ new SideEffects.fromFlags(decoder.getInt(SIDE_EFFECTS));
+ NativeBehavior behavior = new NativeBehavior.internal(sideEffects);
+
+ behavior.typesReturned
+ .addAll(decoder.getTypes(DART_TYPES_RETURNED, isOptional: true));
+ behavior.typesReturned.addAll(decoder
+ .getStrings(SPECIAL_TYPES_RETURNED, isOptional: true)
+ .map(SpecialType.fromName));
+
+ behavior.typesReturned
+ .addAll(decoder.getTypes(DART_TYPES_INSTANTIATED, isOptional: true));
+ behavior.typesReturned.addAll(decoder
+ .getStrings(SPECIAL_TYPES_INSTANTIATED, isOptional: true)
+ .map(SpecialType.fromName));
+
+ behavior.codeTemplateText =
+ decoder.getString(CODE_TEMPLATE, isOptional: true);
+ if (behavior.codeTemplateText != null) {
+ behavior.codeTemplate = js.js.parseForeignJS(behavior.codeTemplateText);
+ }
+
+ behavior.throwBehavior =
+ decoder.getEnum(THROW_BEHAVIOR, NativeThrowBehavior.values);
+ behavior.isAllocation = decoder.getBool(IS_ALLOCATION);
+ behavior.useGvn = decoder.getBool(USE_GVN);
+ return behavior;
+ }
}
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | pkg/compiler/lib/src/native/behavior.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698