Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
| 10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 // We represent function types as canonical signature classes. | 293 // We represent function types as canonical signature classes. |
| 294 return CreateFunctionTypeMirror(cls, type); | 294 return CreateFunctionTypeMirror(cls, type); |
| 295 } else { | 295 } else { |
| 296 // We represent typedefs as non-canonical signature classes. | 296 // We represent typedefs as non-canonical signature classes. |
| 297 return CreateTypedefMirror(cls, owner_mirror); | 297 return CreateTypedefMirror(cls, owner_mirror); |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 | 300 |
| 301 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0); | 301 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0); |
| 302 | 302 |
| 303 // Non-generics always have their runtime types. Generics may or may not. | |
| 304 ASSERT(!(cls.NumTypeParameters() == 0) || !type.IsNull()); | |
|
siva
2013/08/28 23:12:06
The comment here is very cryptic, you probably sho
| |
| 305 | |
| 303 const Array& args = Array::Handle(Array::New(4)); | 306 const Array& args = Array::Handle(Array::New(4)); |
| 304 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 307 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
| 305 args.SetAt(1, type); | 308 args.SetAt(1, type); |
| 306 args.SetAt(2, String::Handle(cls.UserVisibleName())); | 309 args.SetAt(2, String::Handle(cls.UserVisibleName())); |
| 307 args.SetAt(3, is_generic); | 310 args.SetAt(3, is_generic); |
| 308 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); | 311 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); |
| 309 } | 312 } |
| 310 | 313 |
| 311 | 314 |
| 312 static RawInstance* CreateLibraryMirror(const Library& lib) { | 315 static RawInstance* CreateLibraryMirror(const Library& lib) { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 508 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 506 const Class& klass = Class::Handle(ref.GetClassReferent()); | 509 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 507 return klass.UserVisibleName(); | 510 return klass.UserVisibleName(); |
| 508 } | 511 } |
| 509 | 512 |
| 510 | 513 |
| 511 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) { | 514 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) { |
| 512 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 515 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 513 const Class& klass = Class::Handle(ref.GetClassReferent()); | 516 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 514 const Library& library = Library::Handle(klass.library()); | 517 const Library& library = Library::Handle(klass.library()); |
| 515 // TODO(rmacnak): Revisit when we decide what to do about | 518 ASSERT(!library.IsNull()); |
| 516 // reflectClass(dynamic). | |
| 517 if (library.IsNull()) { | |
| 518 return Instance::null(); | |
| 519 } | |
| 520 return CreateLibraryMirror(library); | 519 return CreateLibraryMirror(library); |
| 521 } | 520 } |
| 522 | 521 |
| 523 | 522 |
| 524 DEFINE_NATIVE_ENTRY(ClassMirror_supertype, 1) { | 523 DEFINE_NATIVE_ENTRY(ClassMirror_supertype, 1) { |
| 525 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 524 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 526 const Class& klass = Class::Handle(ref.GetClassReferent()); | 525 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 527 return klass.super_type(); | 526 return klass.super_type(); |
| 528 } | 527 } |
| 529 | 528 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 625 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 624 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 626 const Library& library = Library::Handle(ref.GetLibraryReferent()); | 625 const Library& library = Library::Handle(ref.GetLibraryReferent()); |
| 627 | 626 |
| 628 Instance& member_mirror = Instance::Handle(); | 627 Instance& member_mirror = Instance::Handle(); |
| 629 const GrowableObjectArray& member_mirrors = | 628 const GrowableObjectArray& member_mirrors = |
| 630 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 629 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
| 631 | 630 |
| 632 Object& entry = Object::Handle(); | 631 Object& entry = Object::Handle(); |
| 633 DictionaryIterator entries(library); | 632 DictionaryIterator entries(library); |
| 634 | 633 |
| 634 AbstractType& type = AbstractType::Handle(); | |
| 635 | |
| 635 while (entries.HasNext()) { | 636 while (entries.HasNext()) { |
| 636 entry = entries.GetNext(); | 637 entry = entries.GetNext(); |
| 637 if (entry.IsClass()) { | 638 if (entry.IsClass()) { |
| 638 const Class& klass = Class::Cast(entry); | 639 const Class& klass = Class::Cast(entry); |
| 639 // We filter out implementation classes like Smi, Mint, Bignum, | 640 // We filter out implementation classes like Smi, Mint, Bignum, |
| 640 // OneByteString; function signature classes; and dynamic. | 641 // OneByteString; function signature classes; and dynamic. |
| 641 if (!klass.IsCanonicalSignatureClass() && | 642 if (!klass.IsCanonicalSignatureClass() && |
| 642 !klass.IsDynamicClass() && | 643 !klass.IsDynamicClass() && |
| 643 !RawObject::IsImplementationClassId(klass.id())) { | 644 !RawObject::IsImplementationClassId(klass.id())) { |
| 644 member_mirror = CreateClassMirror(klass, | 645 if (klass.NumTypeParameters() == 0) { |
| 645 AbstractType::Handle(), | 646 // Include runtime type for non-generics only. |
| 646 owner_mirror); | 647 type = RawTypeOfClass(klass); |
| 648 } else { | |
| 649 type = AbstractType::null(); | |
| 650 } | |
| 651 member_mirror = CreateClassMirror(klass, type, owner_mirror); | |
| 647 member_mirrors.Add(member_mirror); | 652 member_mirrors.Add(member_mirror); |
| 648 } | 653 } |
| 649 } else if (entry.IsField()) { | 654 } else if (entry.IsField()) { |
| 650 const Field& field = Field::Cast(entry); | 655 const Field& field = Field::Cast(entry); |
| 651 member_mirror = CreateVariableMirror(field, owner_mirror); | 656 member_mirror = CreateVariableMirror(field, owner_mirror); |
| 652 member_mirrors.Add(member_mirror); | 657 member_mirrors.Add(member_mirror); |
| 653 } else if (entry.IsFunction()) { | 658 } else if (entry.IsFunction()) { |
| 654 const Function& func = Function::Cast(entry); | 659 const Function& func = Function::Cast(entry); |
| 655 if (func.kind() == RawFunction::kRegularFunction || | 660 if (func.kind() == RawFunction::kRegularFunction || |
| 656 func.kind() == RawFunction::kGetterFunction || | 661 func.kind() == RawFunction::kGetterFunction || |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 706 arg_type ^= args.TypeAt(i + num_inherited_args); | 711 arg_type ^= args.TypeAt(i + num_inherited_args); |
| 707 type_mirror = CreateTypeMirror(arg_type); | 712 type_mirror = CreateTypeMirror(arg_type); |
| 708 result.SetAt(i, type_mirror); | 713 result.SetAt(i, type_mirror); |
| 709 } | 714 } |
| 710 return result.raw(); | 715 return result.raw(); |
| 711 } | 716 } |
| 712 | 717 |
| 713 | 718 |
| 714 DEFINE_NATIVE_ENTRY(TypeVariableMirror_owner, 1) { | 719 DEFINE_NATIVE_ENTRY(TypeVariableMirror_owner, 1) { |
| 715 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); | 720 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); |
| 716 return CreateClassMirror(Class::Handle(param.parameterized_class()), | 721 const Class& owner = Class::Handle(param.parameterized_class()); |
| 722 // The owner of a type variable must be a generic class: pass a null runtime | |
| 723 // type to get a mirror on the declaration. | |
| 724 ASSERT(owner.NumTypeParameters() != 0); | |
| 725 return CreateClassMirror(owner, | |
| 717 AbstractType::Handle(), | 726 AbstractType::Handle(), |
| 718 Instance::null_instance()); | 727 Instance::null_instance()); |
| 719 } | 728 } |
| 720 | 729 |
| 721 | 730 |
| 722 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) { | 731 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) { |
| 723 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); | 732 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); |
| 724 return param.bound(); | 733 return param.bound(); |
| 725 } | 734 } |
| 726 | 735 |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1271 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1280 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1272 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1281 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1273 if (func.IsNonImplicitClosureFunction()) { | 1282 if (func.IsNonImplicitClosureFunction()) { |
| 1274 return CreateMethodMirror(Function::Handle( | 1283 return CreateMethodMirror(Function::Handle( |
| 1275 func.parent_function()), Object::null_instance()); | 1284 func.parent_function()), Object::null_instance()); |
| 1276 } | 1285 } |
| 1277 const Class& owner = Class::Handle(func.Owner()); | 1286 const Class& owner = Class::Handle(func.Owner()); |
| 1278 if (owner.IsTopLevel()) { | 1287 if (owner.IsTopLevel()) { |
| 1279 return CreateLibraryMirror(Library::Handle(owner.library())); | 1288 return CreateLibraryMirror(Library::Handle(owner.library())); |
| 1280 } | 1289 } |
| 1281 return CreateClassMirror(owner, | 1290 |
| 1282 AbstractType::Handle(), | 1291 AbstractType& type = AbstractType::Handle(); |
| 1283 Object::null_instance()); | 1292 if (owner.NumTypeParameters() == 0) { |
| 1293 // Include runtime type for non-generics only. | |
| 1294 type = RawTypeOfClass(owner); | |
| 1295 } | |
| 1296 return CreateClassMirror(owner, type, Object::null_instance()); | |
| 1284 } | 1297 } |
| 1285 | 1298 |
| 1286 | 1299 |
| 1287 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 2) { | 1300 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 2) { |
| 1288 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0)); | 1301 GET_NON_NULL_NATIVE_ARGUMENT(Instance, owner, arguments->NativeArgAt(0)); |
| 1289 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 1302 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 1290 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1303 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1291 return CreateParameterMirrorList(func, owner); | 1304 return CreateParameterMirrorList(func, owner); |
| 1292 } | 1305 } |
| 1293 | 1306 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1347 } | 1360 } |
| 1348 | 1361 |
| 1349 | 1362 |
| 1350 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1363 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1351 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1364 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1352 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1365 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1353 return field.type(); | 1366 return field.type(); |
| 1354 } | 1367 } |
| 1355 | 1368 |
| 1356 } // namespace dart | 1369 } // namespace dart |
| OLD | NEW |