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

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') | runtime/vm/parser.cc » ('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 "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 return Instance::null(); // Synthetic.
1936 }
1937 script = cls.script();
1938 token_pos = cls.token_pos();
1939 } else if (decl.IsField()) {
1940 const Field& field = Field::Cast(decl);
1941 const Class& owner = Class::Handle(field.owner());
1942 script = owner.script();
1943 token_pos = field.token_pos();
1944 } else if (decl.IsTypeParameter()) {
1945 const TypeParameter& type_var = TypeParameter::Cast(decl);
1946 const Class& owner = Class::Handle(type_var.parameterized_class());
1947 script = owner.script();
1948 token_pos = type_var.token_pos();
1949 }
1950
1951 ASSERT(!script.IsNull());
1952 ASSERT(token_pos != Scanner::kNoSourcePos);
1953
1913 const String& uri = String::Handle(script.url()); 1954 const String& uri = String::Handle(script.url());
1914 intptr_t from_line = 0; 1955 intptr_t from_line = 0;
1915 intptr_t from_col = 0; 1956 intptr_t from_col = 0;
1916 if (script.HasSource()) { 1957 if (script.HasSource()) {
1917 script.GetTokenLocation(func.token_pos(), &from_line, &from_col); 1958 script.GetTokenLocation(token_pos, &from_line, &from_col);
1918 } else { 1959 } else {
1919 // Avoid the slow path of printing the token stream when precise source 1960 // Avoid the slow path of printing the token stream when precise source
1920 // information is not available. 1961 // information is not available.
1921 script.GetTokenLocation(func.token_pos(), &from_line, NULL); 1962 script.GetTokenLocation(token_pos, &from_line, NULL);
1922 } 1963 }
1923 // We should always have at least the line number. 1964 // We should always have at least the line number.
1924 ASSERT(from_line != 0); 1965 ASSERT(from_line != 0);
1925 return CreateSourceLocation(uri, from_line, from_col); 1966 return CreateSourceLocation(uri, from_line, from_col);
1926 } 1967 }
1927 1968
1928 1969
1929 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { 1970 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) {
1930 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); 1971 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0));
1931 const Class& cls = Class::Handle(type.type_class()); 1972 const Class& cls = Class::Handle(type.type_class());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 } 2006 }
1966 2007
1967 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) { 2008 DEFINE_NATIVE_ENTRY(TypeMirror_moreSpecificTest, 2) {
1968 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); 2009 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0));
1969 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); 2010 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1));
1970 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw(); 2011 return Bool::Get(a.IsMoreSpecificThan(b, NULL)).raw();
1971 } 2012 }
1972 2013
1973 2014
1974 } // namespace dart 2015 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | runtime/vm/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698