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()) { |
| 2041 // We may need to handle more cases when the restrictions on mixins are |
| 2042 // relaxed. In particular we might start associating some source with the |
| 2043 // forwarding constructors when it becomes possible to specify a particular |
| 2044 // constructor from the mixin to use. |
| 2045 return Instance::null(); |
| 2046 } |
2040 const Script& script = Script::Handle(func.script()); | 2047 const Script& script = Script::Handle(func.script()); |
2041 const TokenStream& stream = TokenStream::Handle(script.tokens()); | 2048 const TokenStream& stream = TokenStream::Handle(script.tokens()); |
2042 const TokenStream::Iterator tkit(stream, func.end_token_pos()); | 2049 const TokenStream::Iterator tkit(stream, func.end_token_pos()); |
2043 intptr_t from_line; | 2050 intptr_t from_line; |
2044 intptr_t from_col; | 2051 intptr_t from_col; |
2045 intptr_t to_line; | 2052 intptr_t to_line; |
2046 intptr_t to_col; | 2053 intptr_t to_col; |
2047 script.GetTokenLocation(func.token_pos(), &from_line, &from_col); | 2054 script.GetTokenLocation(func.token_pos(), &from_line, &from_col); |
2048 script.GetTokenLocation(func.end_token_pos(), &to_line, &to_col); | 2055 script.GetTokenLocation(func.end_token_pos(), &to_line, &to_col); |
2049 intptr_t last_tok_len = String::Handle(tkit.CurrentLiteral()).Length(); | 2056 intptr_t last_tok_len = String::Handle(tkit.CurrentLiteral()).Length(); |
2050 // Handle special cases for end tokens of closures (where we exclude the last | 2057 // Handle special cases for end tokens of closures (where we exclude the last |
2051 // token): | 2058 // token): |
2052 // (1) "foo(() => null, bar);": End token is `,', but we don't print it. | 2059 // (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. | 2060 // (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 | 2061 // (3) "var foo = () => null;": End token is `;', but in this case the token |
2055 // semicolon belongs to the assignment so we skip it. | 2062 // semicolon belongs to the assignment so we skip it. |
2056 if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // Case 1. | 2063 if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // Case 1. |
2057 (tkit.CurrentTokenKind() == Token::kRPAREN) || // Case 2. | 2064 (tkit.CurrentTokenKind() == Token::kRPAREN) || // Case 2. |
2058 (tkit.CurrentTokenKind() == Token::kSEMICOLON && | 2065 (tkit.CurrentTokenKind() == Token::kSEMICOLON && |
2059 String::Handle(func.name()).Equals("<anonymous closure>"))) { // Case 3. | 2066 String::Handle(func.name()).Equals("<anonymous closure>"))) { // Case 3. |
2060 last_tok_len = 0; | 2067 last_tok_len = 0; |
2061 } | 2068 } |
2062 return script.GetSnippet(from_line, from_col, to_line, to_col + last_tok_len); | 2069 const Instance& result = Instance::Handle( |
| 2070 script.GetSnippet(from_line, from_col, to_line, to_col + last_tok_len)); |
| 2071 ASSERT(!result.IsNull()); |
| 2072 return result.raw(); |
2063 } | 2073 } |
2064 | 2074 |
2065 | 2075 |
2066 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { | 2076 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { |
2067 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); | 2077 GET_NON_NULL_NATIVE_ARGUMENT(Type, type, arguments->NativeArgAt(0)); |
2068 const Class& cls = Class::Handle(type.type_class()); | 2078 const Class& cls = Class::Handle(type.type_class()); |
2069 const Function& sig_func = Function::Handle(cls.signature_function()); | 2079 const Function& sig_func = Function::Handle(cls.signature_function()); |
2070 const Class& sig_cls = Class::Handle(sig_func.signature_class()); | 2080 const Class& sig_cls = Class::Handle(sig_func.signature_class()); |
2071 | 2081 |
2072 AbstractType& referent_type = AbstractType::Handle(sig_cls.DeclarationType()); | 2082 AbstractType& referent_type = AbstractType::Handle(sig_cls.DeclarationType()); |
(...skipping 16 matching lines...) Expand all Loading... |
2089 | 2099 |
2090 DEFINE_NATIVE_ENTRY(VariableMirror_type, 2) { | 2100 DEFINE_NATIVE_ENTRY(VariableMirror_type, 2) { |
2091 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 2101 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
2092 const Field& field = Field::Handle(ref.GetFieldReferent()); | 2102 const Field& field = Field::Handle(ref.GetFieldReferent()); |
2093 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1)); | 2103 GET_NATIVE_ARGUMENT(AbstractType, instantiator, arguments->NativeArgAt(1)); |
2094 const AbstractType& type = AbstractType::Handle(field.type()); | 2104 const AbstractType& type = AbstractType::Handle(field.type()); |
2095 return InstantiateType(type, instantiator); | 2105 return InstantiateType(type, instantiator); |
2096 } | 2106 } |
2097 | 2107 |
2098 } // namespace dart | 2108 } // namespace dart |
OLD | NEW |