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 "lib/mirrors.h" | 5 #include "lib/mirrors.h" |
6 | 6 |
7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
8 #include "vm/bootstrap_natives.h" | 8 #include "vm/bootstrap_natives.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 1884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1895 intptr_t line, | 1895 intptr_t line, |
1896 intptr_t column) { | 1896 intptr_t column) { |
1897 const Array& args = Array::Handle(Array::New(3)); | 1897 const Array& args = Array::Handle(Array::New(3)); |
1898 args.SetAt(0, uri); | 1898 args.SetAt(0, uri); |
1899 args.SetAt(1, Smi::Handle(Smi::New(line))); | 1899 args.SetAt(1, Smi::Handle(Smi::New(line))); |
1900 args.SetAt(2, Smi::Handle(Smi::New(column))); | 1900 args.SetAt(2, Smi::Handle(Smi::New(column))); |
1901 return CreateMirror(Symbols::_SourceLocation(), args); | 1901 return CreateMirror(Symbols::_SourceLocation(), args); |
1902 } | 1902 } |
1903 | 1903 |
1904 | 1904 |
1905 DEFINE_NATIVE_ENTRY(MethodMirror_location, 1) { | 1905 DEFINE_NATIVE_ENTRY(DeclarationMirror_location, 1) { |
1906 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1906 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0)); |
1907 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1907 Object& decl = Object::Handle(); |
1908 if (func.IsImplicitConstructor() || func.IsSignatureFunction()) { | 1908 if (reflectee.IsMirrorReference()) { |
1909 // These are synthetic methods; they have no source. | 1909 const MirrorReference& decl_ref = MirrorReference::Cast(reflectee); |
1910 return Instance::null(); | 1910 decl = decl_ref.referent(); |
| 1911 } else if (reflectee.IsTypeParameter()) { |
| 1912 decl = reflectee.raw(); |
| 1913 } else { |
| 1914 UNREACHABLE(); |
1911 } | 1915 } |
1912 const Script& script = Script::Handle(func.script()); | 1916 |
| 1917 Script& script = Script::Handle(); |
| 1918 intptr_t token_pos = Scanner::kNoSourcePos; |
| 1919 |
| 1920 if (decl.IsFunction()) { |
| 1921 const Function& func = Function::Cast(decl); |
| 1922 if (func.IsImplicitConstructor() || func.IsSignatureFunction()) { |
| 1923 // These are synthetic methods; they have no source. |
| 1924 return Instance::null(); |
| 1925 } |
| 1926 script = func.script(); |
| 1927 token_pos = func.token_pos(); |
| 1928 } else if (decl.IsClass()) { |
| 1929 const Class& cls = Class::Cast(decl); |
| 1930 const bool is_typedef = cls.IsSignatureClass() && |
| 1931 !cls.IsCanonicalSignatureClass(); |
| 1932 if (cls.is_synthesized_class() && |
| 1933 !is_typedef && |
| 1934 !cls.is_mixin_app_alias() && |
| 1935 !cls.is_enum_class()) { |
| 1936 return Instance::null(); // Synthetic. |
| 1937 } |
| 1938 script = cls.script(); |
| 1939 token_pos = cls.token_pos(); |
| 1940 } else if (decl.IsField()) { |
| 1941 const Field& field = Field::Cast(decl); |
| 1942 const Class& owner = Class::Handle(field.owner()); |
| 1943 script = owner.script(); |
| 1944 token_pos = field.token_pos(); |
| 1945 } else if (decl.IsTypeParameter()) { |
| 1946 const TypeParameter& type_var = TypeParameter::Cast(decl); |
| 1947 const Class& owner = Class::Handle(type_var.parameterized_class()); |
| 1948 script = owner.script(); |
| 1949 token_pos = type_var.token_pos(); |
| 1950 } else if (decl.IsLibrary()) { |
| 1951 const Library& lib = Library::Cast(decl); |
| 1952 if (lib.raw() == Library::NativeWrappersLibrary()) { |
| 1953 return Instance::null(); |
| 1954 } |
| 1955 const Array& scripts = Array::Handle(lib.LoadedScripts()); |
| 1956 for (intptr_t i = 0; i < scripts.Length(); i++) { |
| 1957 script ^= scripts.At(i); |
| 1958 if (script.kind() == RawScript::kLibraryTag) break; |
| 1959 } |
| 1960 ASSERT(!script.IsNull()); |
| 1961 const TokenStream& stream = TokenStream::Handle(script.tokens()); |
| 1962 TokenStream::Iterator tkit(stream, 0); |
| 1963 // TODO(rmacnak): This will incorrectly report the position of metadata |
| 1964 // in a library without a library declaration whose first declaration is |
| 1965 // annotated. |
| 1966 if (tkit.CurrentTokenKind() == Token::kSCRIPTTAG) tkit.Advance(); |
| 1967 if (tkit.CurrentTokenKind() == Token::kAT) { |
| 1968 // Declaration at metadata. Fall through for mapping to source position. |
| 1969 } else { |
| 1970 tkit.Advance(); |
| 1971 if (tkit.CurrentTokenKind() == Token::kLIBRARY) { |
| 1972 // Declaration at library. Fall through for mapping to source position. |
| 1973 } else { |
| 1974 // No library declaration. |
| 1975 const String& uri = String::Handle(script.url()); |
| 1976 return CreateSourceLocation(uri, 1, 1); |
| 1977 } |
| 1978 } |
| 1979 } |
| 1980 |
| 1981 ASSERT(!script.IsNull()); |
| 1982 ASSERT(token_pos != Scanner::kNoSourcePos); |
| 1983 |
1913 const String& uri = String::Handle(script.url()); | 1984 const String& uri = String::Handle(script.url()); |
1914 intptr_t from_line = 0; | 1985 intptr_t from_line = 0; |
1915 intptr_t from_col = 0; | 1986 intptr_t from_col = 0; |
1916 if (script.HasSource()) { | 1987 if (script.HasSource()) { |
1917 script.GetTokenLocation(func.token_pos(), &from_line, &from_col); | 1988 script.GetTokenLocation(token_pos, &from_line, &from_col); |
1918 } else { | 1989 } else { |
1919 // Avoid the slow path of printing the token stream when precise source | 1990 // Avoid the slow path of printing the token stream when precise source |
1920 // information is not available. | 1991 // information is not available. |
1921 script.GetTokenLocation(func.token_pos(), &from_line, NULL); | 1992 script.GetTokenLocation(token_pos, &from_line, NULL); |
1922 } | 1993 } |
1923 // We should always have at least the line number. | 1994 // We should always have at least the line number. |
1924 ASSERT(from_line != 0); | 1995 ASSERT(from_line != 0); |
1925 return CreateSourceLocation(uri, from_line, from_col); | 1996 return CreateSourceLocation(uri, from_line, from_col); |
1926 } | 1997 } |
1927 | 1998 |
1928 | 1999 |
1929 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { | 2000 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { |
1930 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); | 2001 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); |
1931 const Class& cls = Class::Handle(type.type_class()); | 2002 const Class& cls = Class::Handle(type.type_class()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1965 } | 2036 } |
1966 | 2037 |
1967 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { | 2038 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { |
1968 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); | 2039 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); |
1969 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); | 2040 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); |
1970 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); | 2041 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); |
1971 } | 2042 } |
1972 | 2043 |
1973 | 2044 |
1974 } // namespace dart | 2045 } // namespace dart |
OLD | NEW |