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

Unified Diff: pkg/kernel/runtime/reify/interceptors.dart

Issue 2697873007: Merge the work on Generic Types Reification from 'dart-lang/reify' repo (Closed)
Patch Set: Get back parameter erroneously removed by previous commit Created 3 years, 10 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/kernel/runtime/reify/declarations.dart ('k') | pkg/kernel/runtime/reify/types.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/runtime/reify/interceptors.dart
diff --git a/pkg/kernel/runtime/reify/interceptors.dart b/pkg/kernel/runtime/reify/interceptors.dart
new file mode 100644
index 0000000000000000000000000000000000000000..af4368d521cb23340ce2aacd01022c82839b1270
--- /dev/null
+++ b/pkg/kernel/runtime/reify/interceptors.dart
@@ -0,0 +1,73 @@
+// Copyright (c) 2016, 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 kernel.transformations.reify.runtime.interceptors;
+
+import 'types.dart' show ReifiedType;
+
+/// Helper method that generates a [ReifiedType] corresponding to the literal
+/// type [type].
+///
+/// Calls to this method are recognized in the transformation and replaced by
+/// code that constructs the correct type.
+ReifiedType reify(Type type) {
+ throw "This method should never be called in translated code";
+}
+
+/// Marker interface to indicate that we can extract the runtime type using
+/// a property getter.
+abstract class HasRuntimeTypeGetter {
+ ReifiedType get $type;
+}
+
+/// Interceptor to safely access the type of an object.
+///
+/// For native objects that do not have the `$type` field on them, the
+/// interceptor directly returns the type, otherwise the value of the field is
+/// returned.
+ReifiedType type(dynamic o) {
+ if (o == null) {
+ return reify(Null);
+ } else if (o is HasRuntimeTypeGetter) {
+ return o.$type;
+ } else if (o is bool) {
+ return reify(bool);
+ } else if (o is String) {
+ return reify(String);
+ } else if (o is int) {
+ return reify(int);
+ } else if (o is double) {
+ return reify(double);
+ } else if (o is Type) {
+ return reify(Type);
+ } else if (o is AbstractClassInstantiationError) {
+ return reify(AbstractClassInstantiationError);
+ } else if (o is NoSuchMethodError) {
+ return reify(NoSuchMethodError);
+ } else if (o is CyclicInitializationError) {
+ return reify(CyclicInitializationError);
+ } else if (o is UnsupportedError) {
+ return reify(UnsupportedError);
+ } else if (o is IntegerDivisionByZeroException) {
+ return reify(IntegerDivisionByZeroException);
+ } else if (o is RangeError) {
+ return reify(RangeError);
+ } else if (o is ArgumentError) {
+ return reify(ArgumentError);
+ }
+ ReifiedType type = _type[o];
+ if (type != null) {
+ return type;
+ }
+ throw 'Unable to get runtime type of ${o.runtimeType}';
+}
+
+// This constructor call is not intercepted with [attachType] since the runtime
+// library is currently never transformed.
+final Expando _type = new Expando();
+
+dynamic attachType(Object o, ReifiedType t) {
+ _type[o] = t;
+ return o;
+}
« no previous file with comments | « pkg/kernel/runtime/reify/declarations.dart ('k') | pkg/kernel/runtime/reify/types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698