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

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

Issue 1072443005: Deal with type arguments of generic local functions in VM mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 static RawInstance* CreateFunctionTypeMirror(const Class& cls, 233 static RawInstance* CreateFunctionTypeMirror(const Class& cls,
234 const AbstractType& type) { 234 const AbstractType& type) {
235 const Array& args = Array::Handle(Array::New(2)); 235 const Array& args = Array::Handle(Array::New(2));
236 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); 236 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls)));
237 args.SetAt(1, type); 237 args.SetAt(1, type);
238 return CreateMirror(Symbols::_LocalFunctionTypeMirror(), args); 238 return CreateMirror(Symbols::_LocalFunctionTypeMirror(), args);
239 } 239 }
240 240
241 241
242 static RawInstance* CreateMethodMirror(const Function& func, 242 static RawInstance* CreateMethodMirror(const Function& func,
243 const Instance& owner_mirror) { 243 const Instance& owner_mirror,
244 const Array& args = Array::Handle(Array::New(12)); 244 const AbstractType& instantiator) {
245 const Array& args = Array::Handle(Array::New(13));
245 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); 246 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func)));
246 247
247 String& name = String::Handle(func.name()); 248 String& name = String::Handle(func.name());
248 name = String::IdentifierPrettyNameRetainPrivate(name); 249 name = String::IdentifierPrettyNameRetainPrivate(name);
249 args.SetAt(1, name); 250 args.SetAt(1, name);
250 251
251 args.SetAt(2, owner_mirror); 252 args.SetAt(2, owner_mirror);
252 args.SetAt(3, Bool::Get(func.is_static())); 253 args.SetAt(3, instantiator);
253 args.SetAt(4, Bool::Get(func.is_abstract())); 254 args.SetAt(4, Bool::Get(func.is_static()));
254 args.SetAt(5, Bool::Get(func.IsGetterFunction())); 255 args.SetAt(5, Bool::Get(func.is_abstract()));
255 args.SetAt(6, Bool::Get(func.IsSetterFunction())); 256 args.SetAt(6, Bool::Get(func.IsGetterFunction()));
257 args.SetAt(7, Bool::Get(func.IsSetterFunction()));
256 258
257 bool isConstructor = (func.kind() == RawFunction::kConstructor); 259 bool isConstructor = (func.kind() == RawFunction::kConstructor);
258 args.SetAt(7, Bool::Get(isConstructor)); 260 args.SetAt(8, Bool::Get(isConstructor));
259 args.SetAt(8, Bool::Get(isConstructor && func.is_const())); 261 args.SetAt(9, Bool::Get(isConstructor && func.is_const()));
260 args.SetAt(9, Bool::Get(isConstructor && func.IsGenerativeConstructor())); 262 args.SetAt(10, Bool::Get(isConstructor && func.IsGenerativeConstructor()));
261 args.SetAt(10, Bool::Get(isConstructor && func.is_redirecting())); 263 args.SetAt(11, Bool::Get(isConstructor && func.is_redirecting()));
262 args.SetAt(11, Bool::Get(isConstructor && func.IsFactory())); 264 args.SetAt(12, Bool::Get(isConstructor && func.IsFactory()));
263 265
264 return CreateMirror(Symbols::_LocalMethodMirror(), args); 266 return CreateMirror(Symbols::_LocalMethodMirror(), args);
265 } 267 }
266 268
267 269
268 static RawInstance* CreateVariableMirror(const Field& field, 270 static RawInstance* CreateVariableMirror(const Field& field,
269 const Instance& owner_mirror) { 271 const Instance& owner_mirror) {
270 const MirrorReference& field_ref = 272 const MirrorReference& field_ref =
271 MirrorReference::Handle(MirrorReference::New(field)); 273 MirrorReference::Handle(MirrorReference::New(field));
272 274
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 746
745 static RawAbstractType* InstantiateType(const AbstractType& type, 747 static RawAbstractType* InstantiateType(const AbstractType& type,
746 const AbstractType& instantiator) { 748 const AbstractType& instantiator) {
747 ASSERT(type.IsFinalized()); 749 ASSERT(type.IsFinalized());
748 ASSERT(!type.IsMalformed()); 750 ASSERT(!type.IsMalformed());
749 751
750 if (type.IsInstantiated()) { 752 if (type.IsInstantiated()) {
751 return type.Canonicalize(); 753 return type.Canonicalize();
752 } 754 }
753 755
756 if (instantiator.IsNull()) {
757 return type.Canonicalize();
758 }
754 ASSERT(!instantiator.IsNull()); 759 ASSERT(!instantiator.IsNull());
755 ASSERT(instantiator.IsFinalized()); 760 ASSERT(instantiator.IsFinalized());
756 ASSERT(!instantiator.IsMalformed()); 761 ASSERT(!instantiator.IsMalformed());
757 762
758 const TypeArguments& type_args = 763 const TypeArguments& type_args =
759 TypeArguments::Handle(instantiator.arguments()); 764 TypeArguments::Handle(instantiator.arguments());
760 Error& bound_error = Error::Handle(); 765 Error& bound_error = Error::Handle();
761 AbstractType& result = 766 AbstractType& result =
762 AbstractType::Handle(type.InstantiateFrom(type_args, &bound_error)); 767 AbstractType::Handle(type.InstantiateFrom(type_args, &bound_error));
763 if (!bound_error.IsNull()) { 768 if (!bound_error.IsNull()) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 862
858 863
859 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_call_method, 2) { 864 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_call_method, 2) {
860 GET_NON_NULL_NATIVE_ARGUMENT(Instance, 865 GET_NON_NULL_NATIVE_ARGUMENT(Instance,
861 owner_mirror, 866 owner_mirror,
862 arguments->NativeArgAt(0)); 867 arguments->NativeArgAt(0));
863 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 868 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
864 const Class& cls = Class::Handle(ref.GetClassReferent()); 869 const Class& cls = Class::Handle(ref.GetClassReferent());
865 const Function& func = Function::Handle(CallMethod(cls)); 870 const Function& func = Function::Handle(CallMethod(cls));
866 ASSERT(!func.IsNull()); 871 ASSERT(!func.IsNull());
867 return CreateMethodMirror(func, owner_mirror); 872 return CreateMethodMirror(func, owner_mirror, AbstractType::Handle());
868 } 873 }
869 874
870 875
871 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 2) { 876 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 2) {
872 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0)); 877 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0));
873 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 878 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
874 const Class& cls = Class::Handle(ref.GetClassReferent()); 879 const Class& cls = Class::Handle(ref.GetClassReferent());
875 const Function& func = Function::Handle(cls.signature_function()); 880 const Function& func = Function::Handle(cls.signature_function());
876 return CreateParameterMirrorList(func, owner); 881 return CreateParameterMirrorList(func, owner);
877 } 882 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 const Class& cls = Class::Handle(type.type_class()); 1007 const Class& cls = Class::Handle(type.type_class());
1003 const AbstractType& mixin_type = AbstractType::Handle(cls.mixin()); 1008 const AbstractType& mixin_type = AbstractType::Handle(cls.mixin());
1004 if (mixin_type.IsNull()) { 1009 if (mixin_type.IsNull()) {
1005 return mixin_type.raw(); 1010 return mixin_type.raw();
1006 } 1011 }
1007 1012
1008 return InstantiateType(mixin_type, instantiator); 1013 return InstantiateType(mixin_type, instantiator);
1009 } 1014 }
1010 1015
1011 1016
1012 DEFINE_NATIVE_ENTRY(ClassMirror_members, 2) { 1017 DEFINE_NATIVE_ENTRY(ClassMirror_members, 3) {
1013 GET_NON_NULL_NATIVE_ARGUMENT(Instance, 1018 GET_NON_NULL_NATIVE_ARGUMENT(Instance,
1014 owner_mirror, 1019 owner_mirror,
1015 arguments->NativeArgAt(0)); 1020 arguments->NativeArgAt(0));
1016 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 1021 GET_NATIVE_ARGUMENT(AbstractType,
1022 owner_instantiator,
1023 arguments->NativeArgAt(1));
1024 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(2));
1017 const Class& klass = Class::Handle(ref.GetClassReferent()); 1025 const Class& klass = Class::Handle(ref.GetClassReferent());
1018 1026
1019 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); 1027 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate));
1020 if (!error.IsNull()) { 1028 if (!error.IsNull()) {
1021 Exceptions::PropagateError(error); 1029 Exceptions::PropagateError(error);
1022 } 1030 }
1023 1031
1024 const Array& fields = Array::Handle(klass.fields()); 1032 const Array& fields = Array::Handle(klass.fields());
1025 const intptr_t num_fields = fields.Length(); 1033 const intptr_t num_fields = fields.Length();
1026 1034
(...skipping 13 matching lines...) Expand all
1040 } 1048 }
1041 } 1049 }
1042 1050
1043 Function& func = Function::Handle(); 1051 Function& func = Function::Handle();
1044 for (intptr_t i = 0; i < num_functions; i++) { 1052 for (intptr_t i = 0; i < num_functions; i++) {
1045 func ^= functions.At(i); 1053 func ^= functions.At(i);
1046 if (func.is_reflectable() && 1054 if (func.is_reflectable() &&
1047 (func.kind() == RawFunction::kRegularFunction || 1055 (func.kind() == RawFunction::kRegularFunction ||
1048 func.kind() == RawFunction::kGetterFunction || 1056 func.kind() == RawFunction::kGetterFunction ||
1049 func.kind() == RawFunction::kSetterFunction)) { 1057 func.kind() == RawFunction::kSetterFunction)) {
1050 member_mirror = CreateMethodMirror(func, owner_mirror); 1058 member_mirror = CreateMethodMirror(func, owner_mirror,
1059 owner_instantiator);
1051 member_mirrors.Add(member_mirror); 1060 member_mirrors.Add(member_mirror);
1052 } 1061 }
1053 } 1062 }
1054 1063
1055 return member_mirrors.raw(); 1064 return member_mirrors.raw();
1056 } 1065 }
1057 1066
1058 1067
1059 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 2) { 1068 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 3) {
1060 GET_NON_NULL_NATIVE_ARGUMENT(Instance, 1069 GET_NON_NULL_NATIVE_ARGUMENT(Instance,
1061 owner_mirror, 1070 owner_mirror,
1062 arguments->NativeArgAt(0)); 1071 arguments->NativeArgAt(0));
1063 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 1072 GET_NATIVE_ARGUMENT(AbstractType,
1073 owner_instantiator,
1074 arguments->NativeArgAt(1));
1075 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(2));
1064 const Class& klass = Class::Handle(ref.GetClassReferent()); 1076 const Class& klass = Class::Handle(ref.GetClassReferent());
1065 1077
1066 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); 1078 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate));
1067 if (!error.IsNull()) { 1079 if (!error.IsNull()) {
1068 Exceptions::PropagateError(error); 1080 Exceptions::PropagateError(error);
1069 } 1081 }
1070 1082
1071 const Array& functions = Array::Handle(klass.functions()); 1083 const Array& functions = Array::Handle(klass.functions());
1072 const intptr_t num_functions = functions.Length(); 1084 const intptr_t num_functions = functions.Length();
1073 1085
1074 Instance& constructor_mirror = Instance::Handle(); 1086 Instance& constructor_mirror = Instance::Handle();
1075 const GrowableObjectArray& constructor_mirrors = GrowableObjectArray::Handle( 1087 const GrowableObjectArray& constructor_mirrors = GrowableObjectArray::Handle(
1076 GrowableObjectArray::New(num_functions)); 1088 GrowableObjectArray::New(num_functions));
1077 1089
1078 Function& func = Function::Handle(); 1090 Function& func = Function::Handle();
1079 for (intptr_t i = 0; i < num_functions; i++) { 1091 for (intptr_t i = 0; i < num_functions; i++) {
1080 func ^= functions.At(i); 1092 func ^= functions.At(i);
1081 if (func.is_reflectable() && func.kind() == RawFunction::kConstructor) { 1093 if (func.is_reflectable() && func.kind() == RawFunction::kConstructor) {
1082 constructor_mirror = CreateMethodMirror(func, owner_mirror); 1094 constructor_mirror = CreateMethodMirror(func, owner_mirror,
1095 owner_instantiator);
1083 constructor_mirrors.Add(constructor_mirror); 1096 constructor_mirrors.Add(constructor_mirror);
1084 } 1097 }
1085 } 1098 }
1086 1099
1087 return constructor_mirrors.raw(); 1100 return constructor_mirrors.raw();
1088 } 1101 }
1089 1102
1090 1103
1091 DEFINE_NATIVE_ENTRY(LibraryMirror_members, 2) { 1104 DEFINE_NATIVE_ENTRY(LibraryMirror_members, 2) {
1092 GET_NON_NULL_NATIVE_ARGUMENT(Instance, 1105 GET_NON_NULL_NATIVE_ARGUMENT(Instance,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 if (!field.is_synthetic()) { 1140 if (!field.is_synthetic()) {
1128 member_mirror = CreateVariableMirror(field, owner_mirror); 1141 member_mirror = CreateVariableMirror(field, owner_mirror);
1129 member_mirrors.Add(member_mirror); 1142 member_mirrors.Add(member_mirror);
1130 } 1143 }
1131 } else if (entry.IsFunction()) { 1144 } else if (entry.IsFunction()) {
1132 const Function& func = Function::Cast(entry); 1145 const Function& func = Function::Cast(entry);
1133 if (func.is_reflectable() && 1146 if (func.is_reflectable() &&
1134 (func.kind() == RawFunction::kRegularFunction || 1147 (func.kind() == RawFunction::kRegularFunction ||
1135 func.kind() == RawFunction::kGetterFunction || 1148 func.kind() == RawFunction::kGetterFunction ||
1136 func.kind() == RawFunction::kSetterFunction)) { 1149 func.kind() == RawFunction::kSetterFunction)) {
1137 member_mirror = CreateMethodMirror(func, owner_mirror); 1150 member_mirror = CreateMethodMirror(func, owner_mirror,
1151 AbstractType::Handle());
1138 member_mirrors.Add(member_mirror); 1152 member_mirrors.Add(member_mirror);
1139 } 1153 }
1140 } 1154 }
1141 } 1155 }
1142 1156
1143 return member_mirrors.raw(); 1157 return member_mirrors.raw();
1144 } 1158 }
1145 1159
1146 1160
1147 DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 1) { 1161 DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 1) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 Function& function = Function::Handle(); 1391 Function& function = Function::Handle();
1378 bool callable = closure.IsCallable(&function); 1392 bool callable = closure.IsCallable(&function);
1379 if (callable) { 1393 if (callable) {
1380 if (function.IsImplicitClosureFunction()) { 1394 if (function.IsImplicitClosureFunction()) {
1381 // The VM uses separate Functions for tear-offs, but the mirrors consider 1395 // The VM uses separate Functions for tear-offs, but the mirrors consider
1382 // the tear-offs to be the same as the torn-off methods. Avoid handing out 1396 // the tear-offs to be the same as the torn-off methods. Avoid handing out
1383 // a reference to the tear-off here to avoid a special case in the 1397 // a reference to the tear-off here to avoid a special case in the
1384 // the equality test. 1398 // the equality test.
1385 function = function.parent_function(); 1399 function = function.parent_function();
1386 } 1400 }
1387 return CreateMethodMirror(function, Instance::null_instance()); 1401
1402 Type& instantiator = Type::Handle();
1403 if (closure.IsClosure()) {
1404 const TypeArguments& arguments =
1405 TypeArguments::Handle(Closure::GetTypeArguments(closure));
1406 const Class& cls =
1407 Class::Handle(Isolate::Current()->object_store()->object_class());
1408 instantiator = Type::New(cls, arguments, Scanner::kNoSourcePos);
1409 instantiator.SetIsFinalized();
1410 }
1411 return CreateMethodMirror(function,
1412 Instance::null_instance(),
1413 instantiator);
1388 } 1414 }
1389 return Instance::null(); 1415 return Instance::null();
1390 } 1416 }
1391 1417
1392 1418
1393 DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 5) { 1419 DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 5) {
1394 // Argument 0 is the mirror, which is unused by the native. It exists 1420 // Argument 0 is the mirror, which is unused by the native. It exists
1395 // because this native is an instance method in order to be polymorphic 1421 // because this native is an instance method in order to be polymorphic
1396 // with its cousins. 1422 // with its cousins.
1397 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 1423 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1822 InvocationMirror::kTopLevel, 1848 InvocationMirror::kTopLevel,
1823 InvocationMirror::kSetter); 1849 InvocationMirror::kSetter);
1824 UNREACHABLE(); 1850 UNREACHABLE();
1825 } 1851 }
1826 1852
1827 field.set_value(value); 1853 field.set_value(value);
1828 return value.raw(); 1854 return value.raw();
1829 } 1855 }
1830 1856
1831 1857
1832 DEFINE_NATIVE_ENTRY(MethodMirror_owner, 1) { 1858 DEFINE_NATIVE_ENTRY(MethodMirror_owner, 2) {
1833 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1859 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1860 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1));
1834 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1861 const Function& func = Function::Handle(ref.GetFunctionReferent());
1835 if (func.IsNonImplicitClosureFunction()) { 1862 if (func.IsNonImplicitClosureFunction()) {
1836 return CreateMethodMirror(Function::Handle( 1863 return CreateMethodMirror(Function::Handle(
1837 func.parent_function()), Object::null_instance()); 1864 func.parent_function()), Object::null_instance(), instantiator);
1838 } 1865 }
1839 const Class& owner = Class::Handle(func.Owner()); 1866 const Class& owner = Class::Handle(func.Owner());
1840 if (owner.IsTopLevel()) { 1867 if (owner.IsTopLevel()) {
1841 return CreateLibraryMirror(Library::Handle(owner.library())); 1868 return CreateLibraryMirror(Library::Handle(owner.library()));
1842 } 1869 }
1843 1870
1844 AbstractType& type = AbstractType::Handle(owner.DeclarationType()); 1871 AbstractType& type = AbstractType::Handle(owner.DeclarationType());
1845 return CreateClassMirror(owner, type, Bool::True(), Object::null_instance()); 1872 return CreateClassMirror(owner, type, Bool::True(), Object::null_instance());
1846 } 1873 }
1847 1874
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2047 } 2074 }
2048 2075
2049 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { 2076 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) {
2050 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); 2077 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
2051 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); 2078 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
2052 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); 2079 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw();
2053 } 2080 }
2054 2081
2055 2082
2056 } // namespace dart 2083 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698