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

Side by Side Diff: runtime/lib/mirrors.cc

Issue 2615943004: Reapply "reflectType() dynamic type arguments support (#26012)" (Closed)
Patch Set: Add a test. Created 3 years, 11 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/mirrors_used.dart ('k') | runtime/lib/mirrors_impl.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include "lib/mirrors.h" 5 #include "lib/mirrors.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/bootstrap_natives.h" 8 #include "vm/bootstrap_natives.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 Object::null_instance()); 812 Object::null_instance());
813 } 813 }
814 814
815 815
816 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { 816 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) {
817 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); 817 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
818 return CreateTypeMirror(type); 818 return CreateTypeMirror(type);
819 } 819 }
820 820
821 821
822 DEFINE_NATIVE_ENTRY(Mirrors_instantiateGenericType, 2) {
823 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
824 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(1));
825
826 ASSERT(type.HasResolvedTypeClass());
827 const Class& clz = Class::Handle(type.type_class());
828 if (!clz.IsGeneric()) {
829 const Array& error_args = Array::Handle(Array::New(3));
830 error_args.SetAt(0, type);
831 error_args.SetAt(1, String::Handle(String::New("key")));
832 error_args.SetAt(2, String::Handle(String::New(
833 "Type must be a generic class or function.")));
834 Exceptions::ThrowByType(Exceptions::kArgumentValue, error_args);
835 UNREACHABLE();
836 }
837 if (clz.NumTypeParameters() != args.Length()) {
838 const Array& error_args = Array::Handle(Array::New(3));
839 error_args.SetAt(0, args);
840 error_args.SetAt(1, String::Handle(String::New("typeArguments")));
841 error_args.SetAt(2, String::Handle(String::New(
842 "Number of type arguments does not match.")));
843 Exceptions::ThrowByType(Exceptions::kArgumentValue, error_args);
844 UNREACHABLE();
845 }
846
847 intptr_t num_expected_type_arguments = args.Length();
848 TypeArguments& type_args_obj = TypeArguments::Handle();
849 type_args_obj ^= TypeArguments::New(num_expected_type_arguments);
850 AbstractType& type_arg = AbstractType::Handle();
851 Instance& instance = Instance::Handle();
852 for (intptr_t i = 0; i < args.Length(); i++) {
853 instance ^= args.At(i);
854 if (!instance.IsType()) {
855 const Array& error_args = Array::Handle(Array::New(3));
856 error_args.SetAt(0, args);
857 error_args.SetAt(1, String::Handle(String::New("typeArguments")));
858 error_args.SetAt(2, String::Handle(String::New(
859 "Type arguments must be instances of Type.")));
860 Exceptions::ThrowByType(Exceptions::kArgumentValue, error_args);
861 UNREACHABLE();
862 }
863 type_arg ^= args.At(i);
864 type_args_obj.SetTypeAt(i, type_arg);
865 }
866
867 Type& instantiated_type =
868 Type::Handle(Type::New(clz, type_args_obj, TokenPosition::kNoSource));
869 instantiated_type ^= ClassFinalizer::FinalizeType(
870 clz, instantiated_type, ClassFinalizer::kCanonicalize);
871 if (instantiated_type.IsMalbounded()) {
872 const LanguageError& type_error =
873 LanguageError::Handle(instantiated_type.error());
874 const Array& error_args = Array::Handle(Array::New(3));
875 error_args.SetAt(0, args);
876 error_args.SetAt(1, String::Handle(String::New("typeArguments")));
877 error_args.SetAt(2, String::Handle(type_error.FormatMessage()));
878 Exceptions::ThrowByType(Exceptions::kArgumentValue, error_args);
879 UNREACHABLE();
880 }
881
882 return instantiated_type.raw();
883 }
884
885
822 DEFINE_NATIVE_ENTRY(Mirrors_mangleName, 2) { 886 DEFINE_NATIVE_ENTRY(Mirrors_mangleName, 2) {
823 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0)); 887 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0));
824 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 888 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
825 const Library& lib = Library::Handle(ref.GetLibraryReferent()); 889 const Library& lib = Library::Handle(ref.GetLibraryReferent());
826 return lib.IsPrivate(name) ? lib.PrivateName(name) : name.raw(); 890 return lib.IsPrivate(name) ? lib.PrivateName(name) : name.raw();
827 } 891 }
828 892
829 893
830 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { 894 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) {
831 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); 895 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0));
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 2080
2017 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { 2081 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) {
2018 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); 2082 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
2019 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); 2083 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
2020 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw(); 2084 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw();
2021 } 2085 }
2022 2086
2023 #endif // !PRODUCT 2087 #endif // !PRODUCT
2024 2088
2025 } // namespace dart 2089 } // namespace dart
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/mirrors_used.dart ('k') | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698