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/class_finalizer.h" |
8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
9 #include "vm/dart_api_state.h" | 9 #include "vm/dart_api_state.h" |
10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 UNWRAP_AND_CHECK_PARAM(Class, cls, cls_in); | 516 UNWRAP_AND_CHECK_PARAM(Class, cls, cls_in); |
517 return Api::NewHandle(isolate, cls.SuperClass()); | 517 return Api::NewHandle(isolate, cls.SuperClass()); |
518 } | 518 } |
519 | 519 |
520 | 520 |
521 DART_EXPORT Dart_Handle Dart_GetSupertype(Dart_Handle type_in) { | 521 DART_EXPORT Dart_Handle Dart_GetSupertype(Dart_Handle type_in) { |
522 Isolate* isolate = Isolate::Current(); | 522 Isolate* isolate = Isolate::Current(); |
523 DARTSCOPE(isolate); | 523 DARTSCOPE(isolate); |
524 | 524 |
525 UNWRAP_AND_CHECK_PARAM(Type, type, type_in); | 525 UNWRAP_AND_CHECK_PARAM(Type, type, type_in); |
526 if (!type.IsFinalized()) { | |
527 return Api::NewError("%s: type in 'type_in' is not a finalized type", | |
528 CURRENT_FUNC); | |
529 } | |
regis
2013/07/31 23:11:59
You also need to check that type_in is instantiate
siva
2013/07/31 23:24:05
Done.
| |
526 const Class& cls= Class::Handle(type.type_class()); | 530 const Class& cls= Class::Handle(type.type_class()); |
527 intptr_t num_expected_type_arguments = cls.NumTypeParameters(); | 531 if (cls.NumTypeParameters() == 0) { |
528 if (num_expected_type_arguments == 0) { | |
529 // The super type has no type parameters or it is already instantiated | 532 // The super type has no type parameters or it is already instantiated |
530 // just return it. | 533 // just return it. |
531 const AbstractType& type = AbstractType::Handle(cls.super_type()); | 534 const AbstractType& type = AbstractType::Handle(cls.super_type()); |
532 if (type.IsNull()) { | 535 if (type.IsNull()) { |
533 return Dart_Null(); | 536 return Dart_Null(); |
534 } | 537 } |
535 return Api::NewHandle(isolate, type.Canonicalize()); | 538 return Api::NewHandle(isolate, type.Canonicalize()); |
536 } | 539 } |
537 // Set up the type arguments array for the super class type. | 540 // Set up the type arguments array for the super class type. |
538 const Class& super_cls = Class::Handle(cls.SuperClass()); | 541 const Class& super_cls = Class::Handle(cls.SuperClass()); |
539 num_expected_type_arguments = super_cls.NumTypeParameters(); | 542 intptr_t num_expected_type_arguments = super_cls.NumTypeArguments(); |
543 TypeArguments& super_type_args_array = TypeArguments::Handle(); | |
540 const AbstractTypeArguments& type_args_array = | 544 const AbstractTypeArguments& type_args_array = |
541 AbstractTypeArguments::Handle(type.arguments()); | 545 AbstractTypeArguments::Handle(type.arguments()); |
542 const TypeArguments& super_type_args_array = | 546 if (!type_args_array.IsNull() && (num_expected_type_arguments > 0)) { |
543 TypeArguments::Handle(TypeArguments::New(num_expected_type_arguments)); | 547 super_type_args_array = TypeArguments::New(num_expected_type_arguments); |
544 AbstractType& type_arg = AbstractType::Handle(); | 548 AbstractType& type_arg = AbstractType::Handle(); |
545 intptr_t index_offset = | 549 for (intptr_t i = 0; i < num_expected_type_arguments; i++) { |
546 super_cls.NumTypeArguments() - num_expected_type_arguments; | 550 type_arg ^= type_args_array.TypeAt(i); |
547 for (intptr_t i = 0; i < num_expected_type_arguments; i++) { | 551 super_type_args_array.SetTypeAt(i, type_arg); |
548 type_arg ^= type_args_array.TypeAt(i + index_offset); | 552 } |
549 super_type_args_array.SetTypeAt(i, type_arg); | |
550 } | 553 } |
551 | 554 |
552 // Construct the super type object, canonicalize it and return. | 555 // Construct the super type object, canonicalize it and return. |
553 Type& instantiated_type = Type::Handle( | 556 Type& instantiated_type = Type::Handle( |
554 Type::New(super_cls, super_type_args_array, Scanner::kDummyTokenIndex)); | 557 Type::New(super_cls, super_type_args_array, Scanner::kDummyTokenIndex)); |
555 ASSERT(!instantiated_type.IsNull()); | 558 ASSERT(!instantiated_type.IsNull()); |
556 instantiated_type ^= ClassFinalizer::FinalizeType( | 559 instantiated_type.SetIsFinalized(); |
557 super_cls, instantiated_type, ClassFinalizer::kCanonicalize); | 560 return Api::NewHandle(isolate, instantiated_type.Canonicalize()); |
558 return Api::NewHandle(isolate, instantiated_type.raw()); | |
559 } | 561 } |
560 | 562 |
561 | 563 |
562 DART_EXPORT Dart_Handle Dart_GetClassInfo( | 564 DART_EXPORT Dart_Handle Dart_GetClassInfo( |
563 intptr_t cls_id, | 565 intptr_t cls_id, |
564 Dart_Handle* class_name, | 566 Dart_Handle* class_name, |
565 intptr_t* library_id, | 567 intptr_t* library_id, |
566 intptr_t* super_class_id, | 568 intptr_t* super_class_id, |
567 Dart_Handle* static_fields) { | 569 Dart_Handle* static_fields) { |
568 Isolate* isolate = Isolate::Current(); | 570 Isolate* isolate = Isolate::Current(); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 | 829 |
828 | 830 |
829 DART_EXPORT char* Dart_GetVmStatus(const char* request) { | 831 DART_EXPORT char* Dart_GetVmStatus(const char* request) { |
830 if (strncmp(request, "/isolate/", 9) == 0) { | 832 if (strncmp(request, "/isolate/", 9) == 0) { |
831 return Isolate::GetStatus(request); | 833 return Isolate::GetStatus(request); |
832 } | 834 } |
833 return NULL; | 835 return NULL; |
834 } | 836 } |
835 | 837 |
836 } // namespace dart | 838 } // namespace dart |
OLD | NEW |