| 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 1986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1997 } | 1997 } |
| 1998 | 1998 |
| 1999 | 1999 |
| 2000 bool AbstractType::Equals(const AbstractType& other) const { | 2000 bool AbstractType::Equals(const AbstractType& other) const { |
| 2001 // AbstractType is an abstract class. | 2001 // AbstractType is an abstract class. |
| 2002 UNREACHABLE(); | 2002 UNREACHABLE(); |
| 2003 return false; | 2003 return false; |
| 2004 } | 2004 } |
| 2005 | 2005 |
| 2006 | 2006 |
| 2007 bool AbstractType::IsIdentical(const AbstractType& other) const { |
| 2008 // AbstractType is an abstract class. |
| 2009 UNREACHABLE(); |
| 2010 return false; |
| 2011 } |
| 2012 |
| 2013 |
| 2007 RawAbstractType* AbstractType::InstantiateFrom( | 2014 RawAbstractType* AbstractType::InstantiateFrom( |
| 2008 const AbstractTypeArguments& instantiator_type_arguments) const { | 2015 const AbstractTypeArguments& instantiator_type_arguments) const { |
| 2009 // AbstractType is an abstract class. | 2016 // AbstractType is an abstract class. |
| 2010 UNREACHABLE(); | 2017 UNREACHABLE(); |
| 2011 return NULL; | 2018 return NULL; |
| 2012 } | 2019 } |
| 2013 | 2020 |
| 2014 | 2021 |
| 2015 RawAbstractType* AbstractType::Canonicalize() const { | 2022 RawAbstractType* AbstractType::Canonicalize() const { |
| 2016 // AbstractType is an abstract class. | 2023 // AbstractType is an abstract class. |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2302 | 2309 |
| 2303 RawUnresolvedClass* Type::unresolved_class() const { | 2310 RawUnresolvedClass* Type::unresolved_class() const { |
| 2304 ASSERT(!HasResolvedTypeClass()); | 2311 ASSERT(!HasResolvedTypeClass()); |
| 2305 UnresolvedClass& unresolved_class = UnresolvedClass::Handle(); | 2312 UnresolvedClass& unresolved_class = UnresolvedClass::Handle(); |
| 2306 unresolved_class ^= raw_ptr()->type_class_; | 2313 unresolved_class ^= raw_ptr()->type_class_; |
| 2307 ASSERT(!unresolved_class.IsNull()); | 2314 ASSERT(!unresolved_class.IsNull()); |
| 2308 return unresolved_class.raw(); | 2315 return unresolved_class.raw(); |
| 2309 } | 2316 } |
| 2310 | 2317 |
| 2311 | 2318 |
| 2319 RawString* Type::TypeClassName() const { |
| 2320 if (HasResolvedTypeClass()) { |
| 2321 const Class& cls = Class::Handle(type_class()); |
| 2322 return cls.Name(); |
| 2323 } else { |
| 2324 const UnresolvedClass& cls = UnresolvedClass::Handle(unresolved_class()); |
| 2325 return cls.Name(); |
| 2326 } |
| 2327 } |
| 2328 |
| 2329 |
| 2312 RawAbstractTypeArguments* Type::arguments() const { | 2330 RawAbstractTypeArguments* Type::arguments() const { |
| 2313 return raw_ptr()->arguments_; | 2331 return raw_ptr()->arguments_; |
| 2314 } | 2332 } |
| 2315 | 2333 |
| 2316 | 2334 |
| 2317 bool Type::IsInstantiated() const { | 2335 bool Type::IsInstantiated() const { |
| 2318 const AbstractTypeArguments& args = | 2336 const AbstractTypeArguments& args = |
| 2319 AbstractTypeArguments::Handle(arguments()); | 2337 AbstractTypeArguments::Handle(arguments()); |
| 2320 return args.IsNull() || args.IsInstantiated(); | 2338 return args.IsNull() || args.IsInstantiated(); |
| 2321 } | 2339 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2340 | 2358 |
| 2341 | 2359 |
| 2342 bool Type::Equals(const AbstractType& other) const { | 2360 bool Type::Equals(const AbstractType& other) const { |
| 2343 ASSERT(IsFinalized() && other.IsFinalized()); | 2361 ASSERT(IsFinalized() && other.IsFinalized()); |
| 2344 if (raw() == other.raw()) { | 2362 if (raw() == other.raw()) { |
| 2345 return true; | 2363 return true; |
| 2346 } | 2364 } |
| 2347 if (IsMalformed() || !other.IsType() || other.IsMalformed()) { | 2365 if (IsMalformed() || !other.IsType() || other.IsMalformed()) { |
| 2348 return false; | 2366 return false; |
| 2349 } | 2367 } |
| 2350 Type& other_parameterized_type = Type::Handle(); | 2368 Type& other_type = Type::Handle(); |
| 2351 other_parameterized_type ^= other.raw(); | 2369 other_type ^= other.raw(); |
| 2352 if (type_class() != other_parameterized_type.type_class()) { | 2370 if (type_class() != other_type.type_class()) { |
| 2353 return false; | 2371 return false; |
| 2354 } | 2372 } |
| 2355 return AbstractTypeArguments::AreEqual( | 2373 return AbstractTypeArguments::AreEqual( |
| 2356 AbstractTypeArguments::Handle(arguments()), | 2374 AbstractTypeArguments::Handle(arguments()), |
| 2357 AbstractTypeArguments::Handle(other.arguments())); | 2375 AbstractTypeArguments::Handle(other.arguments())); |
| 2358 } | 2376 } |
| 2359 | 2377 |
| 2360 | 2378 |
| 2379 bool Type::IsIdentical(const AbstractType& other) const { |
| 2380 if (raw() == other.raw()) { |
| 2381 return true; |
| 2382 } |
| 2383 if (!other.IsType()) { |
| 2384 return false; |
| 2385 } |
| 2386 Type& other_type = Type::Handle(); |
| 2387 other_type ^= other.raw(); |
| 2388 // Both type classes may not be resolved yet. |
| 2389 String& name = String::Handle(TypeClassName()); |
| 2390 String& other_name = String::Handle(other_type.TypeClassName()); |
| 2391 if (!name.Equals(other_name)) { |
| 2392 return false; |
| 2393 } |
| 2394 return AbstractTypeArguments::AreIdentical( |
| 2395 AbstractTypeArguments::Handle(arguments()), |
| 2396 AbstractTypeArguments::Handle(other.arguments())); |
| 2397 } |
| 2398 |
| 2399 |
| 2361 RawAbstractType* Type::Canonicalize() const { | 2400 RawAbstractType* Type::Canonicalize() const { |
| 2362 ASSERT(IsFinalized()); | 2401 ASSERT(IsFinalized()); |
| 2363 const Class& cls = Class::Handle(type_class()); | 2402 const Class& cls = Class::Handle(type_class()); |
| 2364 Array& canonical_types = Array::Handle(cls.canonical_types()); | 2403 Array& canonical_types = Array::Handle(cls.canonical_types()); |
| 2365 if (canonical_types.IsNull()) { | 2404 if (canonical_types.IsNull()) { |
| 2366 // Types defined in the VM isolate are canonicalized via the object store. | 2405 // Types defined in the VM isolate are canonicalized via the object store. |
| 2367 return this->raw(); | 2406 return this->raw(); |
| 2368 } | 2407 } |
| 2369 if (!IsCanonical()) { | 2408 if (!IsCanonical()) { |
| 2370 const intptr_t canonical_types_len = canonical_types.Length(); | 2409 const intptr_t canonical_types_len = canonical_types.Length(); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2508 } | 2547 } |
| 2509 if (Index() != other_type_param.Index()) { | 2548 if (Index() != other_type_param.Index()) { |
| 2510 return false; | 2549 return false; |
| 2511 } | 2550 } |
| 2512 const String& name = String::Handle(Name()); | 2551 const String& name = String::Handle(Name()); |
| 2513 const String& other_type_param_name = String::Handle(other_type_param.Name()); | 2552 const String& other_type_param_name = String::Handle(other_type_param.Name()); |
| 2514 return name.Equals(other_type_param_name); | 2553 return name.Equals(other_type_param_name); |
| 2515 } | 2554 } |
| 2516 | 2555 |
| 2517 | 2556 |
| 2557 bool TypeParameter::IsIdentical(const AbstractType& other) const { |
| 2558 if (raw() == other.raw()) { |
| 2559 return true; |
| 2560 } |
| 2561 if (!other.IsTypeParameter()) { |
| 2562 return false; |
| 2563 } |
| 2564 TypeParameter& other_type_param = TypeParameter::Handle(); |
| 2565 other_type_param ^= other.raw(); |
| 2566 // Both type parameters may have different type_class and their index may be |
| 2567 // different after finalization, which is OK. Do not check. |
| 2568 String& name = String::Handle(Name()); |
| 2569 String& other_name = String::Handle(other_type_param.Name()); |
| 2570 return name.Equals(other_name); |
| 2571 } |
| 2572 |
| 2573 |
| 2518 void TypeParameter::set_parameterized_class(const Class& value) const { | 2574 void TypeParameter::set_parameterized_class(const Class& value) const { |
| 2519 // Set value may be null. | 2575 // Set value may be null. |
| 2520 StorePointer(&raw_ptr()->parameterized_class_, value.raw()); | 2576 StorePointer(&raw_ptr()->parameterized_class_, value.raw()); |
| 2521 } | 2577 } |
| 2522 | 2578 |
| 2523 | 2579 |
| 2524 void TypeParameter::set_index(intptr_t value) const { | 2580 void TypeParameter::set_index(intptr_t value) const { |
| 2525 ASSERT(value >= 0); | 2581 ASSERT(value >= 0); |
| 2526 raw_ptr()->index_ = value; | 2582 raw_ptr()->index_ = value; |
| 2527 } | 2583 } |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2749 if (arguments.IsNull()) { | 2805 if (arguments.IsNull()) { |
| 2750 return other_arguments.IsDynamicTypes(false, other_arguments.Length()); | 2806 return other_arguments.IsDynamicTypes(false, other_arguments.Length()); |
| 2751 } | 2807 } |
| 2752 if (other_arguments.IsNull()) { | 2808 if (other_arguments.IsNull()) { |
| 2753 return arguments.IsDynamicTypes(false, arguments.Length()); | 2809 return arguments.IsDynamicTypes(false, arguments.Length()); |
| 2754 } | 2810 } |
| 2755 return arguments.Equals(other_arguments); | 2811 return arguments.Equals(other_arguments); |
| 2756 } | 2812 } |
| 2757 | 2813 |
| 2758 | 2814 |
| 2815 bool AbstractTypeArguments::AreIdentical( |
| 2816 const AbstractTypeArguments& arguments, |
| 2817 const AbstractTypeArguments& other_arguments) { |
| 2818 if (arguments.raw() == other_arguments.raw()) { |
| 2819 return true; |
| 2820 } |
| 2821 if (arguments.IsNull() || other_arguments.IsNull()) { |
| 2822 return false; |
| 2823 } |
| 2824 intptr_t num_types = arguments.Length(); |
| 2825 if (num_types != other_arguments.Length()) { |
| 2826 return false; |
| 2827 } |
| 2828 AbstractType& type = AbstractType::Handle(); |
| 2829 AbstractType& other_type = AbstractType::Handle(); |
| 2830 for (intptr_t i = 0; i < num_types; i++) { |
| 2831 type ^= arguments.TypeAt(i); |
| 2832 ASSERT(!type.IsNull()); |
| 2833 other_type ^= other_arguments.TypeAt(i); |
| 2834 if (!type.IsIdentical(other_type)) { |
| 2835 return false; |
| 2836 } |
| 2837 } |
| 2838 return true; |
| 2839 } |
| 2840 |
| 2841 |
| 2759 RawAbstractTypeArguments* AbstractTypeArguments::InstantiateFrom( | 2842 RawAbstractTypeArguments* AbstractTypeArguments::InstantiateFrom( |
| 2760 const AbstractTypeArguments& instantiator_type_arguments) const { | 2843 const AbstractTypeArguments& instantiator_type_arguments) const { |
| 2761 // AbstractTypeArguments is an abstract class. | 2844 // AbstractTypeArguments is an abstract class. |
| 2762 UNREACHABLE(); | 2845 UNREACHABLE(); |
| 2763 return NULL; | 2846 return NULL; |
| 2764 } | 2847 } |
| 2765 | 2848 |
| 2766 | 2849 |
| 2767 bool AbstractTypeArguments::IsDynamicTypes(bool raw_instantiated, | 2850 bool AbstractTypeArguments::IsDynamicTypes(bool raw_instantiated, |
| 2768 intptr_t len) const { | 2851 intptr_t len) const { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2973 type = TypeAt(i); | 3056 type = TypeAt(i); |
| 2974 if (!type.IsInstantiated()) { | 3057 if (!type.IsInstantiated()) { |
| 2975 type = type.InstantiateFrom(instantiator_type_arguments); | 3058 type = type.InstantiateFrom(instantiator_type_arguments); |
| 2976 } | 3059 } |
| 2977 instantiated_array.SetTypeAt(i, type); | 3060 instantiated_array.SetTypeAt(i, type); |
| 2978 } | 3061 } |
| 2979 return instantiated_array.raw(); | 3062 return instantiated_array.raw(); |
| 2980 } | 3063 } |
| 2981 | 3064 |
| 2982 | 3065 |
| 2983 bool TypeArguments::AreIdenticalTypeParameters( | |
| 2984 const TypeArguments& arguments, | |
| 2985 const TypeArguments& other_arguments) { | |
| 2986 if (arguments.raw() == other_arguments.raw()) { | |
| 2987 return true; | |
| 2988 } | |
| 2989 if (arguments.IsNull() || other_arguments.IsNull()) { | |
| 2990 return false; | |
| 2991 } | |
| 2992 intptr_t num_types = arguments.Length(); | |
| 2993 if (num_types != other_arguments.Length()) { | |
| 2994 return false; | |
| 2995 } | |
| 2996 TypeParameter& type = TypeParameter::Handle(); | |
| 2997 TypeParameter& other_type = TypeParameter::Handle(); | |
| 2998 String& name = String::Handle(); | |
| 2999 String& other_name = String::Handle(); | |
| 3000 for (intptr_t i = 0; i < num_types; i++) { | |
| 3001 type ^= arguments.TypeAt(i); | |
| 3002 other_type ^= other_arguments.TypeAt(i); | |
| 3003 if (type.raw() == other_type.raw()) { | |
| 3004 continue; | |
| 3005 } | |
| 3006 // Both type parameters may have different type_class and their index may be | |
| 3007 // different after finalization, which is OK. Do not check. | |
| 3008 name = type.Name(); | |
| 3009 other_name = other_type.Name(); | |
| 3010 if (!name.Equals(other_name)) { | |
| 3011 return false; | |
| 3012 } | |
| 3013 } | |
| 3014 return true; | |
| 3015 } | |
| 3016 | |
| 3017 | |
| 3018 RawTypeArguments* TypeArguments::New(intptr_t len) { | 3066 RawTypeArguments* TypeArguments::New(intptr_t len) { |
| 3019 if ((len < 0) || (len > kMaxTypes)) { | 3067 if ((len < 0) || (len > kMaxTypes)) { |
| 3020 // TODO(iposva): Should we throw an illegal parameter exception? | 3068 // TODO(iposva): Should we throw an illegal parameter exception? |
| 3021 UNIMPLEMENTED(); | 3069 UNIMPLEMENTED(); |
| 3022 return null(); | 3070 return null(); |
| 3023 } | 3071 } |
| 3024 | 3072 |
| 3025 const Class& type_arguments_class = | 3073 const Class& type_arguments_class = |
| 3026 Class::Handle(Object::type_arguments_class()); | 3074 Class::Handle(Object::type_arguments_class()); |
| 3027 TypeArguments& result = TypeArguments::Handle(); | 3075 TypeArguments& result = TypeArguments::Handle(); |
| (...skipping 6018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9046 const String& str = String::Handle(pattern()); | 9094 const String& str = String::Handle(pattern()); |
| 9047 const char* format = "JSRegExp: pattern=%s flags=%s"; | 9095 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 9048 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 9096 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 9049 char* chars = reinterpret_cast<char*>( | 9097 char* chars = reinterpret_cast<char*>( |
| 9050 Isolate::Current()->current_zone()->Allocate(len + 1)); | 9098 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 9051 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 9099 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 9052 return chars; | 9100 return chars; |
| 9053 } | 9101 } |
| 9054 | 9102 |
| 9055 } // namespace dart | 9103 } // namespace dart |
| OLD | NEW |