| 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 1962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 const Array& args = Array::Handle(Array::New(3)); | 1973 const Array& args = Array::Handle(Array::New(3)); |
| 1974 args.SetAt(0, uri); | 1974 args.SetAt(0, uri); |
| 1975 args.SetAt(1, Smi::Handle(Smi::New(line))); | 1975 args.SetAt(1, Smi::Handle(Smi::New(line))); |
| 1976 args.SetAt(2, Smi::Handle(Smi::New(column))); | 1976 args.SetAt(2, Smi::Handle(Smi::New(column))); |
| 1977 return CreateMirror(Symbols::_SourceLocation(), args); | 1977 return CreateMirror(Symbols::_SourceLocation(), args); |
| 1978 } | 1978 } |
| 1979 | 1979 |
| 1980 | 1980 |
| 1981 DEFINE_NATIVE_ENTRY(DeclarationMirror_location, 1) { | 1981 DEFINE_NATIVE_ENTRY(DeclarationMirror_location, 1) { |
| 1982 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0)); | 1982 GET_NON_NULL_NATIVE_ARGUMENT(Instance, reflectee, arguments->NativeArgAt(0)); |
| 1983 Object& decl = Object::Handle(); | 1983 Object& decl = Object::Handle(zone); |
| 1984 if (reflectee.IsMirrorReference()) { | 1984 if (reflectee.IsMirrorReference()) { |
| 1985 const MirrorReference& decl_ref = MirrorReference::Cast(reflectee); | 1985 const MirrorReference& decl_ref = MirrorReference::Cast(reflectee); |
| 1986 decl = decl_ref.referent(); | 1986 decl = decl_ref.referent(); |
| 1987 } else if (reflectee.IsTypeParameter()) { | 1987 } else if (reflectee.IsTypeParameter()) { |
| 1988 decl = reflectee.raw(); | 1988 decl = reflectee.raw(); |
| 1989 } else { | 1989 } else { |
| 1990 UNREACHABLE(); | 1990 UNREACHABLE(); |
| 1991 } | 1991 } |
| 1992 | 1992 |
| 1993 Script& script = Script::Handle(); | 1993 Script& script = Script::Handle(zone); |
| 1994 TokenPosition token_pos = TokenPosition::kNoSource; | 1994 TokenPosition token_pos = TokenPosition::kNoSource; |
| 1995 | 1995 |
| 1996 if (decl.IsFunction()) { | 1996 if (decl.IsFunction()) { |
| 1997 const Function& func = Function::Cast(decl); | 1997 const Function& func = Function::Cast(decl); |
| 1998 if (func.IsImplicitConstructor() || func.IsSignatureFunction()) { | 1998 if (func.IsImplicitConstructor() || func.IsSignatureFunction()) { |
| 1999 // These are synthetic methods; they have no source. | 1999 // These are synthetic methods; they have no source. |
| 2000 return Instance::null(); | 2000 return Instance::null(); |
| 2001 } | 2001 } |
| 2002 script = func.script(); | 2002 script = func.script(); |
| 2003 token_pos = func.token_pos(); | 2003 token_pos = func.token_pos(); |
| 2004 } else if (decl.IsClass()) { | 2004 } else if (decl.IsClass()) { |
| 2005 const Class& cls = Class::Cast(decl); | 2005 const Class& cls = Class::Cast(decl); |
| 2006 const bool is_typedef = cls.IsTypedefClass(); | 2006 const bool is_typedef = cls.IsTypedefClass(); |
| 2007 if (cls.is_synthesized_class() && | 2007 if (cls.is_synthesized_class() && |
| 2008 !is_typedef && | 2008 !is_typedef && |
| 2009 !cls.is_mixin_app_alias() && | 2009 !cls.is_mixin_app_alias() && |
| 2010 !cls.is_enum_class()) { | 2010 !cls.is_enum_class()) { |
| 2011 return Instance::null(); // Synthetic. | 2011 return Instance::null(); // Synthetic. |
| 2012 } | 2012 } |
| 2013 script = cls.script(); | 2013 script = cls.script(); |
| 2014 token_pos = cls.token_pos(); | 2014 token_pos = cls.token_pos(); |
| 2015 } else if (decl.IsField()) { | 2015 } else if (decl.IsField()) { |
| 2016 const Field& field = Field::Cast(decl); | 2016 const Field& field = Field::Cast(decl); |
| 2017 script = field.Script(); | 2017 script = field.Script(); |
| 2018 token_pos = field.token_pos(); | 2018 token_pos = field.token_pos(); |
| 2019 } else if (decl.IsTypeParameter()) { | 2019 } else if (decl.IsTypeParameter()) { |
| 2020 const TypeParameter& type_var = TypeParameter::Cast(decl); | 2020 const TypeParameter& type_var = TypeParameter::Cast(decl); |
| 2021 const Class& owner = Class::Handle(type_var.parameterized_class()); | 2021 const Class& owner = Class::Handle(zone, type_var.parameterized_class()); |
| 2022 script = owner.script(); | 2022 script = owner.script(); |
| 2023 token_pos = type_var.token_pos(); | 2023 token_pos = type_var.token_pos(); |
| 2024 } else if (decl.IsLibrary()) { | 2024 } else if (decl.IsLibrary()) { |
| 2025 const Library& lib = Library::Cast(decl); | 2025 const Library& lib = Library::Cast(decl); |
| 2026 if (lib.raw() == Library::NativeWrappersLibrary()) { | 2026 if (lib.raw() == Library::NativeWrappersLibrary()) { |
| 2027 return Instance::null(); // No source. | 2027 return Instance::null(); // No source. |
| 2028 } | 2028 } |
| 2029 const Array& scripts = Array::Handle(lib.LoadedScripts()); | 2029 const Array& scripts = Array::Handle(zone, lib.LoadedScripts()); |
| 2030 for (intptr_t i = 0; i < scripts.Length(); i++) { | 2030 for (intptr_t i = 0; i < scripts.Length(); i++) { |
| 2031 script ^= scripts.At(i); | 2031 script ^= scripts.At(i); |
| 2032 if (script.kind() == RawScript::kLibraryTag) break; | 2032 if (script.kind() == RawScript::kLibraryTag) break; |
| 2033 } | 2033 } |
| 2034 ASSERT(!script.IsNull()); | 2034 ASSERT(!script.IsNull()); |
| 2035 const String& libname = String::Handle(lib.name()); | 2035 const String& libname = String::Handle(zone, lib.name()); |
| 2036 if (libname.Length() == 0) { | 2036 if (libname.Length() == 0) { |
| 2037 // No library declaration. | 2037 // No library declaration. |
| 2038 const String& uri = String::Handle(script.url()); | 2038 const String& uri = String::Handle(zone, script.url()); |
| 2039 return CreateSourceLocation(uri, 1, 1); | 2039 return CreateSourceLocation(uri, 1, 1); |
| 2040 } | 2040 } |
| 2041 const TokenStream& stream = TokenStream::Handle(script.tokens()); | 2041 const TokenStream& stream = TokenStream::Handle(zone, script.tokens()); |
| 2042 TokenStream::Iterator tkit(stream, TokenPosition::kMinSource); | 2042 TokenStream::Iterator tkit(zone, stream, TokenPosition::kMinSource); |
| 2043 if (tkit.CurrentTokenKind() == Token::kSCRIPTTAG) tkit.Advance(); | 2043 if (tkit.CurrentTokenKind() == Token::kSCRIPTTAG) tkit.Advance(); |
| 2044 token_pos = tkit.CurrentPosition(); | 2044 token_pos = tkit.CurrentPosition(); |
| 2045 } | 2045 } |
| 2046 | 2046 |
| 2047 ASSERT(!script.IsNull()); | 2047 ASSERT(!script.IsNull()); |
| 2048 ASSERT(token_pos != TokenPosition::kNoSource); | 2048 ASSERT(token_pos != TokenPosition::kNoSource); |
| 2049 | 2049 |
| 2050 const String& uri = String::Handle(script.url()); | 2050 const String& uri = String::Handle(zone, script.url()); |
| 2051 intptr_t from_line = 0; | 2051 intptr_t from_line = 0; |
| 2052 intptr_t from_col = 0; | 2052 intptr_t from_col = 0; |
| 2053 if (script.HasSource()) { | 2053 if (script.HasSource()) { |
| 2054 script.GetTokenLocation(token_pos, &from_line, &from_col); | 2054 script.GetTokenLocation(token_pos, &from_line, &from_col); |
| 2055 } else { | 2055 } else { |
| 2056 // Avoid the slow path of printing the token stream when precise source | 2056 // Avoid the slow path of printing the token stream when precise source |
| 2057 // information is not available. | 2057 // information is not available. |
| 2058 script.GetTokenLocation(token_pos, &from_line, NULL); | 2058 script.GetTokenLocation(token_pos, &from_line, NULL); |
| 2059 } | 2059 } |
| 2060 // We should always have at least the line number. | 2060 // We should always have at least the line number. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2097 | 2097 |
| 2098 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { | 2098 DEFINE_NATIVE_ENTRY(TypeMirror_subtypeTest, 2) { |
| 2099 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); | 2099 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, a, arguments->NativeArgAt(0)); |
| 2100 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); | 2100 GET_NON_NULL_NATIVE_ARGUMENT(AbstractType, b, arguments->NativeArgAt(1)); |
| 2101 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw(); | 2101 return Bool::Get(a.IsSubtypeOf(b, NULL, NULL, Heap::kNew)).raw(); |
| 2102 } | 2102 } |
| 2103 | 2103 |
| 2104 #endif // !PRODUCT | 2104 #endif // !PRODUCT |
| 2105 | 2105 |
| 2106 } // namespace dart | 2106 } // namespace dart |
| OLD | NEW |