Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: runtime/lib/mirrors.cc

Issue 24631003: Add proper API for creating private symbols wrt a library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rename StripAccessorPrefix Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/vm/object.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); 226 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls)));
227 args.SetAt(1, type); 227 args.SetAt(1, type);
228 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args); 228 return CreateMirror(Symbols::_LocalFunctionTypeMirrorImpl(), args);
229 } 229 }
230 230
231 231
232 static RawInstance* CreateMethodMirror(const Function& func, 232 static RawInstance* CreateMethodMirror(const Function& func,
233 const Instance& owner_mirror) { 233 const Instance& owner_mirror) {
234 const Array& args = Array::Handle(Array::New(12)); 234 const Array& args = Array::Handle(Array::New(12));
235 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); 235 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func)));
236 args.SetAt(1, String::Handle(func.UserVisibleName())); 236
237 String& name = String::Handle(func.name());
238 name = String::IdentifierPrettyNameRetainPrivate(name);
239 args.SetAt(1, name);
240
237 args.SetAt(2, owner_mirror); 241 args.SetAt(2, owner_mirror);
238 args.SetAt(3, Bool::Get(func.is_static())); 242 args.SetAt(3, Bool::Get(func.is_static()));
239 args.SetAt(4, Bool::Get(func.is_abstract())); 243 args.SetAt(4, Bool::Get(func.is_abstract()));
240 args.SetAt(5, Bool::Get(func.IsGetterFunction())); 244 args.SetAt(5, Bool::Get(func.IsGetterFunction()));
241 args.SetAt(6, Bool::Get(func.IsSetterFunction())); 245 args.SetAt(6, Bool::Get(func.IsSetterFunction()));
242 args.SetAt(7, Bool::Get(func.kind() == RawFunction::kConstructor)); 246 args.SetAt(7, Bool::Get(func.kind() == RawFunction::kConstructor));
243 // TODO(mlippautz): Implement different constructor kinds. 247 // TODO(mlippautz): Implement different constructor kinds.
244 args.SetAt(8, Bool::False()); 248 args.SetAt(8, Bool::False());
245 args.SetAt(9, Bool::False()); 249 args.SetAt(9, Bool::False());
246 args.SetAt(10, Bool::False()); 250 args.SetAt(10, Bool::False());
247 args.SetAt(11, Bool::False()); 251 args.SetAt(11, Bool::False());
248 return CreateMirror(Symbols::_LocalMethodMirrorImpl(), args); 252 return CreateMirror(Symbols::_LocalMethodMirrorImpl(), args);
249 } 253 }
250 254
251 255
252 static RawInstance* CreateVariableMirror(const Field& field, 256 static RawInstance* CreateVariableMirror(const Field& field,
253 const Instance& owner_mirror) { 257 const Instance& owner_mirror) {
254 const MirrorReference& field_ref = 258 const MirrorReference& field_ref =
255 MirrorReference::Handle(MirrorReference::New(field)); 259 MirrorReference::Handle(MirrorReference::New(field));
256 260
257 const String& name = String::Handle(field.UserVisibleName()); 261 const String& name = String::Handle(field.name());
258 262
259 const Array& args = Array::Handle(Array::New(6)); 263 const Array& args = Array::Handle(Array::New(6));
260 args.SetAt(0, field_ref); 264 args.SetAt(0, field_ref);
261 args.SetAt(1, name); 265 args.SetAt(1, name);
262 args.SetAt(2, owner_mirror); 266 args.SetAt(2, owner_mirror);
263 args.SetAt(3, Object::null_instance()); // Null for type. 267 args.SetAt(3, Object::null_instance()); // Null for type.
264 args.SetAt(4, Bool::Get(field.is_static())); 268 args.SetAt(4, Bool::Get(field.is_static()));
265 args.SetAt(5, Bool::Get(field.is_final())); 269 args.SetAt(5, Bool::Get(field.is_final()));
266 270
267 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); 271 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0); 309 const Bool& is_generic = Bool::Get(cls.NumTypeParameters() != 0);
306 const Bool& is_mixin_typedef = Bool::Get(cls.is_mixin_typedef()); 310 const Bool& is_mixin_typedef = Bool::Get(cls.is_mixin_typedef());
307 311
308 const Array& args = Array::Handle(Array::New(6)); 312 const Array& args = Array::Handle(Array::New(6));
309 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls))); 313 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(cls)));
310 args.SetAt(1, type); 314 args.SetAt(1, type);
311 // We do not set the names of anonymous mixin applications because the mirrors 315 // We do not set the names of anonymous mixin applications because the mirrors
312 // use a different naming convention than the VM (lib.S with lib.M and S&M 316 // use a different naming convention than the VM (lib.S with lib.M and S&M
313 // respectively). 317 // respectively).
314 if (!cls.IsMixinApplication() || cls.is_mixin_typedef()) { 318 if (!cls.IsMixinApplication() || cls.is_mixin_typedef()) {
315 args.SetAt(2, String::Handle(cls.UserVisibleName())); 319 args.SetAt(2, String::Handle(cls.Name()));
316 } 320 }
317 args.SetAt(3, is_generic); 321 args.SetAt(3, is_generic);
318 args.SetAt(4, is_mixin_typedef); 322 args.SetAt(4, is_mixin_typedef);
319 args.SetAt(5, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration); 323 args.SetAt(5, cls.NumTypeParameters() == 0 ? Bool::False() : is_declaration);
320 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args); 324 return CreateMirror(Symbols::_LocalClassMirrorImpl(), args);
321 } 325 }
322 326
323 327
324 static RawInstance* CreateLibraryMirror(const Library& lib) { 328 static RawInstance* CreateLibraryMirror(const Library& lib) {
325 const Array& args = Array::Handle(Array::New(3)); 329 const Array& args = Array::Handle(Array::New(3));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 445
442 446
443 static RawInstance* InvokeLibraryGetter(const Library& library, 447 static RawInstance* InvokeLibraryGetter(const Library& library,
444 const String& getter_name, 448 const String& getter_name,
445 const bool throw_nsm_if_absent) { 449 const bool throw_nsm_if_absent) {
446 // To access a top-level we may need to use the Field or the getter Function. 450 // To access a top-level we may need to use the Field or the getter Function.
447 // The getter function may either be in the library or in the field's owner 451 // The getter function may either be in the library or in the field's owner
448 // class, depending on whether it was an actual getter, or an uninitialized 452 // class, depending on whether it was an actual getter, or an uninitialized
449 // field. 453 // field.
450 const Field& field = Field::Handle( 454 const Field& field = Field::Handle(
455 library.LookupLocalField(getter_name));
456 Function& getter = Function::Handle();
457 if (field.IsNull()) {
458 // No field found. Check for a getter in the lib.
459 const String& internal_getter_name =
460 String::Handle(Field::GetterName(getter_name));
461 getter = library.LookupLocalFunction(internal_getter_name);
462 if (getter.IsNull()) {
463 getter = library.LookupLocalFunction(getter_name);
464 if (!getter.IsNull()) {
465 // Looking for a getter but found a regular method: closurize it.
466 const Function& closure_function =
467 Function::Handle(getter.ImplicitClosureFunction());
468 return closure_function.ImplicitStaticClosure();
469 }
470 }
471 } else {
472 if (!field.IsUninitialized()) {
473 return field.value();
474 }
475 // An uninitialized field was found. Check for a getter in the field's
476 // owner classs.
477 const Class& klass = Class::Handle(field.owner());
478 const String& internal_getter_name =
479 String::Handle(Field::GetterName(getter_name));
480 getter = klass.LookupStaticFunction(internal_getter_name);
481 }
482
483 if (!getter.IsNull() && getter.is_visible()) {
484 // Invoke the getter and return the result.
485 const Object& result = Object::Handle(
486 DartEntry::InvokeFunction(getter, Object::empty_array()));
487 return ReturnResult(result);
488 }
489
490 if (throw_nsm_if_absent) {
491 ThrowNoSuchMethod(Instance::null_instance(),
492 getter_name,
493 getter,
494 InvocationMirror::kTopLevel,
495 InvocationMirror::kGetter);
496 UNREACHABLE();
497 }
498
499 // Fall through case: Indicate that we didn't find any function or field using
500 // a special null instance. This is different from a field being null. Callers
501 // make sure that this null does not leak into Dartland.
502 return Object::sentinel().raw();
503 }
504
505
506 // TODO(13656): Remove AllowPrivate.
507 static RawInstance* InvokeLibraryGetterAllowImports(
508 const Library& library,
509 const String& getter_name,
510 const bool throw_nsm_if_absent) {
511 // To access a top-level we may need to use the Field or the getter Function.
512 // The getter function may either be in the library or in the field's owner
513 // class, depending on whether it was an actual getter, or an uninitialized
514 // field.
515 const Field& field = Field::Handle(
451 library.LookupFieldAllowPrivate(getter_name)); 516 library.LookupFieldAllowPrivate(getter_name));
452 Function& getter = Function::Handle(); 517 Function& getter = Function::Handle();
453 if (field.IsNull()) { 518 if (field.IsNull()) {
454 // No field found. Check for a getter in the lib. 519 // No field found. Check for a getter in the lib.
455 const String& internal_getter_name = 520 const String& internal_getter_name =
456 String::Handle(Field::GetterName(getter_name)); 521 String::Handle(Field::GetterName(getter_name));
457 getter = library.LookupFunctionAllowPrivate(internal_getter_name); 522 getter = library.LookupFunctionAllowPrivate(internal_getter_name);
458 if (getter.IsNull()) { 523 if (getter.IsNull()) {
459 getter = library.LookupFunctionAllowPrivate(getter_name); 524 getter = library.LookupFunctionAllowPrivate(getter_name);
460 if (!getter.IsNull()) { 525 if (!getter.IsNull()) {
461 // Looking for a getter but found a regular method: closurize it. 526 // Looking for a getter but found a regular method: closurize it.
462 const Function& closure_function = 527 const Function& closure_function =
463 Function::Handle(getter.ImplicitClosureFunction()); 528 Function::Handle(getter.ImplicitClosureFunction());
464 return closure_function.ImplicitStaticClosure(); 529 return closure_function.ImplicitStaticClosure();
465 } 530 }
466 } 531 }
467 } else { 532 } else {
468 if (!field.IsUninitialized()) { 533 if (!field.IsUninitialized()) {
469 return field.value(); 534 return field.value();
470 } 535 }
471 // An uninitialized field was found. Check for a getter in the field's 536 // An uninitialized field was found. Check for a getter in the field's
472 // owner classs. 537 // owner classs.
473 const Class& klass = Class::Handle(field.owner()); 538 const Class& klass = Class::Handle(field.owner());
474 const String& internal_getter_name = 539 const String& internal_getter_name =
475 String::Handle(Field::GetterName(getter_name)); 540 String::Handle(Field::GetterName(getter_name));
476 getter = klass.LookupStaticFunctionAllowPrivate(internal_getter_name); 541 getter = klass.LookupStaticFunction(internal_getter_name);
477 } 542 }
478 543
479 if (!getter.IsNull() && getter.is_visible()) { 544 if (!getter.IsNull() && getter.is_visible()) {
480 // Invoke the getter and return the result. 545 // Invoke the getter and return the result.
481 const Object& result = Object::Handle( 546 const Object& result = Object::Handle(
482 DartEntry::InvokeFunction(getter, Object::empty_array())); 547 DartEntry::InvokeFunction(getter, Object::empty_array()));
483 return ReturnResult(result); 548 return ReturnResult(result);
484 } 549 }
485 550
486 if (throw_nsm_if_absent) { 551 if (throw_nsm_if_absent) {
(...skipping 14 matching lines...) Expand all
501 566
502 static RawInstance* InvokeClassGetter(const Class& klass, 567 static RawInstance* InvokeClassGetter(const Class& klass,
503 const String& getter_name, 568 const String& getter_name,
504 const bool throw_nsm_if_absent) { 569 const bool throw_nsm_if_absent) {
505 // Note static fields do not have implicit getters. 570 // Note static fields do not have implicit getters.
506 const Field& field = Field::Handle(klass.LookupStaticField(getter_name)); 571 const Field& field = Field::Handle(klass.LookupStaticField(getter_name));
507 if (field.IsNull() || field.IsUninitialized()) { 572 if (field.IsNull() || field.IsUninitialized()) {
508 const String& internal_getter_name = String::Handle( 573 const String& internal_getter_name = String::Handle(
509 Field::GetterName(getter_name)); 574 Field::GetterName(getter_name));
510 Function& getter = Function::Handle( 575 Function& getter = Function::Handle(
511 klass.LookupStaticFunctionAllowPrivate(internal_getter_name)); 576 klass.LookupStaticFunction(internal_getter_name));
512 577
513 if (getter.IsNull() || !getter.is_visible()) { 578 if (getter.IsNull() || !getter.is_visible()) {
514 if (getter.IsNull()) { 579 if (getter.IsNull()) {
515 getter = klass.LookupStaticFunctionAllowPrivate(getter_name); 580 getter = klass.LookupStaticFunction(getter_name);
516 if (!getter.IsNull()) { 581 if (!getter.IsNull()) {
517 // Looking for a getter but found a regular method: closurize it. 582 // Looking for a getter but found a regular method: closurize it.
518 const Function& closure_function = 583 const Function& closure_function =
519 Function::Handle(getter.ImplicitClosureFunction()); 584 Function::Handle(getter.ImplicitClosureFunction());
520 return closure_function.ImplicitStaticClosure(); 585 return closure_function.ImplicitStaticClosure();
521 } 586 }
522 } 587 }
523 if (throw_nsm_if_absent) { 588 if (throw_nsm_if_absent) {
524 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 589 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
525 getter_name, 590 getter_name,
(...skipping 19 matching lines...) Expand all
545 610
546 611
547 612
548 static RawInstance* InvokeInstanceGetter(const Class& klass, 613 static RawInstance* InvokeInstanceGetter(const Class& klass,
549 const Instance& reflectee, 614 const Instance& reflectee,
550 const String& getter_name, 615 const String& getter_name,
551 const bool throw_nsm_if_absent) { 616 const bool throw_nsm_if_absent) {
552 const String& internal_getter_name = String::Handle( 617 const String& internal_getter_name = String::Handle(
553 Field::GetterName(getter_name)); 618 Field::GetterName(getter_name));
554 Function& function = Function::Handle( 619 Function& function = Function::Handle(
555 Resolver::ResolveDynamicAnyArgsAllowPrivate(klass, internal_getter_name)); 620 Resolver::ResolveDynamicAnyArgs(klass, internal_getter_name));
556 621
557 if (!function.IsNull() || throw_nsm_if_absent) { 622 if (!function.IsNull() || throw_nsm_if_absent) {
558 const int kNumArgs = 1; 623 const int kNumArgs = 1;
559 const Array& args = Array::Handle(Array::New(kNumArgs)); 624 const Array& args = Array::Handle(Array::New(kNumArgs));
560 args.SetAt(0, reflectee); 625 args.SetAt(0, reflectee);
561 const Array& args_descriptor = 626 const Array& args_descriptor =
562 Array::Handle(ArgumentsDescriptor::New(args.Length())); 627 Array::Handle(ArgumentsDescriptor::New(args.Length()));
563 628
564 // InvokeDynamic invokes NoSuchMethod if the provided function is null. 629 // InvokeDynamic invokes NoSuchMethod if the provided function is null.
565 return InvokeDynamicFunction(reflectee, 630 return InvokeDynamicFunction(reflectee,
(...skipping 13 matching lines...) Expand all
579 static RawInstance* LookupFunctionOrFieldInLibraryPrefix( 644 static RawInstance* LookupFunctionOrFieldInLibraryPrefix(
580 const LibraryPrefix& prefix, 645 const LibraryPrefix& prefix,
581 const String& lookup_name) { 646 const String& lookup_name) {
582 const Object& entry = Object::Handle(prefix.LookupObject(lookup_name)); 647 const Object& entry = Object::Handle(prefix.LookupObject(lookup_name));
583 if (!entry.IsNull()) { 648 if (!entry.IsNull()) {
584 if (entry.IsField()) { 649 if (entry.IsField()) {
585 const Field& field = Field::Cast(entry); 650 const Field& field = Field::Cast(entry);
586 const Class& field_owner = Class::Handle(field.owner()); 651 const Class& field_owner = Class::Handle(field.owner());
587 const Library& field_library = Library::Handle(field_owner.library()); 652 const Library& field_library = Library::Handle(field_owner.library());
588 const Instance& result = Instance::Handle( 653 const Instance& result = Instance::Handle(
589 InvokeLibraryGetter(field_library, lookup_name, false)); 654 InvokeLibraryGetterAllowImports(field_library, lookup_name, false));
590 if (result.raw() != Object::sentinel().raw()) { 655 if (result.raw() != Object::sentinel().raw()) {
591 return result.raw(); 656 return result.raw();
592 } 657 }
593 } else if (entry.IsFunction()) { 658 } else if (entry.IsFunction()) {
594 const Function& func = Function::Cast(entry); 659 const Function& func = Function::Cast(entry);
595 const Function& closure_function = Function::Handle( 660 const Function& closure_function = Function::Handle(
596 func.ImplicitClosureFunction()); 661 func.ImplicitClosureFunction());
597 return closure_function.ImplicitStaticClosure(); 662 return closure_function.ImplicitStaticClosure();
598 } 663 }
599 } 664 }
(...skipping 10 matching lines...) Expand all
610 const String& lookup_name) { 675 const String& lookup_name) {
611 Instance& result = Instance::Handle( 676 Instance& result = Instance::Handle(
612 InvokeClassGetter(klass, lookup_name, false)); 677 InvokeClassGetter(klass, lookup_name, false));
613 if (result.raw() != Object::sentinel().raw()) { 678 if (result.raw() != Object::sentinel().raw()) {
614 return result.raw(); 679 return result.raw();
615 } 680 }
616 681
617 Function& func = Function::Handle(); 682 Function& func = Function::Handle();
618 Class& lookup_class = Class::Handle(klass.raw()); 683 Class& lookup_class = Class::Handle(klass.raw());
619 while (func.IsNull() && !lookup_class.IsNull()) { 684 while (func.IsNull() && !lookup_class.IsNull()) {
620 func ^= lookup_class.LookupStaticFunctionAllowPrivate(lookup_name); 685 func ^= lookup_class.LookupStaticFunction(lookup_name);
621 lookup_class = lookup_class.SuperClass(); 686 lookup_class = lookup_class.SuperClass();
622 } 687 }
623 if (!func.IsNull()) { 688 if (!func.IsNull()) {
624 const Function& closure_function = Function::Handle( 689 const Function& closure_function = Function::Handle(
625 func.ImplicitClosureFunction()); 690 func.ImplicitClosureFunction());
626 ASSERT(!closure_function.IsNull()); 691 ASSERT(!closure_function.IsNull());
627 return closure_function.ImplicitStaticClosure(); 692 return closure_function.ImplicitStaticClosure();
628 } 693 }
629 694
630 // Fall through case: Indicate that we didn't find any function or field using 695 // Fall through case: Indicate that we didn't find any function or field using
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 return Object::sentinel().raw(); 736 return Object::sentinel().raw();
672 } 737 }
673 738
674 739
675 static RawInstance* LookupFunctionOrFieldInLibraryHelper( 740 static RawInstance* LookupFunctionOrFieldInLibraryHelper(
676 const Library& library, 741 const Library& library,
677 const String& class_name, 742 const String& class_name,
678 const String& lookup_name) { 743 const String& lookup_name) {
679 if (class_name.IsNull()) { 744 if (class_name.IsNull()) {
680 const Instance& result = Instance::Handle( 745 const Instance& result = Instance::Handle(
681 InvokeLibraryGetter(library, lookup_name, false)); 746 InvokeLibraryGetterAllowImports(library, lookup_name, false));
682 if (result.raw() != Object::sentinel().raw()) { 747 if (result.raw() != Object::sentinel().raw()) {
683 return result.raw(); 748 return result.raw();
684 } 749 }
685 const Function& func = Function::Handle( 750 const Function& func = Function::Handle(
686 library.LookupFunctionAllowPrivate(lookup_name)); 751 library.LookupLocalFunction(lookup_name));
687 if (!func.IsNull()) { 752 if (!func.IsNull()) {
688 const Function& closure_function = Function::Handle( 753 const Function& closure_function = Function::Handle(
689 func.ImplicitClosureFunction()); 754 func.ImplicitClosureFunction());
690 return closure_function.ImplicitStaticClosure(); 755 return closure_function.ImplicitStaticClosure();
691 } 756 }
692 } else { 757 } else {
693 const Class& cls = Class::Handle( 758 const Class& cls = Class::Handle(
694 library.LookupClassAllowPrivate(class_name)); 759 library.LookupClass(class_name));
695 if (!cls.IsNull()) { 760 if (!cls.IsNull()) {
696 return LookupStaticFunctionOrFieldInClass(cls, lookup_name); 761 return LookupStaticFunctionOrFieldInClass(cls, lookup_name);
697 } 762 }
698 } 763 }
699 764
700 // Fall through case: Indicate that we didn't find any function or field using 765 // Fall through case: Indicate that we didn't find any function or field using
701 // a special null instance. This is different from a field being null. Callers 766 // a special null instance. This is different from a field being null. Callers
702 // make sure that this null does not leak into Dartland. 767 // make sure that this null does not leak into Dartland.
703 return Object::sentinel().raw(); 768 return Object::sentinel().raw();
704 } 769 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 Bool::True(), // is_declaration 818 Bool::True(), // is_declaration
754 Object::null_instance()); 819 Object::null_instance());
755 } 820 }
756 821
757 822
758 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) { 823 DEFINE_NATIVE_ENTRY(Mirrors_makeLocalTypeMirror, 1) {
759 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0)); 824 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, type, arguments->NativeArgAt(0));
760 return CreateTypeMirror(type); 825 return CreateTypeMirror(type);
761 } 826 }
762 827
828 DEFINE_NATIVE_ENTRY(Mirrors_mangleName, 2) {
829 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0));
830 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
831 const Library& lib = Library::Handle(ref.GetLibraryReferent());
832 return lib.IsPrivate(name) ? lib.PrivateName(name) : name.raw();
833 }
834
835 DEFINE_NATIVE_ENTRY(Mirrors_unmangleName, 1) {
836 GET_NON_NULL_NATIVE_ARGUMENT(String, name, arguments->NativeArgAt(0));
837 // It would be nice to unconditionally use IdentifierPrettyName, alas it
838 // cannot cope with the symbols for the names of anonymous mixin applications.
839 if (Library::IsPrivate(name) ||
840 Field::IsGetterName(name) ||
841 Field::IsSetterName(name)) {
842 return String::IdentifierPrettyName(name);
843 }
844 return name.raw();
845 }
846
763 847
764 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) { 848 DEFINE_NATIVE_ENTRY(MirrorReference_equals, 2) {
765 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0)); 849 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, a, arguments->NativeArgAt(0));
766 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1)); 850 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, b, arguments->NativeArgAt(1));
767 return Bool::Get(a.referent() == b.referent()).raw(); 851 return Bool::Get(a.referent() == b.referent()).raw();
768 } 852 }
769 853
770 854
771 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { 855 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) {
772 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0)); 856 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0));
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 // because this native is an instance method in order to be polymorphic 1167 // because this native is an instance method in order to be polymorphic
1084 // with its cousins. 1168 // with its cousins.
1085 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1)); 1169 GET_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(1));
1086 GET_NON_NULL_NATIVE_ARGUMENT( 1170 GET_NON_NULL_NATIVE_ARGUMENT(
1087 String, function_name, arguments->NativeArgAt(2)); 1171 String, function_name, arguments->NativeArgAt(2));
1088 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); 1172 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3));
1089 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); 1173 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
1090 1174
1091 Class& klass = Class::Handle(reflectee.clazz()); 1175 Class& klass = Class::Handle(reflectee.clazz());
1092 Function& function = Function::Handle( 1176 Function& function = Function::Handle(
1093 Resolver::ResolveDynamicAnyArgsAllowPrivate(klass, function_name)); 1177 Resolver::ResolveDynamicAnyArgs(klass, function_name));
1094 1178
1095 const Array& args_descriptor = 1179 const Array& args_descriptor =
1096 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); 1180 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names));
1097 1181
1098 return InvokeDynamicFunction(reflectee, 1182 return InvokeDynamicFunction(reflectee,
1099 function, 1183 function,
1100 function_name, 1184 function_name,
1101 args, 1185 args,
1102 args_descriptor); 1186 args_descriptor);
1103 } 1187 }
(...skipping 28 matching lines...) Expand all
1132 while (!klass.IsNull()) { 1216 while (!klass.IsNull()) {
1133 field = klass.LookupInstanceField(setter_name); 1217 field = klass.LookupInstanceField(setter_name);
1134 if (!field.IsNull() && field.is_final()) { 1218 if (!field.IsNull() && field.is_final()) {
1135 const String& message = String::Handle( 1219 const String& message = String::Handle(
1136 String::NewFormatted("%s: cannot set final field '%s'.", 1220 String::NewFormatted("%s: cannot set final field '%s'.",
1137 "InstanceMirror_invokeSetter", 1221 "InstanceMirror_invokeSetter",
1138 setter_name.ToCString())); 1222 setter_name.ToCString()));
1139 ThrowMirroredCompilationError(message); 1223 ThrowMirroredCompilationError(message);
1140 UNREACHABLE(); 1224 UNREACHABLE();
1141 } 1225 }
1142 setter = klass.LookupDynamicFunctionAllowPrivate(internal_setter_name); 1226 setter = klass.LookupDynamicFunction(internal_setter_name);
1143 if (!setter.IsNull()) { 1227 if (!setter.IsNull()) {
1144 break; 1228 break;
1145 } 1229 }
1146 klass = klass.SuperClass(); 1230 klass = klass.SuperClass();
1147 } 1231 }
1148 1232
1149 // Invoke the setter and return the result. 1233 // Invoke the setter and return the result.
1150 const int kNumArgs = 2; 1234 const int kNumArgs = 2;
1151 const Array& args = Array::Handle(Array::New(kNumArgs)); 1235 const Array& args = Array::Handle(Array::New(kNumArgs));
1152 args.SetAt(0, reflectee); 1236 args.SetAt(0, reflectee);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 const Class& klass = Class::Handle(ref.GetClassReferent()); 1359 const Class& klass = Class::Handle(ref.GetClassReferent());
1276 GET_NON_NULL_NATIVE_ARGUMENT( 1360 GET_NON_NULL_NATIVE_ARGUMENT(
1277 String, function_name, arguments->NativeArgAt(2)); 1361 String, function_name, arguments->NativeArgAt(2));
1278 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); 1362 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3));
1279 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); 1363 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
1280 1364
1281 const Array& args_descriptor_array = 1365 const Array& args_descriptor_array =
1282 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); 1366 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names));
1283 1367
1284 const Function& function = Function::Handle( 1368 const Function& function = Function::Handle(
1285 klass.LookupStaticFunctionAllowPrivate(function_name)); 1369 klass.LookupStaticFunction(function_name));
1286
1287 1370
1288 ArgumentsDescriptor args_descriptor(args_descriptor_array); 1371 ArgumentsDescriptor args_descriptor(args_descriptor_array);
1289 if (function.IsNull() || 1372 if (function.IsNull() ||
1290 !function.AreValidArguments(args_descriptor, NULL) || 1373 !function.AreValidArguments(args_descriptor, NULL) ||
1291 !function.is_visible()) { 1374 !function.is_visible()) {
1292 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 1375 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
1293 function_name, 1376 function_name,
1294 function, 1377 function,
1295 InvocationMirror::kStatic, 1378 InvocationMirror::kStatic,
1296 InvocationMirror::kMethod); 1379 InvocationMirror::kMethod);
(...skipping 29 matching lines...) Expand all
1326 const Class& klass = Class::Handle(ref.GetClassReferent()); 1409 const Class& klass = Class::Handle(ref.GetClassReferent());
1327 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); 1410 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2));
1328 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); 1411 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3));
1329 1412
1330 // Check for real fields and user-defined setters. 1413 // Check for real fields and user-defined setters.
1331 const Field& field = Field::Handle(klass.LookupStaticField(setter_name)); 1414 const Field& field = Field::Handle(klass.LookupStaticField(setter_name));
1332 if (field.IsNull()) { 1415 if (field.IsNull()) {
1333 const String& internal_setter_name = String::Handle( 1416 const String& internal_setter_name = String::Handle(
1334 Field::SetterName(setter_name)); 1417 Field::SetterName(setter_name));
1335 const Function& setter = Function::Handle( 1418 const Function& setter = Function::Handle(
1336 klass.LookupStaticFunctionAllowPrivate(internal_setter_name)); 1419 klass.LookupStaticFunction(internal_setter_name));
1337 1420
1338 if (setter.IsNull() || !setter.is_visible()) { 1421 if (setter.IsNull() || !setter.is_visible()) {
1339 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 1422 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
1340 setter_name, 1423 setter_name,
1341 setter, 1424 setter,
1342 InvocationMirror::kStatic, 1425 InvocationMirror::kStatic,
1343 InvocationMirror::kSetter); 1426 InvocationMirror::kSetter);
1344 UNREACHABLE(); 1427 UNREACHABLE();
1345 } 1428 }
1346 1429
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 // This convention prevents users from explicitly calling constructors. 1470 // This convention prevents users from explicitly calling constructors.
1388 const String& klass_name = String::Handle(klass.Name()); 1471 const String& klass_name = String::Handle(klass.Name());
1389 String& internal_constructor_name = 1472 String& internal_constructor_name =
1390 String::Handle(String::Concat(klass_name, Symbols::Dot())); 1473 String::Handle(String::Concat(klass_name, Symbols::Dot()));
1391 if (!constructor_name.IsNull()) { 1474 if (!constructor_name.IsNull()) {
1392 internal_constructor_name = 1475 internal_constructor_name =
1393 String::Concat(internal_constructor_name, constructor_name); 1476 String::Concat(internal_constructor_name, constructor_name);
1394 } 1477 }
1395 1478
1396 Function& lookup_constructor = Function::Handle( 1479 Function& lookup_constructor = Function::Handle(
1397 klass.LookupFunctionAllowPrivate(internal_constructor_name)); 1480 klass.LookupFunction(internal_constructor_name));
1398 1481
1399 if (lookup_constructor.IsNull() || 1482 if (lookup_constructor.IsNull() ||
1400 !(lookup_constructor.IsConstructor() || lookup_constructor.IsFactory()) || 1483 !(lookup_constructor.IsConstructor() || lookup_constructor.IsFactory()) ||
1401 !lookup_constructor.is_visible()) { 1484 !lookup_constructor.is_visible()) {
1402 // Pretend we didn't find the constructor at all when the arity is wrong 1485 // Pretend we didn't find the constructor at all when the arity is wrong
1403 // so as to produce the same NoSuchMethodError as the non-reflective case. 1486 // so as to produce the same NoSuchMethodError as the non-reflective case.
1404 lookup_constructor = Function::null(); 1487 lookup_constructor = Function::null();
1405 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()), 1488 ThrowNoSuchMethod(AbstractType::Handle(klass.RareType()),
1406 internal_constructor_name, 1489 internal_constructor_name,
1407 lookup_constructor, 1490 lookup_constructor,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 const Library& library = Library::Handle(ref.GetLibraryReferent()); 1586 const Library& library = Library::Handle(ref.GetLibraryReferent());
1504 GET_NON_NULL_NATIVE_ARGUMENT( 1587 GET_NON_NULL_NATIVE_ARGUMENT(
1505 String, function_name, arguments->NativeArgAt(2)); 1588 String, function_name, arguments->NativeArgAt(2));
1506 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3)); 1589 GET_NON_NULL_NATIVE_ARGUMENT(Array, args, arguments->NativeArgAt(3));
1507 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4)); 1590 GET_NON_NULL_NATIVE_ARGUMENT(Array, arg_names, arguments->NativeArgAt(4));
1508 1591
1509 const Array& args_descriptor_array = 1592 const Array& args_descriptor_array =
1510 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names)); 1593 Array::Handle(ArgumentsDescriptor::New(args.Length(), arg_names));
1511 1594
1512 const Function& function = Function::Handle( 1595 const Function& function = Function::Handle(
1513 library.LookupFunctionAllowPrivate(function_name)); 1596 library.LookupLocalFunction(function_name));
1514 1597
1515 ArgumentsDescriptor args_descriptor(args_descriptor_array); 1598 ArgumentsDescriptor args_descriptor(args_descriptor_array);
1516 if (function.IsNull() || 1599 if (function.IsNull() ||
1517 !function.AreValidArguments(args_descriptor, NULL) || 1600 !function.AreValidArguments(args_descriptor, NULL) ||
1518 !function.is_visible()) { 1601 !function.is_visible()) {
1519 ThrowNoSuchMethod(Instance::null_instance(), 1602 ThrowNoSuchMethod(Instance::null_instance(),
1520 function_name, 1603 function_name,
1521 function, 1604 function,
1522 InvocationMirror::kTopLevel, 1605 InvocationMirror::kTopLevel,
1523 InvocationMirror::kMethod); 1606 InvocationMirror::kMethod);
(...skipping 27 matching lines...) Expand all
1551 // with its cousins. 1634 // with its cousins.
1552 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1)); 1635 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
1553 const Library& library = Library::Handle(ref.GetLibraryReferent()); 1636 const Library& library = Library::Handle(ref.GetLibraryReferent());
1554 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2)); 1637 GET_NON_NULL_NATIVE_ARGUMENT(String, setter_name, arguments->NativeArgAt(2));
1555 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3)); 1638 GET_NATIVE_ARGUMENT(Instance, value, arguments->NativeArgAt(3));
1556 1639
1557 // To access a top-level we may need to use the Field or the 1640 // To access a top-level we may need to use the Field or the
1558 // setter Function. The setter function may either be in the 1641 // setter Function. The setter function may either be in the
1559 // library or in the field's owner class, depending. 1642 // library or in the field's owner class, depending.
1560 const Field& field = Field::Handle( 1643 const Field& field = Field::Handle(
1561 library.LookupFieldAllowPrivate(setter_name)); 1644 library.LookupLocalField(setter_name));
1562 1645
1563 if (field.IsNull()) { 1646 if (field.IsNull()) {
1564 const String& internal_setter_name = 1647 const String& internal_setter_name =
1565 String::Handle(Field::SetterName(setter_name)); 1648 String::Handle(Field::SetterName(setter_name));
1566 const Function& setter = Function::Handle( 1649 const Function& setter = Function::Handle(
1567 library.LookupFunctionAllowPrivate(internal_setter_name)); 1650 library.LookupLocalFunction(internal_setter_name));
1568 if (setter.IsNull() || !setter.is_visible()) { 1651 if (setter.IsNull() || !setter.is_visible()) {
1569 ThrowNoSuchMethod(Instance::null_instance(), 1652 ThrowNoSuchMethod(Instance::null_instance(),
1570 setter_name, 1653 setter_name,
1571 setter, 1654 setter,
1572 InvocationMirror::kTopLevel, 1655 InvocationMirror::kTopLevel,
1573 InvocationMirror::kSetter); 1656 InvocationMirror::kSetter);
1574 UNREACHABLE(); 1657 UNREACHABLE();
1575 } 1658 }
1576 1659
1577 // Invoke the setter and return the result. 1660 // Invoke the setter and return the result.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 } 1764 }
1682 1765
1683 1766
1684 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { 1767 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1685 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1768 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1686 const Field& field = Field::Handle(ref.GetFieldReferent()); 1769 const Field& field = Field::Handle(ref.GetFieldReferent());
1687 return field.type(); 1770 return field.type();
1688 } 1771 }
1689 1772
1690 } // namespace dart 1773 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698