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" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 static void EnsureConstructorsAreCompiled(const Function& func) { | 87 static void EnsureConstructorsAreCompiled(const Function& func) { |
88 // Only generative constructors can have initializing formals. | 88 // Only generative constructors can have initializing formals. |
89 if (!func.IsGenerativeConstructor()) return; | 89 if (!func.IsGenerativeConstructor()) return; |
90 | 90 |
91 Thread* thread = Thread::Current(); | 91 Thread* thread = Thread::Current(); |
92 Zone* zone = thread->zone(); | 92 Zone* zone = thread->zone(); |
93 const Class& cls = Class::Handle(zone, func.Owner()); | 93 const Class& cls = Class::Handle(zone, func.Owner()); |
94 const Error& error = Error::Handle( | 94 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread)); |
95 zone, cls.EnsureIsFinalized(thread->isolate())); | |
96 if (!error.IsNull()) { | 95 if (!error.IsNull()) { |
97 Exceptions::PropagateError(error); | 96 Exceptions::PropagateError(error); |
98 UNREACHABLE(); | 97 UNREACHABLE(); |
99 } | 98 } |
100 if (!func.HasCode()) { | 99 if (!func.HasCode()) { |
101 const Error& error = Error::Handle( | 100 const Error& error = Error::Handle( |
102 zone, Compiler::CompileFunction(thread, func)); | 101 zone, Compiler::CompileFunction(thread, func)); |
103 if (!error.IsNull()) { | 102 if (!error.IsNull()) { |
104 Exceptions::PropagateError(error); | 103 Exceptions::PropagateError(error); |
105 UNREACHABLE(); | 104 UNREACHABLE(); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 if (cls.IsSignatureClass()) { | 337 if (cls.IsSignatureClass()) { |
339 if (cls.IsCanonicalSignatureClass()) { | 338 if (cls.IsCanonicalSignatureClass()) { |
340 // We represent function types as canonical signature classes. | 339 // We represent function types as canonical signature classes. |
341 return CreateFunctionTypeMirror(cls, type); | 340 return CreateFunctionTypeMirror(cls, type); |
342 } else { | 341 } else { |
343 // We represent typedefs as non-canonical signature classes. | 342 // We represent typedefs as non-canonical signature classes. |
344 return CreateTypedefMirror(cls, type, is_declaration, owner_mirror); | 343 return CreateTypedefMirror(cls, type, is_declaration, owner_mirror); |
345 } | 344 } |
346 } | 345 } |
347 | 346 |
348 const Error& error = Error::Handle(cls.EnsureIsFinalized(Isolate::Current())); | 347 const Error& error = Error::Handle(cls.EnsureIsFinalized(Thread::Current())); |
349 if (!error.IsNull()) { | 348 if (!error.IsNull()) { |
350 Exceptions::PropagateError(error); | 349 Exceptions::PropagateError(error); |
351 UNREACHABLE(); | 350 UNREACHABLE(); |
352 } | 351 } |
353 | 352 |
354 const Array& args = Array::Handle(Array::New(9)); | 353 const Array& args = Array::Handle(Array::New(9)); |
355 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 354 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
356 args.SetAt(1, type); | 355 args.SetAt(1, type); |
357 // Note that the VM does not consider mixin application aliases to be mixin | 356 // Note that the VM does not consider mixin application aliases to be mixin |
358 // applications, so this only covers anonymous mixin applications. We do not | 357 // applications, so this only covers anonymous mixin applications. We do not |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 | 581 |
583 const Array& args = Array::Handle(Array::New(2)); | 582 const Array& args = Array::Handle(Array::New(2)); |
584 args.SetAt(0, debug_name); | 583 args.SetAt(0, debug_name); |
585 args.SetAt(1, root_library_mirror); | 584 args.SetAt(1, root_library_mirror); |
586 return CreateMirror(Symbols::_LocalIsolateMirror(), args); | 585 return CreateMirror(Symbols::_LocalIsolateMirror(), args); |
587 } | 586 } |
588 | 587 |
589 | 588 |
590 static void VerifyMethodKindShifts() { | 589 static void VerifyMethodKindShifts() { |
591 #ifdef DEBUG | 590 #ifdef DEBUG |
592 Isolate* isolate = Isolate::Current(); | 591 Thread* thread = Thread::Current(); |
593 const Library& lib = Library::Handle(isolate, Library::MirrorsLibrary()); | 592 Zone* zone = thread->zone(); |
594 const Class& cls = Class::Handle(isolate, | 593 const Library& lib = Library::Handle(zone, Library::MirrorsLibrary()); |
| 594 const Class& cls = Class::Handle(zone, |
595 lib.LookupClassAllowPrivate(Symbols::_LocalMethodMirror())); | 595 lib.LookupClassAllowPrivate(Symbols::_LocalMethodMirror())); |
596 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate)); | 596 const Error& error = Error::Handle(zone, cls.EnsureIsFinalized(thread)); |
597 ASSERT(error.IsNull()); | 597 ASSERT(error.IsNull()); |
598 | 598 |
599 Field& field = Field::Handle(); | 599 Field& field = Field::Handle(); |
600 Smi& value = Smi::Handle(); | 600 Smi& value = Smi::Handle(); |
601 | 601 |
602 #define CHECK_KIND_SHIFT(name) \ | 602 #define CHECK_KIND_SHIFT(name) \ |
603 field = cls.LookupField(String::Handle(String::New(#name))); \ | 603 field = cls.LookupField(String::Handle(String::New(#name))); \ |
604 ASSERT(!field.IsNull()); \ | 604 ASSERT(!field.IsNull()); \ |
605 value ^= field.StaticValue(); \ | 605 value ^= field.StaticValue(); \ |
606 ASSERT(value.Value() == Mirrors::name); | 606 ASSERT(value.Value() == Mirrors::name); |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 | 970 |
971 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces, 1) { | 971 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces, 1) { |
972 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 972 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
973 PROPAGATE_IF_MALFORMED(type); | 973 PROPAGATE_IF_MALFORMED(type); |
974 ASSERT(type.IsFinalized()); | 974 ASSERT(type.IsFinalized()); |
975 if (!type.HasResolvedTypeClass()) { | 975 if (!type.HasResolvedTypeClass()) { |
976 Exceptions::ThrowArgumentError(type); | 976 Exceptions::ThrowArgumentError(type); |
977 UNREACHABLE(); | 977 UNREACHABLE(); |
978 } | 978 } |
979 const Class& cls = Class::Handle(type.type_class()); | 979 const Class& cls = Class::Handle(type.type_class()); |
980 const Error& error = Error::Handle(cls.EnsureIsFinalized(isolate)); | 980 const Error& error = Error::Handle(cls.EnsureIsFinalized(thread)); |
981 if (!error.IsNull()) { | 981 if (!error.IsNull()) { |
982 Exceptions::PropagateError(error); | 982 Exceptions::PropagateError(error); |
983 } | 983 } |
984 | 984 |
985 return cls.interfaces(); | 985 return cls.interfaces(); |
986 } | 986 } |
987 | 987 |
988 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces_instantiated, 1) { | 988 DEFINE_NATIVE_ENTRY(ClassMirror_interfaces_instantiated, 1) { |
989 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); | 989 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
990 PROPAGATE_IF_MALFORMED(type); | 990 PROPAGATE_IF_MALFORMED(type); |
991 ASSERT(type.IsFinalized()); | 991 ASSERT(type.IsFinalized()); |
992 if (!type.HasResolvedTypeClass()) { | 992 if (!type.HasResolvedTypeClass()) { |
993 Exceptions::ThrowArgumentError(type); | 993 Exceptions::ThrowArgumentError(type); |
994 UNREACHABLE(); | 994 UNREACHABLE(); |
995 } | 995 } |
996 const Class& cls = Class::Handle(type.type_class()); | 996 const Class& cls = Class::Handle(type.type_class()); |
997 const Error& error = Error::Handle(cls.EnsureIsFinalized(isolate)); | 997 const Error& error = Error::Handle(cls.EnsureIsFinalized(thread)); |
998 if (!error.IsNull()) { | 998 if (!error.IsNull()) { |
999 Exceptions::PropagateError(error); | 999 Exceptions::PropagateError(error); |
1000 } | 1000 } |
1001 | 1001 |
1002 Array& interfaces = Array::Handle(cls.interfaces()); | 1002 Array& interfaces = Array::Handle(cls.interfaces()); |
1003 Array& interfaces_inst = Array::Handle(Array::New(interfaces.Length())); | 1003 Array& interfaces_inst = Array::Handle(Array::New(interfaces.Length())); |
1004 AbstractType& interface = AbstractType::Handle(); | 1004 AbstractType& interface = AbstractType::Handle(); |
1005 | 1005 |
1006 for (int i = 0; i < interfaces.Length(); i++) { | 1006 for (int i = 0; i < interfaces.Length(); i++) { |
1007 interface ^= interfaces.At(i); | 1007 interface ^= interfaces.At(i); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1052 DEFINE_NATIVE_ENTRY(ClassMirror_members, 3) { | 1052 DEFINE_NATIVE_ENTRY(ClassMirror_members, 3) { |
1053 GET_NON_NULL_NATIVE_ARGUMENT(Instance, | 1053 GET_NON_NULL_NATIVE_ARGUMENT(Instance, |
1054 owner_mirror, | 1054 owner_mirror, |
1055 arguments->NativeArgAt(0)); | 1055 arguments->NativeArgAt(0)); |
1056 GET_NATIVE_ARGUMENT(AbstractType, | 1056 GET_NATIVE_ARGUMENT(AbstractType, |
1057 owner_instantiator, | 1057 owner_instantiator, |
1058 arguments->NativeArgAt(1)); | 1058 arguments->NativeArgAt(1)); |
1059 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(2)); | 1059 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(2)); |
1060 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1060 const Class& klass = Class::Handle(ref.GetClassReferent()); |
1061 | 1061 |
1062 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); | 1062 const Error& error = Error::Handle(klass.EnsureIsFinalized(thread)); |
1063 if (!error.IsNull()) { | 1063 if (!error.IsNull()) { |
1064 Exceptions::PropagateError(error); | 1064 Exceptions::PropagateError(error); |
1065 } | 1065 } |
1066 | 1066 |
1067 const Array& fields = Array::Handle(klass.fields()); | 1067 const Array& fields = Array::Handle(klass.fields()); |
1068 const intptr_t num_fields = fields.Length(); | 1068 const intptr_t num_fields = fields.Length(); |
1069 | 1069 |
1070 const Array& functions = Array::Handle(klass.functions()); | 1070 const Array& functions = Array::Handle(klass.functions()); |
1071 const intptr_t num_functions = functions.Length(); | 1071 const intptr_t num_functions = functions.Length(); |
1072 | 1072 |
(...skipping 30 matching lines...) Expand all Loading... |
1103 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 3) { | 1103 DEFINE_NATIVE_ENTRY(ClassMirror_constructors, 3) { |
1104 GET_NON_NULL_NATIVE_ARGUMENT(Instance, | 1104 GET_NON_NULL_NATIVE_ARGUMENT(Instance, |
1105 owner_mirror, | 1105 owner_mirror, |
1106 arguments->NativeArgAt(0)); | 1106 arguments->NativeArgAt(0)); |
1107 GET_NATIVE_ARGUMENT(AbstractType, | 1107 GET_NATIVE_ARGUMENT(AbstractType, |
1108 owner_instantiator, | 1108 owner_instantiator, |
1109 arguments->NativeArgAt(1)); | 1109 arguments->NativeArgAt(1)); |
1110 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(2)); | 1110 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(2)); |
1111 const Class& klass = Class::Handle(ref.GetClassReferent()); | 1111 const Class& klass = Class::Handle(ref.GetClassReferent()); |
1112 | 1112 |
1113 const Error& error = Error::Handle(klass.EnsureIsFinalized(isolate)); | 1113 const Error& error = Error::Handle(klass.EnsureIsFinalized(thread)); |
1114 if (!error.IsNull()) { | 1114 if (!error.IsNull()) { |
1115 Exceptions::PropagateError(error); | 1115 Exceptions::PropagateError(error); |
1116 } | 1116 } |
1117 | 1117 |
1118 const Array& functions = Array::Handle(klass.functions()); | 1118 const Array& functions = Array::Handle(klass.functions()); |
1119 const intptr_t num_functions = functions.Length(); | 1119 const intptr_t num_functions = functions.Length(); |
1120 | 1120 |
1121 Instance& constructor_mirror = Instance::Handle(); | 1121 Instance& constructor_mirror = Instance::Handle(); |
1122 const GrowableObjectArray& constructor_mirrors = GrowableObjectArray::Handle( | 1122 const GrowableObjectArray& constructor_mirrors = GrowableObjectArray::Handle( |
1123 GrowableObjectArray::New(num_functions)); | 1123 GrowableObjectArray::New(num_functions)); |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2097 } | 2097 } |
2098 | 2098 |
2099 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { | 2099 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { |
2100 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); | 2100 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); |
2101 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); | 2101 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); |
2102 return Bool::Get(a.IsSubtypeOf(b, NULL)).raw(); | 2102 return Bool::Get(a.IsSubtypeOf(b, NULL)).raw(); |
2103 } | 2103 } |
2104 | 2104 |
2105 | 2105 |
2106 } // namespace dart | 2106 } // namespace dart |
OLD | NEW |