| 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 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 ASSERT(!type_name.IsNull()); | 1111 ASSERT(!type_name.IsNull()); |
| 1112 const TypeArguments& type_params = TypeArguments::Handle(type_parameters()); | 1112 const TypeArguments& type_params = TypeArguments::Handle(type_parameters()); |
| 1113 if (!type_params.IsNull()) { | 1113 if (!type_params.IsNull()) { |
| 1114 intptr_t num_type_params = type_params.Length(); | 1114 intptr_t num_type_params = type_params.Length(); |
| 1115 TypeParameter& type_param = TypeParameter::Handle(); | 1115 TypeParameter& type_param = TypeParameter::Handle(); |
| 1116 String& type_param_name = String::Handle(); | 1116 String& type_param_name = String::Handle(); |
| 1117 for (intptr_t i = 0; i < num_type_params; i++) { | 1117 for (intptr_t i = 0; i < num_type_params; i++) { |
| 1118 type_param ^= type_params.TypeAt(i); | 1118 type_param ^= type_params.TypeAt(i); |
| 1119 type_param_name = type_param.Name(); | 1119 type_param_name = type_param.Name(); |
| 1120 if (type_param_name.Equals(type_name)) { | 1120 if (type_param_name.Equals(type_name)) { |
| 1121 ASSERT(type_param.IsFinalized() || (type_param.Index() == i)); | 1121 intptr_t index = type_param.Index(); |
| 1122 // Create a new TypeParameter with the given token_index. | 1122 // Create a non-finalized new TypeParameter with the given token_index. |
| 1123 return TypeParameter::New(i, type_name, token_index); | 1123 if (type_param.IsFinalized()) { |
| 1124 // The index was adjusted during finalization. Revert. |
| 1125 index -= NumTypeArguments() - num_type_params; |
| 1126 } else { |
| 1127 ASSERT(type_param.Index() == i); |
| 1128 } |
| 1129 return TypeParameter::New(*this, index, type_name, token_index); |
| 1124 } | 1130 } |
| 1125 } | 1131 } |
| 1126 } | 1132 } |
| 1127 return TypeParameter::null(); | 1133 return TypeParameter::null(); |
| 1128 } | 1134 } |
| 1129 | 1135 |
| 1130 | 1136 |
| 1131 void Class::CalculateFieldOffsets() const { | 1137 void Class::CalculateFieldOffsets() const { |
| 1132 Array& flds = Array::Handle(fields()); | 1138 Array& flds = Array::Handle(fields()); |
| 1133 const Class& super = Class::Handle(SuperClass()); | 1139 const Class& super = Class::Handle(SuperClass()); |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 if (raw() == other.raw()) { | 1502 if (raw() == other.raw()) { |
| 1497 const intptr_t len = NumTypeArguments(); | 1503 const intptr_t len = NumTypeArguments(); |
| 1498 if (len == 0) { | 1504 if (len == 0) { |
| 1499 return true; | 1505 return true; |
| 1500 } | 1506 } |
| 1501 // Since we do not truncate the type argument vector of a subclass (see | 1507 // Since we do not truncate the type argument vector of a subclass (see |
| 1502 // below), we only check a prefix of the proper length. | 1508 // below), we only check a prefix of the proper length. |
| 1503 // Check for covariance. | 1509 // Check for covariance. |
| 1504 if (type_arguments.IsNull() || | 1510 if (type_arguments.IsNull() || |
| 1505 other_type_arguments.IsNull() || | 1511 other_type_arguments.IsNull() || |
| 1506 type_arguments.IsDynamicTypes(len) || | 1512 type_arguments.IsRawInstantiatedRaw(len) || |
| 1507 other_type_arguments.IsDynamicTypes(len)) { | 1513 other_type_arguments.IsRawInstantiatedRaw(len)) { |
| 1508 return true; | 1514 return true; |
| 1509 } | 1515 } |
| 1510 return type_arguments.IsSubtypeOf(other_type_arguments, | 1516 return type_arguments.IsSubtypeOf(other_type_arguments, |
| 1511 len, | 1517 len, |
| 1512 malformed_error); | 1518 malformed_error); |
| 1513 } | 1519 } |
| 1514 // Check for two function types. | 1520 // Check for two function types. |
| 1515 if (IsSignatureClass() && other.IsSignatureClass()) { | 1521 if (IsSignatureClass() && other.IsSignatureClass()) { |
| 1516 const Function& fun = Function::Handle(signature_function()); | 1522 const Function& fun = Function::Handle(signature_function()); |
| 1517 const Function& other_fun = Function::Handle(other.signature_function()); | 1523 const Function& other_fun = Function::Handle(other.signature_function()); |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2022 String& class_name = String::Handle(); | 2028 String& class_name = String::Handle(); |
| 2023 intptr_t first_type_param_index; | 2029 intptr_t first_type_param_index; |
| 2024 intptr_t num_type_params; // Number of type parameters to print. | 2030 intptr_t num_type_params; // Number of type parameters to print. |
| 2025 if (HasResolvedTypeClass()) { | 2031 if (HasResolvedTypeClass()) { |
| 2026 const Class& cls = Class::Handle(type_class()); | 2032 const Class& cls = Class::Handle(type_class()); |
| 2027 class_name = cls.Name(); | 2033 class_name = cls.Name(); |
| 2028 num_type_params = cls.NumTypeParameters(); // Do not print the full vector. | 2034 num_type_params = cls.NumTypeParameters(); // Do not print the full vector. |
| 2029 if (num_type_params > num_args) { | 2035 if (num_type_params > num_args) { |
| 2030 first_type_param_index = 0; | 2036 first_type_param_index = 0; |
| 2031 if (!IsFinalized() || IsBeingFinalized()) { | 2037 if (!IsFinalized() || IsBeingFinalized()) { |
| 2032 // Most probably an illformed type. Do not fill up with "Dynamic". | 2038 // Most probably an illformed type. Do not fill up with "Dynamic", |
| 2039 // but use actual vector. |
| 2033 num_type_params = num_args; | 2040 num_type_params = num_args; |
| 2034 } else { | 2041 } else { |
| 2035 ASSERT(num_args == 0); // Type is raw. | 2042 ASSERT(num_args == 0); // Type is raw. |
| 2036 // We fill up with "Dynamic". | 2043 // No need to fill up with "Dynamic". |
| 2044 num_type_params = 0; |
| 2037 } | 2045 } |
| 2038 } else { | 2046 } else { |
| 2039 first_type_param_index = num_args - num_type_params; | 2047 first_type_param_index = num_args - num_type_params; |
| 2040 } | 2048 } |
| 2041 if (cls.IsSignatureClass()) { | 2049 if (cls.IsSignatureClass()) { |
| 2042 // We may be reporting an error about an illformed function type. In that | 2050 // We may be reporting an error about an illformed function type. In that |
| 2043 // case, avoid instantiating the signature, since it may lead to cycles. | 2051 // case, avoid instantiating the signature, since it may lead to cycles. |
| 2044 if (!IsFinalized() || IsBeingFinalized()) { | 2052 if (!IsFinalized() || IsBeingFinalized()) { |
| 2045 return class_name.raw(); | 2053 return class_name.raw(); |
| 2046 } | 2054 } |
| 2047 const Function& signature_function = Function::Handle( | 2055 const Function& signature_function = Function::Handle( |
| 2048 cls.signature_function()); | 2056 cls.signature_function()); |
| 2049 // Signature classes have no super type. | 2057 // Signature classes have no super type. |
| 2050 ASSERT(first_type_param_index == 0); | 2058 ASSERT(first_type_param_index == 0); |
| 2051 return signature_function.InstantiatedSignatureFrom(args); | 2059 return signature_function.InstantiatedSignatureFrom(args); |
| 2052 } | 2060 } |
| 2053 } else { | 2061 } else { |
| 2054 const UnresolvedClass& cls = UnresolvedClass::Handle(unresolved_class()); | 2062 const UnresolvedClass& cls = UnresolvedClass::Handle(unresolved_class()); |
| 2055 class_name = cls.Name(); | 2063 class_name = cls.Name(); |
| 2056 num_type_params = num_args; | 2064 num_type_params = num_args; |
| 2057 first_type_param_index = 0; | 2065 first_type_param_index = 0; |
| 2058 } | 2066 } |
| 2059 String& type_name = String::Handle(); | 2067 String& type_name = String::Handle(); |
| 2060 if (num_type_params == 0) { | 2068 if (num_type_params == 0) { |
| 2061 type_name = class_name.raw(); | 2069 type_name = class_name.raw(); |
| 2062 } else { | 2070 } else { |
| 2063 const intptr_t num_strings = 2*num_type_params + 2; // "C""<""T"", ""T"">". | 2071 const String& args_name = String::Handle( |
| 2064 const Array& strings = Array::Handle(Array::New(num_strings)); | 2072 args.SubvectorName(first_type_param_index, num_type_params)); |
| 2065 intptr_t s = 0; | 2073 type_name = String::Concat(class_name, args_name); |
| 2066 strings.SetAt(s++, class_name); | |
| 2067 strings.SetAt(s++, String::Handle(String::NewSymbol("<"))); | |
| 2068 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); | |
| 2069 AbstractType& type = AbstractType::Handle(); | |
| 2070 for (intptr_t i = 0; i < num_type_params; i++) { | |
| 2071 if (first_type_param_index + i >= num_args) { | |
| 2072 type = Type::DynamicType(); | |
| 2073 } else { | |
| 2074 type = args.TypeAt(first_type_param_index + i); | |
| 2075 } | |
| 2076 type_name = type.Name(); | |
| 2077 strings.SetAt(s++, type_name); | |
| 2078 if (i < num_type_params - 1) { | |
| 2079 strings.SetAt(s++, kCommaSpace); | |
| 2080 } | |
| 2081 } | |
| 2082 strings.SetAt(s++, String::Handle(String::NewSymbol(">"))); | |
| 2083 ASSERT(s == num_strings); | |
| 2084 type_name = String::ConcatAll(strings); | |
| 2085 } | 2074 } |
| 2086 // The name is only used for type checking and debugging purposes. | 2075 // The name is only used for type checking and debugging purposes. |
| 2087 // Unless profiling data shows otherwise, it is not worth caching the name in | 2076 // Unless profiling data shows otherwise, it is not worth caching the name in |
| 2088 // the type. | 2077 // the type. |
| 2089 return String::NewSymbol(type_name); | 2078 return String::NewSymbol(type_name); |
| 2090 } | 2079 } |
| 2091 | 2080 |
| 2092 | 2081 |
| 2093 intptr_t AbstractType::Index() const { | 2082 intptr_t AbstractType::Index() const { |
| 2094 // AbstractType is an abstract class. | 2083 // AbstractType is an abstract class. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2147 (type_class() == Type::Handle(Type::ListInterface()).type_class()); | 2136 (type_class() == Type::Handle(Type::ListInterface()).type_class()); |
| 2148 } | 2137 } |
| 2149 | 2138 |
| 2150 | 2139 |
| 2151 bool AbstractType::IsSubtypeOf(const AbstractType& other, | 2140 bool AbstractType::IsSubtypeOf(const AbstractType& other, |
| 2152 Error* malformed_error) const { | 2141 Error* malformed_error) const { |
| 2153 ASSERT(IsFinalized()); | 2142 ASSERT(IsFinalized()); |
| 2154 ASSERT(other.IsFinalized()); | 2143 ASSERT(other.IsFinalized()); |
| 2155 // AbstractType parameters cannot be handled by Class::IsSubtypeOf(). | 2144 // AbstractType parameters cannot be handled by Class::IsSubtypeOf(). |
| 2156 if (IsTypeParameter() || other.IsTypeParameter()) { | 2145 if (IsTypeParameter() || other.IsTypeParameter()) { |
| 2157 return IsTypeParameter() && other.IsTypeParameter() && | 2146 // An uninstantiated type parameter is equivalent to Dynamic. |
| 2158 (Index() == other.Index()); | 2147 return true; |
| 2159 } | 2148 } |
| 2160 const Class& cls = Class::Handle(type_class()); | 2149 const Class& cls = Class::Handle(type_class()); |
| 2161 return cls.IsSubtypeOf(AbstractTypeArguments::Handle(arguments()), | 2150 return cls.IsSubtypeOf(AbstractTypeArguments::Handle(arguments()), |
| 2162 Class::Handle(other.type_class()), | 2151 Class::Handle(other.type_class()), |
| 2163 AbstractTypeArguments::Handle(other.arguments()), | 2152 AbstractTypeArguments::Handle(other.arguments()), |
| 2164 malformed_error); | 2153 malformed_error); |
| 2165 } | 2154 } |
| 2166 | 2155 |
| 2167 RawAbstractType* AbstractType::NewTypeParameter( | 2156 RawAbstractType* AbstractType::NewTypeParameter(const Class& clazz, |
| 2168 intptr_t index, const String& name, intptr_t token_index) { | 2157 intptr_t index, |
| 2169 return TypeParameter::New(index, name, token_index); | 2158 const String& name, |
| 2159 intptr_t token_index) { |
| 2160 return TypeParameter::New(clazz, index, name, token_index); |
| 2170 } | 2161 } |
| 2171 | 2162 |
| 2172 | 2163 |
| 2173 RawAbstractType* AbstractType::NewInstantiatedType( | 2164 RawAbstractType* AbstractType::NewInstantiatedType( |
| 2174 const AbstractType& uninstantiated_type, | 2165 const AbstractType& uninstantiated_type, |
| 2175 const AbstractTypeArguments& instantiator_type_arguments) { | 2166 const AbstractTypeArguments& instantiator_type_arguments) { |
| 2176 return InstantiatedType::New(uninstantiated_type, | 2167 return InstantiatedType::New(uninstantiated_type, |
| 2177 instantiator_type_arguments); | 2168 instantiator_type_arguments); |
| 2178 } | 2169 } |
| 2179 | 2170 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2488 } | 2479 } |
| 2489 } else { | 2480 } else { |
| 2490 return "Unresolved Type"; | 2481 return "Unresolved Type"; |
| 2491 } | 2482 } |
| 2492 } | 2483 } |
| 2493 | 2484 |
| 2494 | 2485 |
| 2495 void TypeParameter::set_is_finalized() const { | 2486 void TypeParameter::set_is_finalized() const { |
| 2496 ASSERT(!IsFinalized()); | 2487 ASSERT(!IsFinalized()); |
| 2497 set_type_state(RawTypeParameter::kFinalized); | 2488 set_type_state(RawTypeParameter::kFinalized); |
| 2489 // Field parameterized_class_ is not needed after finalization anymore. |
| 2490 set_parameterized_class(Class::Handle()); |
| 2498 } | 2491 } |
| 2499 | 2492 |
| 2500 | 2493 |
| 2501 bool TypeParameter::Equals(const AbstractType& other) const { | 2494 bool TypeParameter::Equals(const AbstractType& other) const { |
| 2502 if (raw() == other.raw()) { | 2495 if (raw() == other.raw()) { |
| 2503 return true; | 2496 return true; |
| 2504 } | 2497 } |
| 2505 if (!other.IsTypeParameter()) { | 2498 if (!other.IsTypeParameter()) { |
| 2506 return false; | 2499 return false; |
| 2507 } | 2500 } |
| 2508 TypeParameter& other_type_param = TypeParameter::Handle(); | 2501 TypeParameter& other_type_param = TypeParameter::Handle(); |
| 2509 other_type_param ^= other.raw(); | 2502 other_type_param ^= other.raw(); |
| 2503 if (IsFinalized() != other_type_param.IsFinalized()) { |
| 2504 return false; |
| 2505 } |
| 2506 if (parameterized_class() != other_type_param.parameterized_class()) { |
| 2507 return false; |
| 2508 } |
| 2510 if (Index() != other_type_param.Index()) { | 2509 if (Index() != other_type_param.Index()) { |
| 2511 return false; | 2510 return false; |
| 2512 } | 2511 } |
| 2513 const String& name = String::Handle(Name()); | 2512 const String& name = String::Handle(Name()); |
| 2514 const String& other_type_param_name = String::Handle(other_type_param.Name()); | 2513 const String& other_type_param_name = String::Handle(other_type_param.Name()); |
| 2515 return name.Equals(other_type_param_name); | 2514 return name.Equals(other_type_param_name); |
| 2516 } | 2515 } |
| 2517 | 2516 |
| 2518 | 2517 |
| 2518 void TypeParameter::set_parameterized_class(const Class& value) const { |
| 2519 // Set value may be null. |
| 2520 StorePointer(&raw_ptr()->parameterized_class_, value.raw()); |
| 2521 } |
| 2522 |
| 2523 |
| 2519 void TypeParameter::set_index(intptr_t value) const { | 2524 void TypeParameter::set_index(intptr_t value) const { |
| 2520 ASSERT(value >= 0); | 2525 ASSERT(value >= 0); |
| 2521 raw_ptr()->index_ = value; | 2526 raw_ptr()->index_ = value; |
| 2522 } | 2527 } |
| 2523 | 2528 |
| 2524 | 2529 |
| 2525 void TypeParameter::set_name(const String& value) const { | 2530 void TypeParameter::set_name(const String& value) const { |
| 2526 ASSERT(value.IsSymbol()); | 2531 ASSERT(value.IsSymbol()); |
| 2527 StorePointer(&raw_ptr()->name_, value.raw()); | 2532 StorePointer(&raw_ptr()->name_, value.raw()); |
| 2528 } | 2533 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2541 RawTypeParameter* TypeParameter::New() { | 2546 RawTypeParameter* TypeParameter::New() { |
| 2542 const Class& type_parameter_class = | 2547 const Class& type_parameter_class = |
| 2543 Class::Handle(Object::type_parameter_class()); | 2548 Class::Handle(Object::type_parameter_class()); |
| 2544 RawObject* raw = Object::Allocate(type_parameter_class, | 2549 RawObject* raw = Object::Allocate(type_parameter_class, |
| 2545 TypeParameter::InstanceSize(), | 2550 TypeParameter::InstanceSize(), |
| 2546 Heap::kOld); | 2551 Heap::kOld); |
| 2547 return reinterpret_cast<RawTypeParameter*>(raw); | 2552 return reinterpret_cast<RawTypeParameter*>(raw); |
| 2548 } | 2553 } |
| 2549 | 2554 |
| 2550 | 2555 |
| 2551 RawTypeParameter* TypeParameter::New( | 2556 RawTypeParameter* TypeParameter::New(const Class& parameterized_class, |
| 2552 intptr_t index, const String& name, intptr_t token_index) { | 2557 intptr_t index, |
| 2558 const String& name, |
| 2559 intptr_t token_index) { |
| 2553 const TypeParameter& result = TypeParameter::Handle(TypeParameter::New()); | 2560 const TypeParameter& result = TypeParameter::Handle(TypeParameter::New()); |
| 2561 result.set_parameterized_class(parameterized_class); |
| 2554 result.set_index(index); | 2562 result.set_index(index); |
| 2555 result.set_name(name); | 2563 result.set_name(name); |
| 2556 result.set_token_index(token_index); | 2564 result.set_token_index(token_index); |
| 2557 result.raw_ptr()->type_state_ = RawTypeParameter::kAllocated; | 2565 result.raw_ptr()->type_state_ = RawTypeParameter::kAllocated; |
| 2558 return result.raw(); | 2566 return result.raw(); |
| 2559 } | 2567 } |
| 2560 | 2568 |
| 2561 | 2569 |
| 2562 void TypeParameter::set_token_index(intptr_t token_index) const { | 2570 void TypeParameter::set_token_index(intptr_t token_index) const { |
| 2563 ASSERT(token_index >= 0); | 2571 ASSERT(token_index >= 0); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2675 } | 2683 } |
| 2676 | 2684 |
| 2677 | 2685 |
| 2678 bool AbstractTypeArguments::IsUninstantiatedIdentity() const { | 2686 bool AbstractTypeArguments::IsUninstantiatedIdentity() const { |
| 2679 // AbstractTypeArguments is an abstract class. | 2687 // AbstractTypeArguments is an abstract class. |
| 2680 UNREACHABLE(); | 2688 UNREACHABLE(); |
| 2681 return false; | 2689 return false; |
| 2682 } | 2690 } |
| 2683 | 2691 |
| 2684 | 2692 |
| 2693 RawString* AbstractTypeArguments::SubvectorName(intptr_t from_index, |
| 2694 intptr_t len) const { |
| 2695 ASSERT(from_index + len <= Length()); |
| 2696 String& name = String::Handle(); |
| 2697 const intptr_t num_strings = 2*len + 1; // "<""T"", ""T"">". |
| 2698 const Array& strings = Array::Handle(Array::New(num_strings)); |
| 2699 intptr_t s = 0; |
| 2700 strings.SetAt(s++, String::Handle(String::NewSymbol("<"))); |
| 2701 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); |
| 2702 AbstractType& type = AbstractType::Handle(); |
| 2703 for (intptr_t i = 0; i < len; i++) { |
| 2704 type = TypeAt(from_index + i); |
| 2705 name = type.Name(); |
| 2706 strings.SetAt(s++, name); |
| 2707 if (i < len - 1) { |
| 2708 strings.SetAt(s++, kCommaSpace); |
| 2709 } |
| 2710 } |
| 2711 strings.SetAt(s++, String::Handle(String::NewSymbol(">"))); |
| 2712 ASSERT(s == num_strings); |
| 2713 name = String::ConcatAll(strings); |
| 2714 return String::NewSymbol(name); |
| 2715 } |
| 2716 |
| 2717 |
| 2685 bool AbstractTypeArguments::Equals(const AbstractTypeArguments& other) const { | 2718 bool AbstractTypeArguments::Equals(const AbstractTypeArguments& other) const { |
| 2686 ASSERT(!IsNull()); // Use AbstractTypeArguments::AreEqual(). | 2719 ASSERT(!IsNull()); // Use AbstractTypeArguments::AreEqual(). |
| 2687 if (this->raw() == other.raw()) { | 2720 if (this->raw() == other.raw()) { |
| 2688 return true; | 2721 return true; |
| 2689 } | 2722 } |
| 2690 if (other.IsNull()) { | 2723 if (other.IsNull()) { |
| 2691 return false; | 2724 return false; |
| 2692 } | 2725 } |
| 2693 intptr_t num_types = Length(); | 2726 intptr_t num_types = Length(); |
| 2694 if (num_types != other.Length()) { | 2727 if (num_types != other.Length()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2707 } | 2740 } |
| 2708 | 2741 |
| 2709 | 2742 |
| 2710 bool AbstractTypeArguments::AreEqual( | 2743 bool AbstractTypeArguments::AreEqual( |
| 2711 const AbstractTypeArguments& arguments, | 2744 const AbstractTypeArguments& arguments, |
| 2712 const AbstractTypeArguments& other_arguments) { | 2745 const AbstractTypeArguments& other_arguments) { |
| 2713 if (arguments.raw() == other_arguments.raw()) { | 2746 if (arguments.raw() == other_arguments.raw()) { |
| 2714 return true; | 2747 return true; |
| 2715 } | 2748 } |
| 2716 if (arguments.IsNull()) { | 2749 if (arguments.IsNull()) { |
| 2717 return other_arguments.IsDynamicTypes(other_arguments.Length()); | 2750 return other_arguments.IsDynamicTypes(false, other_arguments.Length()); |
| 2718 } | 2751 } |
| 2719 if (other_arguments.IsNull()) { | 2752 if (other_arguments.IsNull()) { |
| 2720 return arguments.IsDynamicTypes(arguments.Length()); | 2753 return arguments.IsDynamicTypes(false, arguments.Length()); |
| 2721 } | 2754 } |
| 2722 return arguments.Equals(other_arguments); | 2755 return arguments.Equals(other_arguments); |
| 2723 } | 2756 } |
| 2724 | 2757 |
| 2725 | 2758 |
| 2726 RawAbstractTypeArguments* AbstractTypeArguments::InstantiateFrom( | 2759 RawAbstractTypeArguments* AbstractTypeArguments::InstantiateFrom( |
| 2727 const AbstractTypeArguments& instantiator_type_arguments) const { | 2760 const AbstractTypeArguments& instantiator_type_arguments) const { |
| 2728 // AbstractTypeArguments is an abstract class. | 2761 // AbstractTypeArguments is an abstract class. |
| 2729 UNREACHABLE(); | 2762 UNREACHABLE(); |
| 2730 return NULL; | 2763 return NULL; |
| 2731 } | 2764 } |
| 2732 | 2765 |
| 2733 | 2766 |
| 2734 bool AbstractTypeArguments::IsDynamicTypes(intptr_t len) const { | 2767 bool AbstractTypeArguments::IsDynamicTypes(bool raw_instantiated, |
| 2768 intptr_t len) const { |
| 2735 ASSERT(Length() >= len); | 2769 ASSERT(Length() >= len); |
| 2736 AbstractType& type = AbstractType::Handle(); | 2770 AbstractType& type = AbstractType::Handle(); |
| 2737 Class& type_class = Class::Handle(); | 2771 Class& type_class = Class::Handle(); |
| 2738 for (intptr_t i = 0; i < len; i++) { | 2772 for (intptr_t i = 0; i < len; i++) { |
| 2739 type = TypeAt(i); | 2773 type = TypeAt(i); |
| 2740 ASSERT(!type.IsNull()); | 2774 ASSERT(!type.IsNull()); |
| 2741 if (!type.HasResolvedTypeClass()) { | 2775 if (!type.HasResolvedTypeClass()) { |
| 2742 ASSERT(type.IsTypeParameter() || type.IsMalformed()); | 2776 if (raw_instantiated && type.IsTypeParameter()) { |
| 2777 // An uninstantiated type parameter is equivalent to Dynamic. |
| 2778 continue; |
| 2779 } |
| 2780 ASSERT((!raw_instantiated && type.IsTypeParameter()) || |
| 2781 type.IsMalformed()); |
| 2743 return false; | 2782 return false; |
| 2744 } | 2783 } |
| 2745 type_class = type.type_class(); | 2784 type_class = type.type_class(); |
| 2746 if (!type_class.IsDynamicClass()) { | 2785 if (!type_class.IsDynamicClass()) { |
| 2747 return false; | 2786 return false; |
| 2748 } | 2787 } |
| 2749 } | 2788 } |
| 2750 return true; | 2789 return true; |
| 2751 } | 2790 } |
| 2752 | 2791 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2810 "type argument '%s' does not " | 2849 "type argument '%s' does not " |
| 2811 "extend bound '%s' of '%s'\n", | 2850 "extend bound '%s' of '%s'\n", |
| 2812 type_argument_name.ToCString(), | 2851 type_argument_name.ToCString(), |
| 2813 bound_name.ToCString(), | 2852 bound_name.ToCString(), |
| 2814 class_name.ToCString()); | 2853 class_name.ToCString()); |
| 2815 } | 2854 } |
| 2816 return false; | 2855 return false; |
| 2817 } | 2856 } |
| 2818 } | 2857 } |
| 2819 } | 2858 } |
| 2820 const Type& super_type = Type::Handle(cls.super_type()); | 2859 const Class& super_class = Class::Handle(cls.SuperClass()); |
| 2821 if (!super_type.IsNull()) { | 2860 if (!super_class.IsNull() && |
| 2822 ASSERT(super_type.IsFinalized()); | 2861 !IsWithinBoundsOf(super_class, bounds_instantiator, malformed_error)) { |
| 2823 const Class& super_class = Class::Handle(super_type.type_class()); | 2862 return false; |
| 2824 if (!IsWithinBoundsOf(super_class, bounds_instantiator, malformed_error)) { | |
| 2825 return false; | |
| 2826 } | |
| 2827 } | 2863 } |
| 2828 return true; | 2864 return true; |
| 2829 } | 2865 } |
| 2830 | 2866 |
| 2831 | 2867 |
| 2832 bool AbstractTypeArguments::IsSubtypeOf( | 2868 bool AbstractTypeArguments::IsSubtypeOf( |
| 2833 const AbstractTypeArguments& other, | 2869 const AbstractTypeArguments& other, |
| 2834 intptr_t len, | 2870 intptr_t len, |
| 2835 Error* malformed_error) const { | 2871 Error* malformed_error) const { |
| 2836 ASSERT(Length() >= len); | 2872 ASSERT(Length() >= len); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2937 type = TypeAt(i); | 2973 type = TypeAt(i); |
| 2938 if (!type.IsInstantiated()) { | 2974 if (!type.IsInstantiated()) { |
| 2939 type = type.InstantiateFrom(instantiator_type_arguments); | 2975 type = type.InstantiateFrom(instantiator_type_arguments); |
| 2940 } | 2976 } |
| 2941 instantiated_array.SetTypeAt(i, type); | 2977 instantiated_array.SetTypeAt(i, type); |
| 2942 } | 2978 } |
| 2943 return instantiated_array.raw(); | 2979 return instantiated_array.raw(); |
| 2944 } | 2980 } |
| 2945 | 2981 |
| 2946 | 2982 |
| 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 |
| 2947 RawTypeArguments* TypeArguments::New(intptr_t len) { | 3018 RawTypeArguments* TypeArguments::New(intptr_t len) { |
| 2948 if ((len < 0) || (len > kMaxTypes)) { | 3019 if ((len < 0) || (len > kMaxTypes)) { |
| 2949 // TODO(iposva): Should we throw an illegal parameter exception? | 3020 // TODO(iposva): Should we throw an illegal parameter exception? |
| 2950 UNIMPLEMENTED(); | 3021 UNIMPLEMENTED(); |
| 2951 return null(); | 3022 return null(); |
| 2952 } | 3023 } |
| 2953 | 3024 |
| 2954 const Class& type_arguments_class = | 3025 const Class& type_arguments_class = |
| 2955 Class::Handle(Object::type_arguments_class()); | 3026 Class::Handle(Object::type_arguments_class()); |
| 2956 TypeArguments& result = TypeArguments::Handle(); | 3027 TypeArguments& result = TypeArguments::Handle(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3036 } | 3107 } |
| 3037 | 3108 |
| 3038 | 3109 |
| 3039 RawAbstractType* InstantiatedTypeArguments::TypeAt(intptr_t index) const { | 3110 RawAbstractType* InstantiatedTypeArguments::TypeAt(intptr_t index) const { |
| 3040 const AbstractType& type = AbstractType::Handle( | 3111 const AbstractType& type = AbstractType::Handle( |
| 3041 AbstractTypeArguments::Handle( | 3112 AbstractTypeArguments::Handle( |
| 3042 uninstantiated_type_arguments()).TypeAt(index)); | 3113 uninstantiated_type_arguments()).TypeAt(index)); |
| 3043 if (type.IsTypeParameter()) { | 3114 if (type.IsTypeParameter()) { |
| 3044 AbstractTypeArguments& instantiator = | 3115 AbstractTypeArguments& instantiator = |
| 3045 AbstractTypeArguments::Handle(instantiator_type_arguments()); | 3116 AbstractTypeArguments::Handle(instantiator_type_arguments()); |
| 3117 if (instantiator.IsNull()) { |
| 3118 return Type::DynamicType(); |
| 3119 } |
| 3046 return instantiator.TypeAt(type.Index()); | 3120 return instantiator.TypeAt(type.Index()); |
| 3047 } | 3121 } |
| 3048 if (!type.IsInstantiated()) { | 3122 if (!type.IsInstantiated()) { |
| 3049 return InstantiatedType::New( | 3123 return InstantiatedType::New( |
| 3050 type, AbstractTypeArguments::Handle(instantiator_type_arguments())); | 3124 type, AbstractTypeArguments::Handle(instantiator_type_arguments())); |
| 3051 } | 3125 } |
| 3052 return type.raw(); | 3126 return type.raw(); |
| 3053 } | 3127 } |
| 3054 | 3128 |
| 3055 | 3129 |
| (...skipping 3332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6388 (type_arguments.Length() == num_type_arguments) || | 6462 (type_arguments.Length() == num_type_arguments) || |
| 6389 (cls.IsSignatureClass() && | 6463 (cls.IsSignatureClass() && |
| 6390 (type_arguments.Length() > num_type_arguments))); | 6464 (type_arguments.Length() > num_type_arguments))); |
| 6391 } | 6465 } |
| 6392 Class& other_class = Class::Handle(); | 6466 Class& other_class = Class::Handle(); |
| 6393 AbstractTypeArguments& other_type_arguments = AbstractTypeArguments::Handle(); | 6467 AbstractTypeArguments& other_type_arguments = AbstractTypeArguments::Handle(); |
| 6394 // In case 'other' is not instantiated, we could simply call | 6468 // In case 'other' is not instantiated, we could simply call |
| 6395 // other.InstantiateFrom(other_instantiator), however, we can save the | 6469 // other.InstantiateFrom(other_instantiator), however, we can save the |
| 6396 // allocation of a new AbstractType by inlining the code. | 6470 // allocation of a new AbstractType by inlining the code. |
| 6397 if (other.IsTypeParameter()) { | 6471 if (other.IsTypeParameter()) { |
| 6398 AbstractType& instantiated_other = AbstractType::Handle(); | 6472 if (other_instantiator.IsNull()) { |
| 6399 if (!other_instantiator.IsNull()) { | 6473 // An uninstantiated type parameter is equivalent to Dynamic. |
| 6400 instantiated_other = other_instantiator.TypeAt(other.Index()); | 6474 return true; |
| 6401 ASSERT(instantiated_other.IsInstantiated()); | 6475 } |
| 6402 } else { | 6476 AbstractType& instantiated_other = AbstractType::Handle( |
| 6403 instantiated_other = Type::DynamicType(); | 6477 other_instantiator.TypeAt(other.Index())); |
| 6478 if (instantiated_other.IsDynamicType() || |
| 6479 instantiated_other.IsTypeParameter()) { |
| 6480 return true; |
| 6404 } | 6481 } |
| 6405 other_class = instantiated_other.type_class(); | 6482 other_class = instantiated_other.type_class(); |
| 6406 other_type_arguments = instantiated_other.arguments(); | 6483 other_type_arguments = instantiated_other.arguments(); |
| 6407 } else { | 6484 } else { |
| 6408 other_class = other.type_class(); | 6485 other_class = other.type_class(); |
| 6409 other_type_arguments = other.arguments(); | 6486 other_type_arguments = other.arguments(); |
| 6410 if (!other_type_arguments.IsNull() && | 6487 if (!other_type_arguments.IsNull() && |
| 6411 !other_type_arguments.IsInstantiated()) { | 6488 !other_type_arguments.IsInstantiated()) { |
| 6412 other_type_arguments = | 6489 other_type_arguments = |
| 6413 other_type_arguments.InstantiateFrom(other_instantiator); | 6490 other_type_arguments.InstantiateFrom(other_instantiator); |
| (...skipping 2555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8969 const String& str = String::Handle(pattern()); | 9046 const String& str = String::Handle(pattern()); |
| 8970 const char* format = "JSRegExp: pattern=%s flags=%s"; | 9047 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 8971 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 9048 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 8972 char* chars = reinterpret_cast<char*>( | 9049 char* chars = reinterpret_cast<char*>( |
| 8973 Isolate::Current()->current_zone()->Allocate(len + 1)); | 9050 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 8974 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 9051 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 8975 return chars; | 9052 return chars; |
| 8976 } | 9053 } |
| 8977 | 9054 |
| 8978 } // namespace dart | 9055 } // namespace dart |
| OLD | NEW |