d5e2fcb430
This CL adds the work done at https://github.com/dart-lang/reify to SDK. The commit that is used for the merge is a2066a68374d49de92ff75f5e1ffc36335fd9451 (Nov 23, 2016). The code is adjusted to respect the changes of the kernel package in SDK since that commit. The reify transformation is run by specifying 'vmreify' target to 'dartk'. The transformation requires its runtime library to present in the program being transformed. The library is found in its default location in SDK checkout if 'dartk' is run from its default location in SDK checkout. To preserve the library in the output, TreeShaker is disabled in 'vmreify' target. The "golden" set of tests is also copied from 'dart-lang/reify' repository, and the appropriate test suite is defined for it. The bash script 'bin/reified_dart' from 'dart-lang/reify' is rewritten as Dart script 'pkg/kernel/bin/reified_dart.dart'. It requires path to 'dartk' and path to SDK. Those are taken from their default locations in SDK if 'reified_dart.dart' is run from its default location in SDK. The added files were formatted using 'dartfmt' with default settings. Additionally, the files were checked with 'dartanalyzer --strong'. The necessary changes were made to fix the error messages. There are some 'hint' and 'error' messages left for some .dart files from the added test cases, but they reflect intentional errors or conventions in those files. R=asgerf@google.com, karlklose@google.com Review-Url: https://codereview.chromium.org/2697873007 .
74 lines
2.3 KiB
Dart
74 lines
2.3 KiB
Dart
// 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;
|
|
}
|