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 "include/dart_debugger_api.h" | 5 #include "include/dart_debugger_api.h" |
6 | 6 |
| 7 #include "vm/class_finalizer.h" |
7 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
8 #include "vm/dart_api_state.h" | 9 #include "vm/dart_api_state.h" |
9 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
10 #include "vm/isolate.h" | 11 #include "vm/isolate.h" |
11 #include "vm/object_store.h" | 12 #include "vm/object_store.h" |
12 #include "vm/symbols.h" | 13 #include "vm/symbols.h" |
13 | 14 |
14 namespace dart { | 15 namespace dart { |
15 | 16 |
16 #define UNWRAP_AND_CHECK_PARAM(type, var, param) \ | 17 #define UNWRAP_AND_CHECK_PARAM(type, var, param) \ |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 499 |
499 | 500 |
500 DART_EXPORT Dart_Handle Dart_GetSuperclass(Dart_Handle cls_in) { | 501 DART_EXPORT Dart_Handle Dart_GetSuperclass(Dart_Handle cls_in) { |
501 Isolate* isolate = Isolate::Current(); | 502 Isolate* isolate = Isolate::Current(); |
502 DARTSCOPE(isolate); | 503 DARTSCOPE(isolate); |
503 UNWRAP_AND_CHECK_PARAM(Class, cls, cls_in); | 504 UNWRAP_AND_CHECK_PARAM(Class, cls, cls_in); |
504 return Api::NewHandle(isolate, cls.SuperClass()); | 505 return Api::NewHandle(isolate, cls.SuperClass()); |
505 } | 506 } |
506 | 507 |
507 | 508 |
| 509 DART_EXPORT Dart_Handle Dart_GetSupertype(Dart_Handle type_in) { |
| 510 Isolate* isolate = Isolate::Current(); |
| 511 DARTSCOPE(isolate); |
| 512 |
| 513 UNWRAP_AND_CHECK_PARAM(Type, type, type_in); |
| 514 const Class& cls= Class::Handle(type.type_class()); |
| 515 intptr_t num_expected_type_arguments = cls.NumTypeParameters(); |
| 516 if (num_expected_type_arguments == 0) { |
| 517 // The super type has no type parameters or it is already instantiated |
| 518 // just return it. |
| 519 const AbstractType& type = AbstractType::Handle(cls.super_type()); |
| 520 if (type.IsNull()) { |
| 521 return Dart_Null(); |
| 522 } |
| 523 return Api::NewHandle(isolate, type.Canonicalize()); |
| 524 } |
| 525 // Set up the type arguments array for the super class type. |
| 526 const Class& super_cls = Class::Handle(cls.SuperClass()); |
| 527 num_expected_type_arguments = super_cls.NumTypeParameters(); |
| 528 const AbstractTypeArguments& type_args_array = |
| 529 AbstractTypeArguments::Handle(type.arguments()); |
| 530 const TypeArguments& super_type_args_array = |
| 531 TypeArguments::Handle(TypeArguments::New(num_expected_type_arguments)); |
| 532 AbstractType& type_arg = AbstractType::Handle(); |
| 533 intptr_t index_offset = |
| 534 super_cls.NumTypeArguments() - num_expected_type_arguments; |
| 535 for (intptr_t i = 0; i < num_expected_type_arguments; i++) { |
| 536 type_arg ^= type_args_array.TypeAt(i + index_offset); |
| 537 super_type_args_array.SetTypeAt(i, type_arg); |
| 538 } |
| 539 |
| 540 // Construct the super type object, canonicalize it and return. |
| 541 Type& instantiated_type = Type::Handle( |
| 542 Type::New(super_cls, super_type_args_array, Scanner::kDummyTokenIndex)); |
| 543 ASSERT(!instantiated_type.IsNull()); |
| 544 instantiated_type ^= ClassFinalizer::FinalizeType( |
| 545 super_cls, instantiated_type, ClassFinalizer::kCanonicalize); |
| 546 return Api::NewHandle(isolate, instantiated_type.raw()); |
| 547 } |
| 548 |
| 549 |
508 DART_EXPORT Dart_Handle Dart_GetClassInfo( | 550 DART_EXPORT Dart_Handle Dart_GetClassInfo( |
509 intptr_t cls_id, | 551 intptr_t cls_id, |
510 Dart_Handle* class_name, | 552 Dart_Handle* class_name, |
511 intptr_t* library_id, | 553 intptr_t* library_id, |
512 intptr_t* super_class_id, | 554 intptr_t* super_class_id, |
513 Dart_Handle* static_fields) { | 555 Dart_Handle* static_fields) { |
514 Isolate* isolate = Isolate::Current(); | 556 Isolate* isolate = Isolate::Current(); |
515 DARTSCOPE(isolate); | 557 DARTSCOPE(isolate); |
516 if (!isolate->class_table()->IsValidIndex(cls_id)) { | 558 if (!isolate->class_table()->IsValidIndex(cls_id)) { |
517 return Api::NewError("%s: %"Pd" is not a valid class id", | 559 return Api::NewError("%s: %"Pd" is not a valid class id", |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 | 815 |
774 | 816 |
775 DART_EXPORT char* Dart_GetVmStatus(const char* request) { | 817 DART_EXPORT char* Dart_GetVmStatus(const char* request) { |
776 if (strncmp(request, "/isolate/", 9) == 0) { | 818 if (strncmp(request, "/isolate/", 9) == 0) { |
777 return Isolate::GetStatus(request); | 819 return Isolate::GetStatus(request); |
778 } | 820 } |
779 return NULL; | 821 return NULL; |
780 } | 822 } |
781 | 823 |
782 } // namespace dart | 824 } // namespace dart |
OLD | NEW |