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 "vm/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // These are initialized to a value that will force a illegal memory access if | 83 // These are initialized to a value that will force a illegal memory access if |
84 // they are being used. | 84 // they are being used. |
85 #if defined(RAW_NULL) | 85 #if defined(RAW_NULL) |
86 #error RAW_NULL should not be defined. | 86 #error RAW_NULL should not be defined. |
87 #endif | 87 #endif |
88 #define RAW_NULL kHeapObjectTag | 88 #define RAW_NULL kHeapObjectTag |
89 Object* Object::null_object_ = NULL; | 89 Object* Object::null_object_ = NULL; |
90 Array* Object::null_array_ = NULL; | 90 Array* Object::null_array_ = NULL; |
91 String* Object::null_string_ = NULL; | 91 String* Object::null_string_ = NULL; |
92 Instance* Object::null_instance_ = NULL; | 92 Instance* Object::null_instance_ = NULL; |
93 AbstractTypeArguments* Object::null_abstract_type_arguments_ = NULL; | 93 TypeArguments* Object::null_type_arguments_ = NULL; |
94 Array* Object::empty_array_ = NULL; | 94 Array* Object::empty_array_ = NULL; |
95 PcDescriptors* Object::empty_descriptors_ = NULL; | 95 PcDescriptors* Object::empty_descriptors_ = NULL; |
96 Instance* Object::sentinel_ = NULL; | 96 Instance* Object::sentinel_ = NULL; |
97 Instance* Object::transition_sentinel_ = NULL; | 97 Instance* Object::transition_sentinel_ = NULL; |
98 Instance* Object::unknown_constant_ = NULL; | 98 Instance* Object::unknown_constant_ = NULL; |
99 Instance* Object::non_constant_ = NULL; | 99 Instance* Object::non_constant_ = NULL; |
100 Bool* Object::bool_true_ = NULL; | 100 Bool* Object::bool_true_ = NULL; |
101 Bool* Object::bool_false_ = NULL; | 101 Bool* Object::bool_false_ = NULL; |
102 Smi* Object::smi_illegal_cid_ = NULL; | 102 Smi* Object::smi_illegal_cid_ = NULL; |
103 LanguageError* Object::snapshot_writer_error_ = NULL; | 103 LanguageError* Object::snapshot_writer_error_ = NULL; |
104 LanguageError* Object::branch_offset_error_ = NULL; | 104 LanguageError* Object::branch_offset_error_ = NULL; |
105 | 105 |
106 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL); | 106 RawObject* Object::null_ = reinterpret_cast<RawObject*>(RAW_NULL); |
107 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 107 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
108 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 108 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
109 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 109 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
110 RawType* Object::dynamic_type_ = reinterpret_cast<RawType*>(RAW_NULL); | 110 RawType* Object::dynamic_type_ = reinterpret_cast<RawType*>(RAW_NULL); |
111 RawType* Object::void_type_ = reinterpret_cast<RawType*>(RAW_NULL); | 111 RawType* Object::void_type_ = reinterpret_cast<RawType*>(RAW_NULL); |
112 RawClass* Object::unresolved_class_class_ = | 112 RawClass* Object::unresolved_class_class_ = |
113 reinterpret_cast<RawClass*>(RAW_NULL); | 113 reinterpret_cast<RawClass*>(RAW_NULL); |
114 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 114 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
115 RawClass* Object::instantiated_type_arguments_class_ = | |
116 reinterpret_cast<RawClass*>(RAW_NULL); | |
117 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 115 RawClass* Object::patch_class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
118 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 116 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
119 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 117 RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
120 RawClass* Object::redirection_data_class_ = | 118 RawClass* Object::redirection_data_class_ = |
121 reinterpret_cast<RawClass*>(RAW_NULL); | 119 reinterpret_cast<RawClass*>(RAW_NULL); |
122 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 120 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
123 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 121 RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
124 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 122 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
125 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 123 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
126 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 124 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 } | 439 } |
442 | 440 |
443 Isolate* isolate = Isolate::Current(); | 441 Isolate* isolate = Isolate::Current(); |
444 Heap* heap = isolate->heap(); | 442 Heap* heap = isolate->heap(); |
445 | 443 |
446 // Allocate the read only object handles here. | 444 // Allocate the read only object handles here. |
447 null_object_ = Object::ReadOnlyHandle(); | 445 null_object_ = Object::ReadOnlyHandle(); |
448 null_array_ = Array::ReadOnlyHandle(); | 446 null_array_ = Array::ReadOnlyHandle(); |
449 null_string_ = String::ReadOnlyHandle(); | 447 null_string_ = String::ReadOnlyHandle(); |
450 null_instance_ = Instance::ReadOnlyHandle(); | 448 null_instance_ = Instance::ReadOnlyHandle(); |
451 null_abstract_type_arguments_ = AbstractTypeArguments::ReadOnlyHandle(); | 449 null_type_arguments_ = TypeArguments::ReadOnlyHandle(); |
452 empty_array_ = Array::ReadOnlyHandle(); | 450 empty_array_ = Array::ReadOnlyHandle(); |
453 empty_descriptors_ = PcDescriptors::ReadOnlyHandle(); | 451 empty_descriptors_ = PcDescriptors::ReadOnlyHandle(); |
454 sentinel_ = Instance::ReadOnlyHandle(); | 452 sentinel_ = Instance::ReadOnlyHandle(); |
455 transition_sentinel_ = Instance::ReadOnlyHandle(); | 453 transition_sentinel_ = Instance::ReadOnlyHandle(); |
456 unknown_constant_ = Instance::ReadOnlyHandle(); | 454 unknown_constant_ = Instance::ReadOnlyHandle(); |
457 non_constant_ = Instance::ReadOnlyHandle(); | 455 non_constant_ = Instance::ReadOnlyHandle(); |
458 bool_true_ = Bool::ReadOnlyHandle(); | 456 bool_true_ = Bool::ReadOnlyHandle(); |
459 bool_false_ = Bool::ReadOnlyHandle(); | 457 bool_false_ = Bool::ReadOnlyHandle(); |
460 smi_illegal_cid_ = Smi::ReadOnlyHandle(); | 458 smi_illegal_cid_ = Smi::ReadOnlyHandle(); |
461 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(); | 459 snapshot_writer_error_ = LanguageError::ReadOnlyHandle(); |
462 branch_offset_error_ = LanguageError::ReadOnlyHandle(); | 460 branch_offset_error_ = LanguageError::ReadOnlyHandle(); |
463 | 461 |
464 | 462 |
465 // Allocate and initialize the null instance. | 463 // Allocate and initialize the null instance. |
466 // 'null_' must be the first object allocated as it is used in allocation to | 464 // 'null_' must be the first object allocated as it is used in allocation to |
467 // clear the object. | 465 // clear the object. |
468 { | 466 { |
469 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); | 467 uword address = heap->Allocate(Instance::InstanceSize(), Heap::kOld); |
470 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); | 468 null_ = reinterpret_cast<RawInstance*>(address + kHeapObjectTag); |
471 // The call below is using 'null_' to initialize itself. | 469 // The call below is using 'null_' to initialize itself. |
472 InitializeObject(address, kNullCid, Instance::InstanceSize()); | 470 InitializeObject(address, kNullCid, Instance::InstanceSize()); |
473 } | 471 } |
474 | 472 |
475 *null_object_ = Object::null(); | 473 *null_object_ = Object::null(); |
476 *null_array_ = Array::null(); | 474 *null_array_ = Array::null(); |
477 *null_string_ = String::null(); | 475 *null_string_ = String::null(); |
478 *null_instance_ = Instance::null(); | 476 *null_instance_ = Instance::null(); |
479 *null_abstract_type_arguments_ = AbstractTypeArguments::null(); | 477 *null_type_arguments_ = TypeArguments::null(); |
480 | 478 |
481 // Initialize the empty array handle to null_ in order to be able to check | 479 // Initialize the empty array handle to null_ in order to be able to check |
482 // if the empty array was allocated (RAW_NULL is not available). | 480 // if the empty array was allocated (RAW_NULL is not available). |
483 *empty_array_ = Array::null(); | 481 *empty_array_ = Array::null(); |
484 | 482 |
485 Class& cls = Class::Handle(); | 483 Class& cls = Class::Handle(); |
486 | 484 |
487 // Allocate and initialize the class class. | 485 // Allocate and initialize the class class. |
488 { | 486 { |
489 intptr_t size = Class::InstanceSize(); | 487 intptr_t size = Class::InstanceSize(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); | 539 Object::Allocate(kNullCid, Instance::InstanceSize(), Heap::kOld); |
542 } | 540 } |
543 | 541 |
544 // Allocate the remaining VM internal classes. | 542 // Allocate the remaining VM internal classes. |
545 cls = Class::New<UnresolvedClass>(); | 543 cls = Class::New<UnresolvedClass>(); |
546 unresolved_class_class_ = cls.raw(); | 544 unresolved_class_class_ = cls.raw(); |
547 | 545 |
548 cls = Class::New<TypeArguments>(); | 546 cls = Class::New<TypeArguments>(); |
549 type_arguments_class_ = cls.raw(); | 547 type_arguments_class_ = cls.raw(); |
550 | 548 |
551 cls = Class::New<InstantiatedTypeArguments>(); | |
552 instantiated_type_arguments_class_ = cls.raw(); | |
553 | |
554 cls = Class::New<PatchClass>(); | 549 cls = Class::New<PatchClass>(); |
555 patch_class_class_ = cls.raw(); | 550 patch_class_class_ = cls.raw(); |
556 | 551 |
557 cls = Class::New<Function>(); | 552 cls = Class::New<Function>(); |
558 function_class_ = cls.raw(); | 553 function_class_ = cls.raw(); |
559 | 554 |
560 cls = Class::New<ClosureData>(); | 555 cls = Class::New<ClosureData>(); |
561 closure_data_class_ = cls.raw(); | 556 closure_data_class_ = cls.raw(); |
562 | 557 |
563 cls = Class::New<RedirectionData>(); | 558 cls = Class::New<RedirectionData>(); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 error_str = String::New("Branch offset overflow"); | 708 error_str = String::New("Branch offset overflow"); |
714 *branch_offset_error_ = LanguageError::New(error_str); | 709 *branch_offset_error_ = LanguageError::New(error_str); |
715 | 710 |
716 ASSERT(!null_object_->IsSmi()); | 711 ASSERT(!null_object_->IsSmi()); |
717 ASSERT(!null_array_->IsSmi()); | 712 ASSERT(!null_array_->IsSmi()); |
718 ASSERT(null_array_->IsArray()); | 713 ASSERT(null_array_->IsArray()); |
719 ASSERT(!null_string_->IsSmi()); | 714 ASSERT(!null_string_->IsSmi()); |
720 ASSERT(null_string_->IsString()); | 715 ASSERT(null_string_->IsString()); |
721 ASSERT(!null_instance_->IsSmi()); | 716 ASSERT(!null_instance_->IsSmi()); |
722 ASSERT(null_instance_->IsInstance()); | 717 ASSERT(null_instance_->IsInstance()); |
723 ASSERT(!null_abstract_type_arguments_->IsSmi()); | 718 ASSERT(!null_type_arguments_->IsSmi()); |
724 ASSERT(null_abstract_type_arguments_->IsAbstractTypeArguments()); | 719 ASSERT(null_type_arguments_->IsTypeArguments()); |
725 ASSERT(!empty_array_->IsSmi()); | 720 ASSERT(!empty_array_->IsSmi()); |
726 ASSERT(empty_array_->IsArray()); | 721 ASSERT(empty_array_->IsArray()); |
727 ASSERT(!sentinel_->IsSmi()); | 722 ASSERT(!sentinel_->IsSmi()); |
728 ASSERT(sentinel_->IsInstance()); | 723 ASSERT(sentinel_->IsInstance()); |
729 ASSERT(!transition_sentinel_->IsSmi()); | 724 ASSERT(!transition_sentinel_->IsSmi()); |
730 ASSERT(transition_sentinel_->IsInstance()); | 725 ASSERT(transition_sentinel_->IsInstance()); |
731 ASSERT(!unknown_constant_->IsSmi()); | 726 ASSERT(!unknown_constant_->IsSmi()); |
732 ASSERT(unknown_constant_->IsInstance()); | 727 ASSERT(unknown_constant_->IsInstance()); |
733 ASSERT(!non_constant_->IsSmi()); | 728 ASSERT(!non_constant_->IsSmi()); |
734 ASSERT(non_constant_->IsInstance()); | 729 ASSERT(non_constant_->IsInstance()); |
(...skipping 15 matching lines...) Expand all Loading... |
750 | 745 |
751 void Object::RegisterSingletonClassNames() { | 746 void Object::RegisterSingletonClassNames() { |
752 Class& cls = Class::Handle(); | 747 Class& cls = Class::Handle(); |
753 | 748 |
754 // Set up names for all VM singleton classes. | 749 // Set up names for all VM singleton classes. |
755 SET_CLASS_NAME(class, Class); | 750 SET_CLASS_NAME(class, Class); |
756 SET_CLASS_NAME(dynamic, Dynamic); | 751 SET_CLASS_NAME(dynamic, Dynamic); |
757 SET_CLASS_NAME(void, Void); | 752 SET_CLASS_NAME(void, Void); |
758 SET_CLASS_NAME(unresolved_class, UnresolvedClass); | 753 SET_CLASS_NAME(unresolved_class, UnresolvedClass); |
759 SET_CLASS_NAME(type_arguments, TypeArguments); | 754 SET_CLASS_NAME(type_arguments, TypeArguments); |
760 SET_CLASS_NAME(instantiated_type_arguments, InstantiatedTypeArguments); | |
761 SET_CLASS_NAME(patch_class, PatchClass); | 755 SET_CLASS_NAME(patch_class, PatchClass); |
762 SET_CLASS_NAME(function, Function); | 756 SET_CLASS_NAME(function, Function); |
763 SET_CLASS_NAME(closure_data, ClosureData); | 757 SET_CLASS_NAME(closure_data, ClosureData); |
764 SET_CLASS_NAME(redirection_data, RedirectionData); | 758 SET_CLASS_NAME(redirection_data, RedirectionData); |
765 SET_CLASS_NAME(field, Field); | 759 SET_CLASS_NAME(field, Field); |
766 SET_CLASS_NAME(literal_token, LiteralToken); | 760 SET_CLASS_NAME(literal_token, LiteralToken); |
767 SET_CLASS_NAME(token_stream, TokenStream); | 761 SET_CLASS_NAME(token_stream, TokenStream); |
768 SET_CLASS_NAME(script, Script); | 762 SET_CLASS_NAME(script, Script); |
769 SET_CLASS_NAME(library, LibraryClass); | 763 SET_CLASS_NAME(library, LibraryClass); |
770 SET_CLASS_NAME(library_prefix, LibraryPrefix); | 764 SET_CLASS_NAME(library_prefix, LibraryPrefix); |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 | 1615 |
1622 // Return the still unfinalized signature type. | 1616 // Return the still unfinalized signature type. |
1623 ASSERT(!signature_type.IsFinalized()); | 1617 ASSERT(!signature_type.IsFinalized()); |
1624 return signature_type.raw(); | 1618 return signature_type.raw(); |
1625 } | 1619 } |
1626 | 1620 |
1627 | 1621 |
1628 RawAbstractType* Class::RareType() const { | 1622 RawAbstractType* Class::RareType() const { |
1629 const Type& type = Type::Handle(Type::New( | 1623 const Type& type = Type::Handle(Type::New( |
1630 *this, | 1624 *this, |
1631 Object::null_abstract_type_arguments(), | 1625 Object::null_type_arguments(), |
1632 Scanner::kNoSourcePos)); | 1626 Scanner::kNoSourcePos)); |
1633 return ClassFinalizer::FinalizeType(*this, | 1627 return ClassFinalizer::FinalizeType(*this, |
1634 type, | 1628 type, |
1635 ClassFinalizer::kCanonicalize); | 1629 ClassFinalizer::kCanonicalize); |
1636 } | 1630 } |
1637 | 1631 |
1638 | 1632 |
1639 RawAbstractType* Class::DeclarationType() const { | 1633 RawAbstractType* Class::DeclarationType() const { |
1640 const TypeArguments& args = TypeArguments::Handle(type_parameters()); | 1634 const TypeArguments& args = TypeArguments::Handle(type_parameters()); |
1641 const Type& type = Type::Handle(Type::New( | 1635 const Type& type = Type::Handle(Type::New( |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2028 if (!FLAG_overlap_type_arguments || | 2022 if (!FLAG_overlap_type_arguments || |
2029 (num_type_params == 0) || | 2023 (num_type_params == 0) || |
2030 (super_type() == AbstractType::null()) || | 2024 (super_type() == AbstractType::null()) || |
2031 (super_type() == isolate->object_store()->object_type())) { | 2025 (super_type() == isolate->object_store()->object_type())) { |
2032 set_num_own_type_arguments(num_type_params); | 2026 set_num_own_type_arguments(num_type_params); |
2033 return num_type_params; | 2027 return num_type_params; |
2034 } | 2028 } |
2035 ASSERT(!IsMixinApplication() || is_mixin_type_applied()); | 2029 ASSERT(!IsMixinApplication() || is_mixin_type_applied()); |
2036 const AbstractType& sup_type = AbstractType::Handle(isolate, super_type()); | 2030 const AbstractType& sup_type = AbstractType::Handle(isolate, super_type()); |
2037 ASSERT(sup_type.IsResolved()); | 2031 ASSERT(sup_type.IsResolved()); |
2038 const AbstractTypeArguments& sup_type_args = | 2032 const TypeArguments& sup_type_args = |
2039 AbstractTypeArguments::Handle(isolate, sup_type.arguments()); | 2033 TypeArguments::Handle(isolate, sup_type.arguments()); |
2040 if (sup_type_args.IsNull()) { | 2034 if (sup_type_args.IsNull()) { |
2041 // The super type is raw or the super class is non generic. | 2035 // The super type is raw or the super class is non generic. |
2042 // In either case, overlapping is not possible. | 2036 // In either case, overlapping is not possible. |
2043 set_num_own_type_arguments(num_type_params); | 2037 set_num_own_type_arguments(num_type_params); |
2044 return num_type_params; | 2038 return num_type_params; |
2045 } | 2039 } |
2046 const intptr_t num_sup_type_args = sup_type_args.Length(); | 2040 const intptr_t num_sup_type_args = sup_type_args.Length(); |
2047 // At this point, the super type may or may not be finalized. In either case, | 2041 // At this point, the super type may or may not be finalized. In either case, |
2048 // the result of this function must remain the same. | 2042 // the result of this function must remain the same. |
2049 // The value of num_sup_type_args may increase when the super type is | 2043 // The value of num_sup_type_args may increase when the super type is |
2050 // finalized, but the last num_sup_type_args type arguments will not be | 2044 // finalized, but the last num_sup_type_args type arguments will not be |
2051 // modified by finalization, only shifted to higher indices in the vector. | 2045 // modified by finalization, only shifted to higher indices in the vector. |
2052 // They may however get wrapped in a BoundedType, which we skip. | 2046 // They may however get wrapped in a BoundedType, which we skip. |
2053 const AbstractTypeArguments& type_params = | 2047 const TypeArguments& type_params = |
2054 AbstractTypeArguments::Handle(isolate, type_parameters()); | 2048 TypeArguments::Handle(isolate, type_parameters()); |
2055 // Determine the maximum overlap of a prefix of the vector consisting of the | 2049 // Determine the maximum overlap of a prefix of the vector consisting of the |
2056 // type parameters of this class with a suffix of the vector consisting of the | 2050 // type parameters of this class with a suffix of the vector consisting of the |
2057 // type arguments of the super type of this class. | 2051 // type arguments of the super type of this class. |
2058 // The number of own type arguments of this class is the number of its type | 2052 // The number of own type arguments of this class is the number of its type |
2059 // parameters minus the number of type arguments in the overlap. | 2053 // parameters minus the number of type arguments in the overlap. |
2060 // Attempt to overlap the whole vector of type parameters; reduce the size | 2054 // Attempt to overlap the whole vector of type parameters; reduce the size |
2061 // of the vector (keeping the first type parameter) until it fits or until | 2055 // of the vector (keeping the first type parameter) until it fits or until |
2062 // its size is zero. | 2056 // its size is zero. |
2063 TypeParameter& type_param = TypeParameter::Handle(isolate); | 2057 TypeParameter& type_param = TypeParameter::Handle(isolate); |
2064 AbstractType& sup_type_arg = AbstractType::Handle(isolate); | 2058 AbstractType& sup_type_arg = AbstractType::Handle(isolate); |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2935 case kDynamicCid: | 2929 case kDynamicCid: |
2936 return Symbols::Dynamic().raw(); | 2930 return Symbols::Dynamic().raw(); |
2937 case kVoidCid: | 2931 case kVoidCid: |
2938 return Symbols::Void().raw(); | 2932 return Symbols::Void().raw(); |
2939 case kClassCid: | 2933 case kClassCid: |
2940 return Symbols::Class().raw(); | 2934 return Symbols::Class().raw(); |
2941 case kUnresolvedClassCid: | 2935 case kUnresolvedClassCid: |
2942 return Symbols::UnresolvedClass().raw(); | 2936 return Symbols::UnresolvedClass().raw(); |
2943 case kTypeArgumentsCid: | 2937 case kTypeArgumentsCid: |
2944 return Symbols::TypeArguments().raw(); | 2938 return Symbols::TypeArguments().raw(); |
2945 case kInstantiatedTypeArgumentsCid: | |
2946 return Symbols::InstantiatedTypeArguments().raw(); | |
2947 case kPatchClassCid: | 2939 case kPatchClassCid: |
2948 return Symbols::PatchClass().raw(); | 2940 return Symbols::PatchClass().raw(); |
2949 case kFunctionCid: | 2941 case kFunctionCid: |
2950 return Symbols::Function().raw(); | 2942 return Symbols::Function().raw(); |
2951 case kClosureDataCid: | 2943 case kClosureDataCid: |
2952 return Symbols::ClosureData().raw(); | 2944 return Symbols::ClosureData().raw(); |
2953 case kRedirectionDataCid: | 2945 case kRedirectionDataCid: |
2954 return Symbols::RedirectionData().raw(); | 2946 return Symbols::RedirectionData().raw(); |
2955 case kFieldCid: | 2947 case kFieldCid: |
2956 return Symbols::Field().raw(); | 2948 return Symbols::Field().raw(); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3231 return (!function.IsNull() && (function.signature_class() == raw())); | 3223 return (!function.IsNull() && (function.signature_class() == raw())); |
3232 } | 3224 } |
3233 | 3225 |
3234 | 3226 |
3235 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T. | 3227 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T. |
3236 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T. | 3228 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T. |
3237 // Type S is specified by this class parameterized with 'type_arguments', and | 3229 // Type S is specified by this class parameterized with 'type_arguments', and |
3238 // type T by class 'other' parameterized with 'other_type_arguments'. | 3230 // type T by class 'other' parameterized with 'other_type_arguments'. |
3239 // This class and class 'other' do not need to be finalized, however, they must | 3231 // This class and class 'other' do not need to be finalized, however, they must |
3240 // be resolved as well as their interfaces. | 3232 // be resolved as well as their interfaces. |
3241 bool Class::TypeTestNonRecursive( | 3233 bool Class::TypeTestNonRecursive(const Class& cls, |
3242 const Class& cls, | 3234 Class::TypeTestKind test_kind, |
3243 Class::TypeTestKind test_kind, | 3235 const TypeArguments& type_arguments, |
3244 const AbstractTypeArguments& type_arguments, | 3236 const Class& other, |
3245 const Class& other, | 3237 const TypeArguments& other_type_arguments, |
3246 const AbstractTypeArguments& other_type_arguments, | 3238 Error* bound_error) { |
3247 Error* bound_error) { | |
3248 // Use the thsi object as if it was the receiver of this method, but instead | 3239 // Use the thsi object as if it was the receiver of this method, but instead |
3249 // of recursing reset it to the super class and loop. | 3240 // of recursing reset it to the super class and loop. |
3250 Class& thsi = Class::Handle(cls.raw()); | 3241 Class& thsi = Class::Handle(cls.raw()); |
3251 while (true) { | 3242 while (true) { |
3252 ASSERT(!thsi.IsVoidClass()); | 3243 ASSERT(!thsi.IsVoidClass()); |
3253 // Check for DynamicType. | 3244 // Check for DynamicType. |
3254 // Each occurrence of DynamicType in type T is interpreted as the dynamic | 3245 // Each occurrence of DynamicType in type T is interpreted as the dynamic |
3255 // type, a supertype of all types. | 3246 // type, a supertype of all types. |
3256 if (other.IsDynamicClass()) { | 3247 if (other.IsDynamicClass()) { |
3257 return true; | 3248 return true; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3337 bound_error)) { | 3328 bound_error)) { |
3338 return true; | 3329 return true; |
3339 } | 3330 } |
3340 } | 3331 } |
3341 } | 3332 } |
3342 // Check for 'direct super type' specified in the implements clause | 3333 // Check for 'direct super type' specified in the implements clause |
3343 // and check for transitivity at the same time. | 3334 // and check for transitivity at the same time. |
3344 Array& interfaces = Array::Handle(thsi.interfaces()); | 3335 Array& interfaces = Array::Handle(thsi.interfaces()); |
3345 AbstractType& interface = AbstractType::Handle(); | 3336 AbstractType& interface = AbstractType::Handle(); |
3346 Class& interface_class = Class::Handle(); | 3337 Class& interface_class = Class::Handle(); |
3347 AbstractTypeArguments& interface_args = AbstractTypeArguments::Handle(); | 3338 TypeArguments& interface_args = TypeArguments::Handle(); |
3348 Error& error = Error::Handle(); | 3339 Error& error = Error::Handle(); |
3349 for (intptr_t i = 0; i < interfaces.Length(); i++) { | 3340 for (intptr_t i = 0; i < interfaces.Length(); i++) { |
3350 interface ^= interfaces.At(i); | 3341 interface ^= interfaces.At(i); |
3351 if (!interface.IsFinalized()) { | 3342 if (!interface.IsFinalized()) { |
3352 // We may be checking bounds at finalization time and can encounter | 3343 // We may be checking bounds at finalization time and can encounter |
3353 // a still unfinalized interface. | 3344 // a still unfinalized interface. |
3354 ClassFinalizer::FinalizeType( | 3345 ClassFinalizer::FinalizeType( |
3355 thsi, interface, ClassFinalizer::kCanonicalize); | 3346 thsi, interface, ClassFinalizer::kCanonicalize); |
3356 interfaces.SetAt(i, interface); | 3347 interfaces.SetAt(i, interface); |
3357 } | 3348 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3401 return false; | 3392 return false; |
3402 } | 3393 } |
3403 | 3394 |
3404 | 3395 |
3405 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T. | 3396 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T. |
3406 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T. | 3397 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T. |
3407 // Type S is specified by this class parameterized with 'type_arguments', and | 3398 // Type S is specified by this class parameterized with 'type_arguments', and |
3408 // type T by class 'other' parameterized with 'other_type_arguments'. | 3399 // type T by class 'other' parameterized with 'other_type_arguments'. |
3409 // This class and class 'other' do not need to be finalized, however, they must | 3400 // This class and class 'other' do not need to be finalized, however, they must |
3410 // be resolved as well as their interfaces. | 3401 // be resolved as well as their interfaces. |
3411 bool Class::TypeTest( | 3402 bool Class::TypeTest(TypeTestKind test_kind, |
3412 TypeTestKind test_kind, | 3403 const TypeArguments& type_arguments, |
3413 const AbstractTypeArguments& type_arguments, | |
3414 const Class& other, | 3404 const Class& other, |
3415 const AbstractTypeArguments& other_type_arguments, | 3405 const TypeArguments& other_type_arguments, |
3416 Error* bound_error) const { | 3406 Error* bound_error) const { |
3417 return TypeTestNonRecursive(*this, | 3407 return TypeTestNonRecursive(*this, |
3418 test_kind, | 3408 test_kind, |
3419 type_arguments, | 3409 type_arguments, |
3420 other, | 3410 other, |
3421 other_type_arguments, | 3411 other_type_arguments, |
3422 bound_error); | 3412 bound_error); |
3423 } | 3413 } |
3424 | 3414 |
3425 | 3415 |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3848 OS::SNPrint(chars, len, format, cname); | 3838 OS::SNPrint(chars, len, format, cname); |
3849 return chars; | 3839 return chars; |
3850 } | 3840 } |
3851 | 3841 |
3852 | 3842 |
3853 void UnresolvedClass::PrintToJSONStream(JSONStream* stream, bool ref) const { | 3843 void UnresolvedClass::PrintToJSONStream(JSONStream* stream, bool ref) const { |
3854 JSONObject jsobj(stream); | 3844 JSONObject jsobj(stream); |
3855 } | 3845 } |
3856 | 3846 |
3857 | 3847 |
3858 intptr_t AbstractTypeArguments::Length() const { | |
3859 // AbstractTypeArguments is an abstract class. | |
3860 UNREACHABLE(); | |
3861 return -1; | |
3862 } | |
3863 | |
3864 | |
3865 RawAbstractType* AbstractTypeArguments::TypeAt(intptr_t index) const { | |
3866 // AbstractTypeArguments is an abstract class. | |
3867 UNREACHABLE(); | |
3868 return NULL; | |
3869 } | |
3870 | |
3871 | |
3872 void AbstractTypeArguments::SetTypeAt(intptr_t index, | |
3873 const AbstractType& value) const { | |
3874 // AbstractTypeArguments is an abstract class. | |
3875 UNREACHABLE(); | |
3876 } | |
3877 | |
3878 | |
3879 bool AbstractTypeArguments::IsResolved() const { | |
3880 // AbstractTypeArguments is an abstract class. | |
3881 UNREACHABLE(); | |
3882 return false; | |
3883 } | |
3884 | |
3885 | |
3886 bool AbstractTypeArguments::IsInstantiated(GrowableObjectArray* trail) const { | |
3887 // AbstractTypeArguments is an abstract class. | |
3888 UNREACHABLE(); | |
3889 return false; | |
3890 } | |
3891 | |
3892 | |
3893 bool AbstractTypeArguments::IsUninstantiatedIdentity() const { | |
3894 // AbstractTypeArguments is an abstract class. | |
3895 UNREACHABLE(); | |
3896 return false; | |
3897 } | |
3898 | |
3899 | |
3900 bool AbstractTypeArguments::CanShareInstantiatorTypeArguments( | |
3901 const Class& instantiator_class) const { | |
3902 // AbstractTypeArguments is an abstract class. | |
3903 UNREACHABLE(); | |
3904 return false; | |
3905 } | |
3906 | |
3907 | |
3908 bool AbstractTypeArguments::IsBounded() const { | |
3909 // AbstractTypeArguments is an abstract class. | |
3910 UNREACHABLE(); | |
3911 return false; | |
3912 } | |
3913 | |
3914 | |
3915 static intptr_t FinalizeHash(uword hash) { | 3848 static intptr_t FinalizeHash(uword hash) { |
3916 hash += hash << 3; | 3849 hash += hash << 3; |
3917 hash ^= hash >> 11; | 3850 hash ^= hash >> 11; |
3918 hash += hash << 15; | 3851 hash += hash << 15; |
3919 return hash; | 3852 return hash; |
3920 } | 3853 } |
3921 | 3854 |
3922 | 3855 |
3923 intptr_t AbstractTypeArguments::Hash() const { | 3856 intptr_t TypeArguments::Hash() const { |
3924 if (IsNull()) return 0; | 3857 if (IsNull()) return 0; |
3925 uword result = 0; | 3858 uword result = 0; |
3926 const intptr_t num_types = Length(); | 3859 const intptr_t num_types = Length(); |
3927 AbstractType& type = AbstractType::Handle(); | 3860 AbstractType& type = AbstractType::Handle(); |
3928 for (intptr_t i = 0; i < num_types; i++) { | 3861 for (intptr_t i = 0; i < num_types; i++) { |
3929 type = TypeAt(i); | 3862 type = TypeAt(i); |
3930 result += type.Hash(); | 3863 result += type.Hash(); |
3931 result += result << 10; | 3864 result += result << 10; |
3932 result ^= result >> 6; | 3865 result ^= result >> 6; |
3933 } | 3866 } |
3934 return FinalizeHash(result); | 3867 return FinalizeHash(result); |
3935 } | 3868 } |
3936 | 3869 |
3937 | 3870 |
3938 RawString* AbstractTypeArguments::SubvectorName( | 3871 RawString* TypeArguments::SubvectorName(intptr_t from_index, |
3939 intptr_t from_index, | 3872 intptr_t len, |
3940 intptr_t len, | 3873 NameVisibility name_visibility) const { |
3941 NameVisibility name_visibility) const { | |
3942 ASSERT(from_index + len <= Length()); | 3874 ASSERT(from_index + len <= Length()); |
3943 String& name = String::Handle(); | 3875 String& name = String::Handle(); |
3944 const intptr_t num_strings = 2*len + 1; // "<""T"", ""T"">". | 3876 const intptr_t num_strings = 2*len + 1; // "<""T"", ""T"">". |
3945 const Array& strings = Array::Handle(Array::New(num_strings)); | 3877 const Array& strings = Array::Handle(Array::New(num_strings)); |
3946 intptr_t s = 0; | 3878 intptr_t s = 0; |
3947 strings.SetAt(s++, Symbols::LAngleBracket()); | 3879 strings.SetAt(s++, Symbols::LAngleBracket()); |
3948 AbstractType& type = AbstractType::Handle(); | 3880 AbstractType& type = AbstractType::Handle(); |
3949 for (intptr_t i = 0; i < len; i++) { | 3881 for (intptr_t i = 0; i < len; i++) { |
3950 type = TypeAt(from_index + i); | 3882 type = TypeAt(from_index + i); |
3951 name = type.BuildName(name_visibility); | 3883 name = type.BuildName(name_visibility); |
3952 strings.SetAt(s++, name); | 3884 strings.SetAt(s++, name); |
3953 if (i < len - 1) { | 3885 if (i < len - 1) { |
3954 strings.SetAt(s++, Symbols::CommaSpace()); | 3886 strings.SetAt(s++, Symbols::CommaSpace()); |
3955 } | 3887 } |
3956 } | 3888 } |
3957 strings.SetAt(s++, Symbols::RAngleBracket()); | 3889 strings.SetAt(s++, Symbols::RAngleBracket()); |
3958 ASSERT(s == num_strings); | 3890 ASSERT(s == num_strings); |
3959 name = String::ConcatAll(strings); | 3891 name = String::ConcatAll(strings); |
3960 return Symbols::New(name); | 3892 return Symbols::New(name); |
3961 } | 3893 } |
3962 | 3894 |
3963 | 3895 |
3964 bool AbstractTypeArguments::IsEquivalent(const AbstractTypeArguments& other, | 3896 bool TypeArguments::IsEquivalent(const TypeArguments& other, |
3965 GrowableObjectArray* trail) const { | 3897 GrowableObjectArray* trail) const { |
3966 if (this->raw() == other.raw()) { | 3898 if (this->raw() == other.raw()) { |
3967 return true; | 3899 return true; |
3968 } | 3900 } |
3969 if (IsNull() || other.IsNull()) { | 3901 if (IsNull() || other.IsNull()) { |
3970 return false; | 3902 return false; |
3971 } | 3903 } |
3972 const intptr_t num_types = Length(); | 3904 const intptr_t num_types = Length(); |
3973 if (num_types != other.Length()) { | 3905 if (num_types != other.Length()) { |
3974 return false; | 3906 return false; |
3975 } | 3907 } |
3976 AbstractType& type = AbstractType::Handle(); | 3908 AbstractType& type = AbstractType::Handle(); |
3977 AbstractType& other_type = AbstractType::Handle(); | 3909 AbstractType& other_type = AbstractType::Handle(); |
3978 for (intptr_t i = 0; i < num_types; i++) { | 3910 for (intptr_t i = 0; i < num_types; i++) { |
3979 type = TypeAt(i); | 3911 type = TypeAt(i); |
3980 other_type = other.TypeAt(i); | 3912 other_type = other.TypeAt(i); |
3981 if (!type.IsEquivalent(other_type, trail)) { | 3913 if (!type.IsEquivalent(other_type, trail)) { |
3982 return false; | 3914 return false; |
3983 } | 3915 } |
3984 } | 3916 } |
3985 return true; | 3917 return true; |
3986 } | 3918 } |
3987 | 3919 |
3988 | 3920 |
3989 RawAbstractTypeArguments* AbstractTypeArguments::InstantiateFrom( | 3921 bool TypeArguments::IsDynamicTypes(bool raw_instantiated, |
3990 const AbstractTypeArguments& instantiator_type_arguments, | 3922 intptr_t from_index, |
3991 Error* bound_error, | 3923 intptr_t len) const { |
3992 GrowableObjectArray* trail) const { | |
3993 // AbstractTypeArguments is an abstract class. | |
3994 UNREACHABLE(); | |
3995 return NULL; | |
3996 } | |
3997 | |
3998 | |
3999 bool AbstractTypeArguments::IsDynamicTypes(bool raw_instantiated, | |
4000 intptr_t from_index, | |
4001 intptr_t len) const { | |
4002 ASSERT(Length() >= (from_index + len)); | 3924 ASSERT(Length() >= (from_index + len)); |
4003 AbstractType& type = AbstractType::Handle(); | 3925 AbstractType& type = AbstractType::Handle(); |
4004 Class& type_class = Class::Handle(); | 3926 Class& type_class = Class::Handle(); |
4005 for (intptr_t i = 0; i < len; i++) { | 3927 for (intptr_t i = 0; i < len; i++) { |
4006 type = TypeAt(from_index + i); | 3928 type = TypeAt(from_index + i); |
4007 ASSERT(!type.IsNull()); | 3929 ASSERT(!type.IsNull()); |
4008 if (!type.HasResolvedTypeClass()) { | 3930 if (!type.HasResolvedTypeClass()) { |
4009 if (raw_instantiated && type.IsTypeParameter()) { | 3931 if (raw_instantiated && type.IsTypeParameter()) { |
4010 // An uninstantiated type parameter is equivalent to dynamic (even in | 3932 // An uninstantiated type parameter is equivalent to dynamic (even in |
4011 // the presence of a malformed bound in checked mode). | 3933 // the presence of a malformed bound in checked mode). |
4012 continue; | 3934 continue; |
4013 } | 3935 } |
4014 return false; | 3936 return false; |
4015 } | 3937 } |
4016 type_class = type.type_class(); | 3938 type_class = type.type_class(); |
4017 if (!type_class.IsDynamicClass()) { | 3939 if (!type_class.IsDynamicClass()) { |
4018 return false; | 3940 return false; |
4019 } | 3941 } |
4020 } | 3942 } |
4021 return true; | 3943 return true; |
4022 } | 3944 } |
4023 | 3945 |
4024 | 3946 |
4025 bool AbstractTypeArguments::TypeTest(TypeTestKind test_kind, | 3947 bool TypeArguments::TypeTest(TypeTestKind test_kind, |
4026 const AbstractTypeArguments& other, | 3948 const TypeArguments& other, |
4027 intptr_t from_index, | 3949 intptr_t from_index, |
4028 intptr_t len, | 3950 intptr_t len, |
4029 Error* bound_error) const { | 3951 Error* bound_error) const { |
4030 ASSERT(Length() >= (from_index + len)); | 3952 ASSERT(Length() >= (from_index + len)); |
4031 ASSERT(!other.IsNull()); | 3953 ASSERT(!other.IsNull()); |
4032 ASSERT(other.Length() >= (from_index + len)); | 3954 ASSERT(other.Length() >= (from_index + len)); |
4033 AbstractType& type = AbstractType::Handle(); | 3955 AbstractType& type = AbstractType::Handle(); |
4034 AbstractType& other_type = AbstractType::Handle(); | 3956 AbstractType& other_type = AbstractType::Handle(); |
4035 for (intptr_t i = 0; i < len; i++) { | 3957 for (intptr_t i = 0; i < len; i++) { |
4036 type = TypeAt(from_index + i); | 3958 type = TypeAt(from_index + i); |
4037 ASSERT(!type.IsNull()); | 3959 ASSERT(!type.IsNull()); |
4038 other_type = other.TypeAt(from_index + i); | 3960 other_type = other.TypeAt(from_index + i); |
4039 ASSERT(!other_type.IsNull()); | 3961 ASSERT(!other_type.IsNull()); |
4040 if (!type.TypeTest(test_kind, other_type, bound_error)) { | 3962 if (!type.TypeTest(test_kind, other_type, bound_error)) { |
4041 return false; | 3963 return false; |
4042 } | 3964 } |
4043 } | 3965 } |
4044 return true; | 3966 return true; |
4045 } | 3967 } |
4046 | 3968 |
4047 | 3969 |
4048 const char* AbstractTypeArguments::ToCString() const { | 3970 void TypeArguments::PrintToJSONStream(JSONStream* stream, bool ref) const { |
4049 // AbstractTypeArguments is an abstract class, valid only for representing | 3971 JSONObject jsobj(stream); |
4050 // null. | |
4051 if (IsNull()) { | |
4052 return "NULL AbstractTypeArguments"; | |
4053 } | |
4054 UNREACHABLE(); | |
4055 return "AbstractTypeArguments"; | |
4056 } | 3972 } |
4057 | 3973 |
4058 | 3974 |
4059 void AbstractTypeArguments::PrintToJSONStream(JSONStream* stream, | 3975 RawArray* TypeArguments::instantiations() const { |
4060 bool ref) const { | 3976 return raw_ptr()->instantiations_; |
4061 JSONObject jsobj(stream); | 3977 } |
| 3978 |
| 3979 void TypeArguments::set_instantiations(const Array& value) const { |
| 3980 ASSERT(!value.IsNull()); |
| 3981 StorePointer(&raw_ptr()->instantiations_, value.raw()); |
4062 } | 3982 } |
4063 | 3983 |
4064 | 3984 |
4065 intptr_t TypeArguments::Length() const { | 3985 intptr_t TypeArguments::Length() const { |
4066 ASSERT(!IsNull()); | 3986 ASSERT(!IsNull()); |
4067 return Smi::Value(raw_ptr()->length_); | 3987 return Smi::Value(raw_ptr()->length_); |
4068 } | 3988 } |
4069 | 3989 |
4070 | 3990 |
4071 RawAbstractType* TypeArguments::TypeAt(intptr_t index) const { | 3991 RawAbstractType* TypeArguments::TypeAt(intptr_t index) const { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4186 } | 4106 } |
4187 } | 4107 } |
4188 // As a second requirement, the type arguments corresponding to the super type | 4108 // As a second requirement, the type arguments corresponding to the super type |
4189 // must be identical. Overlapping ones have already been checked starting at | 4109 // must be identical. Overlapping ones have already been checked starting at |
4190 // first_type_param_offset. | 4110 // first_type_param_offset. |
4191 if (first_type_param_offset == 0) { | 4111 if (first_type_param_offset == 0) { |
4192 return true; | 4112 return true; |
4193 } | 4113 } |
4194 AbstractType& super_type = AbstractType::Handle( | 4114 AbstractType& super_type = AbstractType::Handle( |
4195 instantiator_class.super_type()); | 4115 instantiator_class.super_type()); |
4196 const AbstractTypeArguments& super_type_args = AbstractTypeArguments::Handle( | 4116 const TypeArguments& super_type_args = TypeArguments::Handle( |
4197 super_type.arguments()); | 4117 super_type.arguments()); |
4198 if (super_type_args.IsNull()) { | 4118 if (super_type_args.IsNull()) { |
4199 return false; | 4119 return false; |
4200 } | 4120 } |
4201 AbstractType& super_type_arg = AbstractType::Handle(); | 4121 AbstractType& super_type_arg = AbstractType::Handle(); |
4202 for (intptr_t i = 0; | 4122 for (intptr_t i = 0; |
4203 (i < first_type_param_offset) && (i < num_type_args); i++) { | 4123 (i < first_type_param_offset) && (i < num_type_args); i++) { |
4204 type_arg = TypeAt(i); | 4124 type_arg = TypeAt(i); |
4205 super_type_arg = super_type_args.TypeAt(i); | 4125 super_type_arg = super_type_args.TypeAt(i); |
4206 if (!type_arg.Equals(super_type_arg)) { | 4126 if (!type_arg.Equals(super_type_arg)) { |
(...skipping 27 matching lines...) Expand all Loading... |
4234 return true; | 4154 return true; |
4235 } | 4155 } |
4236 if (type.IsTypeParameter()) { | 4156 if (type.IsTypeParameter()) { |
4237 const AbstractType& bound = AbstractType::Handle( | 4157 const AbstractType& bound = AbstractType::Handle( |
4238 TypeParameter::Cast(type).bound()); | 4158 TypeParameter::Cast(type).bound()); |
4239 if (!bound.IsObjectType() && !bound.IsDynamicType()) { | 4159 if (!bound.IsObjectType() && !bound.IsDynamicType()) { |
4240 return true; | 4160 return true; |
4241 } | 4161 } |
4242 continue; | 4162 continue; |
4243 } | 4163 } |
4244 const AbstractTypeArguments& type_args = AbstractTypeArguments::Handle( | 4164 const TypeArguments& type_args = TypeArguments::Handle( |
4245 Type::Cast(type).arguments()); | 4165 Type::Cast(type).arguments()); |
4246 if (!type_args.IsNull() && type_args.IsBounded()) { | 4166 if (!type_args.IsNull() && type_args.IsBounded()) { |
4247 return true; | 4167 return true; |
4248 } | 4168 } |
4249 } | 4169 } |
4250 return false; | 4170 return false; |
4251 } | 4171 } |
4252 | 4172 |
4253 | 4173 |
4254 RawAbstractTypeArguments* TypeArguments::InstantiateFrom( | 4174 RawTypeArguments* TypeArguments::InstantiateFrom( |
4255 const AbstractTypeArguments& instantiator_type_arguments, | 4175 const TypeArguments& instantiator_type_arguments, |
4256 Error* bound_error, | 4176 Error* bound_error, |
4257 GrowableObjectArray* trail) const { | 4177 GrowableObjectArray* trail) const { |
4258 ASSERT(!IsInstantiated()); | 4178 ASSERT(!IsInstantiated()); |
4259 if (!instantiator_type_arguments.IsNull() && | 4179 if (!instantiator_type_arguments.IsNull() && |
4260 IsUninstantiatedIdentity() && | 4180 IsUninstantiatedIdentity() && |
4261 (instantiator_type_arguments.Length() == Length())) { | 4181 (instantiator_type_arguments.Length() == Length())) { |
4262 return instantiator_type_arguments.raw(); | 4182 return instantiator_type_arguments.raw(); |
4263 } | 4183 } |
4264 const intptr_t num_types = Length(); | 4184 const intptr_t num_types = Length(); |
4265 TypeArguments& instantiated_array = | 4185 TypeArguments& instantiated_array = |
4266 TypeArguments::Handle(TypeArguments::New(num_types, Heap::kNew)); | 4186 TypeArguments::Handle(TypeArguments::New(num_types, Heap::kNew)); |
4267 AbstractType& type = AbstractType::Handle(); | 4187 AbstractType& type = AbstractType::Handle(); |
4268 for (intptr_t i = 0; i < num_types; i++) { | 4188 for (intptr_t i = 0; i < num_types; i++) { |
4269 type = TypeAt(i); | 4189 type = TypeAt(i); |
4270 if (!type.IsBeingFinalized() && !type.IsInstantiated()) { | 4190 if (!type.IsBeingFinalized() && !type.IsInstantiated()) { |
4271 type = type.InstantiateFrom(instantiator_type_arguments, | 4191 type = type.InstantiateFrom(instantiator_type_arguments, |
4272 bound_error, | 4192 bound_error, |
4273 trail); | 4193 trail); |
4274 } | 4194 } |
4275 instantiated_array.SetTypeAt(i, type); | 4195 instantiated_array.SetTypeAt(i, type); |
4276 } | 4196 } |
4277 return instantiated_array.raw(); | 4197 return instantiated_array.raw(); |
4278 } | 4198 } |
4279 | 4199 |
4280 | 4200 |
| 4201 RawTypeArguments* TypeArguments::InstantiateAndCanonicalizeFrom( |
| 4202 const TypeArguments& instantiator_type_arguments, |
| 4203 Error* bound_error) const { |
| 4204 ASSERT(!IsInstantiated()); |
| 4205 ASSERT(instantiator_type_arguments.IsNull() || |
| 4206 instantiator_type_arguments.IsCanonical()); |
| 4207 // Lookup instantiator and, if found, return paired instantiated result. |
| 4208 Array& prior_instantiations = Array::Handle(instantiations()); |
| 4209 ASSERT(!prior_instantiations.IsNull()); |
| 4210 intptr_t length = prior_instantiations.Length(); |
| 4211 intptr_t index = 0; |
| 4212 while (index < length) { |
| 4213 if (prior_instantiations.At(index) == instantiator_type_arguments.raw()) { |
| 4214 return TypeArguments::RawCast(prior_instantiations.At(index + 1)); |
| 4215 } |
| 4216 if (prior_instantiations.At(index) == Smi::New(StubCode::kNoInstantiator)) { |
| 4217 break; |
| 4218 } |
| 4219 index += 2; |
| 4220 } |
| 4221 // Cache lookup failed. Instantiate the type arguments. |
| 4222 TypeArguments& result = TypeArguments::Handle(); |
| 4223 result = InstantiateFrom(instantiator_type_arguments, bound_error); |
| 4224 if ((bound_error != NULL) && !bound_error->IsNull()) { |
| 4225 return result.raw(); |
| 4226 } |
| 4227 // Instantiation did not result in bound error. Canonicalize type arguments. |
| 4228 result = result.Canonicalize(); |
| 4229 // Add instantiator and result to instantiations array. |
| 4230 if ((index + 2) > length) { |
| 4231 // Grow the instantiations array. |
| 4232 length = (length == 0) ? 2 : length + 4; |
| 4233 prior_instantiations = |
| 4234 Array::Grow(prior_instantiations, length, Heap::kOld); |
| 4235 set_instantiations(prior_instantiations); |
| 4236 } |
| 4237 prior_instantiations.SetAt(index, instantiator_type_arguments); |
| 4238 prior_instantiations.SetAt(index + 1, result); |
| 4239 if ((index + 2) < length) { |
| 4240 prior_instantiations.SetAt(index + 2, |
| 4241 Smi::Handle(Smi::New(StubCode::kNoInstantiator))); |
| 4242 } |
| 4243 return result.raw(); |
| 4244 } |
| 4245 |
| 4246 |
4281 RawTypeArguments* TypeArguments::New(intptr_t len, Heap::Space space) { | 4247 RawTypeArguments* TypeArguments::New(intptr_t len, Heap::Space space) { |
4282 if (len < 0 || len > kMaxElements) { | 4248 if (len < 0 || len > kMaxElements) { |
4283 // This should be caught before we reach here. | 4249 // This should be caught before we reach here. |
4284 FATAL1("Fatal error in TypeArguments::New: invalid len %" Pd "\n", len); | 4250 FATAL1("Fatal error in TypeArguments::New: invalid len %" Pd "\n", len); |
4285 } | 4251 } |
4286 TypeArguments& result = TypeArguments::Handle(); | 4252 TypeArguments& result = TypeArguments::Handle(); |
4287 { | 4253 { |
4288 RawObject* raw = Object::Allocate(TypeArguments::kClassId, | 4254 RawObject* raw = Object::Allocate(TypeArguments::kClassId, |
4289 TypeArguments::InstanceSize(len), | 4255 TypeArguments::InstanceSize(len), |
4290 space); | 4256 space); |
4291 NoGCScope no_gc; | 4257 NoGCScope no_gc; |
4292 result ^= raw; | 4258 result ^= raw; |
4293 // Length must be set before we start storing into the array. | 4259 // Length must be set before we start storing into the array. |
4294 result.SetLength(len); | 4260 result.SetLength(len); |
4295 } | 4261 } |
| 4262 result.set_instantiations(Object::empty_array()); |
4296 return result.raw(); | 4263 return result.raw(); |
4297 } | 4264 } |
4298 | 4265 |
4299 | 4266 |
4300 | 4267 |
4301 RawAbstractType** TypeArguments::TypeAddr(intptr_t index) const { | 4268 RawAbstractType** TypeArguments::TypeAddr(intptr_t index) const { |
4302 // TODO(iposva): Determine if we should throw an exception here. | 4269 // TODO(iposva): Determine if we should throw an exception here. |
4303 ASSERT((index >= 0) && (index < Length())); | 4270 ASSERT((index >= 0) && (index < Length())); |
4304 return &raw_ptr()->types_[index]; | 4271 return &raw_ptr()->types_[index]; |
4305 } | 4272 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4377 TypeArguments& current = TypeArguments::Handle(isolate); | 4344 TypeArguments& current = TypeArguments::Handle(isolate); |
4378 current ^= table.At(index); | 4345 current ^= table.At(index); |
4379 while (!current.IsNull() && !current.Equals(arguments)) { | 4346 while (!current.IsNull() && !current.Equals(arguments)) { |
4380 index = (index + 1) & (table_size - 1); // Move to next element. | 4347 index = (index + 1) & (table_size - 1); // Move to next element. |
4381 current ^= table.At(index); | 4348 current ^= table.At(index); |
4382 } | 4349 } |
4383 return index; // Index of element if found or slot into which to add it. | 4350 return index; // Index of element if found or slot into which to add it. |
4384 } | 4351 } |
4385 | 4352 |
4386 | 4353 |
4387 RawAbstractTypeArguments* TypeArguments::CloneUnfinalized() const { | 4354 RawTypeArguments* TypeArguments::CloneUnfinalized() const { |
4388 if (IsFinalized()) { | 4355 if (IsNull() || IsFinalized()) { |
4389 return raw(); | 4356 return raw(); |
4390 } | 4357 } |
4391 AbstractType& type = AbstractType::Handle(); | 4358 AbstractType& type = AbstractType::Handle(); |
4392 const intptr_t num_types = Length(); | 4359 const intptr_t num_types = Length(); |
4393 const TypeArguments& clone = TypeArguments::Handle( | 4360 const TypeArguments& clone = TypeArguments::Handle( |
4394 TypeArguments::New(num_types)); | 4361 TypeArguments::New(num_types)); |
4395 for (intptr_t i = 0; i < num_types; i++) { | 4362 for (intptr_t i = 0; i < num_types; i++) { |
4396 type = TypeAt(i); | 4363 type = TypeAt(i); |
4397 type = type.CloneUnfinalized(); | 4364 type = type.CloneUnfinalized(); |
4398 clone.SetTypeAt(i, type); | 4365 clone.SetTypeAt(i, type); |
4399 } | 4366 } |
4400 return clone.raw(); | 4367 return clone.raw(); |
4401 } | 4368 } |
4402 | 4369 |
4403 | 4370 |
4404 RawAbstractTypeArguments* TypeArguments::Canonicalize( | 4371 RawTypeArguments* TypeArguments::Canonicalize( |
4405 GrowableObjectArray* trail) const { | 4372 GrowableObjectArray* trail) const { |
4406 if (IsNull() || IsCanonical()) { | 4373 if (IsNull() || IsCanonical()) { |
4407 ASSERT(IsOld()); | 4374 ASSERT(IsOld()); |
4408 return this->raw(); | 4375 return this->raw(); |
4409 } | 4376 } |
4410 Isolate* isolate = Isolate::Current(); | 4377 Isolate* isolate = Isolate::Current(); |
4411 ObjectStore* object_store = isolate->object_store(); | 4378 ObjectStore* object_store = isolate->object_store(); |
4412 const Array& table = Array::Handle(isolate, | 4379 const Array& table = Array::Handle(isolate, |
4413 object_store->canonical_type_arguments()); | 4380 object_store->canonical_type_arguments()); |
4414 ASSERT(table.Length() > 0); | 4381 ASSERT(table.Length() > 0); |
(...skipping 17 matching lines...) Expand all Loading... |
4432 result ^= Object::Clone(*this, Heap::kOld); | 4399 result ^= Object::Clone(*this, Heap::kOld); |
4433 } else { | 4400 } else { |
4434 result ^= this->raw(); | 4401 result ^= this->raw(); |
4435 } | 4402 } |
4436 ASSERT(result.IsOld()); | 4403 ASSERT(result.IsOld()); |
4437 InsertIntoCanonicalTypeArguments(isolate, table, result, index); | 4404 InsertIntoCanonicalTypeArguments(isolate, table, result, index); |
4438 } | 4405 } |
4439 ASSERT(result.Equals(*this)); | 4406 ASSERT(result.Equals(*this)); |
4440 ASSERT(!result.IsNull()); | 4407 ASSERT(!result.IsNull()); |
4441 ASSERT(result.IsTypeArguments()); | 4408 ASSERT(result.IsTypeArguments()); |
| 4409 ASSERT(result.IsCanonical()); |
4442 return result.raw(); | 4410 return result.raw(); |
4443 } | 4411 } |
4444 | 4412 |
4445 | 4413 |
4446 const char* TypeArguments::ToCString() const { | 4414 const char* TypeArguments::ToCString() const { |
4447 if (IsNull()) { | 4415 if (IsNull()) { |
4448 return "NULL TypeArguments"; | 4416 return "NULL TypeArguments"; |
4449 } | 4417 } |
4450 const char* format = "%s [%s]"; | 4418 const char* format = "%s [%s]"; |
4451 const char* prev_cstr = "TypeArguments:"; | 4419 const char* prev_cstr = "TypeArguments:"; |
4452 for (int i = 0; i < Length(); i++) { | 4420 for (int i = 0; i < Length(); i++) { |
4453 const AbstractType& type_at = AbstractType::Handle(TypeAt(i)); | 4421 const AbstractType& type_at = AbstractType::Handle(TypeAt(i)); |
4454 const char* type_cstr = type_at.IsNull() ? "null" : type_at.ToCString(); | 4422 const char* type_cstr = type_at.IsNull() ? "null" : type_at.ToCString(); |
4455 intptr_t len = OS::SNPrint(NULL, 0, format, prev_cstr, type_cstr) + 1; | 4423 intptr_t len = OS::SNPrint(NULL, 0, format, prev_cstr, type_cstr) + 1; |
4456 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 4424 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
4457 OS::SNPrint(chars, len, format, prev_cstr, type_cstr); | 4425 OS::SNPrint(chars, len, format, prev_cstr, type_cstr); |
4458 prev_cstr = chars; | 4426 prev_cstr = chars; |
4459 } | 4427 } |
4460 return prev_cstr; | 4428 return prev_cstr; |
4461 } | 4429 } |
4462 | 4430 |
4463 | 4431 |
4464 void TypeArguments::PrintToJSONStream(JSONStream* stream, bool ref) const { | |
4465 JSONObject jsobj(stream); | |
4466 } | |
4467 | |
4468 | |
4469 intptr_t InstantiatedTypeArguments::Length() const { | |
4470 return AbstractTypeArguments::Handle( | |
4471 uninstantiated_type_arguments()).Length(); | |
4472 } | |
4473 | |
4474 | |
4475 RawAbstractType* InstantiatedTypeArguments::TypeAt(intptr_t index) const { | |
4476 AbstractType& type = AbstractType::Handle(AbstractTypeArguments::Handle( | |
4477 uninstantiated_type_arguments()).TypeAt(index)); | |
4478 if (!type.IsInstantiated()) { | |
4479 const AbstractTypeArguments& instantiator_type_args = | |
4480 AbstractTypeArguments::Handle(instantiator_type_arguments()); | |
4481 Error& bound_error = Error::Handle(); | |
4482 type = type.InstantiateFrom(instantiator_type_args, &bound_error); | |
4483 // InstantiatedTypeArguments cannot include unchecked bounds. | |
4484 // In the presence of unchecked bounds, no InstantiatedTypeArguments are | |
4485 // allocated, but the type arguments are instantiated individually and their | |
4486 // bounds are checked. | |
4487 ASSERT(bound_error.IsNull()); | |
4488 } | |
4489 return type.raw(); | |
4490 } | |
4491 | |
4492 | |
4493 void InstantiatedTypeArguments::SetTypeAt(intptr_t index, | |
4494 const AbstractType& value) const { | |
4495 // We only replace individual argument types during resolution at compile | |
4496 // time, when no type parameters are instantiated yet. | |
4497 UNREACHABLE(); | |
4498 } | |
4499 | |
4500 | |
4501 RawAbstractTypeArguments* InstantiatedTypeArguments::Canonicalize( | |
4502 GrowableObjectArray* trail) const { | |
4503 const intptr_t num_types = Length(); | |
4504 const TypeArguments& type_args = TypeArguments::Handle( | |
4505 TypeArguments::New(num_types, Heap::kOld)); | |
4506 AbstractType& type = AbstractType::Handle(); | |
4507 for (intptr_t i = 0; i < num_types; i++) { | |
4508 type = TypeAt(i); | |
4509 type_args.SetTypeAt(i, type); | |
4510 } | |
4511 return type_args.Canonicalize(trail); | |
4512 } | |
4513 | |
4514 | |
4515 void InstantiatedTypeArguments::set_uninstantiated_type_arguments( | |
4516 const AbstractTypeArguments& value) const { | |
4517 StorePointer(&raw_ptr()->uninstantiated_type_arguments_, value.raw()); | |
4518 } | |
4519 | |
4520 | |
4521 void InstantiatedTypeArguments::set_instantiator_type_arguments( | |
4522 const AbstractTypeArguments& value) const { | |
4523 StorePointer(&raw_ptr()->instantiator_type_arguments_, value.raw()); | |
4524 } | |
4525 | |
4526 | |
4527 RawInstantiatedTypeArguments* InstantiatedTypeArguments::New() { | |
4528 ASSERT(Object::instantiated_type_arguments_class() != Class::null()); | |
4529 RawObject* raw = Object::Allocate(InstantiatedTypeArguments::kClassId, | |
4530 InstantiatedTypeArguments::InstanceSize(), | |
4531 Heap::kNew); | |
4532 return reinterpret_cast<RawInstantiatedTypeArguments*>(raw); | |
4533 } | |
4534 | |
4535 | |
4536 RawInstantiatedTypeArguments* InstantiatedTypeArguments::New( | |
4537 const AbstractTypeArguments& uninstantiated_type_arguments, | |
4538 const AbstractTypeArguments& instantiator_type_arguments) { | |
4539 const InstantiatedTypeArguments& result = | |
4540 InstantiatedTypeArguments::Handle(InstantiatedTypeArguments::New()); | |
4541 result.set_uninstantiated_type_arguments(uninstantiated_type_arguments); | |
4542 result.set_instantiator_type_arguments(instantiator_type_arguments); | |
4543 return result.raw(); | |
4544 } | |
4545 | |
4546 | |
4547 const char* InstantiatedTypeArguments::ToCString() const { | |
4548 if (IsNull()) { | |
4549 return "NULL InstantiatedTypeArguments"; | |
4550 } | |
4551 const char* format = "InstantiatedTypeArguments: [%s] instantiator: [%s]"; | |
4552 const char* arg_cstr = | |
4553 AbstractTypeArguments::Handle( | |
4554 uninstantiated_type_arguments()).ToCString(); | |
4555 const char* instantiator_cstr = | |
4556 AbstractTypeArguments::Handle(instantiator_type_arguments()).ToCString(); | |
4557 intptr_t len = | |
4558 OS::SNPrint(NULL, 0, format, arg_cstr, instantiator_cstr) + 1; | |
4559 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | |
4560 OS::SNPrint(chars, len, format, arg_cstr, instantiator_cstr); | |
4561 return chars; | |
4562 } | |
4563 | |
4564 | |
4565 void InstantiatedTypeArguments::PrintToJSONStream(JSONStream* stream, | |
4566 bool ref) const { | |
4567 JSONObject jsobj(stream); | |
4568 } | |
4569 | |
4570 | |
4571 const char* PatchClass::ToCString() const { | 4432 const char* PatchClass::ToCString() const { |
4572 const char* kFormat = "PatchClass for %s"; | 4433 const char* kFormat = "PatchClass for %s"; |
4573 const Class& cls = Class::Handle(patched_class()); | 4434 const Class& cls = Class::Handle(patched_class()); |
4574 const char* cls_name = cls.ToCString(); | 4435 const char* cls_name = cls.ToCString(); |
4575 intptr_t len = OS::SNPrint(NULL, 0, kFormat, cls_name) + 1; | 4436 intptr_t len = OS::SNPrint(NULL, 0, kFormat, cls_name) + 1; |
4576 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 4437 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
4577 OS::SNPrint(chars, len, kFormat, cls_name); | 4438 OS::SNPrint(chars, len, kFormat, cls_name); |
4578 return chars; | 4439 return chars; |
4579 } | 4440 } |
4580 | 4441 |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5411 return chars; | 5272 return chars; |
5412 } | 5273 } |
5413 | 5274 |
5414 | 5275 |
5415 bool Function::HasCompatibleParametersWith(const Function& other, | 5276 bool Function::HasCompatibleParametersWith(const Function& other, |
5416 Error* bound_error) const { | 5277 Error* bound_error) const { |
5417 ASSERT(FLAG_error_on_bad_override); | 5278 ASSERT(FLAG_error_on_bad_override); |
5418 ASSERT((bound_error != NULL) && bound_error->IsNull()); | 5279 ASSERT((bound_error != NULL) && bound_error->IsNull()); |
5419 // Check that this function's signature type is a subtype of the other | 5280 // Check that this function's signature type is a subtype of the other |
5420 // function's signature type. | 5281 // function's signature type. |
5421 if (!TypeTest(kIsSubtypeOf, Object::null_abstract_type_arguments(), | 5282 if (!TypeTest(kIsSubtypeOf, Object::null_type_arguments(), |
5422 other, Object::null_abstract_type_arguments(), bound_error)) { | 5283 other, Object::null_type_arguments(), bound_error)) { |
5423 // For more informative error reporting, use the location of the other | 5284 // For more informative error reporting, use the location of the other |
5424 // function here, since the caller will use the location of this function. | 5285 // function here, since the caller will use the location of this function. |
5425 *bound_error = LanguageError::NewFormatted( | 5286 *bound_error = LanguageError::NewFormatted( |
5426 *bound_error, // A bound error if non null. | 5287 *bound_error, // A bound error if non null. |
5427 Script::Handle(other.script()), | 5288 Script::Handle(other.script()), |
5428 other.token_pos(), | 5289 other.token_pos(), |
5429 LanguageError::kError, | 5290 LanguageError::kError, |
5430 Heap::kNew, | 5291 Heap::kNew, |
5431 "signature type '%s' of function '%s' is not a subtype of signature " | 5292 "signature type '%s' of function '%s' is not a subtype of signature " |
5432 "type '%s' of function '%s'", | 5293 "type '%s' of function '%s'", |
(...skipping 18 matching lines...) Expand all Loading... |
5451 // parameter of the other function. | 5312 // parameter of the other function. |
5452 // If test_kind == kIsMoreSpecificThan, checks if the type of the specified | 5313 // If test_kind == kIsMoreSpecificThan, checks if the type of the specified |
5453 // parameter of this function is more specific than the type of the specified | 5314 // parameter of this function is more specific than the type of the specified |
5454 // parameter of the other function. | 5315 // parameter of the other function. |
5455 // Note that we do not apply contravariance of parameter types, but covariance | 5316 // Note that we do not apply contravariance of parameter types, but covariance |
5456 // of both parameter types and result type. | 5317 // of both parameter types and result type. |
5457 bool Function::TestParameterType( | 5318 bool Function::TestParameterType( |
5458 TypeTestKind test_kind, | 5319 TypeTestKind test_kind, |
5459 intptr_t parameter_position, | 5320 intptr_t parameter_position, |
5460 intptr_t other_parameter_position, | 5321 intptr_t other_parameter_position, |
5461 const AbstractTypeArguments& type_arguments, | 5322 const TypeArguments& type_arguments, |
5462 const Function& other, | 5323 const Function& other, |
5463 const AbstractTypeArguments& other_type_arguments, | 5324 const TypeArguments& other_type_arguments, |
5464 Error* bound_error) const { | 5325 Error* bound_error) const { |
5465 AbstractType& other_param_type = | 5326 AbstractType& other_param_type = |
5466 AbstractType::Handle(other.ParameterTypeAt(other_parameter_position)); | 5327 AbstractType::Handle(other.ParameterTypeAt(other_parameter_position)); |
5467 if (!other_param_type.IsInstantiated()) { | 5328 if (!other_param_type.IsInstantiated()) { |
5468 other_param_type = other_param_type.InstantiateFrom(other_type_arguments, | 5329 other_param_type = other_param_type.InstantiateFrom(other_type_arguments, |
5469 bound_error); | 5330 bound_error); |
5470 ASSERT((bound_error == NULL) || bound_error->IsNull()); | 5331 ASSERT((bound_error == NULL) || bound_error->IsNull()); |
5471 } | 5332 } |
5472 if (other_param_type.IsDynamicType()) { | 5333 if (other_param_type.IsDynamicType()) { |
5473 return true; | 5334 return true; |
(...skipping 16 matching lines...) Expand all Loading... |
5490 ASSERT(test_kind == kIsMoreSpecificThan); | 5351 ASSERT(test_kind == kIsMoreSpecificThan); |
5491 if (!param_type.IsMoreSpecificThan(other_param_type, bound_error)) { | 5352 if (!param_type.IsMoreSpecificThan(other_param_type, bound_error)) { |
5492 return false; | 5353 return false; |
5493 } | 5354 } |
5494 } | 5355 } |
5495 return true; | 5356 return true; |
5496 } | 5357 } |
5497 | 5358 |
5498 | 5359 |
5499 bool Function::TypeTest(TypeTestKind test_kind, | 5360 bool Function::TypeTest(TypeTestKind test_kind, |
5500 const AbstractTypeArguments& type_arguments, | 5361 const TypeArguments& type_arguments, |
5501 const Function& other, | 5362 const Function& other, |
5502 const AbstractTypeArguments& other_type_arguments, | 5363 const TypeArguments& other_type_arguments, |
5503 Error* bound_error) const { | 5364 Error* bound_error) const { |
5504 const intptr_t num_fixed_params = num_fixed_parameters(); | 5365 const intptr_t num_fixed_params = num_fixed_parameters(); |
5505 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); | 5366 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); |
5506 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); | 5367 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); |
5507 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); | 5368 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); |
5508 const intptr_t other_num_opt_pos_params = | 5369 const intptr_t other_num_opt_pos_params = |
5509 other.NumOptionalPositionalParameters(); | 5370 other.NumOptionalPositionalParameters(); |
5510 const intptr_t other_num_opt_named_params = | 5371 const intptr_t other_num_opt_named_params = |
5511 other.NumOptionalNamedParameters(); | 5372 other.NumOptionalNamedParameters(); |
5512 // This function requires the same arguments or less and accepts the same | 5373 // This function requires the same arguments or less and accepts the same |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5803 const TypeArguments& instantiator = TypeArguments::Handle(); | 5664 const TypeArguments& instantiator = TypeArguments::Handle(); |
5804 BuildSignatureParameters(false, kUserVisibleName, instantiator, pieces); | 5665 BuildSignatureParameters(false, kUserVisibleName, instantiator, pieces); |
5805 const Array& strings = Array::Handle(Array::MakeArray(pieces)); | 5666 const Array& strings = Array::Handle(Array::MakeArray(pieces)); |
5806 return String::ConcatAll(strings); | 5667 return String::ConcatAll(strings); |
5807 } | 5668 } |
5808 | 5669 |
5809 | 5670 |
5810 void Function::BuildSignatureParameters( | 5671 void Function::BuildSignatureParameters( |
5811 bool instantiate, | 5672 bool instantiate, |
5812 NameVisibility name_visibility, | 5673 NameVisibility name_visibility, |
5813 const AbstractTypeArguments& instantiator, | 5674 const TypeArguments& instantiator, |
5814 const GrowableObjectArray& pieces) const { | 5675 const GrowableObjectArray& pieces) const { |
5815 AbstractType& param_type = AbstractType::Handle(); | 5676 AbstractType& param_type = AbstractType::Handle(); |
5816 const intptr_t num_params = NumParameters(); | 5677 const intptr_t num_params = NumParameters(); |
5817 const intptr_t num_fixed_params = num_fixed_parameters(); | 5678 const intptr_t num_fixed_params = num_fixed_parameters(); |
5818 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); | 5679 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); |
5819 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); | 5680 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); |
5820 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; | 5681 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; |
5821 ASSERT((num_fixed_params + num_opt_params) == num_params); | 5682 ASSERT((num_fixed_params + num_opt_params) == num_params); |
5822 String& name = String::Handle(); | 5683 String& name = String::Handle(); |
5823 intptr_t i = 0; | 5684 intptr_t i = 0; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5877 ObjectStore* object_store = Isolate::Current()->object_store(); | 5738 ObjectStore* object_store = Isolate::Current()->object_store(); |
5878 const Context& context = Context::Handle(object_store->empty_context()); | 5739 const Context& context = Context::Handle(object_store->empty_context()); |
5879 const Instance& closure = | 5740 const Instance& closure = |
5880 Instance::Handle(Closure::New(*this, context, Heap::kOld)); | 5741 Instance::Handle(Closure::New(*this, context, Heap::kOld)); |
5881 set_implicit_static_closure(closure); | 5742 set_implicit_static_closure(closure); |
5882 } | 5743 } |
5883 return implicit_static_closure(); | 5744 return implicit_static_closure(); |
5884 } | 5745 } |
5885 | 5746 |
5886 | 5747 |
5887 RawString* Function::BuildSignature( | 5748 RawString* Function::BuildSignature(bool instantiate, |
5888 bool instantiate, | 5749 NameVisibility name_visibility, |
5889 NameVisibility name_visibility, | 5750 const TypeArguments& instantiator) const { |
5890 const AbstractTypeArguments& instantiator) const { | |
5891 const GrowableObjectArray& pieces = | 5751 const GrowableObjectArray& pieces = |
5892 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 5752 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
5893 String& name = String::Handle(); | 5753 String& name = String::Handle(); |
5894 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { | 5754 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { |
5895 // Prefix the signature with its signature class and type parameters, if any | 5755 // Prefix the signature with its signature class and type parameters, if any |
5896 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the | 5756 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the |
5897 // signature class name is the alias name. | 5757 // signature class name is the alias name. |
5898 // The signature of static functions cannot be type parameterized. | 5758 // The signature of static functions cannot be type parameterized. |
5899 const Class& function_class = Class::Handle(Owner()); | 5759 const Class& function_class = Class::Handle(Owner()); |
5900 ASSERT(!function_class.IsNull()); | 5760 ASSERT(!function_class.IsNull()); |
(...skipping 5432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11333 | 11193 |
11334 | 11194 |
11335 intptr_t SubtypeTestCache::NumberOfChecks() const { | 11195 intptr_t SubtypeTestCache::NumberOfChecks() const { |
11336 // Do not count the sentinel; | 11196 // Do not count the sentinel; |
11337 return (Array::Handle(cache()).Length() / kTestEntryLength) - 1; | 11197 return (Array::Handle(cache()).Length() / kTestEntryLength) - 1; |
11338 } | 11198 } |
11339 | 11199 |
11340 | 11200 |
11341 void SubtypeTestCache::AddCheck( | 11201 void SubtypeTestCache::AddCheck( |
11342 intptr_t instance_class_id, | 11202 intptr_t instance_class_id, |
11343 const AbstractTypeArguments& instance_type_arguments, | 11203 const TypeArguments& instance_type_arguments, |
11344 const AbstractTypeArguments& instantiator_type_arguments, | 11204 const TypeArguments& instantiator_type_arguments, |
11345 const Bool& test_result) const { | 11205 const Bool& test_result) const { |
11346 intptr_t old_num = NumberOfChecks(); | 11206 intptr_t old_num = NumberOfChecks(); |
11347 Array& data = Array::Handle(cache()); | 11207 Array& data = Array::Handle(cache()); |
11348 intptr_t new_len = data.Length() + kTestEntryLength; | 11208 intptr_t new_len = data.Length() + kTestEntryLength; |
11349 data = Array::Grow(data, new_len); | 11209 data = Array::Grow(data, new_len); |
11350 set_cache(data); | 11210 set_cache(data); |
11351 intptr_t data_pos = old_num * kTestEntryLength; | 11211 intptr_t data_pos = old_num * kTestEntryLength; |
11352 data.SetAt(data_pos + kInstanceClassId, | 11212 data.SetAt(data_pos + kInstanceClassId, |
11353 Smi::Handle(Smi::New(instance_class_id))); | 11213 Smi::Handle(Smi::New(instance_class_id))); |
11354 data.SetAt(data_pos + kInstanceTypeArguments, instance_type_arguments); | 11214 data.SetAt(data_pos + kInstanceTypeArguments, instance_type_arguments); |
11355 data.SetAt(data_pos + kInstantiatorTypeArguments, | 11215 data.SetAt(data_pos + kInstantiatorTypeArguments, |
11356 instantiator_type_arguments); | 11216 instantiator_type_arguments); |
11357 data.SetAt(data_pos + kTestResult, test_result); | 11217 data.SetAt(data_pos + kTestResult, test_result); |
11358 } | 11218 } |
11359 | 11219 |
11360 | 11220 |
11361 void SubtypeTestCache::GetCheck( | 11221 void SubtypeTestCache::GetCheck(intptr_t ix, |
11362 intptr_t ix, | 11222 intptr_t* instance_class_id, |
11363 intptr_t* instance_class_id, | 11223 TypeArguments* instance_type_arguments, |
11364 AbstractTypeArguments* instance_type_arguments, | 11224 TypeArguments* instantiator_type_arguments, |
11365 AbstractTypeArguments* instantiator_type_arguments, | 11225 Bool* test_result) const { |
11366 Bool* test_result) const { | |
11367 Array& data = Array::Handle(cache()); | 11226 Array& data = Array::Handle(cache()); |
11368 intptr_t data_pos = ix * kTestEntryLength; | 11227 intptr_t data_pos = ix * kTestEntryLength; |
11369 *instance_class_id = | 11228 *instance_class_id = |
11370 Smi::Value(Smi::RawCast(data.At(data_pos + kInstanceClassId))); | 11229 Smi::Value(Smi::RawCast(data.At(data_pos + kInstanceClassId))); |
11371 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments); | 11230 *instance_type_arguments ^= data.At(data_pos + kInstanceTypeArguments); |
11372 *instantiator_type_arguments ^= | 11231 *instantiator_type_arguments ^= |
11373 data.At(data_pos + kInstantiatorTypeArguments); | 11232 data.At(data_pos + kInstantiatorTypeArguments); |
11374 *test_result ^= data.At(data_pos + kTestResult); | 11233 *test_result ^= data.At(data_pos + kTestResult); |
11375 } | 11234 } |
11376 | 11235 |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11911 } | 11770 } |
11912 | 11771 |
11913 | 11772 |
11914 RawType* Instance::GetType() const { | 11773 RawType* Instance::GetType() const { |
11915 if (IsNull()) { | 11774 if (IsNull()) { |
11916 return Type::NullType(); | 11775 return Type::NullType(); |
11917 } | 11776 } |
11918 const Class& cls = Class::Handle(clazz()); | 11777 const Class& cls = Class::Handle(clazz()); |
11919 Type& type = Type::Handle(cls.CanonicalType()); | 11778 Type& type = Type::Handle(cls.CanonicalType()); |
11920 if (type.IsNull()) { | 11779 if (type.IsNull()) { |
11921 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); | 11780 TypeArguments& type_arguments = TypeArguments::Handle(); |
11922 if (cls.NumTypeArguments() > 0) { | 11781 if (cls.NumTypeArguments() > 0) { |
11923 type_arguments = GetTypeArguments(); | 11782 type_arguments = GetTypeArguments(); |
11924 } | 11783 } |
11925 type = Type::New(cls, type_arguments, Scanner::kNoSourcePos); | 11784 type = Type::New(cls, type_arguments, Scanner::kNoSourcePos); |
11926 type.SetIsFinalized(); | 11785 type.SetIsFinalized(); |
11927 type ^= type.Canonicalize(); | 11786 type ^= type.Canonicalize(); |
11928 } | 11787 } |
11929 return type.raw(); | 11788 return type.raw(); |
11930 } | 11789 } |
11931 | 11790 |
11932 | 11791 |
11933 RawAbstractTypeArguments* Instance::GetTypeArguments() const { | 11792 RawTypeArguments* Instance::GetTypeArguments() const { |
11934 const Class& cls = Class::Handle(clazz()); | 11793 const Class& cls = Class::Handle(clazz()); |
11935 intptr_t field_offset = cls.type_arguments_field_offset(); | 11794 intptr_t field_offset = cls.type_arguments_field_offset(); |
11936 ASSERT(field_offset != Class::kNoTypeArguments); | 11795 ASSERT(field_offset != Class::kNoTypeArguments); |
11937 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); | 11796 TypeArguments& type_arguments = TypeArguments::Handle(); |
11938 type_arguments ^= *FieldAddrAtOffset(field_offset); | 11797 type_arguments ^= *FieldAddrAtOffset(field_offset); |
11939 return type_arguments.raw(); | 11798 return type_arguments.raw(); |
11940 } | 11799 } |
11941 | 11800 |
11942 | 11801 |
11943 void Instance::SetTypeArguments(const AbstractTypeArguments& value) const { | 11802 void Instance::SetTypeArguments(const TypeArguments& value) const { |
| 11803 ASSERT(value.IsNull() || value.IsCanonical()); |
11944 const Class& cls = Class::Handle(clazz()); | 11804 const Class& cls = Class::Handle(clazz()); |
11945 intptr_t field_offset = cls.type_arguments_field_offset(); | 11805 intptr_t field_offset = cls.type_arguments_field_offset(); |
11946 ASSERT(field_offset != Class::kNoTypeArguments); | 11806 ASSERT(field_offset != Class::kNoTypeArguments); |
11947 SetFieldAtOffset(field_offset, value); | 11807 SetFieldAtOffset(field_offset, value); |
11948 } | 11808 } |
11949 | 11809 |
11950 | 11810 |
11951 bool Instance::IsInstanceOf(const AbstractType& other, | 11811 bool Instance::IsInstanceOf(const AbstractType& other, |
11952 const AbstractTypeArguments& other_instantiator, | 11812 const TypeArguments& other_instantiator, |
11953 Error* bound_error) const { | 11813 Error* bound_error) const { |
11954 ASSERT(other.IsFinalized()); | 11814 ASSERT(other.IsFinalized()); |
11955 ASSERT(!other.IsDynamicType()); | 11815 ASSERT(!other.IsDynamicType()); |
11956 ASSERT(!other.IsMalformed()); | 11816 ASSERT(!other.IsMalformed()); |
11957 ASSERT(!other.IsMalbounded()); | 11817 ASSERT(!other.IsMalbounded()); |
11958 if (other.IsVoidType()) { | 11818 if (other.IsVoidType()) { |
11959 return false; | 11819 return false; |
11960 } | 11820 } |
11961 Isolate* isolate = Isolate::Current(); | 11821 Isolate* isolate = Isolate::Current(); |
11962 const Class& cls = Class::Handle(isolate, clazz()); | 11822 const Class& cls = Class::Handle(isolate, clazz()); |
11963 AbstractTypeArguments& type_arguments = | 11823 TypeArguments& type_arguments = |
11964 AbstractTypeArguments::Handle(isolate); | 11824 TypeArguments::Handle(isolate); |
11965 if (cls.NumTypeArguments() > 0) { | 11825 if (cls.NumTypeArguments() > 0) { |
11966 type_arguments = GetTypeArguments(); | 11826 type_arguments = GetTypeArguments(); |
11967 if (!type_arguments.IsNull() && !type_arguments.IsCanonical()) { | 11827 ASSERT(type_arguments.IsNull() || type_arguments.IsCanonical()); |
11968 type_arguments = type_arguments.Canonicalize(); | |
11969 SetTypeArguments(type_arguments); | |
11970 } | |
11971 // The number of type arguments in the instance must be greater or equal to | 11828 // The number of type arguments in the instance must be greater or equal to |
11972 // the number of type arguments expected by the instance class. | 11829 // the number of type arguments expected by the instance class. |
11973 // A discrepancy is allowed for closures, which borrow the type argument | 11830 // A discrepancy is allowed for closures, which borrow the type argument |
11974 // vector of their instantiator, which may be of a subclass of the class | 11831 // vector of their instantiator, which may be of a subclass of the class |
11975 // defining the closure. Truncating the vector to the correct length on | 11832 // defining the closure. Truncating the vector to the correct length on |
11976 // instantiation is unnecessary. The vector may therefore be longer. | 11833 // instantiation is unnecessary. The vector may therefore be longer. |
11977 // Also, an optimization reuses the type argument vector of the instantiator | 11834 // Also, an optimization reuses the type argument vector of the instantiator |
11978 // of generic instances when its layout is compatible. | 11835 // of generic instances when its layout is compatible. |
11979 ASSERT(type_arguments.IsNull() || | 11836 ASSERT(type_arguments.IsNull() || |
11980 (type_arguments.Length() >= cls.NumTypeArguments())); | 11837 (type_arguments.Length() >= cls.NumTypeArguments())); |
11981 } | 11838 } |
11982 Class& other_class = Class::Handle(isolate); | 11839 Class& other_class = Class::Handle(isolate); |
11983 AbstractTypeArguments& other_type_arguments = | 11840 TypeArguments& other_type_arguments = TypeArguments::Handle(isolate); |
11984 AbstractTypeArguments::Handle(isolate); | |
11985 // Note that we may encounter a bound error in checked mode. | 11841 // Note that we may encounter a bound error in checked mode. |
11986 if (!other.IsInstantiated()) { | 11842 if (!other.IsInstantiated()) { |
11987 const AbstractType& instantiated_other = AbstractType::Handle( | 11843 const AbstractType& instantiated_other = AbstractType::Handle( |
11988 isolate, other.InstantiateFrom(other_instantiator, bound_error)); | 11844 isolate, other.InstantiateFrom(other_instantiator, bound_error)); |
11989 if ((bound_error != NULL) && !bound_error->IsNull()) { | 11845 if ((bound_error != NULL) && !bound_error->IsNull()) { |
11990 ASSERT(FLAG_enable_type_checks); | 11846 ASSERT(FLAG_enable_type_checks); |
11991 return false; | 11847 return false; |
11992 } | 11848 } |
11993 other_class = instantiated_other.type_class(); | 11849 other_class = instantiated_other.type_class(); |
11994 other_type_arguments = instantiated_other.arguments(); | 11850 other_type_arguments = instantiated_other.arguments(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12101 return "non_constant"; | 11957 return "non_constant"; |
12102 } else if (Isolate::Current()->no_gc_scope_depth() > 0) { | 11958 } else if (Isolate::Current()->no_gc_scope_depth() > 0) { |
12103 // Can occur when running disassembler. | 11959 // Can occur when running disassembler. |
12104 return "Instance"; | 11960 return "Instance"; |
12105 } else { | 11961 } else { |
12106 if (IsClosure()) { | 11962 if (IsClosure()) { |
12107 return Closure::ToCString(*this); | 11963 return Closure::ToCString(*this); |
12108 } | 11964 } |
12109 const char* kFormat = "Instance of '%s'"; | 11965 const char* kFormat = "Instance of '%s'"; |
12110 const Class& cls = Class::Handle(clazz()); | 11966 const Class& cls = Class::Handle(clazz()); |
12111 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); | 11967 TypeArguments& type_arguments = TypeArguments::Handle(); |
12112 const intptr_t num_type_arguments = cls.NumTypeArguments(); | 11968 const intptr_t num_type_arguments = cls.NumTypeArguments(); |
12113 if (num_type_arguments > 0) { | 11969 if (num_type_arguments > 0) { |
12114 type_arguments = GetTypeArguments(); | 11970 type_arguments = GetTypeArguments(); |
12115 } | 11971 } |
12116 const Type& type = | 11972 const Type& type = |
12117 Type::Handle(Type::New(cls, type_arguments, Scanner::kNoSourcePos)); | 11973 Type::Handle(Type::New(cls, type_arguments, Scanner::kNoSourcePos)); |
12118 const String& type_name = String::Handle(type.UserVisibleName()); | 11974 const String& type_name = String::Handle(type.UserVisibleName()); |
12119 // Calculate the size of the string. | 11975 // Calculate the size of the string. |
12120 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1; | 11976 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1; |
12121 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 11977 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12209 } | 12065 } |
12210 | 12066 |
12211 | 12067 |
12212 RawUnresolvedClass* AbstractType::unresolved_class() const { | 12068 RawUnresolvedClass* AbstractType::unresolved_class() const { |
12213 // AbstractType is an abstract class. | 12069 // AbstractType is an abstract class. |
12214 UNREACHABLE(); | 12070 UNREACHABLE(); |
12215 return UnresolvedClass::null(); | 12071 return UnresolvedClass::null(); |
12216 } | 12072 } |
12217 | 12073 |
12218 | 12074 |
12219 RawAbstractTypeArguments* AbstractType::arguments() const { | 12075 RawTypeArguments* AbstractType::arguments() const { |
12220 // AbstractType is an abstract class. | 12076 // AbstractType is an abstract class. |
12221 UNREACHABLE(); | 12077 UNREACHABLE(); |
12222 return NULL; | 12078 return NULL; |
12223 } | 12079 } |
12224 | 12080 |
12225 | 12081 |
12226 intptr_t AbstractType::token_pos() const { | 12082 intptr_t AbstractType::token_pos() const { |
12227 // AbstractType is an abstract class. | 12083 // AbstractType is an abstract class. |
12228 UNREACHABLE(); | 12084 UNREACHABLE(); |
12229 return -1; | 12085 return -1; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12287 | 12143 |
12288 bool AbstractType::IsEquivalent(const Instance& other, | 12144 bool AbstractType::IsEquivalent(const Instance& other, |
12289 GrowableObjectArray* trail) const { | 12145 GrowableObjectArray* trail) const { |
12290 // AbstractType is an abstract class. | 12146 // AbstractType is an abstract class. |
12291 UNREACHABLE(); | 12147 UNREACHABLE(); |
12292 return false; | 12148 return false; |
12293 } | 12149 } |
12294 | 12150 |
12295 | 12151 |
12296 RawAbstractType* AbstractType::InstantiateFrom( | 12152 RawAbstractType* AbstractType::InstantiateFrom( |
12297 const AbstractTypeArguments& instantiator_type_arguments, | 12153 const TypeArguments& instantiator_type_arguments, |
12298 Error* bound_error, | 12154 Error* bound_error, |
12299 GrowableObjectArray* trail) const { | 12155 GrowableObjectArray* trail) const { |
12300 // AbstractType is an abstract class. | 12156 // AbstractType is an abstract class. |
12301 UNREACHABLE(); | 12157 UNREACHABLE(); |
12302 return NULL; | 12158 return NULL; |
12303 } | 12159 } |
12304 | 12160 |
12305 | 12161 |
12306 RawAbstractType* AbstractType::CloneUnfinalized() const { | 12162 RawAbstractType* AbstractType::CloneUnfinalized() const { |
12307 // AbstractType is an abstract class. | 12163 // AbstractType is an abstract class. |
(...skipping 20 matching lines...) Expand all Loading... |
12328 type_name = String::Concat(type_name, Symbols::SpaceExtendsSpace()); | 12184 type_name = String::Concat(type_name, Symbols::SpaceExtendsSpace()); |
12329 // Build the bound name without causing divergence. | 12185 // Build the bound name without causing divergence. |
12330 const AbstractType& bound = AbstractType::Handle( | 12186 const AbstractType& bound = AbstractType::Handle( |
12331 BoundedType::Cast(*this).bound()); | 12187 BoundedType::Cast(*this).bound()); |
12332 String& bound_name = String::Handle(); | 12188 String& bound_name = String::Handle(); |
12333 if (bound.IsTypeParameter()) { | 12189 if (bound.IsTypeParameter()) { |
12334 bound_name = TypeParameter::Cast(bound).name(); | 12190 bound_name = TypeParameter::Cast(bound).name(); |
12335 } else if (bound.IsType()) { | 12191 } else if (bound.IsType()) { |
12336 const Class& cls = Class::Handle(Type::Cast(bound).type_class()); | 12192 const Class& cls = Class::Handle(Type::Cast(bound).type_class()); |
12337 bound_name = cls.Name(); | 12193 bound_name = cls.Name(); |
12338 if (Type::Cast(bound).arguments() != AbstractTypeArguments::null()) { | 12194 if (Type::Cast(bound).arguments() != TypeArguments::null()) { |
12339 bound_name = String::Concat(bound_name, Symbols::OptimizedOut()); | 12195 bound_name = String::Concat(bound_name, Symbols::OptimizedOut()); |
12340 } | 12196 } |
12341 } else { | 12197 } else { |
12342 bound_name = String::New(Symbols::OptimizedOut()); | 12198 bound_name = String::New(Symbols::OptimizedOut()); |
12343 } | 12199 } |
12344 type_name = String::Concat(type_name, bound_name); | 12200 type_name = String::Concat(type_name, bound_name); |
12345 return Symbols::New(type_name); | 12201 return Symbols::New(type_name); |
12346 } | 12202 } |
12347 if (IsTypeParameter()) { | 12203 if (IsTypeParameter()) { |
12348 return TypeParameter::Cast(*this).name(); | 12204 return TypeParameter::Cast(*this).name(); |
12349 } | 12205 } |
12350 // If the type is still being finalized, we may be reporting an error about | 12206 // If the type is still being finalized, we may be reporting an error about |
12351 // a malformed type, so proceed with caution. | 12207 // a malformed type, so proceed with caution. |
12352 const AbstractTypeArguments& args = | 12208 const TypeArguments& args = TypeArguments::Handle(arguments()); |
12353 AbstractTypeArguments::Handle(arguments()); | |
12354 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); | 12209 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); |
12355 String& class_name = String::Handle(); | 12210 String& class_name = String::Handle(); |
12356 intptr_t first_type_param_index; | 12211 intptr_t first_type_param_index; |
12357 intptr_t num_type_params; // Number of type parameters to print. | 12212 intptr_t num_type_params; // Number of type parameters to print. |
12358 if (HasResolvedTypeClass()) { | 12213 if (HasResolvedTypeClass()) { |
12359 const Class& cls = Class::Handle(type_class()); | 12214 const Class& cls = Class::Handle(type_class()); |
12360 num_type_params = cls.NumTypeParameters(); // Do not print the full vector. | 12215 num_type_params = cls.NumTypeParameters(); // Do not print the full vector. |
12361 if (name_visibility == kInternalName) { | 12216 if (name_visibility == kInternalName) { |
12362 class_name = cls.Name(); | 12217 class_name = cls.Name(); |
12363 } else { | 12218 } else { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12552 if (bound.IsMoreSpecificThan(other, bound_error)) { | 12407 if (bound.IsMoreSpecificThan(other, bound_error)) { |
12553 return true; | 12408 return true; |
12554 } | 12409 } |
12555 return false; // TODO(regis): We should return "maybe after instantiation". | 12410 return false; // TODO(regis): We should return "maybe after instantiation". |
12556 } | 12411 } |
12557 if (other.IsTypeParameter()) { | 12412 if (other.IsTypeParameter()) { |
12558 return false; // TODO(regis): We should return "maybe after instantiation". | 12413 return false; // TODO(regis): We should return "maybe after instantiation". |
12559 } | 12414 } |
12560 const Class& cls = Class::Handle(type_class()); | 12415 const Class& cls = Class::Handle(type_class()); |
12561 return cls.TypeTest(test_kind, | 12416 return cls.TypeTest(test_kind, |
12562 AbstractTypeArguments::Handle(arguments()), | 12417 TypeArguments::Handle(arguments()), |
12563 Class::Handle(other.type_class()), | 12418 Class::Handle(other.type_class()), |
12564 AbstractTypeArguments::Handle(other.arguments()), | 12419 TypeArguments::Handle(other.arguments()), |
12565 bound_error); | 12420 bound_error); |
12566 } | 12421 } |
12567 | 12422 |
12568 | 12423 |
12569 intptr_t AbstractType::Hash() const { | 12424 intptr_t AbstractType::Hash() const { |
12570 // AbstractType is an abstract class. | 12425 // AbstractType is an abstract class. |
12571 UNREACHABLE(); | 12426 UNREACHABLE(); |
12572 return 0; | 12427 return 0; |
12573 } | 12428 } |
12574 | 12429 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12745 } | 12600 } |
12746 | 12601 |
12747 | 12602 |
12748 bool Type::IsResolved() const { | 12603 bool Type::IsResolved() const { |
12749 if (IsFinalized()) { | 12604 if (IsFinalized()) { |
12750 return true; | 12605 return true; |
12751 } | 12606 } |
12752 if (!HasResolvedTypeClass()) { | 12607 if (!HasResolvedTypeClass()) { |
12753 return false; | 12608 return false; |
12754 } | 12609 } |
12755 const AbstractTypeArguments& args = | 12610 const TypeArguments& args = TypeArguments::Handle(arguments()); |
12756 AbstractTypeArguments::Handle(arguments()); | |
12757 return args.IsNull() || args.IsResolved(); | 12611 return args.IsNull() || args.IsResolved(); |
12758 } | 12612 } |
12759 | 12613 |
12760 | 12614 |
12761 bool Type::HasResolvedTypeClass() const { | 12615 bool Type::HasResolvedTypeClass() const { |
12762 const Object& type_class = Object::Handle(raw_ptr()->type_class_); | 12616 const Object& type_class = Object::Handle(raw_ptr()->type_class_); |
12763 return !type_class.IsNull() && type_class.IsClass(); | 12617 return !type_class.IsNull() && type_class.IsClass(); |
12764 } | 12618 } |
12765 | 12619 |
12766 | 12620 |
(...skipping 17 matching lines...) Expand all Loading... |
12784 ASSERT(!unresolved_class.IsNull()); | 12638 ASSERT(!unresolved_class.IsNull()); |
12785 return unresolved_class.raw(); | 12639 return unresolved_class.raw(); |
12786 #else | 12640 #else |
12787 ASSERT(!Object::Handle(raw_ptr()->type_class_).IsNull()); | 12641 ASSERT(!Object::Handle(raw_ptr()->type_class_).IsNull()); |
12788 ASSERT(Object::Handle(raw_ptr()->type_class_).IsUnresolvedClass()); | 12642 ASSERT(Object::Handle(raw_ptr()->type_class_).IsUnresolvedClass()); |
12789 return reinterpret_cast<RawUnresolvedClass*>(raw_ptr()->type_class_); | 12643 return reinterpret_cast<RawUnresolvedClass*>(raw_ptr()->type_class_); |
12790 #endif | 12644 #endif |
12791 } | 12645 } |
12792 | 12646 |
12793 | 12647 |
12794 RawAbstractTypeArguments* Type::arguments() const { | 12648 RawTypeArguments* Type::arguments() const { |
12795 return raw_ptr()->arguments_; | 12649 return raw_ptr()->arguments_; |
12796 } | 12650 } |
12797 | 12651 |
12798 | 12652 |
12799 bool Type::IsInstantiated(GrowableObjectArray* trail) const { | 12653 bool Type::IsInstantiated(GrowableObjectArray* trail) const { |
12800 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) { | 12654 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) { |
12801 return true; | 12655 return true; |
12802 } | 12656 } |
12803 if (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated) { | 12657 if (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated) { |
12804 return false; | 12658 return false; |
12805 } | 12659 } |
12806 const AbstractTypeArguments& args = | 12660 const TypeArguments& args = TypeArguments::Handle(arguments()); |
12807 AbstractTypeArguments::Handle(arguments()); | |
12808 return args.IsNull() || args.IsInstantiated(trail); | 12661 return args.IsNull() || args.IsInstantiated(trail); |
12809 } | 12662 } |
12810 | 12663 |
12811 | 12664 |
12812 RawAbstractType* Type::InstantiateFrom( | 12665 RawAbstractType* Type::InstantiateFrom( |
12813 const AbstractTypeArguments& instantiator_type_arguments, | 12666 const TypeArguments& instantiator_type_arguments, |
12814 Error* bound_error, | 12667 Error* bound_error, |
12815 GrowableObjectArray* trail) const { | 12668 GrowableObjectArray* trail) const { |
12816 ASSERT(IsFinalized() || IsBeingFinalized()); | 12669 ASSERT(IsFinalized() || IsBeingFinalized()); |
12817 ASSERT(!IsInstantiated()); | 12670 ASSERT(!IsInstantiated()); |
12818 // Return the uninstantiated type unchanged if malformed. No copy needed. | 12671 // Return the uninstantiated type unchanged if malformed. No copy needed. |
12819 if (IsMalformed()) { | 12672 if (IsMalformed()) { |
12820 return raw(); | 12673 return raw(); |
12821 } | 12674 } |
12822 AbstractTypeArguments& type_arguments = | 12675 TypeArguments& type_arguments = TypeArguments::Handle(arguments()); |
12823 AbstractTypeArguments::Handle(arguments()); | |
12824 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, | 12676 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, |
12825 bound_error, | 12677 bound_error, |
12826 trail); | 12678 trail); |
12827 // Note that the type class has to be resolved at this time, but not | 12679 // Note that the type class has to be resolved at this time, but not |
12828 // necessarily finalized yet. We may be checking bounds at compile time. | 12680 // necessarily finalized yet. We may be checking bounds at compile time. |
12829 const Class& cls = Class::Handle(type_class()); | 12681 const Class& cls = Class::Handle(type_class()); |
12830 // This uninstantiated type is not modified, as it can be instantiated | 12682 // This uninstantiated type is not modified, as it can be instantiated |
12831 // with different instantiators. | 12683 // with different instantiators. |
12832 Type& instantiated_type = Type::Handle( | 12684 Type& instantiated_type = Type::Handle( |
12833 Type::New(cls, type_arguments, token_pos())); | 12685 Type::New(cls, type_arguments, token_pos())); |
12834 ASSERT(type_arguments.IsNull() || | 12686 ASSERT(type_arguments.IsNull() || |
12835 (type_arguments.Length() == cls.NumTypeArguments())); | 12687 (type_arguments.Length() == cls.NumTypeArguments())); |
12836 instantiated_type.SetIsFinalized(); | 12688 instantiated_type.SetIsFinalized(); |
| 12689 // Canonicalization is not part of instantiation. |
12837 return instantiated_type.raw(); | 12690 return instantiated_type.raw(); |
12838 } | 12691 } |
12839 | 12692 |
12840 | 12693 |
12841 bool Type::IsEquivalent(const Instance& other, | 12694 bool Type::IsEquivalent(const Instance& other, |
12842 GrowableObjectArray* trail) const { | 12695 GrowableObjectArray* trail) const { |
12843 ASSERT(!IsNull()); | 12696 ASSERT(!IsNull()); |
12844 if (raw() == other.raw()) { | 12697 if (raw() == other.raw()) { |
12845 return true; | 12698 return true; |
12846 } | 12699 } |
(...skipping 22 matching lines...) Expand all Loading... |
12869 return true; | 12722 return true; |
12870 } | 12723 } |
12871 const Class& cls = Class::Handle(type_class()); | 12724 const Class& cls = Class::Handle(type_class()); |
12872 const intptr_t num_type_params = cls.NumTypeParameters(); | 12725 const intptr_t num_type_params = cls.NumTypeParameters(); |
12873 if (num_type_params == 0) { | 12726 if (num_type_params == 0) { |
12874 // Shortcut unnecessary handle allocation below. | 12727 // Shortcut unnecessary handle allocation below. |
12875 return true; | 12728 return true; |
12876 } | 12729 } |
12877 const intptr_t num_type_args = cls.NumTypeArguments(); | 12730 const intptr_t num_type_args = cls.NumTypeArguments(); |
12878 const intptr_t from_index = num_type_args - num_type_params; | 12731 const intptr_t from_index = num_type_args - num_type_params; |
12879 const AbstractTypeArguments& type_args = AbstractTypeArguments::Handle( | 12732 const TypeArguments& type_args = TypeArguments::Handle(arguments()); |
12880 arguments()); | 12733 const TypeArguments& other_type_args = TypeArguments::Handle( |
12881 const AbstractTypeArguments& other_type_args = AbstractTypeArguments::Handle( | |
12882 other_type.arguments()); | 12734 other_type.arguments()); |
12883 if (type_args.IsNull()) { | 12735 if (type_args.IsNull()) { |
12884 return other_type_args.IsRaw(from_index, num_type_params); | 12736 return other_type_args.IsRaw(from_index, num_type_params); |
12885 } | 12737 } |
12886 if (other_type_args.IsNull()) { | 12738 if (other_type_args.IsNull()) { |
12887 return type_args.IsRaw(from_index, num_type_params); | 12739 return type_args.IsRaw(from_index, num_type_params); |
12888 } | 12740 } |
12889 ASSERT(type_args.Length() >= (from_index + num_type_params)); | 12741 ASSERT(type_args.Length() >= (from_index + num_type_params)); |
12890 ASSERT(other_type_args.Length() >= (from_index + num_type_params)); | 12742 ASSERT(other_type_args.Length() >= (from_index + num_type_params)); |
12891 AbstractType& type_arg = AbstractType::Handle(); | 12743 AbstractType& type_arg = AbstractType::Handle(); |
12892 AbstractType& other_type_arg = AbstractType::Handle(); | 12744 AbstractType& other_type_arg = AbstractType::Handle(); |
12893 for (intptr_t i = 0; i < num_type_params; i++) { | 12745 for (intptr_t i = 0; i < num_type_params; i++) { |
12894 type_arg = type_args.TypeAt(from_index + i); | 12746 type_arg = type_args.TypeAt(from_index + i); |
12895 other_type_arg = other_type_args.TypeAt(from_index + i); | 12747 other_type_arg = other_type_args.TypeAt(from_index + i); |
12896 if (!type_arg.IsEquivalent(other_type_arg, trail)) { | 12748 if (!type_arg.IsEquivalent(other_type_arg, trail)) { |
12897 return false; | 12749 return false; |
12898 } | 12750 } |
12899 } | 12751 } |
12900 return true; | 12752 return true; |
12901 } | 12753 } |
12902 | 12754 |
12903 | 12755 |
12904 RawAbstractType* Type::CloneUnfinalized() const { | 12756 RawAbstractType* Type::CloneUnfinalized() const { |
12905 ASSERT(IsResolved()); | 12757 ASSERT(IsResolved()); |
12906 if (IsFinalized()) { | 12758 if (IsFinalized()) { |
12907 return raw(); | 12759 return raw(); |
12908 } | 12760 } |
12909 ASSERT(!IsMalformed()); // Malformed types are finalized. | 12761 ASSERT(!IsMalformed()); // Malformed types are finalized. |
12910 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. | 12762 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. |
12911 AbstractTypeArguments& type_args = AbstractTypeArguments::Handle(arguments()); | 12763 TypeArguments& type_args = TypeArguments::Handle(arguments()); |
12912 type_args = type_args.CloneUnfinalized(); | 12764 type_args = type_args.CloneUnfinalized(); |
12913 const Class& type_cls = Class::Handle(type_class()); | 12765 const Class& type_cls = Class::Handle(type_class()); |
12914 return Type::New(type_cls, type_args, token_pos()); | 12766 return Type::New(type_cls, type_args, token_pos()); |
12915 } | 12767 } |
12916 | 12768 |
12917 | 12769 |
12918 RawAbstractType* Type::Canonicalize(GrowableObjectArray* trail) const { | 12770 RawAbstractType* Type::Canonicalize(GrowableObjectArray* trail) const { |
12919 ASSERT(IsFinalized()); | 12771 ASSERT(IsFinalized()); |
12920 if (IsCanonical() || IsMalformed()) { | 12772 if (IsCanonical() || IsMalformed()) { |
12921 ASSERT(IsMalformed() || AbstractTypeArguments::Handle(arguments()).IsOld()); | 12773 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld()); |
12922 return this->raw(); | 12774 return this->raw(); |
12923 } | 12775 } |
12924 Isolate* isolate = Isolate::Current(); | 12776 Isolate* isolate = Isolate::Current(); |
12925 Type& type = Type::Handle(isolate); | 12777 Type& type = Type::Handle(isolate); |
12926 const Class& cls = Class::Handle(isolate, type_class()); | 12778 const Class& cls = Class::Handle(isolate, type_class()); |
12927 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) { | 12779 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) { |
12928 return Object::dynamic_type(); | 12780 return Object::dynamic_type(); |
12929 } | 12781 } |
12930 // Fast canonical lookup/registry for simple types. | 12782 // Fast canonical lookup/registry for simple types. |
12931 if ((cls.NumTypeArguments() == 0) && !cls.IsSignatureClass()) { | 12783 if ((cls.NumTypeArguments() == 0) && !cls.IsSignatureClass()) { |
(...skipping 24 matching lines...) Expand all Loading... |
12956 if (type.IsNull()) { | 12808 if (type.IsNull()) { |
12957 break; | 12809 break; |
12958 } | 12810 } |
12959 ASSERT(type.IsFinalized()); | 12811 ASSERT(type.IsFinalized()); |
12960 if (this->Equals(type)) { | 12812 if (this->Equals(type)) { |
12961 return type.raw(); | 12813 return type.raw(); |
12962 } | 12814 } |
12963 index++; | 12815 index++; |
12964 } | 12816 } |
12965 // Canonicalize the type arguments. | 12817 // Canonicalize the type arguments. |
12966 AbstractTypeArguments& type_args = | 12818 TypeArguments& type_args = TypeArguments::Handle(isolate, arguments()); |
12967 AbstractTypeArguments::Handle(isolate, arguments()); | |
12968 // In case the type is first canonicalized at runtime, its type argument | 12819 // In case the type is first canonicalized at runtime, its type argument |
12969 // vector may be longer than necessary. This is not an issue. | 12820 // vector may be longer than necessary. This is not an issue. |
12970 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments())); | 12821 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments())); |
12971 type_args = type_args.Canonicalize(trail); | 12822 type_args = type_args.Canonicalize(trail); |
12972 set_arguments(type_args); | 12823 set_arguments(type_args); |
12973 // The type needs to be added to the list. Grow the list if it is full. | 12824 // The type needs to be added to the list. Grow the list if it is full. |
12974 if (index == canonical_types_len) { | 12825 if (index == canonical_types_len) { |
12975 const intptr_t kLengthIncrement = 2; // Raw and parameterized. | 12826 const intptr_t kLengthIncrement = 2; // Raw and parameterized. |
12976 const intptr_t new_length = canonical_types.Length() + kLengthIncrement; | 12827 const intptr_t new_length = canonical_types.Length() + kLengthIncrement; |
12977 const Array& new_canonical_types = Array::Handle( | 12828 const Array& new_canonical_types = Array::Handle( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13010 SetCanonical(); | 12861 SetCanonical(); |
13011 return this->raw(); | 12862 return this->raw(); |
13012 } | 12863 } |
13013 | 12864 |
13014 | 12865 |
13015 intptr_t Type::Hash() const { | 12866 intptr_t Type::Hash() const { |
13016 ASSERT(IsFinalized()); | 12867 ASSERT(IsFinalized()); |
13017 uword result = 1; | 12868 uword result = 1; |
13018 if (IsMalformed()) return result; | 12869 if (IsMalformed()) return result; |
13019 result += Class::Handle(type_class()).id(); | 12870 result += Class::Handle(type_class()).id(); |
13020 result += AbstractTypeArguments::Handle(arguments()).Hash(); | 12871 result += TypeArguments::Handle(arguments()).Hash(); |
13021 return FinalizeHash(result); | 12872 return FinalizeHash(result); |
13022 } | 12873 } |
13023 | 12874 |
13024 | 12875 |
13025 void Type::set_type_class(const Object& value) const { | 12876 void Type::set_type_class(const Object& value) const { |
13026 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass())); | 12877 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass())); |
13027 StorePointer(&raw_ptr()->type_class_, value.raw()); | 12878 StorePointer(&raw_ptr()->type_class_, value.raw()); |
13028 } | 12879 } |
13029 | 12880 |
13030 | 12881 |
13031 void Type::set_arguments(const AbstractTypeArguments& value) const { | 12882 void Type::set_arguments(const TypeArguments& value) const { |
13032 StorePointer(&raw_ptr()->arguments_, value.raw()); | 12883 StorePointer(&raw_ptr()->arguments_, value.raw()); |
13033 } | 12884 } |
13034 | 12885 |
13035 | 12886 |
13036 RawType* Type::New(Heap::Space space) { | 12887 RawType* Type::New(Heap::Space space) { |
13037 ASSERT(Isolate::Current()->object_store()->type_class() != Class::null()); | 12888 ASSERT(Isolate::Current()->object_store()->type_class() != Class::null()); |
13038 RawObject* raw = Object::Allocate(Type::kClassId, | 12889 RawObject* raw = Object::Allocate(Type::kClassId, |
13039 Type::InstanceSize(), | 12890 Type::InstanceSize(), |
13040 space); | 12891 space); |
13041 return reinterpret_cast<RawType*>(raw); | 12892 return reinterpret_cast<RawType*>(raw); |
13042 } | 12893 } |
13043 | 12894 |
13044 | 12895 |
13045 RawType* Type::New(const Object& clazz, | 12896 RawType* Type::New(const Object& clazz, |
13046 const AbstractTypeArguments& arguments, | 12897 const TypeArguments& arguments, |
13047 intptr_t token_pos, | 12898 intptr_t token_pos, |
13048 Heap::Space space) { | 12899 Heap::Space space) { |
13049 const Type& result = Type::Handle(Type::New(space)); | 12900 const Type& result = Type::Handle(Type::New(space)); |
13050 result.set_type_class(clazz); | 12901 result.set_type_class(clazz); |
13051 result.set_arguments(arguments); | 12902 result.set_arguments(arguments); |
13052 result.set_token_pos(token_pos); | 12903 result.set_token_pos(token_pos); |
13053 result.raw_ptr()->type_state_ = RawType::kAllocated; | 12904 result.raw_ptr()->type_state_ = RawType::kAllocated; |
13054 return result.raw(); | 12905 return result.raw(); |
13055 } | 12906 } |
13056 | 12907 |
13057 | 12908 |
13058 void Type::set_token_pos(intptr_t token_pos) const { | 12909 void Type::set_token_pos(intptr_t token_pos) const { |
13059 ASSERT(token_pos >= 0); | 12910 ASSERT(token_pos >= 0); |
13060 raw_ptr()->token_pos_ = token_pos; | 12911 raw_ptr()->token_pos_ = token_pos; |
13061 } | 12912 } |
13062 | 12913 |
13063 | 12914 |
13064 void Type::set_type_state(int8_t state) const { | 12915 void Type::set_type_state(int8_t state) const { |
13065 ASSERT((state == RawType::kAllocated) || | 12916 ASSERT((state == RawType::kAllocated) || |
13066 (state == RawType::kBeingFinalized) || | 12917 (state == RawType::kBeingFinalized) || |
13067 (state == RawType::kFinalizedInstantiated) || | 12918 (state == RawType::kFinalizedInstantiated) || |
13068 (state == RawType::kFinalizedUninstantiated)); | 12919 (state == RawType::kFinalizedUninstantiated)); |
13069 raw_ptr()->type_state_ = state; | 12920 raw_ptr()->type_state_ = state; |
13070 } | 12921 } |
13071 | 12922 |
13072 | 12923 |
13073 const char* Type::ToCString() const { | 12924 const char* Type::ToCString() const { |
13074 if (IsResolved()) { | 12925 if (IsResolved()) { |
13075 const AbstractTypeArguments& type_arguments = | 12926 const TypeArguments& type_arguments = TypeArguments::Handle(arguments()); |
13076 AbstractTypeArguments::Handle(arguments()); | |
13077 const char* class_name; | 12927 const char* class_name; |
13078 if (HasResolvedTypeClass()) { | 12928 if (HasResolvedTypeClass()) { |
13079 class_name = String::Handle( | 12929 class_name = String::Handle( |
13080 Class::Handle(type_class()).Name()).ToCString(); | 12930 Class::Handle(type_class()).Name()).ToCString(); |
13081 } else { | 12931 } else { |
13082 class_name = UnresolvedClass::Handle(unresolved_class()).ToCString(); | 12932 class_name = UnresolvedClass::Handle(unresolved_class()).ToCString(); |
13083 } | 12933 } |
13084 if (type_arguments.IsNull()) { | 12934 if (type_arguments.IsNull()) { |
13085 const char* format = "Type: class '%s'"; | 12935 const char* format = "Type: class '%s'"; |
13086 intptr_t len = OS::SNPrint(NULL, 0, format, class_name) + 1; | 12936 intptr_t len = OS::SNPrint(NULL, 0, format, class_name) + 1; |
13087 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 12937 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
13088 OS::SNPrint(chars, len, format, class_name); | 12938 OS::SNPrint(chars, len, format, class_name); |
13089 return chars; | 12939 return chars; |
13090 } else { | 12940 } else { |
13091 const char* format = "Type: class '%s', args:[%s]"; | 12941 const char* format = "Type: class '%s', args:[%s]"; |
13092 const char* args_cstr = | 12942 const char* args_cstr = TypeArguments::Handle(arguments()).ToCString(); |
13093 AbstractTypeArguments::Handle(arguments()).ToCString(); | |
13094 intptr_t len = OS::SNPrint(NULL, 0, format, class_name, args_cstr) + 1; | 12943 intptr_t len = OS::SNPrint(NULL, 0, format, class_name, args_cstr) + 1; |
13095 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 12944 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
13096 OS::SNPrint(chars, len, format, class_name, args_cstr); | 12945 OS::SNPrint(chars, len, format, class_name, args_cstr); |
13097 return chars; | 12946 return chars; |
13098 } | 12947 } |
13099 } else { | 12948 } else { |
13100 return "Unresolved Type"; | 12949 return "Unresolved Type"; |
13101 } | 12950 } |
13102 } | 12951 } |
13103 | 12952 |
(...skipping 17 matching lines...) Expand all Loading... |
13121 return true; | 12970 return true; |
13122 } | 12971 } |
13123 if (TestAndAddBuddyToTrail(&trail, other)) { | 12972 if (TestAndAddBuddyToTrail(&trail, other)) { |
13124 return true; | 12973 return true; |
13125 } | 12974 } |
13126 return AbstractType::Handle(type()).IsEquivalent(other, trail); | 12975 return AbstractType::Handle(type()).IsEquivalent(other, trail); |
13127 } | 12976 } |
13128 | 12977 |
13129 | 12978 |
13130 RawAbstractType* TypeRef::InstantiateFrom( | 12979 RawAbstractType* TypeRef::InstantiateFrom( |
13131 const AbstractTypeArguments& instantiator_type_arguments, | 12980 const TypeArguments& instantiator_type_arguments, |
13132 Error* bound_error, | 12981 Error* bound_error, |
13133 GrowableObjectArray* trail) const { | 12982 GrowableObjectArray* trail) const { |
13134 TypeRef& instantiated_type_ref = TypeRef::Handle(); | 12983 TypeRef& instantiated_type_ref = TypeRef::Handle(); |
13135 instantiated_type_ref ^= OnlyBuddyInTrail(trail); | 12984 instantiated_type_ref ^= OnlyBuddyInTrail(trail); |
13136 if (!instantiated_type_ref.IsNull()) { | 12985 if (!instantiated_type_ref.IsNull()) { |
13137 return instantiated_type_ref.raw(); | 12986 return instantiated_type_ref.raw(); |
13138 } | 12987 } |
13139 instantiated_type_ref = TypeRef::New(Type::Handle(Type::DynamicType())); | 12988 instantiated_type_ref = TypeRef::New(Type::Handle(Type::DynamicType())); |
13140 AddOnlyBuddyToTrail(&trail, instantiated_type_ref); | 12989 AddOnlyBuddyToTrail(&trail, instantiated_type_ref); |
13141 const AbstractType& ref_type = AbstractType::Handle(type()); | 12990 const AbstractType& ref_type = AbstractType::Handle(type()); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13255 result.set_type(type); | 13104 result.set_type(type); |
13256 return result.raw(); | 13105 return result.raw(); |
13257 } | 13106 } |
13258 | 13107 |
13259 | 13108 |
13260 const char* TypeRef::ToCString() const { | 13109 const char* TypeRef::ToCString() const { |
13261 const char* format = "TypeRef: %s%s"; | 13110 const char* format = "TypeRef: %s%s"; |
13262 const char* type_cstr = String::Handle(Class::Handle(AbstractType::Handle( | 13111 const char* type_cstr = String::Handle(Class::Handle(AbstractType::Handle( |
13263 type()).type_class()).Name()).ToCString(); | 13112 type()).type_class()).Name()).ToCString(); |
13264 const char* args_cstr = (AbstractType::Handle( | 13113 const char* args_cstr = (AbstractType::Handle( |
13265 type()).arguments() == AbstractTypeArguments::null()) ? "" : "<...>"; | 13114 type()).arguments() == TypeArguments::null()) ? "" : "<...>"; |
13266 intptr_t len = OS::SNPrint(NULL, 0, format, type_cstr, args_cstr) + 1; | 13115 intptr_t len = OS::SNPrint(NULL, 0, format, type_cstr, args_cstr) + 1; |
13267 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 13116 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
13268 OS::SNPrint(chars, len, format, type_cstr, args_cstr); | 13117 OS::SNPrint(chars, len, format, type_cstr, args_cstr); |
13269 return chars; | 13118 return chars; |
13270 } | 13119 } |
13271 | 13120 |
13272 | 13121 |
13273 void TypeRef::PrintToJSONStream(JSONStream* stream, bool ref) const { | 13122 void TypeRef::PrintToJSONStream(JSONStream* stream, bool ref) const { |
13274 JSONObject jsobj(stream); | 13123 JSONObject jsobj(stream); |
13275 } | 13124 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13324 StorePointer(&raw_ptr()->name_, value.raw()); | 13173 StorePointer(&raw_ptr()->name_, value.raw()); |
13325 } | 13174 } |
13326 | 13175 |
13327 | 13176 |
13328 void TypeParameter::set_bound(const AbstractType& value) const { | 13177 void TypeParameter::set_bound(const AbstractType& value) const { |
13329 StorePointer(&raw_ptr()->bound_, value.raw()); | 13178 StorePointer(&raw_ptr()->bound_, value.raw()); |
13330 } | 13179 } |
13331 | 13180 |
13332 | 13181 |
13333 RawAbstractType* TypeParameter::InstantiateFrom( | 13182 RawAbstractType* TypeParameter::InstantiateFrom( |
13334 const AbstractTypeArguments& instantiator_type_arguments, | 13183 const TypeArguments& instantiator_type_arguments, |
13335 Error* bound_error, | 13184 Error* bound_error, |
13336 GrowableObjectArray* trail) const { | 13185 GrowableObjectArray* trail) const { |
13337 ASSERT(IsFinalized()); | 13186 ASSERT(IsFinalized()); |
13338 if (instantiator_type_arguments.IsNull()) { | 13187 if (instantiator_type_arguments.IsNull()) { |
13339 return Type::DynamicType(); | 13188 return Type::DynamicType(); |
13340 } | 13189 } |
13341 const AbstractType& type_arg = AbstractType::Handle( | 13190 const AbstractType& type_arg = AbstractType::Handle( |
13342 instantiator_type_arguments.TypeAt(index())); | 13191 instantiator_type_arguments.TypeAt(index())); |
13343 // There is no need to canonicalize the instantiated type parameter, since all | 13192 // There is no need to canonicalize the instantiated type parameter, since all |
13344 // type arguments are canonicalized at type finalization time. It would be too | 13193 // type arguments are canonicalized at type finalization time. It would be too |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13549 | 13398 |
13550 void BoundedType::set_type_parameter(const TypeParameter& value) const { | 13399 void BoundedType::set_type_parameter(const TypeParameter& value) const { |
13551 // A null type parameter is set when marking a type malformed because of a | 13400 // A null type parameter is set when marking a type malformed because of a |
13552 // bound error at compile time. | 13401 // bound error at compile time. |
13553 ASSERT(value.IsNull() || value.IsFinalized()); | 13402 ASSERT(value.IsNull() || value.IsFinalized()); |
13554 StorePointer(&raw_ptr()->type_parameter_, value.raw()); | 13403 StorePointer(&raw_ptr()->type_parameter_, value.raw()); |
13555 } | 13404 } |
13556 | 13405 |
13557 | 13406 |
13558 RawAbstractType* BoundedType::InstantiateFrom( | 13407 RawAbstractType* BoundedType::InstantiateFrom( |
13559 const AbstractTypeArguments& instantiator_type_arguments, | 13408 const TypeArguments& instantiator_type_arguments, |
13560 Error* bound_error, | 13409 Error* bound_error, |
13561 GrowableObjectArray* trail) const { | 13410 GrowableObjectArray* trail) const { |
13562 ASSERT(IsFinalized()); | 13411 ASSERT(IsFinalized()); |
13563 AbstractType& bounded_type = AbstractType::Handle(type()); | 13412 AbstractType& bounded_type = AbstractType::Handle(type()); |
13564 if (!bounded_type.IsInstantiated()) { | 13413 if (!bounded_type.IsInstantiated()) { |
13565 bounded_type = bounded_type.InstantiateFrom(instantiator_type_arguments, | 13414 bounded_type = bounded_type.InstantiateFrom(instantiator_type_arguments, |
13566 bound_error, | 13415 bound_error, |
13567 trail); | 13416 trail); |
13568 } | 13417 } |
13569 if (FLAG_enable_type_checks && bound_error->IsNull()) { | 13418 if (FLAG_enable_type_checks && bound_error->IsNull()) { |
(...skipping 2657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16227 // Both handles point to the same raw instance. | 16076 // Both handles point to the same raw instance. |
16228 return true; | 16077 return true; |
16229 } | 16078 } |
16230 | 16079 |
16231 // An Array may be compared to an ImmutableArray. | 16080 // An Array may be compared to an ImmutableArray. |
16232 if (!other.IsArray() || other.IsNull()) { | 16081 if (!other.IsArray() || other.IsNull()) { |
16233 return false; | 16082 return false; |
16234 } | 16083 } |
16235 | 16084 |
16236 // Both arrays must have the same type arguments. | 16085 // Both arrays must have the same type arguments. |
16237 const AbstractTypeArguments& type_args = AbstractTypeArguments::Handle( | 16086 const TypeArguments& type_args = TypeArguments::Handle(GetTypeArguments()); |
16238 GetTypeArguments()); | 16087 const TypeArguments& other_type_args = TypeArguments::Handle( |
16239 const AbstractTypeArguments& other_type_args = AbstractTypeArguments::Handle( | |
16240 other.GetTypeArguments()); | 16088 other.GetTypeArguments()); |
16241 if (!type_args.Equals(other_type_args)) { | 16089 if (!type_args.Equals(other_type_args)) { |
16242 return false; | 16090 return false; |
16243 } | 16091 } |
16244 | 16092 |
16245 const Array& other_arr = Array::Cast(other); | 16093 const Array& other_arr = Array::Cast(other); |
16246 | 16094 |
16247 intptr_t len = this->Length(); | 16095 intptr_t len = this->Length(); |
16248 if (len != other_arr.Length()) { | 16096 if (len != other_arr.Length()) { |
16249 return false; | 16097 return false; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16306 void Array::PrintToJSONStream(JSONStream* stream, bool ref) const { | 16154 void Array::PrintToJSONStream(JSONStream* stream, bool ref) const { |
16307 Instance::PrintToJSONStream(stream, ref); | 16155 Instance::PrintToJSONStream(stream, ref); |
16308 } | 16156 } |
16309 | 16157 |
16310 | 16158 |
16311 RawArray* Array::Grow(const Array& source, int new_length, Heap::Space space) { | 16159 RawArray* Array::Grow(const Array& source, int new_length, Heap::Space space) { |
16312 const Array& result = Array::Handle(Array::New(new_length, space)); | 16160 const Array& result = Array::Handle(Array::New(new_length, space)); |
16313 intptr_t len = 0; | 16161 intptr_t len = 0; |
16314 if (!source.IsNull()) { | 16162 if (!source.IsNull()) { |
16315 len = source.Length(); | 16163 len = source.Length(); |
16316 result.SetTypeArguments( | 16164 result.SetTypeArguments(TypeArguments::Handle(source.GetTypeArguments())); |
16317 AbstractTypeArguments::Handle(source.GetTypeArguments())); | |
16318 } | 16165 } |
16319 ASSERT(new_length >= len); // Cannot copy 'source' into new array. | 16166 ASSERT(new_length >= len); // Cannot copy 'source' into new array. |
16320 ASSERT(new_length != len); // Unnecessary copying of array. | 16167 ASSERT(new_length != len); // Unnecessary copying of array. |
16321 Object& obj = Object::Handle(); | 16168 Object& obj = Object::Handle(); |
16322 for (int i = 0; i < len; i++) { | 16169 for (int i = 0; i < len; i++) { |
16323 obj = source.At(i); | 16170 obj = source.At(i); |
16324 result.SetAt(i, obj); | 16171 result.SetAt(i, obj); |
16325 } | 16172 } |
16326 return result.raw(); | 16173 return result.raw(); |
16327 } | 16174 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16451 } | 16298 } |
16452 | 16299 |
16453 const GrowableObjectArray& other_arr = GrowableObjectArray::Cast(other); | 16300 const GrowableObjectArray& other_arr = GrowableObjectArray::Cast(other); |
16454 | 16301 |
16455 // The capacity and length of both objects must be equal. | 16302 // The capacity and length of both objects must be equal. |
16456 if (Capacity() != other_arr.Capacity() || Length() != other_arr.Length()) { | 16303 if (Capacity() != other_arr.Capacity() || Length() != other_arr.Length()) { |
16457 return false; | 16304 return false; |
16458 } | 16305 } |
16459 | 16306 |
16460 // Both arrays must have the same type arguments. | 16307 // Both arrays must have the same type arguments. |
16461 const AbstractTypeArguments& type_args = AbstractTypeArguments::Handle( | 16308 const TypeArguments& type_args = TypeArguments::Handle(GetTypeArguments()); |
16462 GetTypeArguments()); | 16309 const TypeArguments& other_type_args = TypeArguments::Handle( |
16463 const AbstractTypeArguments& other_type_args = AbstractTypeArguments::Handle( | |
16464 other.GetTypeArguments()); | 16310 other.GetTypeArguments()); |
16465 if (!type_args.Equals(other_type_args)) { | 16311 if (!type_args.Equals(other_type_args)) { |
16466 return false; | 16312 return false; |
16467 } | 16313 } |
16468 | 16314 |
16469 // The data part in both arrays must be identical. | 16315 // The data part in both arrays must be identical. |
16470 const Array& contents = Array::Handle(data()); | 16316 const Array& contents = Array::Handle(data()); |
16471 const Array& other_contents = Array::Handle(other_arr.data()); | 16317 const Array& other_contents = Array::Handle(other_arr.data()); |
16472 for (intptr_t i = 0; i < Length(); i++) { | 16318 for (intptr_t i = 0; i < Length(); i++) { |
16473 if (contents.At(i) != other_contents.At(i)) { | 16319 if (contents.At(i) != other_contents.At(i)) { |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17470 return "_MirrorReference"; | 17316 return "_MirrorReference"; |
17471 } | 17317 } |
17472 | 17318 |
17473 | 17319 |
17474 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 17320 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
17475 Instance::PrintToJSONStream(stream, ref); | 17321 Instance::PrintToJSONStream(stream, ref); |
17476 } | 17322 } |
17477 | 17323 |
17478 | 17324 |
17479 } // namespace dart | 17325 } // namespace dart |
OLD | NEW |