| 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/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 8 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
| 9 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| 10 #include "vm/port.h" | 11 #include "vm/port.h" |
| 11 #include "vm/symbols.h" | 12 #include "vm/symbols.h" |
| 12 | 13 |
| 13 namespace dart { | 14 namespace dart { |
| 14 | 15 |
| 15 static RawInstance* CreateMirror(const String& mirror_class_name, | 16 static RawInstance* CreateMirror(const String& mirror_class_name, |
| 16 const Array& constructor_arguments) { | 17 const Array& constructor_arguments) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 static RawInstance* CreateTypedefMirror(const Class& cls, | 102 static RawInstance* CreateTypedefMirror(const Class& cls, |
| 102 const Instance& owner_mirror) { | 103 const Instance& owner_mirror) { |
| 103 const Array& args = Array::Handle(Array::New(3)); | 104 const Array& args = Array::Handle(Array::New(3)); |
| 104 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 105 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
| 105 args.SetAt(1, String::Handle(cls.UserVisibleName())); | 106 args.SetAt(1, String::Handle(cls.UserVisibleName())); |
| 106 args.SetAt(2, owner_mirror); | 107 args.SetAt(2, owner_mirror); |
| 107 return CreateMirror(Symbols::_LocalTypedefMirrorImpl(), args); | 108 return CreateMirror(Symbols::_LocalTypedefMirrorImpl(), args); |
| 108 } | 109 } |
| 109 | 110 |
| 110 | 111 |
| 111 static RawInstance* CreateFunctionTypeMirror(const Class& cls) { | 112 static RawInstance* CreateFunctionTypeMirror(const Class& cls, |
| 112 const Array& args = Array::Handle(Array::New(1)); | 113 const AbstractType& type) { |
| 114 const Array& args = Array::Handle(Array::New(2)); |
| 113 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 115 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
| 116 args.SetAt(1, type); |
| 114 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); | 117 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); |
| 115 } | 118 } |
| 116 | 119 |
| 117 | 120 |
| 118 static RawInstance* CreateMethodMirror(const Function& func, | 121 static RawInstance* CreateMethodMirror(const Function& func, |
| 119 const Instance& owner_mirror) { | 122 const Instance& owner_mirror) { |
| 120 const Array& args = Array::Handle(Array::New(12)); | 123 const Array& args = Array::Handle(Array::New(12)); |
| 121 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); | 124 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
| 122 args.SetAt(1, String::Handle(func.UserVisibleName())); | 125 args.SetAt(1, String::Handle(func.UserVisibleName())); |
| 123 args.SetAt(2, owner_mirror); | 126 args.SetAt(2, owner_mirror); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 148 args.SetAt(2, owner_mirror); | 151 args.SetAt(2, owner_mirror); |
| 149 args.SetAt(3, Instance::Handle()); // Null for type. | 152 args.SetAt(3, Instance::Handle()); // Null for type. |
| 150 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); | 153 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); |
| 151 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); | 154 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); |
| 152 | 155 |
| 153 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); | 156 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); |
| 154 } | 157 } |
| 155 | 158 |
| 156 | 159 |
| 157 static RawInstance* CreateClassMirror(const Class& cls, | 160 static RawInstance* CreateClassMirror(const Class& cls, |
| 161 const AbstractType& type, |
| 158 const Instance& owner_mirror) { | 162 const Instance& owner_mirror) { |
| 159 if (cls.IsSignatureClass()) { | 163 if (cls.IsSignatureClass()) { |
| 160 if (cls.IsCanonicalSignatureClass()) { | 164 if (cls.IsCanonicalSignatureClass()) { |
| 161 // We represent function types as canonical signature classes. | 165 // We represent function types as canonical signature classes. |
| 162 return CreateFunctionTypeMirror(cls); | 166 return CreateFunctionTypeMirror(cls, type); |
| 163 } else { | 167 } else { |
| 164 // We represent typedefs as non-canonical signature classes. | 168 // We represent typedefs as non-canonical signature classes. |
| 165 return CreateTypedefMirror(cls, owner_mirror); | 169 return CreateTypedefMirror(cls, owner_mirror); |
| 166 } | 170 } |
| 167 } | 171 } |
| 168 | 172 |
| 169 const Array& args = Array::Handle(Array::New(2)); | 173 const Bool& is_generic = |
| 174 (cls.NumTypeParameters() == 0) ? Bool::False() : Bool::True(); |
| 175 |
| 176 const Array& args = Array::Handle(Array::New(4)); |
| 170 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); | 177 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); |
| 171 args.SetAt(1, String::Handle(cls.UserVisibleName())); | 178 args.SetAt(1, type); |
| 179 args.SetAt(2, String::Handle(cls.UserVisibleName())); |
| 180 args.SetAt(3, is_generic); |
| 172 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); | 181 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); |
| 173 } | 182 } |
| 174 | 183 |
| 175 | 184 |
| 185 // Note a "raw type" is not the same as a RawType. |
| 186 static RawAbstractType* RawTypeOfClass(const Class& cls) { |
| 187 Type& type = Type::Handle(Type::New(cls, |
| 188 Object::null_abstract_type_arguments(), |
| 189 Scanner::kDummyTokenIndex)); |
| 190 return ClassFinalizer::FinalizeType(cls, type, ClassFinalizer::kCanonicalize); |
| 191 } |
| 192 |
| 193 |
| 176 static RawInstance* CreateLibraryMirror(const Library& lib) { | 194 static RawInstance* CreateLibraryMirror(const Library& lib) { |
| 177 const Array& args = Array::Handle(Array::New(3)); | 195 const Array& args = Array::Handle(Array::New(3)); |
| 178 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); | 196 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); |
| 179 String& str = String::Handle(); | 197 String& str = String::Handle(); |
| 180 str = lib.name(); | 198 str = lib.name(); |
| 181 args.SetAt(1, str); | 199 args.SetAt(1, str); |
| 182 str = lib.url(); | 200 str = lib.url(); |
| 183 args.SetAt(2, str); | 201 args.SetAt(2, str); |
| 184 return CreateMirror(Symbols::_LocalLibraryMirrorImpl(), args); | 202 return CreateMirror(Symbols::_LocalLibraryMirrorImpl(), args); |
| 185 } | 203 } |
| 186 | 204 |
| 187 | 205 |
| 188 static RawInstance* CreateTypeMirror(const AbstractType& type) { | 206 static RawInstance* CreateTypeMirror(const AbstractType& type) { |
| 189 ASSERT(!type.IsMalformed()); | 207 ASSERT(!type.IsMalformed()); |
| 190 if (type.HasResolvedTypeClass()) { | 208 if (type.HasResolvedTypeClass()) { |
| 191 const Class& cls = Class::Handle(type.type_class()); | 209 const Class& cls = Class::Handle(type.type_class()); |
| 192 // Handle void and dynamic types. | 210 // Handle void and dynamic types. |
| 193 if (cls.IsVoidClass()) { | 211 if (cls.IsVoidClass()) { |
| 194 Array& args = Array::Handle(Array::New(1)); | 212 Array& args = Array::Handle(Array::New(1)); |
| 195 args.SetAt(0, Symbols::Void()); | 213 args.SetAt(0, Symbols::Void()); |
| 196 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. | 214 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. |
| 197 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); | 215 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); |
| 198 } else if (cls.IsDynamicClass()) { | 216 } else if (cls.IsDynamicClass()) { |
| 199 Array& args = Array::Handle(Array::New(1)); | 217 Array& args = Array::Handle(Array::New(1)); |
| 200 args.SetAt(0, Symbols::Dynamic()); | 218 args.SetAt(0, Symbols::Dynamic()); |
| 201 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. | 219 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. |
| 202 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); | 220 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); |
| 203 } | 221 } |
| 204 return CreateClassMirror(cls, Object::null_instance()); | 222 return CreateClassMirror(cls, type, Object::null_instance()); |
| 205 } else if (type.IsTypeParameter()) { | 223 } else if (type.IsTypeParameter()) { |
| 206 return CreateTypeVariableMirror(TypeParameter::Cast(type), | 224 return CreateTypeVariableMirror(TypeParameter::Cast(type), |
| 207 Object::null_instance()); | 225 Object::null_instance()); |
| 208 } | 226 } |
| 209 UNREACHABLE(); | 227 UNREACHABLE(); |
| 210 return Instance::null(); | 228 return Instance::null(); |
| 211 } | 229 } |
| 212 | 230 |
| 213 | 231 |
| 214 static RawInstance* CreateIsolateMirror() { | 232 static RawInstance* CreateIsolateMirror() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 270 |
| 253 | 271 |
| 254 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalMirrorSystem, 0) { | 272 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalMirrorSystem, 0) { |
| 255 return CreateMirrorSystem(); | 273 return CreateMirrorSystem(); |
| 256 } | 274 } |
| 257 | 275 |
| 258 | 276 |
| 259 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) { | 277 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalClassMirror, 1) { |
| 260 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); | 278 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); |
| 261 const Class& cls = Class::Handle(type.type_class()); | 279 const Class& cls = Class::Handle(type.type_class()); |
| 262 return CreateClassMirror(cls, Object::null_instance()); | 280 ASSERT(!cls.IsNull()); |
| 281 return CreateClassMirror(cls, |
| 282 AbstractType::Handle(), |
| 283 Instance::null_instance()); |
| 263 } | 284 } |
| 264 | 285 |
| 265 | 286 |
| 287 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { |
| 288 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
| 289 return CreateTypeMirror(type); |
| 290 } |
| 291 |
| 292 |
| 266 static void ThrowMirroredCompilationError(const String& message) { | 293 static void ThrowMirroredCompilationError(const String& message) { |
| 267 Array& args = Array::Handle(Array::New(1)); | 294 Array& args = Array::Handle(Array::New(1)); |
| 268 args.SetAt(0, message); | 295 args.SetAt(0, message); |
| 269 | 296 |
| 270 Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args); | 297 Exceptions::ThrowByType(Exceptions::kMirroredCompilationError, args); |
| 271 UNREACHABLE(); | 298 UNREACHABLE(); |
| 272 } | 299 } |
| 273 | 300 |
| 274 | 301 |
| 275 static void ThrowInvokeError(const Error& error) { | 302 static void ThrowInvokeError(const Error& error) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 const Class& cls = Class::Handle(ref.GetClassReferent()); | 355 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 329 const Function& func = Function::Handle(cls.signature_function()); | 356 const Function& func = Function::Handle(cls.signature_function()); |
| 330 return CreateParameterMirrorList(func); | 357 return CreateParameterMirrorList(func); |
| 331 } | 358 } |
| 332 | 359 |
| 333 | 360 |
| 334 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { | 361 DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) { |
| 335 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 362 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 336 const Class& cls = Class::Handle(ref.GetClassReferent()); | 363 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 337 const Function& func = Function::Handle(cls.signature_function()); | 364 const Function& func = Function::Handle(cls.signature_function()); |
| 338 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 365 return func.result_type(); |
| 339 return CreateTypeMirror(return_type); | |
| 340 } | 366 } |
| 341 | 367 |
| 342 | 368 |
| 343 static bool FieldIsUninitialized(const Field& field) { | 369 static bool FieldIsUninitialized(const Field& field) { |
| 344 ASSERT(!field.IsNull()); | 370 ASSERT(!field.IsNull()); |
| 345 | 371 |
| 346 // Return getter method for uninitialized fields, rather than the | 372 // Return getter method for uninitialized fields, rather than the |
| 347 // field object, since the value in the field object will not be | 373 // field object, since the value in the field object will not be |
| 348 // initialized until the first time the getter is invoked. | 374 // initialized until the first time the getter is invoked. |
| 349 const Instance& value = Instance::Handle(field.value()); | 375 const Instance& value = Instance::Handle(field.value()); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 DictionaryIterator entries(library); | 518 DictionaryIterator entries(library); |
| 493 | 519 |
| 494 while (entries.HasNext()) { | 520 while (entries.HasNext()) { |
| 495 entry = entries.GetNext(); | 521 entry = entries.GetNext(); |
| 496 if (entry.IsClass()) { | 522 if (entry.IsClass()) { |
| 497 const Class& klass = Class::Cast(entry); | 523 const Class& klass = Class::Cast(entry); |
| 498 if (!klass.IsCanonicalSignatureClass()) { | 524 if (!klass.IsCanonicalSignatureClass()) { |
| 499 // The various implementations of public classes don't always have the | 525 // The various implementations of public classes don't always have the |
| 500 // expected superinterfaces or other properties, so we filter them out. | 526 // expected superinterfaces or other properties, so we filter them out. |
| 501 if (!RawObject::IsImplementationClassId(klass.id())) { | 527 if (!RawObject::IsImplementationClassId(klass.id())) { |
| 502 member_mirror = CreateClassMirror(klass, owner_mirror); | 528 member_mirror = CreateClassMirror(klass, |
| 529 AbstractType::Handle(), |
| 530 owner_mirror); |
| 503 member_mirrors.Add(member_mirror); | 531 member_mirrors.Add(member_mirror); |
| 504 } | 532 } |
| 505 } | 533 } |
| 506 } else if (entry.IsField()) { | 534 } else if (entry.IsField()) { |
| 507 const Field& field = Field::Cast(entry); | 535 const Field& field = Field::Cast(entry); |
| 508 member_mirror = CreateVariableMirror(field, owner_mirror); | 536 member_mirror = CreateVariableMirror(field, owner_mirror); |
| 509 member_mirrors.Add(member_mirror); | 537 member_mirrors.Add(member_mirror); |
| 510 } else if (entry.IsFunction()) { | 538 } else if (entry.IsFunction()) { |
| 511 const Function& func = Function::Cast(entry); | 539 const Function& func = Function::Cast(entry); |
| 512 if (func.kind() == RawFunction::kRegularFunction || | 540 if (func.kind() == RawFunction::kRegularFunction || |
| 513 func.kind() == RawFunction::kGetterFunction || | 541 func.kind() == RawFunction::kGetterFunction || |
| 514 func.kind() == RawFunction::kSetterFunction) { | 542 func.kind() == RawFunction::kSetterFunction) { |
| 515 member_mirror = CreateMethodMirror(func, owner_mirror); | 543 member_mirror = CreateMethodMirror(func, owner_mirror); |
| 516 member_mirrors.Add(member_mirror); | 544 member_mirrors.Add(member_mirror); |
| 517 } | 545 } |
| 518 } | 546 } |
| 519 } | 547 } |
| 520 | 548 |
| 521 return member_mirrors.raw(); | 549 return member_mirrors.raw(); |
| 522 } | 550 } |
| 523 | 551 |
| 524 | 552 |
| 525 DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 1) { | 553 DEFINE_NATIVE_ENTRY(ClassMirror_type_variables, 1) { |
| 526 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 554 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 527 const Class& klass = Class::Handle(ref.GetClassReferent()); | 555 const Class& klass = Class::Handle(ref.GetClassReferent()); |
| 528 return CreateTypeVariableList(klass); | 556 return CreateTypeVariableList(klass); |
| 529 } | 557 } |
| 530 | 558 |
| 531 | 559 |
| 532 DEFINE_NATIVE_ENTRY(LocalTypeVariableMirror_owner, 1) { | 560 DEFINE_NATIVE_ENTRY(ClassMirror_type_arguments, 1) { |
| 561 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); |
| 562 |
| 563 const AbstractTypeArguments& args = |
| 564 AbstractTypeArguments::Handle(type.arguments()); |
| 565 if (args.IsNull()) { |
| 566 return Object::empty_array().raw(); |
| 567 } |
| 568 |
| 569 const Class& cls = Class::Handle(type.type_class()); |
| 570 const intptr_t num_params = cls.NumTypeParameters(); |
| 571 const intptr_t num_inherited_args = args.Length() - num_params; |
| 572 |
| 573 const Array& result = Array::Handle(Array::New(num_params)); |
| 574 AbstractType& arg_type = AbstractType::Handle(); |
| 575 Instance& type_mirror = Instance::Handle(); |
| 576 for (intptr_t i = 0; i < num_params; i++) { |
| 577 arg_type ^= args.TypeAt(i + num_inherited_args); |
| 578 type_mirror = CreateTypeMirror(arg_type); |
| 579 result.SetAt(i, type_mirror); |
| 580 } |
| 581 return result.raw(); |
| 582 } |
| 583 |
| 584 |
| 585 DEFINE_NATIVE_ENTRY(TypeVariableMirror_owner, 1) { |
| 533 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); | 586 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); |
| 534 return CreateClassMirror(Class::Handle(param.parameterized_class()), | 587 return CreateClassMirror(Class::Handle(param.parameterized_class()), |
| 588 AbstractType::Handle(), |
| 535 Instance::null_instance()); | 589 Instance::null_instance()); |
| 536 } | 590 } |
| 537 | 591 |
| 538 | 592 |
| 539 DEFINE_NATIVE_ENTRY(LocalTypeVariableMirror_upper_bound, 1) { | 593 DEFINE_NATIVE_ENTRY(TypeVariableMirror_upper_bound, 1) { |
| 540 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); | 594 GET_NON_NULL_NATIVE_ARGUMENT(TypeParameter, param, arguments->NativeArgAt(0)); |
| 541 return CreateTypeMirror(AbstractType::Handle(param.bound())); | 595 return param.bound(); |
| 542 } | 596 } |
| 543 | 597 |
| 544 | 598 |
| 545 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled | 599 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled |
| 546 // exceptions. Wrap and propagate any compilation errors. | 600 // exceptions. Wrap and propagate any compilation errors. |
| 547 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, | 601 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, |
| 548 const Function& function, | 602 const Function& function, |
| 549 const String& target_name, | 603 const String& target_name, |
| 550 const Array& arguments) { | 604 const Array& arguments) { |
| 551 // Note "arguments" is already the internal arguments with the receiver as | 605 // Note "arguments" is already the internal arguments with the receiver as |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, args); | 810 Exceptions::ThrowByType(Exceptions::kNoSuchMethod, args); |
| 757 UNREACHABLE(); | 811 UNREACHABLE(); |
| 758 } | 812 } |
| 759 | 813 |
| 760 | 814 |
| 761 static void ThrowNoSuchMethod(const Class& klass, | 815 static void ThrowNoSuchMethod(const Class& klass, |
| 762 const String& function_name, | 816 const String& function_name, |
| 763 const Function& function, | 817 const Function& function, |
| 764 const InvocationMirror::Call call, | 818 const InvocationMirror::Call call, |
| 765 const InvocationMirror::Type type) { | 819 const InvocationMirror::Type type) { |
| 766 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); | 820 AbstractType& runtime_type = AbstractType::Handle(RawTypeOfClass(klass)); |
| 767 Type& pre_type = Type::Handle( | |
| 768 Type::New(klass, type_arguments, Scanner::kDummyTokenIndex)); | |
| 769 pre_type.SetIsFinalized(); | |
| 770 AbstractType& runtime_type = AbstractType::Handle(pre_type.Canonicalize()); | |
| 771 | 821 |
| 772 ThrowNoSuchMethod(runtime_type, | 822 ThrowNoSuchMethod(runtime_type, |
| 773 function_name, | 823 function_name, |
| 774 function, | 824 function, |
| 775 call, | 825 call, |
| 776 type); | 826 type); |
| 777 UNREACHABLE(); | 827 UNREACHABLE(); |
| 778 } | 828 } |
| 779 | 829 |
| 780 | 830 |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1194 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1145 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1195 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1146 if (func.IsNonImplicitClosureFunction()) { | 1196 if (func.IsNonImplicitClosureFunction()) { |
| 1147 return CreateMethodMirror(Function::Handle( | 1197 return CreateMethodMirror(Function::Handle( |
| 1148 func.parent_function()), Object::null_instance()); | 1198 func.parent_function()), Object::null_instance()); |
| 1149 } | 1199 } |
| 1150 const Class& owner = Class::Handle(func.Owner()); | 1200 const Class& owner = Class::Handle(func.Owner()); |
| 1151 if (owner.IsTopLevel()) { | 1201 if (owner.IsTopLevel()) { |
| 1152 return CreateLibraryMirror(Library::Handle(owner.library())); | 1202 return CreateLibraryMirror(Library::Handle(owner.library())); |
| 1153 } | 1203 } |
| 1154 return CreateClassMirror(owner, Object::null_instance()); | 1204 return CreateClassMirror(owner, |
| 1205 AbstractType::Handle(), |
| 1206 Object::null_instance()); |
| 1155 } | 1207 } |
| 1156 | 1208 |
| 1157 | 1209 |
| 1158 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 1) { | 1210 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 1) { |
| 1159 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1211 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1160 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1212 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1161 return CreateParameterMirrorList(func); | 1213 return CreateParameterMirrorList(func); |
| 1162 } | 1214 } |
| 1163 | 1215 |
| 1164 | 1216 |
| 1165 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { | 1217 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { |
| 1166 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1218 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1167 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1219 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1168 // We handle constructors in Dart code. | 1220 // We handle constructors in Dart code. |
| 1169 ASSERT(!func.IsConstructor()); | 1221 ASSERT(!func.IsConstructor()); |
| 1170 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 1222 return func.result_type(); |
| 1171 return CreateTypeMirror(return_type); | |
| 1172 } | 1223 } |
| 1173 | 1224 |
| 1174 | 1225 |
| 1175 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { | 1226 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { |
| 1176 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1227 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1177 const Class& cls = Class::Handle(ref.GetClassReferent()); | 1228 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 1178 const Function& sig_func = Function::Handle(cls.signature_function()); | 1229 const Function& sig_func = Function::Handle(cls.signature_function()); |
| 1179 const Class& sig_cls = Class::Handle(sig_func.signature_class()); | 1230 const Class& sig_cls = Class::Handle(sig_func.signature_class()); |
| 1180 return MirrorReference::New(sig_cls); | 1231 return MirrorReference::New(sig_cls); |
| 1181 } | 1232 } |
| 1182 | 1233 |
| 1183 | 1234 |
| 1184 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) { | 1235 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) { |
| 1185 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1236 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1186 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1)); | 1237 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1)); |
| 1187 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1238 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1188 const AbstractType& param_type = AbstractType::Handle(func.ParameterTypeAt( | 1239 return func.ParameterTypeAt(func.NumImplicitParameters() + pos.Value()); |
| 1189 func.NumImplicitParameters() + pos.Value())); | |
| 1190 return CreateTypeMirror(param_type); | |
| 1191 } | 1240 } |
| 1192 | 1241 |
| 1193 | 1242 |
| 1194 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1243 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1195 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1244 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1196 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1245 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1197 | 1246 return field.type(); |
| 1198 const AbstractType& type = AbstractType::Handle(field.type()); | |
| 1199 return CreateTypeMirror(type); | |
| 1200 } | 1247 } |
| 1201 | 1248 |
| 1202 } // namespace dart | 1249 } // namespace dart |
| OLD | NEW |