| 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/become.h" | 10 #include "vm/become.h" |
| (...skipping 3802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3813 const Class& other, | 3813 const Class& other, |
| 3814 const TypeArguments& other_type_arguments, | 3814 const TypeArguments& other_type_arguments, |
| 3815 Error* bound_error, | 3815 Error* bound_error, |
| 3816 TrailPtr bound_trail, | 3816 TrailPtr bound_trail, |
| 3817 Heap::Space space) { | 3817 Heap::Space space) { |
| 3818 // Use the thsi object as if it was the receiver of this method, but instead | 3818 // Use the thsi object as if it was the receiver of this method, but instead |
| 3819 // of recursing reset it to the super class and loop. | 3819 // of recursing reset it to the super class and loop. |
| 3820 Zone* zone = Thread::Current()->zone(); | 3820 Zone* zone = Thread::Current()->zone(); |
| 3821 Class& thsi = Class::Handle(zone, cls.raw()); | 3821 Class& thsi = Class::Handle(zone, cls.raw()); |
| 3822 while (true) { | 3822 while (true) { |
| 3823 ASSERT(!thsi.IsVoidClass()); | |
| 3824 // Check for DynamicType. | 3823 // Check for DynamicType. |
| 3825 // Each occurrence of DynamicType in type T is interpreted as the dynamic | 3824 // Each occurrence of DynamicType in type T is interpreted as the dynamic |
| 3826 // type, a supertype of all types. | 3825 // type, a supertype of all types. |
| 3827 if (other.IsDynamicClass()) { | 3826 if (other.IsDynamicClass()) { |
| 3828 return true; | 3827 return true; |
| 3829 } | 3828 } |
| 3830 // Check for NullType, which, as of Dart 1.5, is a subtype of (and is more | 3829 // Check for NullType, which, as of Dart 1.5, is a subtype of (and is more |
| 3831 // specific than) any type. Note that the null instance is not handled here. | 3830 // specific than) any type. Note that the null instance is not handled here. |
| 3832 if (thsi.IsNullClass()) { | 3831 if (thsi.IsNullClass()) { |
| 3833 return true; | 3832 return true; |
| 3834 } | 3833 } |
| 3835 // In the case of a subtype test, each occurrence of DynamicType in type S | 3834 // In the case of a subtype test, each occurrence of DynamicType in type S |
| 3836 // is interpreted as the bottom type, a subtype of all types. | 3835 // is interpreted as the bottom type, a subtype of all types. |
| 3837 // However, DynamicType is not more specific than any type. | 3836 // However, DynamicType is not more specific than any type. |
| 3838 if (thsi.IsDynamicClass()) { | 3837 if (thsi.IsDynamicClass()) { |
| 3839 return test_kind == Class::kIsSubtypeOf; | 3838 return test_kind == Class::kIsSubtypeOf; |
| 3840 } | 3839 } |
| 3841 // Check for ObjectType. Any type that is not NullType or DynamicType | 3840 // Check for ObjectType. Any type that is not NullType or DynamicType |
| 3842 // (already checked above), is more specific than ObjectType. | 3841 // (already checked above), is more specific than ObjectType/VoidType. |
| 3843 if (other.IsObjectClass()) { | 3842 if (other.IsObjectClass() || other.IsVoidClass()) { |
| 3844 return true; | 3843 return true; |
| 3845 } | 3844 } |
| 3845 // If other is neither Object, dynamic or void, then ObjectType/VoidType |
| 3846 // can't be a subtype of other. |
| 3847 if (thsi.IsObjectClass() || thsi.IsVoidClass()) { |
| 3848 return false; |
| 3849 } |
| 3846 // Check for reflexivity. | 3850 // Check for reflexivity. |
| 3847 if (thsi.raw() == other.raw()) { | 3851 if (thsi.raw() == other.raw()) { |
| 3848 const intptr_t num_type_params = thsi.NumTypeParameters(); | 3852 const intptr_t num_type_params = thsi.NumTypeParameters(); |
| 3849 if (num_type_params == 0) { | 3853 if (num_type_params == 0) { |
| 3850 return true; | 3854 return true; |
| 3851 } | 3855 } |
| 3852 const intptr_t num_type_args = thsi.NumTypeArguments(); | 3856 const intptr_t num_type_args = thsi.NumTypeArguments(); |
| 3853 const intptr_t from_index = num_type_args - num_type_params; | 3857 const intptr_t from_index = num_type_args - num_type_params; |
| 3854 // Since we do not truncate the type argument vector of a subclass (see | 3858 // Since we do not truncate the type argument vector of a subclass (see |
| 3855 // below), we only check a subvector of the proper length. | 3859 // below), we only check a subvector of the proper length. |
| (...skipping 11967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15823 const AbstractType& other, | 15827 const AbstractType& other, |
| 15824 const TypeArguments& other_instantiator_type_arguments, | 15828 const TypeArguments& other_instantiator_type_arguments, |
| 15825 const TypeArguments& other_function_type_arguments, | 15829 const TypeArguments& other_function_type_arguments, |
| 15826 Error* bound_error) const { | 15830 Error* bound_error) const { |
| 15827 ASSERT(other.IsFinalized()); | 15831 ASSERT(other.IsFinalized()); |
| 15828 ASSERT(!other.IsDynamicType()); | 15832 ASSERT(!other.IsDynamicType()); |
| 15829 ASSERT(!other.IsTypeRef()); // Must be dereferenced at compile time. | 15833 ASSERT(!other.IsTypeRef()); // Must be dereferenced at compile time. |
| 15830 ASSERT(!other.IsMalformed()); | 15834 ASSERT(!other.IsMalformed()); |
| 15831 ASSERT(!other.IsMalbounded()); | 15835 ASSERT(!other.IsMalbounded()); |
| 15832 if (other.IsVoidType()) { | 15836 if (other.IsVoidType()) { |
| 15833 return false; | 15837 return true; |
| 15834 } | 15838 } |
| 15835 Zone* zone = Thread::Current()->zone(); | 15839 Zone* zone = Thread::Current()->zone(); |
| 15836 const Class& cls = Class::Handle(zone, clazz()); | 15840 const Class& cls = Class::Handle(zone, clazz()); |
| 15837 if (cls.IsClosureClass()) { | 15841 if (cls.IsClosureClass()) { |
| 15838 if (other.IsObjectType() || other.IsDartFunctionType() || | 15842 if (other.IsObjectType() || other.IsDartFunctionType() || |
| 15839 other.IsDartClosureType()) { | 15843 other.IsDartClosureType()) { |
| 15840 return true; | 15844 return true; |
| 15841 } | 15845 } |
| 15842 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw()); | 15846 AbstractType& instantiated_other = AbstractType::Handle(zone, other.raw()); |
| 15843 // Note that we may encounter a bound error in checked mode. | 15847 // Note that we may encounter a bound error in checked mode. |
| (...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16641 return false; | 16645 return false; |
| 16642 } | 16646 } |
| 16643 if (other.IsMalbounded()) { | 16647 if (other.IsMalbounded()) { |
| 16644 ASSERT(Isolate::Current()->type_checks()); | 16648 ASSERT(Isolate::Current()->type_checks()); |
| 16645 if ((bound_error != NULL) && bound_error->IsNull()) { | 16649 if ((bound_error != NULL) && bound_error->IsNull()) { |
| 16646 *bound_error = other.error(); | 16650 *bound_error = other.error(); |
| 16647 } | 16651 } |
| 16648 return false; | 16652 return false; |
| 16649 } | 16653 } |
| 16650 // Any type is a subtype of (and is more specific than) Object and dynamic. | 16654 // Any type is a subtype of (and is more specific than) Object and dynamic. |
| 16655 // As of Dart 1.24, void is dynamically treated like Object (except when |
| 16656 // comparing function-types). |
| 16651 // As of Dart 1.5, the Null type is a subtype of (and is more specific than) | 16657 // As of Dart 1.5, the Null type is a subtype of (and is more specific than) |
| 16652 // any type. | 16658 // any type. |
| 16653 if (other.IsObjectType() || other.IsDynamicType() || IsNullType()) { | 16659 if (other.IsObjectType() || other.IsDynamicType() || other.IsVoidType() || |
| 16660 IsNullType()) { |
| 16654 return true; | 16661 return true; |
| 16655 } | 16662 } |
| 16656 Zone* zone = Thread::Current()->zone(); | 16663 Zone* zone = Thread::Current()->zone(); |
| 16657 if (IsBoundedType() || other.IsBoundedType()) { | 16664 if (IsBoundedType() || other.IsBoundedType()) { |
| 16658 if (Equals(other)) { | 16665 if (Equals(other)) { |
| 16659 return true; | 16666 return true; |
| 16660 } | 16667 } |
| 16661 // Redundant check if other type is equal to the upper bound of this type. | 16668 // Redundant check if other type is equal to the upper bound of this type. |
| 16662 if (IsBoundedType() && | 16669 if (IsBoundedType() && |
| 16663 AbstractType::Handle(BoundedType::Cast(*this).bound()).Equals(other)) { | 16670 AbstractType::Handle(BoundedType::Cast(*this).bound()).Equals(other)) { |
| (...skipping 6661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 23325 return UserTag::null(); | 23332 return UserTag::null(); |
| 23326 } | 23333 } |
| 23327 | 23334 |
| 23328 | 23335 |
| 23329 const char* UserTag::ToCString() const { | 23336 const char* UserTag::ToCString() const { |
| 23330 const String& tag_label = String::Handle(label()); | 23337 const String& tag_label = String::Handle(label()); |
| 23331 return tag_label.ToCString(); | 23338 return tag_label.ToCString(); |
| 23332 } | 23339 } |
| 23333 | 23340 |
| 23334 } // namespace dart | 23341 } // namespace dart |
| OLD | NEW |