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

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

Issue 19512003: Implement VariableMirror creation with non-API code. To break circular initialization, have them fi… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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/lib/mirrors_impl.dart » ('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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_debugger_api.h" 6 #include "include/dart_debugger_api.h"
7 #include "include/dart_mirrors_api.h" 7 #include "include/dart_mirrors_api.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" // TODO(11742): Remove with CreateMirrorRef. 9 #include "vm/dart_api_state.h" // TODO(11742): Remove with CreateMirrorRef.
10 #include "vm/bootstrap_natives.h" 10 #include "vm/bootstrap_natives.h"
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 Api::False(), 593 Api::False(),
594 Api::False(), 594 Api::False(),
595 Api::False(), 595 Api::False(),
596 Api::False() 596 Api::False()
597 }; 597 };
598 Dart_Handle mirror = 598 Dart_Handle mirror =
599 Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args); 599 Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args);
600 return mirror; 600 return mirror;
601 } 601 }
602 602
603 static RawInstance* CreateVariableMirror(const Field& field,
604 const Instance& owner_mirror) {
605 const MirrorReference& field_ref =
606 MirrorReference::Handle(MirrorReference::New());
607 field_ref.set_referent(field);
603 608
604 static Dart_Handle CreateVariableMirror(Dart_Handle var, 609 const String& name = String::Handle(field.UserVisibleName());
605 Dart_Handle var_name,
606 Dart_Handle owner_mirror) {
607 ASSERT(Dart_IsVariable(var));
608 Dart_Handle cls_name = NewString("_LocalVariableMirrorImpl");
609 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL);
610 if (Dart_IsError(type)) {
611 return type;
612 }
613 610
614 bool is_static = false; 611 const Array& args = Array::Handle(Array::New(6));
615 bool is_final = false; 612 args.SetAt(0, field_ref);
613 args.SetAt(1, name);
614 args.SetAt(2, owner_mirror);
615 args.SetAt(3, Instance::Handle()); // Null for type.
616 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False());
617 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False());
616 618
617 Dart_Handle result = Dart_VariableIsStatic(var, &is_static); 619 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args);
618 if (Dart_IsError(result)) {
619 return result;
620 }
621 result = Dart_VariableIsFinal(var, &is_final);
622 if (Dart_IsError(result)) {
623 return result;
624 }
625
626 Dart_Handle var_type = Dart_VariableType(var);
627 if (Dart_IsError(var_type)) {
628 return var_type;
629 }
630
631 Dart_Handle args[] = {
632 CreateMirrorReference(var),
633 var_name,
634 owner_mirror,
635 CreateLazyMirror(var_type),
636 Dart_NewBoolean(is_static),
637 Dart_NewBoolean(is_final),
638 };
639 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args);
640 return mirror;
641 } 620 }
642 621
643 622
644 static Dart_Handle AddMemberClasses(Dart_Handle map, 623 static Dart_Handle AddMemberClasses(Dart_Handle map,
645 Dart_Handle owner, 624 Dart_Handle owner,
646 Dart_Handle owner_mirror) { 625 Dart_Handle owner_mirror) {
647 ASSERT(Dart_IsLibrary(owner)); 626 ASSERT(Dart_IsLibrary(owner));
648 Dart_Handle result; 627 Dart_Handle result;
649 Dart_Handle names = Dart_LibraryGetClassNames(owner); 628 Dart_Handle names = Dart_LibraryGetClassNames(owner);
650 if (Dart_IsError(names)) { 629 if (Dart_IsError(names)) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 return result; 738 return result;
760 } 739 }
761 } 740 }
762 return Dart_True(); 741 return Dart_True();
763 } 742 }
764 743
765 744
766 static Dart_Handle AddMemberVariables(Dart_Handle map, 745 static Dart_Handle AddMemberVariables(Dart_Handle map,
767 Dart_Handle owner, 746 Dart_Handle owner,
768 Dart_Handle owner_mirror) { 747 Dart_Handle owner_mirror) {
748 Isolate* isolate = Isolate::Current();
769 Dart_Handle result; 749 Dart_Handle result;
770 Dart_Handle names = Dart_GetVariableNames(owner); 750 Dart_Handle names = Dart_GetVariableNames(owner);
771 if (Dart_IsError(names)) { 751 if (Dart_IsError(names)) {
772 return names; 752 return names;
773 } 753 }
774 intptr_t len; 754 intptr_t len;
775 result = Dart_ListLength(names, &len); 755 result = Dart_ListLength(names, &len);
776 if (Dart_IsError(result)) { 756 if (Dart_IsError(result)) {
777 return result; 757 return result;
778 } 758 }
779 for (intptr_t i = 0; i < len; i++) { 759 for (intptr_t i = 0; i < len; i++) {
780 Dart_Handle var_name = Dart_ListGetAt(names, i); 760 Dart_Handle var_name = Dart_ListGetAt(names, i);
781 Dart_Handle var = Dart_LookupVariable(owner, var_name); 761 Dart_Handle var = Dart_LookupVariable(owner, var_name);
782 if (Dart_IsError(var)) { 762 if (Dart_IsError(var)) {
783 return var; 763 return var;
784 } 764 }
785 ASSERT(!Dart_IsNull(var)); 765 ASSERT(!Dart_IsNull(var));
786 Dart_Handle var_mirror = CreateVariableMirror(var, var_name, owner_mirror); 766 ASSERT(Dart_IsVariable(var));
787 if (Dart_IsError(var_mirror)) { 767 const Field& field = Api::UnwrapFieldHandle(isolate, var);
788 return var_mirror; 768 const Instance& owner_mirror_inst =
789 } 769 Api::UnwrapInstanceHandle(isolate, owner_mirror);
770 const Instance& var_mirror_inst =
771 Instance::Handle(CreateVariableMirror(field, owner_mirror_inst));
772 Dart_Handle var_mirror = Api::NewHandle(isolate, var_mirror_inst.raw());
773
790 result = MapAdd(map, var_name, var_mirror); 774 result = MapAdd(map, var_name, var_mirror);
791 if (Dart_IsError(result)) { 775 if (Dart_IsError(result)) {
792 return result; 776 return result;
793 } 777 }
794 } 778 }
795 return Dart_True(); 779 return Dart_True();
796 } 780 }
797 781
798 782
799 static Dart_Handle CreateMemberMap(Dart_Handle owner, 783 static Dart_Handle CreateMemberMap(Dart_Handle owner,
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 1840
1857 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { 1841 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) {
1858 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1842 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1859 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1843 const Function& func = Function::Handle(ref.GetFunctionReferent());
1860 // We handle constructors in Dart code. 1844 // We handle constructors in Dart code.
1861 ASSERT(!func.IsConstructor()); 1845 ASSERT(!func.IsConstructor());
1862 const AbstractType& return_type = AbstractType::Handle(func.result_type()); 1846 const AbstractType& return_type = AbstractType::Handle(func.result_type());
1863 return CreateTypeMirror(return_type); 1847 return CreateTypeMirror(return_type);
1864 } 1848 }
1865 1849
1850
1851 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1852 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1853 const Field& field = Field::Handle(ref.GetFieldReferent());
1854
1855 const AbstractType& type = AbstractType::Handle(field.type());
1856 return CreateTypeMirror(type);
1857 }
1858
1866 } // namespace dart 1859 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/lib/mirrors_impl.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698