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/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" |
11 #include "vm/dart_entry.h" | 11 #include "vm/dart_entry.h" |
12 #include "vm/exceptions.h" | 12 #include "vm/exceptions.h" |
13 #include "vm/object_store.h" | 13 #include "vm/object_store.h" |
14 #include "vm/parser.h" | 14 #include "vm/parser.h" |
15 #include "vm/port.h" | 15 #include "vm/port.h" |
16 #include "vm/resolver.h" | 16 #include "vm/resolver.h" |
17 #include "vm/symbols.h" | 17 #include "vm/symbols.h" |
18 | 18 |
19 namespace dart { | 19 namespace dart { |
20 | 20 |
| 21 #define PROPOGATE_IF_MALFOMRED(type) \ |
| 22 if (type.IsMalformed()) { \ |
| 23 Exceptions::PropagateError(Error::Handle(type.error())); \ |
| 24 } \ |
| 25 |
21 static RawInstance* CreateMirror(const String& mirror_class_name, | 26 static RawInstance* CreateMirror(const String& mirror_class_name, |
22 const Array& constructor_arguments) { | 27 const Array& constructor_arguments) { |
23 const Library& mirrors_lib = Library::Handle(Library::MirrorsLibrary()); | 28 const Library& mirrors_lib = Library::Handle(Library::MirrorsLibrary()); |
24 const String& constructor_name = Symbols::Dot(); | 29 const String& constructor_name = Symbols::Dot(); |
25 | 30 |
26 const Object& result = Object::Handle( | 31 const Object& result = Object::Handle( |
27 DartLibraryCalls::InstanceCreate(mirrors_lib, | 32 DartLibraryCalls::InstanceCreate(mirrors_lib, |
28 mirror_class_name, | 33 mirror_class_name, |
29 constructor_name, | 34 constructor_name, |
30 constructor_arguments)); | 35 constructor_arguments)); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 const TypeArguments& args = TypeArguments::Handle(cls.type_parameters()); | 203 const TypeArguments& args = TypeArguments::Handle(cls.type_parameters()); |
199 if (args.IsNull()) { | 204 if (args.IsNull()) { |
200 return Object::empty_array().raw(); | 205 return Object::empty_array().raw(); |
201 } | 206 } |
202 const Array& result = Array::Handle(Array::New(args.Length() * 2)); | 207 const Array& result = Array::Handle(Array::New(args.Length() * 2)); |
203 TypeParameter& type = TypeParameter::Handle(); | 208 TypeParameter& type = TypeParameter::Handle(); |
204 String& name = String::Handle(); | 209 String& name = String::Handle(); |
205 for (intptr_t i = 0; i < args.Length(); i++) { | 210 for (intptr_t i = 0; i < args.Length(); i++) { |
206 type ^= args.TypeAt(i); | 211 type ^= args.TypeAt(i); |
207 ASSERT(type.IsTypeParameter()); | 212 ASSERT(type.IsTypeParameter()); |
208 ASSERT(!type.IsMalformed()); | 213 PROPOGATE_IF_MALFOMRED(type); |
209 ASSERT(type.IsFinalized()); | 214 ASSERT(type.IsFinalized()); |
210 name ^= type.name(); | 215 name ^= type.name(); |
211 result.SetAt(2 * i, name); | 216 result.SetAt(2 * i, name); |
212 result.SetAt(2 * i + 1, type); | 217 result.SetAt(2 * i + 1, type); |
213 } | 218 } |
214 return result.raw(); | 219 return result.raw(); |
215 } | 220 } |
216 | 221 |
217 | 222 |
218 static RawInstance* CreateTypedefMirror(const Class& cls, | 223 static RawInstance* CreateTypedefMirror(const Class& cls, |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 bool is_show) { | 383 bool is_show) { |
379 const Array& args = Array::Handle(Array::New(2)); | 384 const Array& args = Array::Handle(Array::New(2)); |
380 args.SetAt(0, identifiers); | 385 args.SetAt(0, identifiers); |
381 args.SetAt(1, Bool::Get(is_show)); | 386 args.SetAt(1, Bool::Get(is_show)); |
382 return CreateMirror(Symbols::_LocalCombinatorMirror(), args); | 387 return CreateMirror(Symbols::_LocalCombinatorMirror(), args); |
383 } | 388 } |
384 | 389 |
385 | 390 |
386 static RawInstance* CreateLibraryDependencyMirror(const Instance& importer, | 391 static RawInstance* CreateLibraryDependencyMirror(const Instance& importer, |
387 const Namespace& ns, | 392 const Namespace& ns, |
388 const String& prefix, | 393 const LibraryPrefix& prefix, |
389 const bool is_import, | 394 const bool is_import, |
390 const bool is_deferred) { | 395 const bool is_deferred) { |
391 const Library& importee = Library::Handle(ns.library()); | 396 const Library& importee = Library::Handle(ns.library()); |
392 const Instance& importee_mirror = | 397 const Instance& importee_mirror = |
393 Instance::Handle(CreateLibraryMirror(importee)); | 398 Instance::Handle(CreateLibraryMirror(importee)); |
394 if (importee_mirror.IsNull()) { | 399 if (importee_mirror.IsNull()) { |
395 // Imported library is censored: censor the import. | 400 // Imported library is censored: censor the import. |
396 return Instance::null(); | 401 return Instance::null(); |
397 } | 402 } |
398 | 403 |
(...skipping 16 matching lines...) Expand all Loading... |
415 } | 420 } |
416 | 421 |
417 Object& metadata = Object::Handle(ns.GetMetadata()); | 422 Object& metadata = Object::Handle(ns.GetMetadata()); |
418 if (metadata.IsError()) { | 423 if (metadata.IsError()) { |
419 Exceptions::PropagateError(Error::Cast(metadata)); | 424 Exceptions::PropagateError(Error::Cast(metadata)); |
420 UNREACHABLE(); | 425 UNREACHABLE(); |
421 } | 426 } |
422 | 427 |
423 const Array& args = Array::Handle(Array::New(7)); | 428 const Array& args = Array::Handle(Array::New(7)); |
424 args.SetAt(0, importer); | 429 args.SetAt(0, importer); |
425 args.SetAt(1, importee_mirror); | 430 args.SetAt(1, importee.Loaded() ? importee_mirror : prefix); |
426 args.SetAt(2, combinators); | 431 args.SetAt(2, combinators); |
427 args.SetAt(3, prefix); | 432 args.SetAt(3, prefix.IsNull() ? Object::null_object() |
| 433 : String::Handle(prefix.name())); |
428 args.SetAt(4, Bool::Get(is_import)); | 434 args.SetAt(4, Bool::Get(is_import)); |
429 args.SetAt(5, Bool::Get(is_deferred)); | 435 args.SetAt(5, Bool::Get(is_deferred)); |
430 args.SetAt(6, metadata); | 436 args.SetAt(6, metadata); |
431 return CreateMirror(Symbols::_LocalLibraryDependencyMirror(), args); | 437 return CreateMirror(Symbols::_LocalLibraryDependencyMirror(), args); |
432 } | 438 } |
433 | 439 |
434 | 440 |
| 441 DEFINE_NATIVE_ENTRY(LibraryMirror_fromPrefix, 1) { |
| 442 GET_NON_NULL_NATIVE_ARGUMENT(LibraryPrefix, prefix, |
| 443 arguments->NativeArgAt(0)); |
| 444 const Library& deferred_lib = Library::Handle(prefix.GetLibrary(0)); |
| 445 if (!deferred_lib.Loaded()) { |
| 446 return Instance::null(); |
| 447 } |
| 448 return CreateLibraryMirror(deferred_lib); |
| 449 } |
| 450 |
| 451 |
435 DEFINE_NATIVE_ENTRY(LibraryMirror_libraryDependencies, 2) { | 452 DEFINE_NATIVE_ENTRY(LibraryMirror_libraryDependencies, 2) { |
436 GET_NON_NULL_NATIVE_ARGUMENT(Instance, lib_mirror, arguments->NativeArgAt(0)); | 453 GET_NON_NULL_NATIVE_ARGUMENT(Instance, lib_mirror, arguments->NativeArgAt(0)); |
437 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); | 454 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
438 const Library& lib = Library::Handle(ref.GetLibraryReferent()); | 455 const Library& lib = Library::Handle(ref.GetLibraryReferent()); |
439 | 456 |
440 Array& ports = Array::Handle(); | 457 Array& ports = Array::Handle(); |
441 Namespace& ns = Namespace::Handle(); | 458 Namespace& ns = Namespace::Handle(); |
442 Instance& dep = Instance::Handle(); | 459 Instance& dep = Instance::Handle(); |
443 String& prefix = String::Handle(); | 460 LibraryPrefix& prefix = LibraryPrefix::Handle(); |
444 GrowableObjectArray& deps = | 461 GrowableObjectArray& deps = |
445 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 462 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
446 | 463 |
447 // Unprefixed imports. | 464 // Unprefixed imports. |
448 ports = lib.imports(); | 465 ports = lib.imports(); |
449 for (intptr_t i = 0; i < ports.Length(); i++) { | 466 for (intptr_t i = 0; i < ports.Length(); i++) { |
450 ns ^= ports.At(i); | 467 ns ^= ports.At(i); |
451 if (!ns.IsNull()) { | 468 if (!ns.IsNull()) { |
452 dep = CreateLibraryDependencyMirror(lib_mirror, ns, prefix, true, false); | 469 dep = CreateLibraryDependencyMirror(lib_mirror, ns, prefix, true, false); |
453 if (!dep.IsNull()) { | 470 if (!dep.IsNull()) { |
(...skipping 11 matching lines...) Expand all Loading... |
465 deps.Add(dep); | 482 deps.Add(dep); |
466 } | 483 } |
467 } | 484 } |
468 | 485 |
469 // Prefixed imports. | 486 // Prefixed imports. |
470 DictionaryIterator entries(lib); | 487 DictionaryIterator entries(lib); |
471 Object& entry = Object::Handle(); | 488 Object& entry = Object::Handle(); |
472 while (entries.HasNext()) { | 489 while (entries.HasNext()) { |
473 entry = entries.GetNext(); | 490 entry = entries.GetNext(); |
474 if (entry.IsLibraryPrefix()) { | 491 if (entry.IsLibraryPrefix()) { |
475 const LibraryPrefix& lib_prefix = LibraryPrefix::Cast(entry); | 492 prefix ^= entry.raw(); |
476 prefix = lib_prefix.name(); | 493 ports = prefix.imports(); |
477 ports = lib_prefix.imports(); | |
478 for (intptr_t i = 0; i < ports.Length(); i++) { | 494 for (intptr_t i = 0; i < ports.Length(); i++) { |
479 ns ^= ports.At(i); | 495 ns ^= ports.At(i); |
480 if (!ns.IsNull()) { | 496 if (!ns.IsNull()) { |
481 dep = CreateLibraryDependencyMirror(lib_mirror, ns, prefix, true, | 497 dep = CreateLibraryDependencyMirror(lib_mirror, ns, prefix, true, |
482 lib_prefix.is_deferred_load()); | 498 prefix.is_deferred_load()); |
483 if (!dep.IsNull()) { | 499 if (!dep.IsNull()) { |
484 deps.Add(dep); | 500 deps.Add(dep); |
485 } | 501 } |
486 } | 502 } |
487 } | 503 } |
488 } | 504 } |
489 } | 505 } |
490 | 506 |
491 return deps.raw(); | 507 return deps.raw(); |
492 } | 508 } |
493 | 509 |
| 510 |
494 static RawInstance* CreateTypeMirror(const AbstractType& type) { | 511 static RawInstance* CreateTypeMirror(const AbstractType& type) { |
495 if (type.IsTypeRef()) { | 512 if (type.IsTypeRef()) { |
496 AbstractType& ref_type = AbstractType::Handle(TypeRef::Cast(type).type()); | 513 AbstractType& ref_type = AbstractType::Handle(TypeRef::Cast(type).type()); |
497 ASSERT(!ref_type.IsTypeRef()); | 514 ASSERT(!ref_type.IsTypeRef()); |
498 ASSERT(ref_type.IsCanonical()); | 515 ASSERT(ref_type.IsCanonical()); |
499 return CreateTypeMirror(ref_type); | 516 return CreateTypeMirror(ref_type); |
500 } | 517 } |
501 ASSERT(type.IsFinalized()); | 518 ASSERT(type.IsFinalized()); |
502 ASSERT(!type.IsMalformed()); | 519 PROPOGATE_IF_MALFOMRED(type); |
| 520 |
503 if (type.HasResolvedTypeClass()) { | 521 if (type.HasResolvedTypeClass()) { |
504 const Class& cls = Class::Handle(type.type_class()); | 522 const Class& cls = Class::Handle(type.type_class()); |
505 // Handle void and dynamic types. | 523 // Handle void and dynamic types. |
506 if (cls.IsVoidClass()) { | 524 if (cls.IsVoidClass()) { |
507 Array& args = Array::Handle(Array::New(1)); | 525 Array& args = Array::Handle(Array::New(1)); |
508 args.SetAt(0, Symbols::Void()); | 526 args.SetAt(0, Symbols::Void()); |
509 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. | |
510 return CreateMirror(Symbols::_SpecialTypeMirror(), args); | 527 return CreateMirror(Symbols::_SpecialTypeMirror(), args); |
511 } else if (cls.IsDynamicClass()) { | 528 } else if (cls.IsDynamicClass()) { |
512 Array& args = Array::Handle(Array::New(1)); | 529 Array& args = Array::Handle(Array::New(1)); |
513 args.SetAt(0, Symbols::Dynamic()); | 530 args.SetAt(0, Symbols::Dynamic()); |
514 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. | |
515 return CreateMirror(Symbols::_SpecialTypeMirror(), args); | 531 return CreateMirror(Symbols::_SpecialTypeMirror(), args); |
516 } | 532 } |
517 return CreateClassMirror(cls, type, Bool::False(), Object::null_instance()); | 533 return CreateClassMirror(cls, type, Bool::False(), Object::null_instance()); |
518 } else if (type.IsTypeParameter()) { | 534 } else if (type.IsTypeParameter()) { |
519 return CreateTypeVariableMirror(TypeParameter::Cast(type), | 535 return CreateTypeVariableMirror(TypeParameter::Cast(type), |
520 Object::null_instance()); | 536 Object::null_instance()); |
521 } else if (type.IsBoundedType()) { | 537 } else if (type.IsBoundedType()) { |
522 AbstractType& actual_type = | 538 AbstractType& actual_type = |
523 AbstractType::Handle(BoundedType::Cast(type).type()); | 539 AbstractType::Handle(BoundedType::Cast(type).type()); |
524 return CreateTypeMirror(actual_type); | 540 return CreateTypeMirror(actual_type); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 field = cls.LookupField(String::Handle(String::New(#name))); \ | 575 field = cls.LookupField(String::Handle(String::New(#name))); \ |
560 ASSERT(!field.IsNull()); \ | 576 ASSERT(!field.IsNull()); \ |
561 value ^= field.value(); \ | 577 value ^= field.value(); \ |
562 ASSERT(value.Value() == Mirrors::name); | 578 ASSERT(value.Value() == Mirrors::name); |
563 MIRRORS_KIND_SHIFT_LIST(CHECK_KIND_SHIFT) | 579 MIRRORS_KIND_SHIFT_LIST(CHECK_KIND_SHIFT) |
564 #undef CHECK_KIND_SHIFT | 580 #undef CHECK_KIND_SHIFT |
565 #endif | 581 #endif |
566 } | 582 } |
567 | 583 |
568 | 584 |
569 static RawInstance* CreateMirrorSystem() { | |
570 VerifyMethodKindShifts(); | |
571 | |
572 Isolate* isolate = Isolate::Current(); | |
573 const GrowableObjectArray& libraries = GrowableObjectArray::Handle( | |
574 isolate, isolate->object_store()->libraries()); | |
575 | |
576 const intptr_t num_libraries = libraries.Length(); | |
577 const GrowableObjectArray& library_mirrors = GrowableObjectArray::Handle( | |
578 isolate, GrowableObjectArray::New(num_libraries)); | |
579 Library& library = Library::Handle(isolate); | |
580 Instance& library_mirror = Instance::Handle(isolate); | |
581 | |
582 for (int i = 0; i < num_libraries; i++) { | |
583 library ^= libraries.At(i); | |
584 library_mirror = CreateLibraryMirror(library); | |
585 if (!library_mirror.IsNull()) { | |
586 library_mirrors.Add(library_mirror); | |
587 } | |
588 } | |
589 | |
590 const Instance& isolate_mirror = Instance::Handle(CreateIsolateMirror()); | |
591 | |
592 const Array& args = Array::Handle(Array::New(2)); | |
593 args.SetAt(0, library_mirrors); | |
594 args.SetAt(1, isolate_mirror); | |
595 return CreateMirror(Symbols::_LocalMirrorSystem(), args); | |
596 } | |
597 | |
598 | |
599 static RawInstance* ReturnResult(const Object& result) { | 585 static RawInstance* ReturnResult(const Object& result) { |
600 if (result.IsError()) { | 586 if (result.IsError()) { |
601 Exceptions::PropagateError(Error::Cast(result)); | 587 Exceptions::PropagateError(Error::Cast(result)); |
602 UNREACHABLE(); | 588 UNREACHABLE(); |
603 } | 589 } |
604 if (result.IsInstance()) { | 590 if (result.IsInstance()) { |
605 return Instance::Cast(result).raw(); | 591 return Instance::Cast(result).raw(); |
606 } | 592 } |
607 ASSERT(result.IsNull()); | 593 ASSERT(result.IsNull()); |
608 return Instance::null(); | 594 return Instance::null(); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 // Fall through case: Indicate that we didn't find any function or field using | 755 // Fall through case: Indicate that we didn't find any function or field using |
770 // a special null instance. This is different from a field being null. Callers | 756 // a special null instance. This is different from a field being null. Callers |
771 // make sure that this null does not leak into Dartland. | 757 // make sure that this null does not leak into Dartland. |
772 return Object::sentinel().raw(); | 758 return Object::sentinel().raw(); |
773 } | 759 } |
774 | 760 |
775 | 761 |
776 static RawAbstractType* InstantiateType(const AbstractType& type, | 762 static RawAbstractType* InstantiateType(const AbstractType& type, |
777 const AbstractType& instantiator) { | 763 const AbstractType& instantiator) { |
778 ASSERT(type.IsFinalized()); | 764 ASSERT(type.IsFinalized()); |
779 ASSERT(!type.IsMalformed()); | 765 PROPOGATE_IF_MALFOMRED(type); |
780 | 766 |
781 if (type.IsInstantiated() || instantiator.IsNull()) { | 767 if (type.IsInstantiated() || instantiator.IsNull()) { |
782 return type.Canonicalize(); | 768 return type.Canonicalize(); |
783 } | 769 } |
784 | 770 |
785 ASSERT(!instantiator.IsNull()); | 771 ASSERT(!instantiator.IsNull()); |
786 ASSERT(instantiator.IsFinalized()); | 772 ASSERT(instantiator.IsFinalized()); |
787 ASSERT(!instantiator.IsMalformed()); | 773 PROPOGATE_IF_MALFOMRED(instantiator); |
788 | 774 |
789 const TypeArguments& type_args = | 775 const TypeArguments& type_args = |
790 TypeArguments::Handle(instantiator.arguments()); | 776 TypeArguments::Handle(instantiator.arguments()); |
791 Error& bound_error = Error::Handle(); | 777 Error& bound_error = Error::Handle(); |
792 AbstractType& result = | 778 AbstractType& result = |
793 AbstractType::Handle(type.InstantiateFrom(type_args, &bound_error)); | 779 AbstractType::Handle(type.InstantiateFrom(type_args, &bound_error)); |
794 if (!bound_error.IsNull()) { | 780 if (!bound_error.IsNull()) { |
795 Exceptions::PropagateError(bound_error); | 781 Exceptions::PropagateError(bound_error); |
796 UNREACHABLE(); | 782 UNREACHABLE(); |
797 } | 783 } |
798 ASSERT(result.IsFinalized()); | 784 ASSERT(result.IsFinalized()); |
799 return result.Canonicalize(); | 785 return result.Canonicalize(); |
800 } | 786 } |
801 | 787 |
802 | 788 |
803 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalMirrorSystem, 0) { | 789 DEFINE_NATIVE_ENTRY(MirrorSystem_libraries, 0) { |
804 return CreateMirrorSystem(); | 790 const GrowableObjectArray& libraries = GrowableObjectArray::Handle( |
| 791 isolate, isolate->object_store()->libraries()); |
| 792 |
| 793 const intptr_t num_libraries = libraries.Length(); |
| 794 const GrowableObjectArray& library_mirrors = GrowableObjectArray::Handle( |
| 795 isolate, GrowableObjectArray::New(num_libraries)); |
| 796 Library& library = Library::Handle(isolate); |
| 797 Instance& library_mirror = Instance::Handle(isolate); |
| 798 |
| 799 for (int i = 0; i < num_libraries; i++) { |
| 800 library ^= libraries.At(i); |
| 801 library_mirror = CreateLibraryMirror(library); |
| 802 if (!library_mirror.IsNull() && library.Loaded()) { |
| 803 library_mirrors.Add(library_mirror); |
| 804 } |
| 805 } |
| 806 return library_mirrors.raw(); |
| 807 } |
| 808 |
| 809 |
| 810 DEFINE_NATIVE_ENTRY(MirrorSystem_isolate, 0) { |
| 811 VerifyMethodKindShifts(); |
| 812 |
| 813 return CreateIsolateMirror(); |
805 } | 814 } |
806 | 815 |
807 | 816 |
808 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) { | 817 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) { |
809 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 818 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
810 ASSERT(!type.IsMalformed()); | 819 PROPOGATE_IF_MALFOMRED(type); |
811 ASSERT(type.IsFinalized()); | 820 ASSERT(type.IsFinalized()); |
812 ASSERT(type.HasResolvedTypeClass()); | 821 ASSERT(type.HasResolvedTypeClass()); |
813 const Class& cls = Class::Handle(type.type_class()); | 822 const Class& cls = Class::Handle(type.type_class()); |
814 ASSERT(!cls.IsNull()); | 823 ASSERT(!cls.IsNull()); |
815 if (cls.IsDynamicClass() || | 824 if (cls.IsDynamicClass() || |
816 cls.IsVoidClass() || | 825 cls.IsVoidClass() || |
817 (cls.IsSignatureClass() && !cls.IsCanonicalSignatureClass())) { | 826 (cls.IsSignatureClass() && !cls.IsCanonicalSignatureClass())) { |
818 Exceptions::ThrowArgumentError(type); | 827 Exceptions::ThrowArgumentError(type); |
819 UNREACHABLE(); | 828 UNREACHABLE(); |
820 } | 829 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 934 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
926 const Class& klass = Class::Handle(ref.GetClassReferent()); | 935 const Class& klass = Class::Handle(ref.GetClassReferent()); |
927 const Library& library = Library::Handle(klass.library()); | 936 const Library& library = Library::Handle(klass.library()); |
928 ASSERT(!library.IsNull()); | 937 ASSERT(!library.IsNull()); |
929 return library.url(); | 938 return library.url(); |
930 } | 939 } |
931 | 940 |
932 | 941 |
933 DEFINE_NATIVE_ENTRY(ClassMirror_supertype, 1) { | 942 DEFINE_NATIVE_ENTRY(ClassMirror_supertype, 1) { |
934 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 943 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
935 ASSERT(!type.IsMalformed()); | 944 PROPOGATE_IF_MALFOMRED(type); |
936 ASSERT(type.IsFinalized()); | 945 ASSERT(type.IsFinalized()); |
937 if (!type.HasResolvedTypeClass()) { | 946 if (!type.HasResolvedTypeClass()) { |
938 Exceptions::ThrowArgumentError(type); | 947 Exceptions::ThrowArgumentError(type); |
939 UNREACHABLE(); | 948 UNREACHABLE(); |
940 } | 949 } |
941 const Class& cls = Class::Handle(type.type_class()); | 950 const Class& cls = Class::Handle(type.type_class()); |
942 const AbstractType& super_type = AbstractType::Handle(cls.super_type()); | 951 const AbstractType& super_type = AbstractType::Handle(cls.super_type()); |
943 ASSERT(super_type.IsNull() || super_type.IsFinalized()); | 952 ASSERT(super_type.IsNull() || super_type.IsFinalized()); |
944 return super_type.raw(); | 953 return super_type.raw(); |
945 } | 954 } |
946 | 955 |
947 | 956 |
948 DEFINE_NATIVE_ENTRY(ClassMirror_supertype_instantiated, 1) { | 957 DEFINE_NATIVE_ENTRY(ClassMirror_supertype_instantiated, 1) { |
949 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 958 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
950 ASSERT(!type.IsMalformed()); | 959 PROPOGATE_IF_MALFOMRED(type); |
951 ASSERT(type.IsFinalized()); | 960 ASSERT(type.IsFinalized()); |
952 if (!type.HasResolvedTypeClass()) { | 961 if (!type.HasResolvedTypeClass()) { |
953 Exceptions::ThrowArgumentError(type); | 962 Exceptions::ThrowArgumentError(type); |
954 UNREACHABLE(); | 963 UNREACHABLE(); |
955 } | 964 } |
956 const Class& cls = Class::Handle(type.type_class()); | 965 const Class& cls = Class::Handle(type.type_class()); |
957 const AbstractType& super_type = AbstractType::Handle(cls.super_type()); | 966 const AbstractType& super_type = AbstractType::Handle(cls.super_type()); |
958 return InstantiateType(super_type, type); | 967 return InstantiateType(super_type, type); |
959 } | 968 } |
960 | 969 |
961 | 970 |
962 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces, 1) { | 971 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces, 1) { |
963 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 972 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
964 ASSERT(!type.IsMalformed()); | 973 PROPOGATE_IF_MALFOMRED(type); |
965 ASSERT(type.IsFinalized()); | 974 ASSERT(type.IsFinalized()); |
966 if (!type.HasResolvedTypeClass()) { | 975 if (!type.HasResolvedTypeClass()) { |
967 Exceptions::ThrowArgumentError(type); | 976 Exceptions::ThrowArgumentError(type); |
968 UNREACHABLE(); | 977 UNREACHABLE(); |
969 } | 978 } |
970 const Class& cls = Class::Handle(type.type_class()); | 979 const Class& cls = Class::Handle(type.type_class()); |
971 const Error& error = Error::Handle(cls.EnsureIsFinalized(isolate)); | 980 const Error& error = Error::Handle(cls.EnsureIsFinalized(isolate)); |
972 if (!error.IsNull()) { | 981 if (!error.IsNull()) { |
973 Exceptions::PropagateError(error); | 982 Exceptions::PropagateError(error); |
974 } | 983 } |
975 | 984 |
976 return cls.interfaces(); | 985 return cls.interfaces(); |
977 } | 986 } |
978 | 987 |
979 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces_instantiated, 1) { | 988 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces_instantiated, 1) { |
980 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 989 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
981 ASSERT(!type.IsMalformed()); | 990 PROPOGATE_IF_MALFOMRED(type); |
982 ASSERT(type.IsFinalized()); | 991 ASSERT(type.IsFinalized()); |
983 if (!type.HasResolvedTypeClass()) { | 992 if (!type.HasResolvedTypeClass()) { |
984 Exceptions::ThrowArgumentError(type); | 993 Exceptions::ThrowArgumentError(type); |
985 UNREACHABLE(); | 994 UNREACHABLE(); |
986 } | 995 } |
987 const Class& cls = Class::Handle(type.type_class()); | 996 const Class& cls = Class::Handle(type.type_class()); |
988 const Error& error = Error::Handle(cls.EnsureIsFinalized(isolate)); | 997 const Error& error = Error::Handle(cls.EnsureIsFinalized(isolate)); |
989 if (!error.IsNull()) { | 998 if (!error.IsNull()) { |
990 Exceptions::PropagateError(error); | 999 Exceptions::PropagateError(error); |
991 } | 1000 } |
992 | 1001 |
993 Array& interfaces = Array::Handle(cls.interfaces()); | 1002 Array& interfaces = Array::Handle(cls.interfaces()); |
994 Array& interfaces_inst = Array::Handle(Array::New(interfaces.Length())); | 1003 Array& interfaces_inst = Array::Handle(Array::New(interfaces.Length())); |
995 AbstractType& interface = AbstractType::Handle(); | 1004 AbstractType& interface = AbstractType::Handle(); |
996 | 1005 |
997 for (int i = 0; i < interfaces.Length(); i++) { | 1006 for (int i = 0; i < interfaces.Length(); i++) { |
998 interface ^= interfaces.At(i); | 1007 interface ^= interfaces.At(i); |
999 interface = InstantiateType(interface, type); | 1008 interface = InstantiateType(interface, type); |
1000 interfaces_inst.SetAt(i, interface); | 1009 interfaces_inst.SetAt(i, interface); |
1001 } | 1010 } |
1002 | 1011 |
1003 return interfaces_inst.raw(); | 1012 return interfaces_inst.raw(); |
1004 } | 1013 } |
1005 | 1014 |
1006 | 1015 |
1007 DEFINE_NATIVE_ENTRY(ClassMirror_mixin, 1) { | 1016 DEFINE_NATIVE_ENTRY(ClassMirror_mixin, 1) { |
1008 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 1017 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
1009 ASSERT(!type.IsMalformed()); | 1018 PROPOGATE_IF_MALFOMRED(type); |
1010 ASSERT(type.IsFinalized()); | 1019 ASSERT(type.IsFinalized()); |
1011 if (!type.HasResolvedTypeClass()) { | 1020 if (!type.HasResolvedTypeClass()) { |
1012 Exceptions::ThrowArgumentError(type); | 1021 Exceptions::ThrowArgumentError(type); |
1013 UNREACHABLE(); | 1022 UNREACHABLE(); |
1014 } | 1023 } |
1015 const Class& cls = Class::Handle(type.type_class()); | 1024 const Class& cls = Class::Handle(type.type_class()); |
1016 const AbstractType& mixin_type = AbstractType::Handle(cls.mixin()); | 1025 const AbstractType& mixin_type = AbstractType::Handle(cls.mixin()); |
1017 ASSERT(mixin_type.IsNull() || mixin_type.IsFinalized()); | 1026 ASSERT(mixin_type.IsNull() || mixin_type.IsFinalized()); |
1018 return mixin_type.raw(); | 1027 return mixin_type.raw(); |
1019 } | 1028 } |
1020 | 1029 |
1021 | 1030 |
1022 DEFINE_NATIVE_ENTRY(ClassMirror_mixin_instantiated, 2) { | 1031 DEFINE_NATIVE_ENTRY(ClassMirror_mixin_instantiated, 2) { |
1023 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 1032 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
1024 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, | 1033 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, |
1025 instantiator, | 1034 instantiator, |
1026 arguments->NativeArgAt(1)); | 1035 arguments->NativeArgAt(1)); |
1027 ASSERT(!type.IsMalformed()); | 1036 PROPOGATE_IF_MALFOMRED(type); |
1028 ASSERT(type.IsFinalized()); | 1037 ASSERT(type.IsFinalized()); |
1029 if (!type.HasResolvedTypeClass()) { | 1038 if (!type.HasResolvedTypeClass()) { |
1030 Exceptions::ThrowArgumentError(type); | 1039 Exceptions::ThrowArgumentError(type); |
1031 UNREACHABLE(); | 1040 UNREACHABLE(); |
1032 } | 1041 } |
1033 const Class& cls = Class::Handle(type.type_class()); | 1042 const Class& cls = Class::Handle(type.type_class()); |
1034 const AbstractType& mixin_type = AbstractType::Handle(cls.mixin()); | 1043 const AbstractType& mixin_type = AbstractType::Handle(cls.mixin()); |
1035 if (mixin_type.IsNull()) { | 1044 if (mixin_type.IsNull()) { |
1036 return mixin_type.raw(); | 1045 return mixin_type.raw(); |
1037 } | 1046 } |
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2062 } | 2071 } |
2063 | 2072 |
2064 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { | 2073 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { |
2065 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); | 2074 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); |
2066 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); | 2075 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); |
2067 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); | 2076 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); |
2068 } | 2077 } |
2069 | 2078 |
2070 | 2079 |
2071 } // namespace dart | 2080 } // namespace dart |
OLD | NEW |