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

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') | 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/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 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 859
858 860
859 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_call_method, 2) { 861 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_call_method, 2) {
860 GET_NON_NULL_NATIVE_ARGUMENT(Instance, 862 GET_NON_NULL_NATIVE_ARGUMENT(Instance,
861 owner_mirror, 863 owner_mirror,
862 arguments->NativeArgAt(0)); 864 arguments->NativeArgAt(0));
863 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 865 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
864 const Class& cls = Class::Handle(ref.GetClassReferent()); 866 const Class& cls = Class::Handle(ref.GetClassReferent());
865 const Function& func = Function::Handle(CallMethod(cls)); 867 const Function& func = Function::Handle(CallMethod(cls));
866 ASSERT(!func.IsNull()); 868 ASSERT(!func.IsNull());
867 return CreateMethodMirror(func, owner_mirror); 869 return CreateMethodMirror(func, owner_mirror, AbstractType::Handle());
868 } 870 }
869 871
870 872
871 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 2) { 873 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 2) {
872 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0)); 874 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0));
873 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 875 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
874 const Class& cls = Class::Handle(ref.GetClassReferent()); 876 const Class& cls = Class::Handle(ref.GetClassReferent());
875 const Function& func = Function::Handle(cls.signature_function()); 877 const Function& func = Function::Handle(cls.signature_function());
876 return CreateParameterMirrorList(func, owner); 878 return CreateParameterMirrorList(func, owner);
877 } 879 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 } 1042 }
1041 } 1043 }
1042 1044
1043 Function& func = Function::Handle(); 1045 Function& func = Function::Handle();
1044 for (intptr_t i = 0; i < num_functions; i++) { 1046 for (intptr_t i = 0; i < num_functions; i++) {
1045 func ^= functions.At(i); 1047 func ^= functions.At(i);
1046 if (func.is_reflectable() && 1048 if (func.is_reflectable() &&
1047 (func.kind() == RawFunction::kRegularFunction || 1049 (func.kind() == RawFunction::kRegularFunction ||
1048 func.kind() == RawFunction::kGetterFunction || 1050 func.kind() == RawFunction::kGetterFunction ||
1049 func.kind() == RawFunction::kSetterFunction)) { 1051 func.kind() == RawFunction::kSetterFunction)) {
1050 member_mirror = CreateMethodMirror(func, owner_mirror); 1052 member_mirror = CreateMethodMirror(func, owner_mirror,
1053 AbstractType::Handle());
1051 member_mirrors.Add(member_mirror); 1054 member_mirrors.Add(member_mirror);
1052 } 1055 }
1053 } 1056 }
1054 1057
1055 return member_mirrors.raw(); 1058 return member_mirrors.raw();
1056 } 1059 }
1057 1060
1058 1061
1059 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 2) { 1062 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 2) {
1060 GET_NON_NULL_NATIVE_ARGUMENT(Instance, 1063 GET_NON_NULL_NATIVE_ARGUMENT(Instance,
(...skipping 11 matching lines...) Expand all
1072 const intptr_t num_functions = functions.Length(); 1075 const intptr_t num_functions = functions.Length();
1073 1076
1074 Instance& constructor_mirror = Instance::Handle(); 1077 Instance& constructor_mirror = Instance::Handle();
1075 const GrowableObjectArray& constructor_mirrors = GrowableObjectArray::Handle( 1078 const GrowableObjectArray& constructor_mirrors = GrowableObjectArray::Handle(
1076 GrowableObjectArray::New(num_functions)); 1079 GrowableObjectArray::New(num_functions));
1077 1080
1078 Function& func = Function::Handle(); 1081 Function& func = Function::Handle();
1079 for (intptr_t i = 0; i < num_functions; i++) { 1082 for (intptr_t i = 0; i < num_functions; i++) {
1080 func ^= functions.At(i); 1083 func ^= functions.At(i);
1081 if (func.is_reflectable() && func.kind() == RawFunction::kConstructor) { 1084 if (func.is_reflectable() && func.kind() == RawFunction::kConstructor) {
1082 constructor_mirror = CreateMethodMirror(func, owner_mirror); 1085 constructor_mirror = CreateMethodMirror(func, owner_mirror,
1086 AbstractType::Handle());
1083 constructor_mirrors.Add(constructor_mirror); 1087 constructor_mirrors.Add(constructor_mirror);
1084 } 1088 }
1085 } 1089 }
1086 1090
1087 return constructor_mirrors.raw(); 1091 return constructor_mirrors.raw();
1088 } 1092 }
1089 1093
1090 1094
1091 DEFINE_NATIVE_ENTRY(LibraryMirror_members, 2) { 1095 DEFINE_NATIVE_ENTRY(LibraryMirror_members, 2) {
1092 GET_NON_NULL_NATIVE_ARGUMENT(Instance, 1096 GET_NON_NULL_NATIVE_ARGUMENT(Instance,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 if (!field.is_synthetic()) { 1131 if (!field.is_synthetic()) {
1128 member_mirror = CreateVariableMirror(field, owner_mirror); 1132 member_mirror = CreateVariableMirror(field, owner_mirror);
1129 member_mirrors.Add(member_mirror); 1133 member_mirrors.Add(member_mirror);
1130 } 1134 }
1131 } else if (entry.IsFunction()) { 1135 } else if (entry.IsFunction()) {
1132 const Function& func = Function::Cast(entry); 1136 const Function& func = Function::Cast(entry);
1133 if (func.is_reflectable() && 1137 if (func.is_reflectable() &&
1134 (func.kind() == RawFunction::kRegularFunction || 1138 (func.kind() == RawFunction::kRegularFunction ||
1135 func.kind() == RawFunction::kGetterFunction || 1139 func.kind() == RawFunction::kGetterFunction ||
1136 func.kind() == RawFunction::kSetterFunction)) { 1140 func.kind() == RawFunction::kSetterFunction)) {
1137 member_mirror = CreateMethodMirror(func, owner_mirror); 1141 member_mirror = CreateMethodMirror(func, owner_mirror,
1142 AbstractType::Handle());
1138 member_mirrors.Add(member_mirror); 1143 member_mirrors.Add(member_mirror);
1139 } 1144 }
1140 } 1145 }
1141 } 1146 }
1142 1147
1143 return member_mirrors.raw(); 1148 return member_mirrors.raw();
1144 } 1149 }
1145 1150
1146 1151
1147 DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 1) { 1152 DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 1) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 Function& function = Function::Handle(); 1382 Function& function = Function::Handle();
1378 bool callable = closure.IsCallable(&function); 1383 bool callable = closure.IsCallable(&function);
1379 if (callable) { 1384 if (callable) {
1380 if (function.IsImplicitClosureFunction()) { 1385 if (function.IsImplicitClosureFunction()) {
1381 // The VM uses separate Functions for tear-offs, but the mirrors consider 1386 // 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 1387 // 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 1388 // a reference to the tear-off here to avoid a special case in the
1384 // the equality test. 1389 // the equality test.
1385 function = function.parent_function(); 1390 function = function.parent_function();
1386 } 1391 }
1387 return CreateMethodMirror(function, Instance::null_instance()); 1392
1393 Type& instantiator = Type::Handle();
1394 if (closure.IsClosure()) {
1395 const TypeArguments& arguments =
1396 TypeArguments::Handle(Closure::GetTypeArguments(closure));
1397 const Class& cls =
1398 Class::Handle(Isolate::Current()->object_store()->object_class());
1399 instantiator = Type::New(cls, arguments, Scanner::kNoSourcePos);
1400 instantiator.SetIsFinalized();
1401 }
1402 return CreateMethodMirror(function,
1403 Instance::null_instance(),
1404 instantiator);
1388 } 1405 }
1389 return Instance::null(); 1406 return Instance::null();
1390 } 1407 }
1391 1408
1392 1409
1393 DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 5) { 1410 DEFINE_NATIVE_ENTRY(ClassMirror_invoke, 5) {
1394 // Argument 0 is the mirror, which is unused by the native. It exists 1411 // 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 1412 // because this native is an instance method in order to be polymorphic
1396 // with its cousins. 1413 // with its cousins.
1397 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 1414 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, 1839 InvocationMirror::kTopLevel,
1823 InvocationMirror::kSetter); 1840 InvocationMirror::kSetter);
1824 UNREACHABLE(); 1841 UNREACHABLE();
1825 } 1842 }
1826 1843
1827 field.set_value(value); 1844 field.set_value(value);
1828 return value.raw(); 1845 return value.raw();
1829 } 1846 }
1830 1847
1831 1848
1832 DEFINE_NATIVE_ENTRY(MethodMirror_owner, 1) { 1849 DEFINE_NATIVE_ENTRY(MethodMirror_owner, 2) {
1833 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1850 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1851 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1));
1834 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1852 const Function& func = Function::Handle(ref.GetFunctionReferent());
1835 if (func.IsNonImplicitClosureFunction()) { 1853 if (func.IsNonImplicitClosureFunction()) {
1836 return CreateMethodMirror(Function::Handle( 1854 return CreateMethodMirror(Function::Handle(
1837 func.parent_function()), Object::null_instance()); 1855 func.parent_function()), Object::null_instance(), instantiator);
1838 } 1856 }
1839 const Class& owner = Class::Handle(func.Owner()); 1857 const Class& owner = Class::Handle(func.Owner());
1840 if (owner.IsTopLevel()) { 1858 if (owner.IsTopLevel()) {
1841 return CreateLibraryMirror(Library::Handle(owner.library())); 1859 return CreateLibraryMirror(Library::Handle(owner.library()));
1842 } 1860 }
1843 1861
1844 AbstractType& type = AbstractType::Handle(owner.DeclarationType()); 1862 AbstractType& type = AbstractType::Handle(owner.DeclarationType());
1845 return CreateClassMirror(owner, type, Bool::True(), Object::null_instance()); 1863 return CreateClassMirror(owner, type, Bool::True(), Object::null_instance());
1846 } 1864 }
1847 1865
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2047 } 2065 }
2048 2066
2049 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { 2067 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) {
2050 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); 2068 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
2051 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); 2069 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
2052 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); 2070 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw();
2053 } 2071 }
2054 2072
2055 2073
2056 } // namespace dart 2074 } // 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