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 "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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
559 | 559 |
560 static Dart_Handle CreateMethodMirror(Dart_Handle func, | 560 static Dart_Handle CreateMethodMirror(Dart_Handle func, |
561 Dart_Handle owner_mirror) { | 561 Dart_Handle owner_mirror) { |
562 ASSERT(Dart_IsFunction(func)); | 562 ASSERT(Dart_IsFunction(func)); |
563 Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl"); | 563 Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl"); |
564 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); | 564 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); |
565 if (Dart_IsError(mirror_type)) { | 565 if (Dart_IsError(mirror_type)) { |
566 return mirror_type; | 566 return mirror_type; |
567 } | 567 } |
568 | 568 |
569 bool is_static = false; | |
570 bool is_abstract = false; | |
571 bool is_getter = false; | |
572 bool is_setter = false; | |
573 bool is_constructor = false; | |
574 | |
575 Dart_Handle result = Dart_FunctionIsStatic(func, &is_static); | |
576 if (Dart_IsError(result)) { | |
577 return result; | |
578 } | |
579 result = Dart_FunctionIsAbstract(func, &is_abstract); | |
580 if (Dart_IsError(result)) { | |
581 return result; | |
582 } | |
583 result = Dart_FunctionIsGetter(func, &is_getter); | |
584 if (Dart_IsError(result)) { | |
585 return result; | |
586 } | |
587 result = Dart_FunctionIsSetter(func, &is_setter); | |
588 if (Dart_IsError(result)) { | |
589 return result; | |
590 } | |
591 result = Dart_FunctionIsConstructor(func, &is_constructor); | |
592 if (Dart_IsError(result)) { | |
593 return result; | |
594 } | |
595 | |
596 Dart_Handle return_type = Dart_FunctionReturnType(func); | 569 Dart_Handle return_type = Dart_FunctionReturnType(func); |
597 if (Dart_IsError(return_type)) { | 570 if (Dart_IsError(return_type)) { |
598 return return_type; | 571 return return_type; |
599 } | 572 } |
600 | 573 |
601 int64_t fixed_param_count; | |
602 int64_t opt_param_count; | |
603 result = Dart_FunctionParameterCounts(func, | |
604 &fixed_param_count, | |
605 &opt_param_count); | |
606 if (Dart_IsError(result)) { | |
607 return result; | |
608 } | |
609 | |
610 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). | |
611 Dart_Handle args[] = { | 574 Dart_Handle args[] = { |
612 CreateMirrorReference(func), | 575 CreateMirrorReference(func), |
613 owner_mirror, | 576 owner_mirror, |
614 CreateParameterMirrorList(func), | 577 CreateParameterMirrorList(func), |
615 CreateLazyMirror(return_type), | 578 CreateLazyMirror(return_type), |
616 Dart_NewBoolean(is_static), | |
617 Dart_NewBoolean(is_abstract), | |
618 Dart_NewBoolean(is_getter), | |
619 Dart_NewBoolean(is_setter), | |
620 Dart_NewBoolean(is_constructor), | |
621 Dart_False(), | |
622 Dart_False(), | |
623 Dart_False(), | |
624 Dart_False(), | |
625 }; | 579 }; |
626 Dart_Handle mirror = | 580 Dart_Handle mirror = |
627 Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args); | 581 Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args); |
628 return mirror; | 582 return mirror; |
629 } | 583 } |
630 | 584 |
631 | 585 |
632 static Dart_Handle CreateVariableMirror(Dart_Handle var, | 586 static Dart_Handle CreateVariableMirror(Dart_Handle var, |
633 Dart_Handle var_name, | 587 Dart_Handle var_name, |
634 Dart_Handle lib_mirror) { | 588 Dart_Handle lib_mirror) { |
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1807 "LibraryMirror_invokeSetter", | 1761 "LibraryMirror_invokeSetter", |
1808 setter_name.ToCString())); | 1762 setter_name.ToCString())); |
1809 ThrowMirroredCompilationError(message); | 1763 ThrowMirroredCompilationError(message); |
1810 UNREACHABLE(); | 1764 UNREACHABLE(); |
1811 } | 1765 } |
1812 | 1766 |
1813 field.set_value(value); | 1767 field.set_value(value); |
1814 return value.raw(); | 1768 return value.raw(); |
1815 } | 1769 } |
1816 | 1770 |
1817 | |
1818 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { | 1771 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { |
1819 const MirrorReference& func_ref = | 1772 const MirrorReference& func_ref = |
1820 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 1773 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); |
1821 Function& func = Function::Handle(); | 1774 Function& func = Function::Handle(); |
1822 func ^= func_ref.referent(); | 1775 func ^= func_ref.referent(); |
1823 return func.UserVisibleName(); | 1776 return func.UserVisibleName(); |
1824 } | 1777 } |
1825 | 1778 |
1779 // Keep in sync with _propertyIsXXX in mirrors_impl.dart. | |
1780 enum MethodMirrorProperty { | |
1781 isStatic = 0, | |
rmacnak
2013/07/16 20:44:53
VM code tends to prefix constants like these with
Michael Lippautz (Google)
2013/07/16 21:14:00
Done.
| |
1782 isAbstract, | |
1783 isGetter, | |
1784 isSetter, | |
1785 isConstructor, | |
1786 }; | |
1787 | |
1788 DEFINE_NATIVE_ENTRY(MethodMirror_get_property, 2) { | |
1789 const MirrorReference& func_ref = | |
1790 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | |
1791 const Smi& property = | |
1792 Smi::CheckedHandle(arguments->NativeArgAt(1)); | |
1793 Function& func = Function::Handle(); | |
1794 func ^= func_ref.referent(); | |
1795 switch (property.Value()) { | |
1796 case isStatic: | |
1797 return Bool::Get(func.is_static()); | |
1798 case isAbstract: | |
1799 return Bool::Get(func.is_abstract()); | |
1800 case isGetter: | |
1801 return Bool::Get(func.IsGetterFunction()); | |
1802 case isSetter: | |
1803 return Bool::Get(func.IsSetterFunction()); | |
1804 case isConstructor: | |
1805 return Bool::Get(func.IsConstructor()); | |
1806 default: | |
1807 UNREACHABLE(); | |
1808 } | |
1809 UNREACHABLE(); | |
1810 return NULL; | |
rmacnak
2013/07/16 20:44:53
Instance::null()
Michael Lippautz (Google)
2013/07/16 21:14:00
Done.
| |
1811 } | |
1812 | |
1826 } // namespace dart | 1813 } // namespace dart |
OLD | NEW |