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

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

Issue 26344006: Substitution for type variables in mirrors on instantiated generics. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/lib/mirrors_impl.dart » ('J')
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/invocation_mirror.h" 5 #include "lib/invocation_mirror.h"
6 #include "vm/bootstrap_natives.h" 6 #include "vm/bootstrap_natives.h"
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/exceptions.h" 10 #include "vm/exceptions.h"
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) { 862 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) {
863 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 863 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
864 const Class& klass = Class::Handle(ref.GetClassReferent()); 864 const Class& klass = Class::Handle(ref.GetClassReferent());
865 const Library& library = Library::Handle(klass.library()); 865 const Library& library = Library::Handle(klass.library());
866 ASSERT(!library.IsNull()); 866 ASSERT(!library.IsNull());
867 return CreateLibraryMirror(library); 867 return CreateLibraryMirror(library);
868 } 868 }
869 869
870 870
871 DEFINE_NATIVE_ENTRY(ClassMirror_supertype, 1) { 871 DEFINE_NATIVE_ENTRY(ClassMirror_supertype, 1) {
872 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 872 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0));
873 const Class& klass = Class::Handle(ref.GetClassReferent()); 873 const Class& cls = Class::Handle(type.type_class());
874 return klass.super_type(); 874 AbstractType& super_type = AbstractType::Handle(cls.super_type());
875 return super_type.raw();
regis 2013/10/09 15:46:51 You can spare a handle: return cls.super_type();
rmacnak 2013/10/11 01:04:22 Done.
876 }
877
878 DEFINE_NATIVE_ENTRY(ClassMirror_supertype_instantiated, 1) {
879 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0));
880 const Class& cls = Class::Handle(type.type_class());
881 AbstractType& super_type = AbstractType::Handle(cls.super_type());
882 AbstractType& result = AbstractType::Handle(super_type.raw());
883
884 ASSERT(super_type.IsType() || super_type.IsMixinAppType());
regis 2013/10/09 15:46:51 That is not correct. This could also be a BoundedT
rmacnak 2013/10/11 01:04:22 We never see a BoundType here even with the additi
885 if (!super_type.IsInstantiated()) {
886 // Why should mixin app types always be instantiated?
regis 2013/10/09 15:46:51 MixinAppType live at compile time only.
rmacnak 2013/10/11 01:04:22 ASSERT now excludes MixinAppType
887 ASSERT(super_type.IsType());
regis 2013/10/09 15:46:51 || super_type.IsBoundedType()
888 AbstractTypeArguments& type_args =
889 AbstractTypeArguments::Handle(type.arguments());
890 Error& error = Error::Handle();
891 result ^= super_type.InstantiateFrom(type_args, &error);
regis 2013/10/09 15:46:51 Instantiating is correct, but using a prefix of ty
892 // Is result canonical?
regis 2013/10/09 15:46:51 No, result is finalized, but not canonical.
893 ASSERT(error.IsNull());
regis 2013/10/09 15:46:51 You could get a bound error if the instance was cr
rmacnak 2013/10/11 01:04:22 Added ThrowInvokeError to be cautious.
894 ASSERT(result.IsType());
895 }
896
897 return result.raw();
875 } 898 }
876 899
877 900
878 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces, 1) { 901 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces, 1) {
879 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 902 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
880 const Class& klass = Class::Handle(ref.GetClassReferent()); 903 const Class& klass = Class::Handle(ref.GetClassReferent());
881 904
882 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); 905 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate));
883 if (!error.IsNull()) { 906 if (!error.IsNull()) {
884 ThrowInvokeError(error); 907 ThrowInvokeError(error);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 Instance::null_instance()); 1102 Instance::null_instance());
1080 } 1103 }
1081 1104
1082 1105
1083 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) { 1106 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) {
1084 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); 1107 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0));
1085 return param.bound(); 1108 return param.bound();
1086 } 1109 }
1087 1110
1088 1111
1112 DEFINE_NATIVE_ENTRY(TypeVariableMirror_instantiate_from, 2) {
1113 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0));
1114 GET_NON_NULL_NATIVE_ARGUMENT(Type, instantiator, arguments->NativeArgAt(1));
1115 AbstractTypeArguments& type_args =
1116 AbstractTypeArguments::Handle(instantiator.arguments());
1117 Error& error = Error::Handle();
1118 AbstractType& result =
1119 AbstractType::Handle(param.InstantiateFrom(type_args, &error));
1120 ASSERT(error.IsNull());
regis 2013/10/09 15:46:51 Why are you certain you will not get a bound error
rmacnak 2013/10/11 01:04:22 The instantiator should always be the type of the
1121 return result.raw();
1122 }
1123
1124
1089 DEFINE_NATIVE_ENTRY(InstanceMirror_invoke, 5) { 1125 DEFINE_NATIVE_ENTRY(InstanceMirror_invoke, 5) {
1090 // Argument 0 is the mirror, which is unused by the native. It exists 1126 // Argument 0 is the mirror, which is unused by the native. It exists
1091 // because this native is an instance method in order to be polymorphic 1127 // because this native is an instance method in order to be polymorphic
1092 // with its cousins. 1128 // with its cousins.
1093 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); 1129 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1));
1094 GET_NON_NULL_NATIVE_ARGUMENT( 1130 GET_NON_NULL_NATIVE_ARGUMENT(
1095 String, function_name, arguments->NativeArgAt(2)); 1131 String, function_name, arguments->NativeArgAt(2));
1096 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); 1132 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3));
1097 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); 1133 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
1098 1134
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 } 1750 }
1715 1751
1716 1752
1717 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1753 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1718 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1754 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1719 const Field& field = Field::Handle(ref.GetFieldReferent()); 1755 const Field& field = Field::Handle(ref.GetFieldReferent());
1720 return field.type(); 1756 return field.type();
1721 } 1757 }
1722 1758
1723 } // namespace dart 1759 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/lib/mirrors_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698