| 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/dart_entry.h" | 7 #include "vm/dart_entry.h" |
| 8 #include "vm/exceptions.h" | 8 #include "vm/exceptions.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 #include "vm/port.h" | 10 #include "vm/port.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 args.SetAt(0, field_ref); | 146 args.SetAt(0, field_ref); |
| 147 args.SetAt(1, name); | 147 args.SetAt(1, name); |
| 148 args.SetAt(2, owner_mirror); | 148 args.SetAt(2, owner_mirror); |
| 149 args.SetAt(3, Instance::Handle()); // Null for type. | 149 args.SetAt(3, Instance::Handle()); // Null for type. |
| 150 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); | 150 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); |
| 151 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); | 151 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); |
| 152 | 152 |
| 153 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); | 153 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); |
| 154 } | 154 } |
| 155 | 155 |
| 156 static RawFunction* CallMethod(const Class& cls) { |
| 157 if (cls.IsSignatureClass()) { |
| 158 return cls.signature_function(); |
| 159 } |
| 160 |
| 161 Class& lookup_cls = Class::Handle(cls.raw()); |
| 162 Function& call_function = Function::Handle(); |
| 163 do { |
| 164 call_function = lookup_cls.LookupDynamicFunction(Symbols::Call()); |
| 165 if (!call_function.IsNull()) { |
| 166 return call_function.raw(); |
| 167 } |
| 168 lookup_cls = lookup_cls.SuperClass(); |
| 169 } while (!lookup_cls.IsNull()); |
| 170 return Function::null(); |
| 171 } |
| 156 | 172 |
| 157 static RawInstance* CreateClassMirror(const Class& cls, | 173 static RawInstance* CreateClassMirror(const Class& cls, |
| 158 const Instance& owner_mirror) { | 174 const Instance& owner_mirror) { |
| 159 if (cls.IsSignatureClass()) { | 175 if (cls.IsSignatureClass()) { |
| 160 if (cls.IsCanonicalSignatureClass()) { | 176 if (cls.IsCanonicalSignatureClass()) { |
| 161 // We represent function types as canonical signature classes. | 177 // We represent function types as canonical signature classes. |
| 162 return CreateFunctionTypeMirror(cls); | 178 return CreateFunctionTypeMirror(cls); |
| 163 } else { | 179 } else { |
| 164 // We represent typedefs as non-canonical signature classes. | 180 // We represent typedefs as non-canonical signature classes. |
| 165 return CreateTypedefMirror(cls, owner_mirror); | 181 return CreateTypedefMirror(cls, owner_mirror); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 } | 332 } |
| 317 | 333 |
| 318 const Object& metadata = Object::Handle(library.GetMetadata(decl)); | 334 const Object& metadata = Object::Handle(library.GetMetadata(decl)); |
| 319 if (metadata.IsError()) { | 335 if (metadata.IsError()) { |
| 320 ThrowInvokeError(Error::Cast(metadata)); | 336 ThrowInvokeError(Error::Cast(metadata)); |
| 321 } | 337 } |
| 322 return metadata.raw(); | 338 return metadata.raw(); |
| 323 } | 339 } |
| 324 | 340 |
| 325 | 341 |
| 342 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_call_method, 2) { |
| 343 GET_NON_NULL_NATIVE_ARGUMENT(Instance, |
| 344 owner_mirror, |
| 345 arguments->NativeArgAt(0)); |
| 346 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); |
| 347 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 348 const Function& func = Function::Handle(CallMethod(cls)); |
| 349 ASSERT(!func.IsNull()); |
| 350 return CreateMethodMirror(func, owner_mirror); |
| 351 } |
| 352 |
| 353 |
| 326 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) { | 354 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) { |
| 327 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 355 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 328 const Class& cls = Class::Handle(ref.GetClassReferent()); | 356 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 329 const Function& func = Function::Handle(cls.signature_function()); | 357 const Function& func = Function::Handle(CallMethod(cls)); |
| 358 ASSERT(!func.IsNull()); |
| 330 return CreateParameterMirrorList(func); | 359 return CreateParameterMirrorList(func); |
| 331 } | 360 } |
| 332 | 361 |
| 333 | 362 |
| 334 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { | 363 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { |
| 335 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 364 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 336 const Class& cls = Class::Handle(ref.GetClassReferent()); | 365 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 337 const Function& func = Function::Handle(cls.signature_function()); | 366 const Function& func = Function::Handle(CallMethod(cls)); |
| 367 ASSERT(!func.IsNull()); |
| 338 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 368 const AbstractType& return_type = AbstractType::Handle(func.result_type()); |
| 339 return CreateTypeMirror(return_type); | 369 return CreateTypeMirror(return_type); |
| 340 } | 370 } |
| 341 | 371 |
| 342 | 372 |
| 343 static bool FieldIsUninitialized(const Field& field) { | 373 static bool FieldIsUninitialized(const Field& field) { |
| 344 ASSERT(!field.IsNull()); | 374 ASSERT(!field.IsNull()); |
| 345 | 375 |
| 346 // Return getter method for uninitialized fields, rather than the | 376 // Return getter method for uninitialized fields, rather than the |
| 347 // field object, since the value in the field object will not be | 377 // field object, since the value in the field object will not be |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 if (obj.IsError()) { | 746 if (obj.IsError()) { |
| 717 ThrowInvokeError(Error::Cast(obj)); | 747 ThrowInvokeError(Error::Cast(obj)); |
| 718 UNREACHABLE(); | 748 UNREACHABLE(); |
| 719 } | 749 } |
| 720 return obj.raw(); | 750 return obj.raw(); |
| 721 } | 751 } |
| 722 | 752 |
| 723 | 753 |
| 724 DEFINE_NATIVE_ENTRY(ClosureMirror_function, 1) { | 754 DEFINE_NATIVE_ENTRY(ClosureMirror_function, 1) { |
| 725 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); | 755 GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0)); |
| 726 ASSERT(closure.IsClosure()); | 756 ASSERT(!closure.IsNull()); |
| 727 | 757 |
| 728 const Function& func = Function::Handle(Closure::function(closure)); | 758 Function& function = Function::Handle(); |
| 729 return CreateMethodMirror(func, Instance::null_instance()); | 759 bool callable = closure.IsCallable(&function, NULL); |
| 760 ASSERT(callable); |
| 761 |
| 762 return CreateMethodMirror(function, Instance::null_instance()); |
| 730 } | 763 } |
| 731 | 764 |
| 732 | 765 |
| 733 static void ThrowNoSuchMethod(const Instance& receiver, | 766 static void ThrowNoSuchMethod(const Instance& receiver, |
| 734 const String& function_name, | 767 const String& function_name, |
| 735 const Function& function, | 768 const Function& function, |
| 736 const InvocationMirror::Call call, | 769 const InvocationMirror::Call call, |
| 737 const InvocationMirror::Type type) { | 770 const InvocationMirror::Type type) { |
| 738 const Smi& invocation_type = Smi::Handle(Smi::New( | 771 const Smi& invocation_type = Smi::Handle(Smi::New( |
| 739 InvocationMirror::EncodeType(call, type))); | 772 InvocationMirror::EncodeType(call, type))); |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 | 1226 |
| 1194 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1227 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1195 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1228 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1196 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1229 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1197 | 1230 |
| 1198 const AbstractType& type = AbstractType::Handle(field.type()); | 1231 const AbstractType& type = AbstractType::Handle(field.type()); |
| 1199 return CreateTypeMirror(type); | 1232 return CreateTypeMirror(type); |
| 1200 } | 1233 } |
| 1201 | 1234 |
| 1202 } // namespace dart | 1235 } // namespace dart |
| OLD | NEW |