| 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/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
| 10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
| (...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 | 1285 |
| 1286 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { | 1286 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { |
| 1287 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1287 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1288 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1288 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1289 // We handle constructors in Dart code. | 1289 // We handle constructors in Dart code. |
| 1290 ASSERT(!func.IsConstructor()); | 1290 ASSERT(!func.IsConstructor()); |
| 1291 return func.result_type(); | 1291 return func.result_type(); |
| 1292 } | 1292 } |
| 1293 | 1293 |
| 1294 | 1294 |
| 1295 DEFINE_NATIVE_ENTRY(MethodMirror_source, 1) { |
| 1296 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1297 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1298 const Script& script = Script::Handle(func.script()); |
| 1299 const TokenStream& stream = TokenStream::Handle(script.tokens()); |
| 1300 const TokenStream::Iterator tkit(stream, func.end_token_pos()); |
| 1301 intptr_t from_line; |
| 1302 intptr_t from_col; |
| 1303 intptr_t to_line; |
| 1304 intptr_t to_col; |
| 1305 script.GetTokenLocation(func.token_pos(), &from_line, &from_col); |
| 1306 script.GetTokenLocation(func.end_token_pos(), &to_line, &to_col); |
| 1307 intptr_t last_tok_len = String::Handle(tkit.CurrentLiteral()).Length(); |
| 1308 // Handle special cases for end tokens of closures (where we exclude the last |
| 1309 // token): |
| 1310 // (1) "foo(() => null, bar);": End token is `,', but we don't print it. |
| 1311 // (2) "foo(() => null);": End token is ')`, but we don't print it. |
| 1312 // (3) "var foo = () => null;": End token is `;', but in this case the token |
| 1313 // semicolon belongs to the assignment so we skip it. |
| 1314 if ((tkit.CurrentTokenKind() == Token::kCOMMA) || // Case 1. |
| 1315 (tkit.CurrentTokenKind() == Token::kRPAREN) || // Case 2. |
| 1316 (tkit.CurrentTokenKind() == Token::kSEMICOLON && |
| 1317 String::Handle(func.name()).Equals("<anonymous closure>"))) { // Case 3. |
| 1318 last_tok_len = 0; |
| 1319 } |
| 1320 return script.GetSnippet(from_line, from_col, to_line, to_col + last_tok_len); |
| 1321 } |
| 1322 |
| 1323 |
| 1295 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { | 1324 DEFINE_NATIVE_ENTRY(TypedefMirror_referent, 1) { |
| 1296 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1325 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1297 const Class& cls = Class::Handle(ref.GetClassReferent()); | 1326 const Class& cls = Class::Handle(ref.GetClassReferent()); |
| 1298 const Function& sig_func = Function::Handle(cls.signature_function()); | 1327 const Function& sig_func = Function::Handle(cls.signature_function()); |
| 1299 const Class& sig_cls = Class::Handle(sig_func.signature_class()); | 1328 const Class& sig_cls = Class::Handle(sig_func.signature_class()); |
| 1300 return MirrorReference::New(sig_cls); | 1329 return MirrorReference::New(sig_cls); |
| 1301 } | 1330 } |
| 1302 | 1331 |
| 1303 | 1332 |
| 1304 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) { | 1333 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) { |
| 1305 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1334 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1306 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1)); | 1335 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1)); |
| 1307 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1336 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1308 return func.ParameterTypeAt(func.NumImplicitParameters() + pos.Value()); | 1337 return func.ParameterTypeAt(func.NumImplicitParameters() + pos.Value()); |
| 1309 } | 1338 } |
| 1310 | 1339 |
| 1311 | 1340 |
| 1312 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1341 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1313 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1342 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1314 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1343 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1315 return field.type(); | 1344 return field.type(); |
| 1316 } | 1345 } |
| 1317 | 1346 |
| 1318 } // namespace dart | 1347 } // namespace dart |
| OLD | NEW |