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

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.
rmacnak 2013/07/20 00:46:52 We still pass this argument because ParameterMirro
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
623 static Dart_Handle CreateVariableMirrorUsingApi(Dart_Handle var,
624 Dart_Handle var_name,
625 Dart_Handle owner_mirror) {
626 ASSERT(Dart_IsVariable(var));
627 Isolate* isolate = Isolate::Current();
628 const Field& field = Api::UnwrapFieldHandle(isolate, var);
629 const Instance& owner_mirror_inst =
630 Api::UnwrapInstanceHandle(isolate, owner_mirror);
631 const Instance& var_mirror =
632 Instance::Handle(CreateVariableMirror(field, owner_mirror_inst));
633 return Api::NewHandle(isolate, var_mirror.raw());
634 }
635
636
644 static Dart_Handle AddMemberClasses(Dart_Handle map, 637 static Dart_Handle AddMemberClasses(Dart_Handle map,
645 Dart_Handle owner, 638 Dart_Handle owner,
646 Dart_Handle owner_mirror) { 639 Dart_Handle owner_mirror) {
647 ASSERT(Dart_IsLibrary(owner)); 640 ASSERT(Dart_IsLibrary(owner));
648 Dart_Handle result; 641 Dart_Handle result;
649 Dart_Handle names = Dart_LibraryGetClassNames(owner); 642 Dart_Handle names = Dart_LibraryGetClassNames(owner);
650 if (Dart_IsError(names)) { 643 if (Dart_IsError(names)) {
651 return names; 644 return names;
652 } 645 }
653 intptr_t len; 646 intptr_t len;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 if (Dart_IsError(result)) { 769 if (Dart_IsError(result)) {
777 return result; 770 return result;
778 } 771 }
779 for (intptr_t i = 0; i < len; i++) { 772 for (intptr_t i = 0; i < len; i++) {
780 Dart_Handle var_name = Dart_ListGetAt(names, i); 773 Dart_Handle var_name = Dart_ListGetAt(names, i);
781 Dart_Handle var = Dart_LookupVariable(owner, var_name); 774 Dart_Handle var = Dart_LookupVariable(owner, var_name);
782 if (Dart_IsError(var)) { 775 if (Dart_IsError(var)) {
783 return var; 776 return var;
784 } 777 }
785 ASSERT(!Dart_IsNull(var)); 778 ASSERT(!Dart_IsNull(var));
786 Dart_Handle var_mirror = CreateVariableMirror(var, var_name, owner_mirror); 779 Dart_Handle var_mirror = CreateVariableMirrorUsingApi(var,
780 var_name,
781 owner_mirror);
siva 2013/07/22 05:25:32 Looks like this is the only caller for CreateVaria
rmacnak 2013/07/22 19:05:09 I don't. Inlined.
787 if (Dart_IsError(var_mirror)) { 782 if (Dart_IsError(var_mirror)) {
788 return var_mirror; 783 return var_mirror;
789 } 784 }
790 result = MapAdd(map, var_name, var_mirror); 785 result = MapAdd(map, var_name, var_mirror);
791 if (Dart_IsError(result)) { 786 if (Dart_IsError(result)) {
792 return result; 787 return result;
793 } 788 }
794 } 789 }
795 return Dart_True(); 790 return Dart_True();
796 } 791 }
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 1906
1912 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { 1907 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) {
1913 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1908 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1914 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1909 const Function& func = Function::Handle(ref.GetFunctionReferent());
1915 // We handle constructors in Dart code. 1910 // We handle constructors in Dart code.
1916 ASSERT(!func.IsConstructor()); 1911 ASSERT(!func.IsConstructor());
1917 const AbstractType& return_type = AbstractType::Handle(func.result_type()); 1912 const AbstractType& return_type = AbstractType::Handle(func.result_type());
1918 return CreateTypeMirror(return_type); 1913 return CreateTypeMirror(return_type);
1919 } 1914 }
1920 1915
1916
1917 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) {
1918 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1919 const Field& field = Field::Handle(ref.GetFieldReferent());
1920
1921 const AbstractType& type = AbstractType::Handle(field.type());
1922 return CreateTypeMirror(type);
1923 }
1924
1921 } // namespace dart 1925 } // 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