Chromium Code Reviews| 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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 2008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2019 // type, a supertype of all types. | 2019 // type, a supertype of all types. |
| 2020 if (other.IsDynamicClass()) { | 2020 if (other.IsDynamicClass()) { |
| 2021 return true; | 2021 return true; |
| 2022 } | 2022 } |
| 2023 // In the case of a subtype test, each occurrence of DynamicType in type S is | 2023 // In the case of a subtype test, each occurrence of DynamicType in type S is |
| 2024 // interpreted as the bottom type, a subtype of all types. | 2024 // interpreted as the bottom type, a subtype of all types. |
| 2025 // However, DynamicType is not more specific than any type. | 2025 // However, DynamicType is not more specific than any type. |
| 2026 if (IsDynamicClass()) { | 2026 if (IsDynamicClass()) { |
| 2027 return test_kind == kIsSubtypeOf; | 2027 return test_kind == kIsSubtypeOf; |
| 2028 } | 2028 } |
| 2029 // Check for NullType, which is not a subtype of any type, but is more | 2029 // Check for NullType, which is only a subtype of ObjectType, of DynamicType, |
| 2030 // specific than any type. | 2030 // or of itself, and which is more specific than any type. |
| 2031 if (IsNullClass()) { | 2031 if (IsNullClass()) { |
| 2032 // User code cannot refer to class Null, therefore, we can only encounter | 2032 // We already checked for other.IsDynamicClass() above. |
| 2033 // NullType here as the type of the null constant, which must be treated | 2033 return (test_kind == kIsMoreSpecificThan) || |
| 2034 // separately in 'instance of' checks. Therefore, the NullType can only | 2034 other.IsObjectClass() || other.IsNullClass(); |
|
srdjan
2013/01/05 00:38:58
|| other.IsDynamicClass()
regis
2013/01/05 00:45:39
See comment on line 2032.
| |
| 2035 // be encountered here during optimizations in 'more specific than' tests. | |
| 2036 ASSERT(test_kind == kIsMoreSpecificThan); | |
| 2037 return true; | |
| 2038 } | 2035 } |
| 2039 // Check for ObjectType. Any type that is not NullType or DynamicType (already | 2036 // Check for ObjectType. Any type that is not NullType or DynamicType (already |
| 2040 // checked above), is more specific than ObjectType. | 2037 // checked above), is more specific than ObjectType. |
| 2041 if (other.IsObjectClass()) { | 2038 if (other.IsObjectClass()) { |
| 2042 return true; | 2039 return true; |
| 2043 } | 2040 } |
| 2044 // Check for reflexivity. | 2041 // Check for reflexivity. |
| 2045 if (raw() == other.raw()) { | 2042 if (raw() == other.raw()) { |
| 2046 const intptr_t len = NumTypeArguments(); | 2043 const intptr_t len = NumTypeArguments(); |
| 2047 if (len == 0) { | 2044 if (len == 0) { |
| (...skipping 6293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8341 SetFieldAtOffset(field_offset, value); | 8338 SetFieldAtOffset(field_offset, value); |
| 8342 } | 8339 } |
| 8343 | 8340 |
| 8344 | 8341 |
| 8345 bool Instance::IsInstanceOf(const AbstractType& other, | 8342 bool Instance::IsInstanceOf(const AbstractType& other, |
| 8346 const AbstractTypeArguments& other_instantiator, | 8343 const AbstractTypeArguments& other_instantiator, |
| 8347 Error* malformed_error) const { | 8344 Error* malformed_error) const { |
| 8348 ASSERT(other.IsFinalized()); | 8345 ASSERT(other.IsFinalized()); |
| 8349 ASSERT(!other.IsDynamicType()); | 8346 ASSERT(!other.IsDynamicType()); |
| 8350 ASSERT(!other.IsMalformed()); | 8347 ASSERT(!other.IsMalformed()); |
| 8351 const Class& cls = Class::Handle(clazz()); | |
| 8352 if (cls.IsNullClass()) { | |
| 8353 if (!IsNull()) { | |
| 8354 // We can only encounter Object::sentinel() or | |
| 8355 // Object::transition_sentinel() if type checks were not eliminated at | |
| 8356 // compile time. Both sentinels are instances of the Null class, but they | |
| 8357 // are not the Object::null() instance. | |
| 8358 ASSERT((raw() == Object::transition_sentinel().raw()) || | |
| 8359 (raw() == Object::sentinel().raw())); | |
| 8360 ASSERT(!FLAG_eliminate_type_checks); | |
| 8361 return true; // We are doing an instance of test as part of a type check. | |
| 8362 } | |
| 8363 // The null instance can be returned from a void function. | |
| 8364 if (other.IsVoidType()) { | |
| 8365 return true; | |
| 8366 } | |
| 8367 // Otherwise, null is only an instance of Object and of dynamic. | |
| 8368 // It is not necessary to fully instantiate the other type for this test. | |
| 8369 Class& other_class = Class::Handle(); | |
| 8370 if (other.IsTypeParameter()) { | |
| 8371 if (other_instantiator.IsNull()) { | |
| 8372 return true; // Other type is uninstantiated, i.e. dynamic. | |
| 8373 } | |
| 8374 const TypeParameter& other_type_param = TypeParameter::Cast(other); | |
| 8375 const AbstractType& instantiated_other = AbstractType::Handle( | |
| 8376 other_instantiator.TypeAt(other_type_param.index())); | |
| 8377 ASSERT(instantiated_other.IsInstantiated()); | |
| 8378 other_class = instantiated_other.type_class(); | |
| 8379 } else { | |
| 8380 other_class = other.type_class(); | |
| 8381 } | |
| 8382 return other_class.IsObjectClass() || other_class.IsDynamicClass(); | |
| 8383 } | |
| 8384 if (other.IsVoidType()) { | 8348 if (other.IsVoidType()) { |
| 8385 return false; | 8349 return false; |
| 8386 } | 8350 } |
| 8351 const Class& cls = Class::Handle(clazz()); | |
| 8387 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); | 8352 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); |
| 8388 const intptr_t num_type_arguments = cls.NumTypeArguments(); | 8353 const intptr_t num_type_arguments = cls.NumTypeArguments(); |
| 8389 if (num_type_arguments > 0) { | 8354 if (num_type_arguments > 0) { |
| 8390 type_arguments = GetTypeArguments(); | 8355 type_arguments = GetTypeArguments(); |
| 8391 if (!type_arguments.IsNull() && !type_arguments.IsCanonical()) { | 8356 if (!type_arguments.IsNull() && !type_arguments.IsCanonical()) { |
| 8392 type_arguments = type_arguments.Canonicalize(); | 8357 type_arguments = type_arguments.Canonicalize(); |
| 8393 SetTypeArguments(type_arguments); | 8358 SetTypeArguments(type_arguments); |
| 8394 } | 8359 } |
| 8395 // Verify that the number of type arguments in the instance matches the | 8360 // Verify that the number of type arguments in the instance matches the |
| 8396 // number of type arguments expected by the instance class. | 8361 // number of type arguments expected by the instance class. |
| (...skipping 4022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12419 } | 12384 } |
| 12420 return result.raw(); | 12385 return result.raw(); |
| 12421 } | 12386 } |
| 12422 | 12387 |
| 12423 | 12388 |
| 12424 const char* WeakProperty::ToCString() const { | 12389 const char* WeakProperty::ToCString() const { |
| 12425 return "_WeakProperty"; | 12390 return "_WeakProperty"; |
| 12426 } | 12391 } |
| 12427 | 12392 |
| 12428 } // namespace dart | 12393 } // namespace dart |
| OLD | NEW |