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

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

Issue 922023002: Implement DeclarationMirror.location for all but ParameterMirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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') | no next file with comments »
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 "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
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(); // No source.
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 String& libname = String::Handle(lib.name());
1962 if (libname.Length() == 0) {
1963 // No library declaration.
1964 const String& uri = String::Handle(script.url());
1965 return CreateSourceLocation(uri, 1, 1);
1966 }
1967 const TokenStream& stream = TokenStream::Handle(script.tokens());
1968 TokenStream::Iterator tkit(stream, 0);
1969 if (tkit.CurrentTokenKind() == Token::kSCRIPTTAG) tkit.Advance();
1970 token_pos = tkit.CurrentPosition();
1971 }
1972
1973 ASSERT(!script.IsNull());
1974 ASSERT(token_pos != Scanner::kNoSourcePos);
1975
1913 const String& uri = String::Handle(script.url()); 1976 const String& uri = String::Handle(script.url());
1914 intptr_t from_line = 0; 1977 intptr_t from_line = 0;
1915 intptr_t from_col = 0; 1978 intptr_t from_col = 0;
1916 if (script.HasSource()) { 1979 if (script.HasSource()) {
1917 script.GetTokenLocation(func.token_pos(), &from_line, &from_col); 1980 script.GetTokenLocation(token_pos, &from_line, &from_col);
1918 } else { 1981 } else {
1919 // Avoid the slow path of printing the token stream when precise source 1982 // Avoid the slow path of printing the token stream when precise source
1920 // information is not available. 1983 // information is not available.
1921 script.GetTokenLocation(func.token_pos(), &from_line, NULL); 1984 script.GetTokenLocation(token_pos, &from_line, NULL);
1922 } 1985 }
1923 // We should always have at least the line number. 1986 // We should always have at least the line number.
1924 ASSERT(from_line != 0); 1987 ASSERT(from_line != 0);
1925 return CreateSourceLocation(uri, from_line, from_col); 1988 return CreateSourceLocation(uri, from_line, from_col);
1926 } 1989 }
1927 1990
1928 1991
1929 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { 1992 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) {
1930 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); 1993 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0));
1931 const Class& cls = Class::Handle(type.type_class()); 1994 const Class& cls = Class::Handle(type.type_class());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 } 2028 }
1966 2029
1967 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { 2030 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) {
1968 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); 2031 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
1969 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); 2032 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
1970 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); 2033 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw();
1971 } 2034 }
1972 2035
1973 2036
1974 } // namespace dart 2037 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698