| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 DEFINE_FLAG(int, huge_method_cutoff_in_code_size, 200000, | 54 DEFINE_FLAG(int, huge_method_cutoff_in_code_size, 200000, |
| 55 "Huge method cutoff in unoptimized code size (in bytes)."); | 55 "Huge method cutoff in unoptimized code size (in bytes)."); |
| 56 DEFINE_FLAG(bool, throw_on_javascript_int_overflow, false, | 56 DEFINE_FLAG(bool, throw_on_javascript_int_overflow, false, |
| 57 "Throw an exception when the result of an integer calculation will not " | 57 "Throw an exception when the result of an integer calculation will not " |
| 58 "fit into a javascript integer."); | 58 "fit into a javascript integer."); |
| 59 DECLARE_FLAG(bool, trace_compiler); | 59 DECLARE_FLAG(bool, trace_compiler); |
| 60 DECLARE_FLAG(bool, eliminate_type_checks); | 60 DECLARE_FLAG(bool, eliminate_type_checks); |
| 61 DECLARE_FLAG(bool, enable_type_checks); | 61 DECLARE_FLAG(bool, enable_type_checks); |
| 62 DECLARE_FLAG(bool, trace_deoptimization); | 62 DECLARE_FLAG(bool, trace_deoptimization); |
| 63 DECLARE_FLAG(bool, trace_deoptimization_verbose); | 63 DECLARE_FLAG(bool, trace_deoptimization_verbose); |
| 64 DECLARE_FLAG(bool, error_on_malformed_type); |
| 64 DECLARE_FLAG(bool, error_on_bad_override); | 65 DECLARE_FLAG(bool, error_on_bad_override); |
| 65 | 66 |
| 66 static const char* kGetterPrefix = "get:"; | 67 static const char* kGetterPrefix = "get:"; |
| 67 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); | 68 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); |
| 68 static const char* kSetterPrefix = "set:"; | 69 static const char* kSetterPrefix = "set:"; |
| 69 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); | 70 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); |
| 70 | 71 |
| 71 cpp_vtable Object::handle_vtable_ = 0; | 72 cpp_vtable Object::handle_vtable_ = 0; |
| 72 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 }; | 73 cpp_vtable Object::builtin_vtables_[kNumPredefinedCids] = { 0 }; |
| 73 cpp_vtable Smi::handle_vtable_ = 0; | 74 cpp_vtable Smi::handle_vtable_ = 0; |
| (...skipping 1670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1744 // Return null otherwise. | 1745 // Return null otherwise. |
| 1745 RawTypeParameter* Class::LookupTypeParameter(const String& type_name) const { | 1746 RawTypeParameter* Class::LookupTypeParameter(const String& type_name) const { |
| 1746 ASSERT(!type_name.IsNull()); | 1747 ASSERT(!type_name.IsNull()); |
| 1747 Isolate* isolate = Isolate::Current(); | 1748 Isolate* isolate = Isolate::Current(); |
| 1748 ReusableHandleScope reused_handles(isolate); | 1749 ReusableHandleScope reused_handles(isolate); |
| 1749 TypeArguments& type_params = reused_handles.TypeArgumentsHandle(); | 1750 TypeArguments& type_params = reused_handles.TypeArgumentsHandle(); |
| 1750 type_params ^= type_parameters(); | 1751 type_params ^= type_parameters(); |
| 1751 TypeParameter& type_param = reused_handles.TypeParameterHandle(); | 1752 TypeParameter& type_param = reused_handles.TypeParameterHandle(); |
| 1752 String& type_param_name = reused_handles.StringHandle(); | 1753 String& type_param_name = reused_handles.StringHandle(); |
| 1753 if (!type_params.IsNull()) { | 1754 if (!type_params.IsNull()) { |
| 1754 intptr_t num_type_params = type_params.Length(); | 1755 const intptr_t num_type_params = type_params.Length(); |
| 1755 for (intptr_t i = 0; i < num_type_params; i++) { | 1756 for (intptr_t i = 0; i < num_type_params; i++) { |
| 1756 type_param ^= type_params.TypeAt(i); | 1757 type_param ^= type_params.TypeAt(i); |
| 1757 type_param_name = type_param.name(); | 1758 type_param_name = type_param.name(); |
| 1758 if (type_param_name.Equals(type_name)) { | 1759 if (type_param_name.Equals(type_name)) { |
| 1759 return type_param.raw(); | 1760 return type_param.raw(); |
| 1760 } | 1761 } |
| 1761 } | 1762 } |
| 1762 } | 1763 } |
| 1763 return TypeParameter::null(); | 1764 return TypeParameter::null(); |
| 1764 } | 1765 } |
| (...skipping 1311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3076 hash += hash << 3; | 3077 hash += hash << 3; |
| 3077 hash ^= hash >> 11; | 3078 hash ^= hash >> 11; |
| 3078 hash += hash << 15; | 3079 hash += hash << 15; |
| 3079 return hash; | 3080 return hash; |
| 3080 } | 3081 } |
| 3081 | 3082 |
| 3082 | 3083 |
| 3083 intptr_t AbstractTypeArguments::Hash() const { | 3084 intptr_t AbstractTypeArguments::Hash() const { |
| 3084 if (IsNull()) return 0; | 3085 if (IsNull()) return 0; |
| 3085 uword result = 0; | 3086 uword result = 0; |
| 3086 intptr_t num_types = Length(); | 3087 const intptr_t num_types = Length(); |
| 3087 AbstractType& type = AbstractType::Handle(); | 3088 AbstractType& type = AbstractType::Handle(); |
| 3088 for (intptr_t i = 0; i < num_types; i++) { | 3089 for (intptr_t i = 0; i < num_types; i++) { |
| 3089 type = TypeAt(i); | 3090 type = TypeAt(i); |
| 3090 result += type.Hash(); | 3091 result += type.Hash(); |
| 3091 result += result << 10; | 3092 result += result << 10; |
| 3092 result ^= result >> 6; | 3093 result ^= result >> 6; |
| 3093 } | 3094 } |
| 3094 return FinalizeHash(result); | 3095 return FinalizeHash(result); |
| 3095 } | 3096 } |
| 3096 | 3097 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3122 | 3123 |
| 3123 | 3124 |
| 3124 bool AbstractTypeArguments::Equals(const AbstractTypeArguments& other) const { | 3125 bool AbstractTypeArguments::Equals(const AbstractTypeArguments& other) const { |
| 3125 ASSERT(!IsNull()); // Use AbstractTypeArguments::AreEqual(). | 3126 ASSERT(!IsNull()); // Use AbstractTypeArguments::AreEqual(). |
| 3126 if (this->raw() == other.raw()) { | 3127 if (this->raw() == other.raw()) { |
| 3127 return true; | 3128 return true; |
| 3128 } | 3129 } |
| 3129 if (other.IsNull()) { | 3130 if (other.IsNull()) { |
| 3130 return false; | 3131 return false; |
| 3131 } | 3132 } |
| 3132 intptr_t num_types = Length(); | 3133 const intptr_t num_types = Length(); |
| 3133 if (num_types != other.Length()) { | 3134 if (num_types != other.Length()) { |
| 3134 return false; | 3135 return false; |
| 3135 } | 3136 } |
| 3136 AbstractType& type = AbstractType::Handle(); | 3137 AbstractType& type = AbstractType::Handle(); |
| 3137 AbstractType& other_type = AbstractType::Handle(); | 3138 AbstractType& other_type = AbstractType::Handle(); |
| 3138 for (intptr_t i = 0; i < num_types; i++) { | 3139 for (intptr_t i = 0; i < num_types; i++) { |
| 3139 type = TypeAt(i); | 3140 type = TypeAt(i); |
| 3140 other_type = other.TypeAt(i); | 3141 other_type = other.TypeAt(i); |
| 3141 if (!type.Equals(other_type)) { | 3142 if (!type.Equals(other_type)) { |
| 3142 return false; | 3143 return false; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3251 | 3252 |
| 3252 | 3253 |
| 3253 void TypeArguments::SetTypeAt(intptr_t index, const AbstractType& value) const { | 3254 void TypeArguments::SetTypeAt(intptr_t index, const AbstractType& value) const { |
| 3254 ASSERT(!IsCanonical()); | 3255 ASSERT(!IsCanonical()); |
| 3255 StorePointer(TypeAddr(index), value.raw()); | 3256 StorePointer(TypeAddr(index), value.raw()); |
| 3256 } | 3257 } |
| 3257 | 3258 |
| 3258 | 3259 |
| 3259 bool TypeArguments::IsResolved() const { | 3260 bool TypeArguments::IsResolved() const { |
| 3260 AbstractType& type = AbstractType::Handle(); | 3261 AbstractType& type = AbstractType::Handle(); |
| 3261 intptr_t num_types = Length(); | 3262 const intptr_t num_types = Length(); |
| 3262 for (intptr_t i = 0; i < num_types; i++) { | 3263 for (intptr_t i = 0; i < num_types; i++) { |
| 3263 type = TypeAt(i); | 3264 type = TypeAt(i); |
| 3264 if (!type.IsResolved()) { | 3265 if (!type.IsResolved()) { |
| 3265 return false; | 3266 return false; |
| 3266 } | 3267 } |
| 3267 } | 3268 } |
| 3268 return true; | 3269 return true; |
| 3269 } | 3270 } |
| 3270 | 3271 |
| 3271 | 3272 |
| 3272 bool TypeArguments::IsInstantiated() const { | 3273 bool TypeArguments::IsInstantiated() const { |
| 3273 AbstractType& type = AbstractType::Handle(); | 3274 AbstractType& type = AbstractType::Handle(); |
| 3274 intptr_t num_types = Length(); | 3275 const intptr_t num_types = Length(); |
| 3275 for (intptr_t i = 0; i < num_types; i++) { | 3276 for (intptr_t i = 0; i < num_types; i++) { |
| 3276 type = TypeAt(i); | 3277 type = TypeAt(i); |
| 3277 ASSERT(!type.IsNull()); | 3278 ASSERT(!type.IsNull()); |
| 3278 if (!type.IsInstantiated()) { | 3279 if (!type.IsInstantiated()) { |
| 3279 return false; | 3280 return false; |
| 3280 } | 3281 } |
| 3281 } | 3282 } |
| 3282 return true; | 3283 return true; |
| 3283 } | 3284 } |
| 3284 | 3285 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3362 if (!type_arg.Equals(super_type_arg)) { | 3363 if (!type_arg.Equals(super_type_arg)) { |
| 3363 return false; | 3364 return false; |
| 3364 } | 3365 } |
| 3365 } | 3366 } |
| 3366 return true; | 3367 return true; |
| 3367 } | 3368 } |
| 3368 | 3369 |
| 3369 | 3370 |
| 3370 bool TypeArguments::IsBounded() const { | 3371 bool TypeArguments::IsBounded() const { |
| 3371 AbstractType& type = AbstractType::Handle(); | 3372 AbstractType& type = AbstractType::Handle(); |
| 3372 intptr_t num_types = Length(); | 3373 const intptr_t num_types = Length(); |
| 3373 for (intptr_t i = 0; i < num_types; i++) { | 3374 for (intptr_t i = 0; i < num_types; i++) { |
| 3374 type = TypeAt(i); | 3375 type = TypeAt(i); |
| 3375 if (type.IsBoundedType()) { | 3376 if (type.IsBoundedType()) { |
| 3376 return true; | 3377 return true; |
| 3377 } | 3378 } |
| 3378 if (type.IsTypeParameter()) { | 3379 if (type.IsTypeParameter()) { |
| 3379 const AbstractType& bound = AbstractType::Handle( | 3380 const AbstractType& bound = AbstractType::Handle( |
| 3380 TypeParameter::Cast(type).bound()); | 3381 TypeParameter::Cast(type).bound()); |
| 3381 if (!bound.IsObjectType() && !bound.IsDynamicType()) { | 3382 if (!bound.IsObjectType() && !bound.IsDynamicType()) { |
| 3382 return true; | 3383 return true; |
| (...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4808 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the | 4809 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the |
| 4809 // signature class name is the alias name. | 4810 // signature class name is the alias name. |
| 4810 // The signature of static functions cannot be type parameterized. | 4811 // The signature of static functions cannot be type parameterized. |
| 4811 const Class& function_class = Class::Handle(Owner()); | 4812 const Class& function_class = Class::Handle(Owner()); |
| 4812 ASSERT(!function_class.IsNull()); | 4813 ASSERT(!function_class.IsNull()); |
| 4813 const TypeArguments& type_parameters = TypeArguments::Handle( | 4814 const TypeArguments& type_parameters = TypeArguments::Handle( |
| 4814 function_class.type_parameters()); | 4815 function_class.type_parameters()); |
| 4815 if (!type_parameters.IsNull()) { | 4816 if (!type_parameters.IsNull()) { |
| 4816 const String& function_class_name = String::Handle(function_class.Name()); | 4817 const String& function_class_name = String::Handle(function_class.Name()); |
| 4817 pieces.Add(function_class_name); | 4818 pieces.Add(function_class_name); |
| 4818 intptr_t num_type_parameters = type_parameters.Length(); | 4819 const intptr_t num_type_parameters = type_parameters.Length(); |
| 4819 pieces.Add(Symbols::LAngleBracket()); | 4820 pieces.Add(Symbols::LAngleBracket()); |
| 4820 TypeParameter& type_parameter = TypeParameter::Handle(); | 4821 TypeParameter& type_parameter = TypeParameter::Handle(); |
| 4821 AbstractType& bound = AbstractType::Handle(); | 4822 AbstractType& bound = AbstractType::Handle(); |
| 4822 for (intptr_t i = 0; i < num_type_parameters; i++) { | 4823 for (intptr_t i = 0; i < num_type_parameters; i++) { |
| 4823 type_parameter ^= type_parameters.TypeAt(i); | 4824 type_parameter ^= type_parameters.TypeAt(i); |
| 4824 name = type_parameter.name(); | 4825 name = type_parameter.name(); |
| 4825 pieces.Add(name); | 4826 pieces.Add(name); |
| 4826 bound = type_parameter.bound(); | 4827 bound = type_parameter.bound(); |
| 4827 if (!bound.IsNull() && !bound.IsObjectType()) { | 4828 if (!bound.IsNull() && !bound.IsObjectType()) { |
| 4828 pieces.Add(Symbols::SpaceExtendsSpace()); | 4829 pieces.Add(Symbols::SpaceExtendsSpace()); |
| (...skipping 3543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8372 RawExceptionHandlers::HandlerInfo info; | 8373 RawExceptionHandlers::HandlerInfo info; |
| 8373 // First compute the buffer size required. | 8374 // First compute the buffer size required. |
| 8374 const char* kFormat = "%" Pd " => %#" Px " (%" Pd | 8375 const char* kFormat = "%" Pd " => %#" Px " (%" Pd |
| 8375 " types) (outer %" Pd ")\n"; | 8376 " types) (outer %" Pd ")\n"; |
| 8376 const char* kFormat2 = " %d. %s\n"; | 8377 const char* kFormat2 = " %d. %s\n"; |
| 8377 intptr_t len = 1; // Trailing '\0'. | 8378 intptr_t len = 1; // Trailing '\0'. |
| 8378 for (intptr_t i = 0; i < Length(); i++) { | 8379 for (intptr_t i = 0; i < Length(); i++) { |
| 8379 GetHandlerInfo(i, &info); | 8380 GetHandlerInfo(i, &info); |
| 8380 handled_types = GetHandledTypes(i); | 8381 handled_types = GetHandledTypes(i); |
| 8381 ASSERT(!handled_types.IsNull()); | 8382 ASSERT(!handled_types.IsNull()); |
| 8382 intptr_t num_types = handled_types.Length(); | 8383 const intptr_t num_types = handled_types.Length(); |
| 8383 len += OS::SNPrint(NULL, 0, kFormat, | 8384 len += OS::SNPrint(NULL, 0, kFormat, |
| 8384 i, | 8385 i, |
| 8385 info.handler_pc, | 8386 info.handler_pc, |
| 8386 num_types, | 8387 num_types, |
| 8387 info.outer_try_index); | 8388 info.outer_try_index); |
| 8388 for (int k = 0; k < num_types; k++) { | 8389 for (int k = 0; k < num_types; k++) { |
| 8389 type ^= handled_types.At(k); | 8390 type ^= handled_types.At(k); |
| 8390 ASSERT(!type.IsNull()); | 8391 ASSERT(!type.IsNull()); |
| 8391 len += OS::SNPrint(NULL, 0, kFormat2, k, type.ToCString()); | 8392 len += OS::SNPrint(NULL, 0, kFormat2, k, type.ToCString()); |
| 8392 } | 8393 } |
| 8393 } | 8394 } |
| 8394 // Allocate the buffer. | 8395 // Allocate the buffer. |
| 8395 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len); | 8396 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 8396 // Layout the fields in the buffer. | 8397 // Layout the fields in the buffer. |
| 8397 intptr_t num_chars = 0; | 8398 intptr_t num_chars = 0; |
| 8398 for (intptr_t i = 0; i < Length(); i++) { | 8399 for (intptr_t i = 0; i < Length(); i++) { |
| 8399 GetHandlerInfo(i, &info); | 8400 GetHandlerInfo(i, &info); |
| 8400 handled_types = GetHandledTypes(i); | 8401 handled_types = GetHandledTypes(i); |
| 8401 intptr_t num_types = handled_types.Length(); | 8402 const intptr_t num_types = handled_types.Length(); |
| 8402 num_chars += OS::SNPrint((buffer + num_chars), | 8403 num_chars += OS::SNPrint((buffer + num_chars), |
| 8403 (len - num_chars), | 8404 (len - num_chars), |
| 8404 kFormat, | 8405 kFormat, |
| 8405 i, | 8406 i, |
| 8406 info.handler_pc, | 8407 info.handler_pc, |
| 8407 num_types, | 8408 num_types, |
| 8408 info.outer_try_index); | 8409 info.outer_try_index); |
| 8409 for (int k = 0; k < num_types; k++) { | 8410 for (int k = 0; k < num_types; k++) { |
| 8410 type ^= handled_types.At(k); | 8411 type ^= handled_types.At(k); |
| 8411 num_chars += OS::SNPrint((buffer + num_chars), | 8412 num_chars += OS::SNPrint((buffer + num_chars), |
| (...skipping 1834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10246 | 10247 |
| 10247 | 10248 |
| 10248 void Instance::SetTypeArguments(const AbstractTypeArguments& value) const { | 10249 void Instance::SetTypeArguments(const AbstractTypeArguments& value) const { |
| 10249 const Class& cls = Class::Handle(clazz()); | 10250 const Class& cls = Class::Handle(clazz()); |
| 10250 intptr_t field_offset = cls.type_arguments_field_offset(); | 10251 intptr_t field_offset = cls.type_arguments_field_offset(); |
| 10251 ASSERT(field_offset != Class::kNoTypeArguments); | 10252 ASSERT(field_offset != Class::kNoTypeArguments); |
| 10252 SetFieldAtOffset(field_offset, value); | 10253 SetFieldAtOffset(field_offset, value); |
| 10253 } | 10254 } |
| 10254 | 10255 |
| 10255 | 10256 |
| 10257 // TODO(regis): Rename malformed_error to bound_error. |
| 10256 bool Instance::IsInstanceOf(const AbstractType& other, | 10258 bool Instance::IsInstanceOf(const AbstractType& other, |
| 10257 const AbstractTypeArguments& other_instantiator, | 10259 const AbstractTypeArguments& other_instantiator, |
| 10258 Error* malformed_error) const { | 10260 Error* malformed_error) const { |
| 10259 ASSERT(other.IsFinalized()); | 10261 ASSERT(other.IsFinalized()); |
| 10260 ASSERT(!other.IsDynamicType()); | 10262 ASSERT(!other.IsDynamicType()); |
| 10261 ASSERT(!other.IsMalformed()); | 10263 ASSERT(!other.IsMalformed()); |
| 10264 ASSERT(!other.IsMalbounded()); |
| 10262 if (other.IsVoidType()) { | 10265 if (other.IsVoidType()) { |
| 10263 return false; | 10266 return false; |
| 10264 } | 10267 } |
| 10265 const Class& cls = Class::Handle(clazz()); | 10268 const Class& cls = Class::Handle(clazz()); |
| 10266 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); | 10269 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); |
| 10267 const intptr_t num_type_arguments = cls.NumTypeArguments(); | 10270 const intptr_t num_type_arguments = cls.NumTypeArguments(); |
| 10268 if (num_type_arguments > 0) { | 10271 if (num_type_arguments > 0) { |
| 10269 type_arguments = GetTypeArguments(); | 10272 type_arguments = GetTypeArguments(); |
| 10270 if (!type_arguments.IsNull() && !type_arguments.IsCanonical()) { | 10273 if (!type_arguments.IsNull() && !type_arguments.IsCanonical()) { |
| 10271 type_arguments = type_arguments.Canonicalize(); | 10274 type_arguments = type_arguments.Canonicalize(); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10478 } | 10481 } |
| 10479 | 10482 |
| 10480 | 10483 |
| 10481 bool AbstractType::IsMalformed() const { | 10484 bool AbstractType::IsMalformed() const { |
| 10482 // AbstractType is an abstract class. | 10485 // AbstractType is an abstract class. |
| 10483 UNREACHABLE(); | 10486 UNREACHABLE(); |
| 10484 return false; | 10487 return false; |
| 10485 } | 10488 } |
| 10486 | 10489 |
| 10487 | 10490 |
| 10491 bool AbstractType::IsMalboundedWithError(Error* bound_error) const { |
| 10492 // AbstractType is an abstract class. |
| 10493 UNREACHABLE(); |
| 10494 return false; |
| 10495 } |
| 10496 |
| 10497 |
| 10488 RawError* AbstractType::malformed_error() const { | 10498 RawError* AbstractType::malformed_error() const { |
| 10489 // AbstractType is an abstract class. | 10499 // AbstractType is an abstract class. |
| 10490 UNREACHABLE(); | 10500 UNREACHABLE(); |
| 10491 return Error::null(); | 10501 return Error::null(); |
| 10492 } | 10502 } |
| 10493 | 10503 |
| 10494 | 10504 |
| 10495 void AbstractType::set_malformed_error(const Error& value) const { | 10505 void AbstractType::set_malformed_error(const Error& value) const { |
| 10496 // AbstractType is an abstract class. | 10506 // AbstractType is an abstract class. |
| 10497 UNREACHABLE(); | 10507 UNREACHABLE(); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10875 ASSERT(!IsFinalized() && !IsBeingFinalized()); | 10885 ASSERT(!IsFinalized() && !IsBeingFinalized()); |
| 10876 set_type_state(RawType::kBeingFinalized); | 10886 set_type_state(RawType::kBeingFinalized); |
| 10877 } | 10887 } |
| 10878 | 10888 |
| 10879 | 10889 |
| 10880 bool Type::IsMalformed() const { | 10890 bool Type::IsMalformed() const { |
| 10881 return raw_ptr()->malformed_error_ != Error::null(); | 10891 return raw_ptr()->malformed_error_ != Error::null(); |
| 10882 } | 10892 } |
| 10883 | 10893 |
| 10884 | 10894 |
| 10895 bool Type::IsMalboundedWithError(Error* bound_error) const { |
| 10896 if (!FLAG_enable_type_checks && !FLAG_error_on_malformed_type) { |
| 10897 return false; |
| 10898 } |
| 10899 ASSERT(IsFinalized()); |
| 10900 ASSERT(!IsMalformed()); // Must be checked first. |
| 10901 if (arguments() == AbstractTypeArguments::null()) { |
| 10902 return false; |
| 10903 } |
| 10904 const AbstractTypeArguments& type_arguments = |
| 10905 AbstractTypeArguments::Handle(arguments()); |
| 10906 const intptr_t num_type_args = type_arguments.Length(); |
| 10907 AbstractType& type_arg = AbstractType::Handle(); |
| 10908 for (intptr_t i = 0; i < num_type_args; i++) { |
| 10909 type_arg = type_arguments.TypeAt(i); |
| 10910 ASSERT(!type_arg.IsNull()); |
| 10911 if (type_arg.IsMalboundedWithError(bound_error)) { |
| 10912 return true; |
| 10913 } |
| 10914 } |
| 10915 return false; |
| 10916 } |
| 10917 |
| 10918 |
| 10885 void Type::set_malformed_error(const Error& value) const { | 10919 void Type::set_malformed_error(const Error& value) const { |
| 10886 StorePointer(&raw_ptr()->malformed_error_, value.raw()); | 10920 StorePointer(&raw_ptr()->malformed_error_, value.raw()); |
| 10887 } | 10921 } |
| 10888 | 10922 |
| 10889 | 10923 |
| 10890 RawError* Type::malformed_error() const { | 10924 RawError* Type::malformed_error() const { |
| 10891 ASSERT(IsMalformed()); | 10925 ASSERT(IsMalformed()); |
| 10892 return raw_ptr()->malformed_error_; | 10926 return raw_ptr()->malformed_error_; |
| 10893 } | 10927 } |
| 10894 | 10928 |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11248 if (instantiator_type_arguments.IsNull()) { | 11282 if (instantiator_type_arguments.IsNull()) { |
| 11249 return Type::DynamicType(); | 11283 return Type::DynamicType(); |
| 11250 } | 11284 } |
| 11251 // Bound checks may appear in the instantiator type arguments, as is the case | 11285 // Bound checks may appear in the instantiator type arguments, as is the case |
| 11252 // with a pair of type parameters of the same class referring to each other | 11286 // with a pair of type parameters of the same class referring to each other |
| 11253 // via their bounds. | 11287 // via their bounds. |
| 11254 AbstractType& type_arg = AbstractType::Handle( | 11288 AbstractType& type_arg = AbstractType::Handle( |
| 11255 instantiator_type_arguments.TypeAt(index())); | 11289 instantiator_type_arguments.TypeAt(index())); |
| 11256 if (type_arg.IsBoundedType()) { | 11290 if (type_arg.IsBoundedType()) { |
| 11257 const BoundedType& bounded_type = BoundedType::Cast(type_arg); | 11291 const BoundedType& bounded_type = BoundedType::Cast(type_arg); |
| 11258 ASSERT(!bounded_type.IsInstantiated()); | 11292 // Bounds checking of a type is postponed to run time if the type is still |
| 11259 ASSERT(AbstractType::Handle(bounded_type.bound()).IsInstantiated()); | 11293 // uninstantiated at compile time, or if the bound and the type are mutually |
| 11260 type_arg = bounded_type.InstantiateFrom(AbstractTypeArguments::Handle(), | 11294 // recursive. In the latter case, the type may already be instantiated. |
| 11261 malformed_error); | 11295 if (!bounded_type.IsInstantiated()) { |
| 11296 ASSERT(AbstractType::Handle(bounded_type.bound()).IsInstantiated()); |
| 11297 type_arg = bounded_type.InstantiateFrom(AbstractTypeArguments::Handle(), |
| 11298 malformed_error); |
| 11299 } |
| 11262 } | 11300 } |
| 11263 return type_arg.raw(); | 11301 return type_arg.raw(); |
| 11264 } | 11302 } |
| 11265 | 11303 |
| 11266 | 11304 |
| 11267 bool TypeParameter::CheckBound(const AbstractType& bounded_type, | 11305 bool TypeParameter::CheckBound(const AbstractType& bounded_type, |
| 11268 const AbstractType& upper_bound, | 11306 const AbstractType& upper_bound, |
| 11269 Error* malformed_error) const { | 11307 Error* malformed_error) const { |
| 11270 ASSERT((malformed_error == NULL) || malformed_error->IsNull()); | 11308 ASSERT((malformed_error == NULL) || malformed_error->IsNull()); |
| 11271 ASSERT(bounded_type.IsFinalized()); | 11309 ASSERT(bounded_type.IsFinalized()); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11368 } | 11406 } |
| 11369 | 11407 |
| 11370 | 11408 |
| 11371 void TypeParameter::PrintToJSONStream(JSONStream* stream, bool ref) const { | 11409 void TypeParameter::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 11372 stream->OpenObject(); | 11410 stream->OpenObject(); |
| 11373 stream->CloseObject(); | 11411 stream->CloseObject(); |
| 11374 } | 11412 } |
| 11375 | 11413 |
| 11376 | 11414 |
| 11377 bool BoundedType::IsMalformed() const { | 11415 bool BoundedType::IsMalformed() const { |
| 11378 return FLAG_enable_type_checks && AbstractType::Handle(bound()).IsMalformed(); | 11416 return AbstractType::Handle(type()).IsMalformed(); |
| 11417 } |
| 11418 |
| 11419 |
| 11420 bool BoundedType::IsMalboundedWithError(Error* bound_error) const { |
| 11421 if (!FLAG_enable_type_checks && !FLAG_error_on_malformed_type) { |
| 11422 return false; |
| 11423 } |
| 11424 const AbstractType& upper_bound = AbstractType::Handle(bound()); |
| 11425 if (upper_bound.IsMalformed()) { |
| 11426 if (bound_error != NULL) { |
| 11427 *bound_error = upper_bound.malformed_error(); |
| 11428 ASSERT(!bound_error->IsNull()); |
| 11429 } |
| 11430 return true; |
| 11431 } |
| 11432 return false; |
| 11379 } | 11433 } |
| 11380 | 11434 |
| 11381 | 11435 |
| 11382 RawError* BoundedType::malformed_error() const { | 11436 RawError* BoundedType::malformed_error() const { |
| 11383 ASSERT(FLAG_enable_type_checks); | 11437 return AbstractType::Handle(type()).malformed_error(); |
| 11384 return AbstractType::Handle(bound()).malformed_error(); | |
| 11385 } | 11438 } |
| 11386 | 11439 |
| 11387 | 11440 |
| 11388 bool BoundedType::Equals(const Instance& other) const { | 11441 bool BoundedType::Equals(const Instance& other) const { |
| 11389 // BoundedType are not canonicalized, because their bound may get finalized | 11442 // BoundedType are not canonicalized, because their bound may get finalized |
| 11390 // after the BoundedType is created and initialized. | 11443 // after the BoundedType is created and initialized. |
| 11391 if (raw() == other.raw()) { | 11444 if (raw() == other.raw()) { |
| 11392 return true; | 11445 return true; |
| 11393 } | 11446 } |
| 11394 if (!other.IsBoundedType()) { | 11447 if (!other.IsBoundedType()) { |
| (...skipping 3404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14799 } | 14852 } |
| 14800 | 14853 |
| 14801 | 14854 |
| 14802 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14855 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 14803 stream->OpenObject(); | 14856 stream->OpenObject(); |
| 14804 stream->CloseObject(); | 14857 stream->CloseObject(); |
| 14805 } | 14858 } |
| 14806 | 14859 |
| 14807 | 14860 |
| 14808 } // namespace dart | 14861 } // namespace dart |
| OLD | NEW |