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

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

Issue 19662003: Refactor resolution code in the vm to properly handle ambiguity errors. (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
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 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 library ^= library_ref.referent(); 1721 library ^= library_ref.referent();
1722 1722
1723 const String& function_name = 1723 const String& function_name =
1724 String::CheckedHandle(arguments->NativeArgAt(2)); 1724 String::CheckedHandle(arguments->NativeArgAt(2));
1725 1725
1726 const Array& positional_args = 1726 const Array& positional_args =
1727 Array::CheckedHandle(arguments->NativeArgAt(3)); 1727 Array::CheckedHandle(arguments->NativeArgAt(3));
1728 intptr_t number_of_arguments = positional_args.Length(); 1728 intptr_t number_of_arguments = positional_args.Length();
1729 1729
1730 1730
1731 String& ambiguity_error_msg = String::Handle(isolate);
1731 const Function& function = Function::Handle( 1732 const Function& function = Function::Handle(
1732 library.LookupFunctionAllowPrivate(function_name)); 1733 library.LookupFunctionAllowPrivate(function_name, &ambiguity_error_msg));
1733 1734
1734 if (function.IsNull()) { 1735 if (function.IsNull()) {
1735 const String& message = String::Handle( 1736 if (ambiguity_error_msg.IsNull()) {
1736 String::NewFormatted("%s: did not find top-level function '%s'.", 1737 const String& message = String::Handle(
1737 "LibraryMirror_invoke", 1738 String::NewFormatted("%s: did not find top-level function '%s'.",
1738 function_name.ToCString())); 1739 "LibraryMirror_invoke",
1739 ThrowMirroredCompilationError(message); 1740 function_name.ToCString()));
1741 ThrowMirroredCompilationError(message);
1742 } else {
1743 ThrowMirroredCompilationError(ambiguity_error_msg);
1744 }
1740 UNREACHABLE(); 1745 UNREACHABLE();
1741 } 1746 }
1742 1747
1743 // LookupFunctionAllowPrivate does not check argument arity, so we 1748 // LookupFunctionAllowPrivate does not check argument arity, so we
1744 // do it here. 1749 // do it here.
1745 String& error_message = String::Handle(); 1750 String& error_message = String::Handle();
1746 if (!function.AreValidArgumentCounts(number_of_arguments, 1751 if (!function.AreValidArgumentCounts(number_of_arguments,
1747 /* num_named_args */ 0, 1752 /* num_named_args */ 0,
1748 &error_message)) { 1753 &error_message)) {
1749 const String& message = String::Handle( 1754 const String& message = String::Handle(
(...skipping 24 matching lines...) Expand all
1774 MirrorReference::CheckedHandle(arguments->NativeArgAt(1)); 1779 MirrorReference::CheckedHandle(arguments->NativeArgAt(1));
1775 Library& library = Library::Handle(); 1780 Library& library = Library::Handle();
1776 library ^= library_ref.referent(); 1781 library ^= library_ref.referent();
1777 1782
1778 const String& getter_name = 1783 const String& getter_name =
1779 String::CheckedHandle(arguments->NativeArgAt(2)); 1784 String::CheckedHandle(arguments->NativeArgAt(2));
1780 1785
1781 // To access a top-level we may need to use the Field or the 1786 // To access a top-level we may need to use the Field or the
1782 // getter Function. The getter function may either be in the 1787 // getter Function. The getter function may either be in the
1783 // library or in the field's owner class, depending. 1788 // library or in the field's owner class, depending.
1784 const Field& field = 1789 String& ambiguity_error_msg = String::Handle(isolate);
1785 Field::Handle(library.LookupFieldAllowPrivate(getter_name)); 1790 const Field& field = Field::Handle(
1791 library.LookupFieldAllowPrivate(getter_name, &ambiguity_error_msg));
1786 Function& getter = Function::Handle(); 1792 Function& getter = Function::Handle();
1787 if (field.IsNull()) { 1793 if (field.IsNull() && ambiguity_error_msg.IsNull()) {
1788 // No field found. Check for a getter in the lib. 1794 // No field found and no ambiguity error. Check for a getter in the lib.
1789 const String& internal_getter_name = 1795 const String& internal_getter_name =
1790 String::Handle(Field::GetterName(getter_name)); 1796 String::Handle(Field::GetterName(getter_name));
1791 getter = library.LookupFunctionAllowPrivate(internal_getter_name); 1797 getter = library.LookupFunctionAllowPrivate(internal_getter_name,
1792 } else if (FieldIsUninitialized(field)) { 1798 &ambiguity_error_msg);
1799 } else if (!field.IsNull() && FieldIsUninitialized(field)) {
1793 // A field was found. Check for a getter in the field's owner classs. 1800 // A field was found. Check for a getter in the field's owner classs.
1794 const Class& klass = Class::Handle(field.owner()); 1801 const Class& klass = Class::Handle(field.owner());
1795 const String& internal_getter_name = 1802 const String& internal_getter_name =
1796 String::Handle(Field::GetterName(getter_name)); 1803 String::Handle(Field::GetterName(getter_name));
1797 getter = klass.LookupStaticFunctionAllowPrivate(internal_getter_name); 1804 getter = klass.LookupStaticFunctionAllowPrivate(internal_getter_name);
1798 } 1805 }
1799 1806
1800 if (!getter.IsNull()) { 1807 if (!getter.IsNull()) {
1801 // Invoke the getter and return the result. 1808 // Invoke the getter and return the result.
1802 const Object& result = Object::Handle( 1809 const Object& result = Object::Handle(
1803 DartEntry::InvokeFunction(getter, Object::empty_array())); 1810 DartEntry::InvokeFunction(getter, Object::empty_array()));
1804 if (result.IsError()) { 1811 if (result.IsError()) {
1805 ThrowInvokeError(Error::Cast(result)); 1812 ThrowInvokeError(Error::Cast(result));
1806 UNREACHABLE(); 1813 UNREACHABLE();
1807 } 1814 }
1808 return result.raw(); 1815 return result.raw();
1809 } else if (!field.IsNull()) { 1816 }
1817 if (!field.IsNull()) {
1810 return field.value(); 1818 return field.value();
1811 } else { 1819 }
1820 if (ambiguity_error_msg.IsNull()) {
1812 const String& message = String::Handle( 1821 const String& message = String::Handle(
1813 String::NewFormatted("%s: did not find top-level variable '%s'.", 1822 String::NewFormatted("%s: did not find top-level variable '%s'.",
1814 "LibraryMirror_invokeGetter", 1823 "LibraryMirror_invokeGetter",
1815 getter_name.ToCString())); 1824 getter_name.ToCString()));
1816 ThrowMirroredCompilationError(message); 1825 ThrowMirroredCompilationError(message);
1817 UNREACHABLE(); 1826 } else {
1818 return Instance::null(); 1827 ThrowMirroredCompilationError(ambiguity_error_msg);
1819 } 1828 }
1829 UNREACHABLE();
1830 return Instance::null();
1820 } 1831 }
1821 1832
1822 1833
1823 DEFINE_NATIVE_ENTRY(LibraryMirror_invokeSetter, 4) { 1834 DEFINE_NATIVE_ENTRY(LibraryMirror_invokeSetter, 4) {
1824 // Argument 0 is the mirror, which is unused by the native. It exists 1835 // Argument 0 is the mirror, which is unused by the native. It exists
1825 // because this native is an instance method in order to be polymorphic 1836 // because this native is an instance method in order to be polymorphic
1826 // with its cousins. 1837 // with its cousins.
1827 1838
1828 const MirrorReference& library_ref = 1839 const MirrorReference& library_ref =
1829 MirrorReference::CheckedHandle(arguments->NativeArgAt(1)); 1840 MirrorReference::CheckedHandle(arguments->NativeArgAt(1));
1830 Library& library = Library::Handle(); 1841 Library& library = Library::Handle();
1831 library ^= library_ref.referent(); 1842 library ^= library_ref.referent();
1832 1843
1833 const String& setter_name = 1844 const String& setter_name =
1834 String::CheckedHandle(arguments->NativeArgAt(2)); 1845 String::CheckedHandle(arguments->NativeArgAt(2));
1835 1846
1836 const Instance& value = Instance::CheckedHandle(arguments->NativeArgAt(3)); 1847 const Instance& value = Instance::CheckedHandle(arguments->NativeArgAt(3));
1837 1848
1838 // To access a top-level we may need to use the Field or the 1849 // To access a top-level we may need to use the Field or the
1839 // setter Function. The setter function may either be in the 1850 // setter Function. The setter function may either be in the
1840 // library or in the field's owner class, depending. 1851 // library or in the field's owner class, depending.
1841 const Field& field = 1852 String& ambiguity_error_msg = String::Handle(isolate);
1842 Field::Handle(library.LookupFieldAllowPrivate(setter_name)); 1853 const Field& field = Field::Handle(
1854 library.LookupFieldAllowPrivate(setter_name, &ambiguity_error_msg));
1843 1855
1844 if (field.IsNull()) { 1856 if (field.IsNull() && ambiguity_error_msg.IsNull()) {
1845 const String& internal_setter_name = 1857 const String& internal_setter_name =
1846 String::Handle(Field::SetterName(setter_name)); 1858 String::Handle(Field::SetterName(setter_name));
1847 const Function& setter = Function::Handle( 1859 const Function& setter = Function::Handle(
1848 library.LookupFunctionAllowPrivate(internal_setter_name)); 1860 library.LookupFunctionAllowPrivate(internal_setter_name,
1849 1861 &ambiguity_error_msg));
1850 if (setter.IsNull()) { 1862 if (setter.IsNull()) {
1851 const String& message = String::Handle( 1863 if (ambiguity_error_msg.IsNull()) {
1852 String::NewFormatted("%s: did not find top-level variable '%s'.", 1864 const String& message = String::Handle(
1853 "LibraryMirror_invokeSetter", 1865 String::NewFormatted("%s: did not find top-level variable '%s'.",
1854 setter_name.ToCString())); 1866 "LibraryMirror_invokeSetter",
1855 ThrowMirroredCompilationError(message); 1867 setter_name.ToCString()));
1868 ThrowMirroredCompilationError(message);
1869 } else {
1870 ThrowMirroredCompilationError(ambiguity_error_msg);
1871 }
1856 UNREACHABLE(); 1872 UNREACHABLE();
1857 } 1873 }
1858 1874
1859 // Invoke the setter and return the result. 1875 // Invoke the setter and return the result.
1860 const int kNumArgs = 1; 1876 const int kNumArgs = 1;
1861 const Array& args = Array::Handle(Array::New(kNumArgs)); 1877 const Array& args = Array::Handle(Array::New(kNumArgs));
1862 args.SetAt(0, value); 1878 args.SetAt(0, value);
1863 const Object& result = Object::Handle( 1879 const Object& result = Object::Handle(
1864 DartEntry::InvokeFunction(setter, args)); 1880 DartEntry::InvokeFunction(setter, args));
1865 if (result.IsError()) { 1881 if (result.IsError()) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { 1928 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) {
1913 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); 1929 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
1914 const Function& func = Function::Handle(ref.GetFunctionReferent()); 1930 const Function& func = Function::Handle(ref.GetFunctionReferent());
1915 // We handle constructors in Dart code. 1931 // We handle constructors in Dart code.
1916 ASSERT(!func.IsConstructor()); 1932 ASSERT(!func.IsConstructor());
1917 const AbstractType& return_type = AbstractType::Handle(func.result_type()); 1933 const AbstractType& return_type = AbstractType::Handle(func.result_type());
1918 return CreateTypeMirror(return_type); 1934 return CreateTypeMirror(return_type);
1919 } 1935 }
1920 1936
1921 } // namespace dart 1937 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/isolate.cc ('k') | runtime/vm/cha_test.cc » ('j') | runtime/vm/cha_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698