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 "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 2185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2196 } | 2196 } |
| 2197 if (other.IsMalformed()) { | 2197 if (other.IsMalformed()) { |
| 2198 ASSERT(FLAG_enable_type_checks); | 2198 ASSERT(FLAG_enable_type_checks); |
| 2199 if (malformed_error->IsNull()) { | 2199 if (malformed_error->IsNull()) { |
| 2200 *malformed_error = other.malformed_error(); | 2200 *malformed_error = other.malformed_error(); |
| 2201 } | 2201 } |
| 2202 return false; | 2202 return false; |
| 2203 } | 2203 } |
| 2204 // AbstractType parameters cannot be handled by Class::IsSubtypeOf(). | 2204 // AbstractType parameters cannot be handled by Class::IsSubtypeOf(). |
| 2205 if (IsTypeParameter() || other.IsTypeParameter()) { | 2205 if (IsTypeParameter() || other.IsTypeParameter()) { |
| 2206 // An uninstantiated type parameter is equivalent to Dynamic. | 2206 return IsTypeParameter() && other.IsTypeParameter() && |
| 2207 return true; | 2207 (Index() == other.Index()); |
|
srdjan
2012/05/01 23:30:51
I do not understand this change.
regis
2012/05/02 01:34:16
The previous test was too lenient. You can imagine
| |
| 2208 } | 2208 } |
| 2209 const Class& cls = Class::Handle(type_class()); | 2209 const Class& cls = Class::Handle(type_class()); |
| 2210 return cls.IsSubtypeOf(AbstractTypeArguments::Handle(arguments()), | 2210 return cls.IsSubtypeOf(AbstractTypeArguments::Handle(arguments()), |
| 2211 Class::Handle(other.type_class()), | 2211 Class::Handle(other.type_class()), |
| 2212 AbstractTypeArguments::Handle(other.arguments()), | 2212 AbstractTypeArguments::Handle(other.arguments()), |
| 2213 malformed_error); | 2213 malformed_error); |
| 2214 } | 2214 } |
| 2215 | 2215 |
| 2216 RawAbstractType* AbstractType::NewTypeParameter(const Class& clazz, | 2216 RawAbstractType* AbstractType::NewTypeParameter(const Class& clazz, |
| 2217 intptr_t index, | 2217 intptr_t index, |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2622 | 2622 |
| 2623 bool TypeParameter::IsIdentical(const AbstractType& other) const { | 2623 bool TypeParameter::IsIdentical(const AbstractType& other) const { |
| 2624 if (raw() == other.raw()) { | 2624 if (raw() == other.raw()) { |
| 2625 return true; | 2625 return true; |
| 2626 } | 2626 } |
| 2627 if (!other.IsTypeParameter()) { | 2627 if (!other.IsTypeParameter()) { |
| 2628 return false; | 2628 return false; |
| 2629 } | 2629 } |
| 2630 TypeParameter& other_type_param = TypeParameter::Handle(); | 2630 TypeParameter& other_type_param = TypeParameter::Handle(); |
| 2631 other_type_param ^= other.raw(); | 2631 other_type_param ^= other.raw(); |
| 2632 // Both type parameters may have different type_class and their index may be | 2632 // IsIdentical may be called on type parameters belonging to different |
| 2633 // different after finalization, which is OK. Do not check. | 2633 // classes, e.g. to an interface and to its default factory class. |
| 2634 // Therefore, both type parameters may have different parameterized classes | |
| 2635 // and different indices. Compare the type parameter names only. | |
| 2634 String& name = String::Handle(Name()); | 2636 String& name = String::Handle(Name()); |
| 2635 String& other_name = String::Handle(other_type_param.Name()); | 2637 String& other_name = String::Handle(other_type_param.Name()); |
| 2636 return name.Equals(other_name); | 2638 return name.Equals(other_name); |
| 2637 } | 2639 } |
| 2638 | 2640 |
| 2639 | 2641 |
| 2640 void TypeParameter::set_parameterized_class(const Class& value) const { | 2642 void TypeParameter::set_parameterized_class(const Class& value) const { |
| 2641 // Set value may be null. | 2643 // Set value may be null. |
| 2642 StorePointer(&raw_ptr()->parameterized_class_, value.raw()); | 2644 StorePointer(&raw_ptr()->parameterized_class_, value.raw()); |
| 2643 } | 2645 } |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2952 "Error", format, args); | 2954 "Error", format, args); |
| 2953 } | 2955 } |
| 2954 } | 2956 } |
| 2955 | 2957 |
| 2956 | 2958 |
| 2957 bool AbstractTypeArguments::IsWithinBoundsOf( | 2959 bool AbstractTypeArguments::IsWithinBoundsOf( |
| 2958 const Class& cls, | 2960 const Class& cls, |
| 2959 const AbstractTypeArguments& bounds_instantiator, | 2961 const AbstractTypeArguments& bounds_instantiator, |
| 2960 Error* malformed_error) const { | 2962 Error* malformed_error) const { |
| 2961 ASSERT(FLAG_enable_type_checks); | 2963 ASSERT(FLAG_enable_type_checks); |
| 2962 ASSERT(IsInstantiated()); | 2964 // This function may be called at compile time on (partially) uninstantiated |
| 2965 // type arguments and may return true, in which case a run time bounds check | |
| 2966 // can be avoided. | |
| 2963 ASSERT(Length() >= cls.NumTypeArguments()); | 2967 ASSERT(Length() >= cls.NumTypeArguments()); |
| 2964 const intptr_t num_type_params = cls.NumTypeParameters(); | 2968 const intptr_t num_type_params = cls.NumTypeParameters(); |
| 2965 const intptr_t offset = cls.NumTypeArguments() - num_type_params; | 2969 const intptr_t offset = cls.NumTypeArguments() - num_type_params; |
| 2966 AbstractType& type = AbstractType::Handle(); | 2970 AbstractType& type = AbstractType::Handle(); |
| 2967 AbstractType& bound = AbstractType::Handle(); | 2971 AbstractType& bound = AbstractType::Handle(); |
| 2968 const TypeArguments& bounds = | 2972 const TypeArguments& bounds = |
| 2969 TypeArguments::Handle(cls.type_parameter_bounds()); | 2973 TypeArguments::Handle(cls.type_parameter_bounds()); |
| 2970 ASSERT((bounds.IsNull() && (num_type_params == 0)) || | 2974 ASSERT((bounds.IsNull() && (num_type_params == 0)) || |
| 2971 (bounds.Length() == num_type_params)); | 2975 (bounds.Length() == num_type_params)); |
| 2972 for (intptr_t i = 0; i < num_type_params; i++) { | 2976 for (intptr_t i = 0; i < num_type_params; i++) { |
| (...skipping 6316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9289 const String& str = String::Handle(pattern()); | 9293 const String& str = String::Handle(pattern()); |
| 9290 const char* format = "JSRegExp: pattern=%s flags=%s"; | 9294 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 9291 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 9295 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 9292 char* chars = reinterpret_cast<char*>( | 9296 char* chars = reinterpret_cast<char*>( |
| 9293 Isolate::Current()->current_zone()->Allocate(len + 1)); | 9297 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 9294 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 9298 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 9295 return chars; | 9299 return chars; |
| 9296 } | 9300 } |
| 9297 | 9301 |
| 9298 } // namespace dart | 9302 } // namespace dart |
| OLD | NEW |