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/invocation_mirror.h" | 5 #include "lib/invocation_mirror.h" |
6 #include "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/compiler.h" | 8 #include "vm/compiler.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
(...skipping 2019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2030 // We handle constructors in Dart code. | 2030 // We handle constructors in Dart code. |
2031 ASSERT(!func.IsConstructor()); | 2031 ASSERT(!func.IsConstructor()); |
2032 const AbstractType& type = AbstractType::Handle(func.result_type()); | 2032 const AbstractType& type = AbstractType::Handle(func.result_type()); |
2033 return InstantiateType(type, instantiator); | 2033 return InstantiateType(type, instantiator); |
2034 } | 2034 } |
2035 | 2035 |
2036 | 2036 |
2037 DEFINE_NATIVE_ENTRY(MethodMirror_source, 1) { | 2037 DEFINE_NATIVE_ENTRY(MethodMirror_source, 1) { |
2038 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 2038 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
2039 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 2039 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
2040 if (func.IsImplicitConstructor() || func.IsSignatureFunction()) { | |
hausner
2014/02/07 21:07:58
There may be other cases of functions that have no
rmacnak
2014/02/07 21:28:46
Now it is considered an implicit constructor. Leav
| |
2041 return Instance::null(); | |
2042 } | |
2040 const Script& script = Script::Handle(func.script()); | 2043 const Script& script = Script::Handle(func.script()); |
2041 const TokenStream& stream = TokenStream::Handle(script.tokens()); | 2044 const TokenStream& stream = TokenStream::Handle(script.tokens()); |
2042 const TokenStream::Iterator tkit(stream, func.end_token_pos()); | 2045 const TokenStream::Iterator tkit(stream, func.end_token_pos()); |
2043 intptr_t from_line; | 2046 intptr_t from_line; |
2044 intptr_t from_col; | 2047 intptr_t from_col; |
2045 intptr_t to_line; | 2048 intptr_t to_line; |
2046 intptr_t to_col; | 2049 intptr_t to_col; |
2047 script.GetTokenLocation(func.token_pos(), &from_line, &from_col); | 2050 script.GetTokenLocation(func.token_pos(), &from_line, &from_col); |
2048 script.GetTokenLocation(func.end_token_pos(), &to_line, &to_col); | 2051 script.GetTokenLocation(func.end_token_pos(), &to_line, &to_col); |
2049 intptr_t last_tok_len = String::Handle(tkit.CurrentLiteral()).Length(); | 2052 intptr_t last_tok_len = String::Handle(tkit.CurrentLiteral()).Length(); |
2050 // Handle special cases for end tokens of closures (where we exclude the last | 2053 // Handle special cases for end tokens of closures (where we exclude the last |
2051 // token): | 2054 // token): |
2052 // (1) "foo(() => null, bar);": End token is `,', but we don't print it. | 2055 // (1) "foo(() => null, bar);": End token is `,', but we don't print it. |
2053 // (2) "foo(() => null);": End token is ')`, but we don't print it. | 2056 // (2) "foo(() => null);": End token is ')`, but we don't print it. |
2054 // (3) "var foo = () => null;": End token is `;', but in this case the token | 2057 // (3) "var foo = () => null;": End token is `;', but in this case the token |
2055 // semicolon belongs to the assignment so we skip it. | 2058 // semicolon belongs to the assignment so we skip it. |
2056 if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // Case 1. | 2059 if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // Case 1. |
2057 (tkit.CurrentTokenKind() == Token::kRPAREN) || // Case 2. | 2060 (tkit.CurrentTokenKind() == Token::kRPAREN) || // Case 2. |
2058 (tkit.CurrentTokenKind() == Token::kSEMICOLON && | 2061 (tkit.CurrentTokenKind() == Token::kSEMICOLON && |
2059 String::Handle(func.name()).Equals("<anonymous closure>"))) { // Case 3. | 2062 String::Handle(func.name()).Equals("<anonymous closure>"))) { // Case 3. |
2060 last_tok_len = 0; | 2063 last_tok_len = 0; |
2061 } | 2064 } |
2062 return script.GetSnippet(from_line, from_col, to_line, to_col + last_tok_len); | 2065 const Instance& result = Instance::Handle( |
2066 script.GetSnippet(from_line, from_col, to_line, to_col + last_tok_len)); | |
2067 ASSERT(!result.IsNull()); | |
2068 return result.raw(); | |
2063 } | 2069 } |
2064 | 2070 |
2065 | 2071 |
2066 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { | 2072 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { |
2067 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); | 2073 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); |
2068 const Class& cls = Class::Handle(type.type_class()); | 2074 const Class& cls = Class::Handle(type.type_class()); |
2069 const Function& sig_func = Function::Handle(cls.signature_function()); | 2075 const Function& sig_func = Function::Handle(cls.signature_function()); |
2070 const Class& sig_cls = Class::Handle(sig_func.signature_class()); | 2076 const Class& sig_cls = Class::Handle(sig_func.signature_class()); |
2071 | 2077 |
2072 AbstractType& referent_type = AbstractType::Handle(sig_cls.DeclarationType()); | 2078 AbstractType& referent_type = AbstractType::Handle(sig_cls.DeclarationType()); |
(...skipping 16 matching lines...) Expand all Loading... | |
2089 | 2095 |
2090 DEFINE_NATIVE_ENTRY(VariableMirror_type, 2) { | 2096 DEFINE_NATIVE_ENTRY(VariableMirror_type, 2) { |
2091 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 2097 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
2092 const Field& field = Field::Handle(ref.GetFieldReferent()); | 2098 const Field& field = Field::Handle(ref.GetFieldReferent()); |
2093 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1)); | 2099 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1)); |
2094 const AbstractType& type = AbstractType::Handle(field.type()); | 2100 const AbstractType& type = AbstractType::Handle(field.type()); |
2095 return InstantiateType(type, instantiator); | 2101 return InstantiateType(type, instantiator); |
2096 } | 2102 } |
2097 | 2103 |
2098 } // namespace dart | 2104 } // namespace dart |
OLD | NEW |