| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 RawObject* Object::null_ = reinterpret_cast<RawInstance*>(RAW_NULL); | 43 RawObject* Object::null_ = reinterpret_cast<RawInstance*>(RAW_NULL); |
| 44 RawInstance* Object::sentinel_ = reinterpret_cast<RawInstance*>(RAW_NULL); | 44 RawInstance* Object::sentinel_ = reinterpret_cast<RawInstance*>(RAW_NULL); |
| 45 RawInstance* Object::transition_sentinel_ = | 45 RawInstance* Object::transition_sentinel_ = |
| 46 reinterpret_cast<RawInstance*>(RAW_NULL); | 46 reinterpret_cast<RawInstance*>(RAW_NULL); |
| 47 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 47 RawClass* Object::class_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 48 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 48 RawClass* Object::null_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 49 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 49 RawClass* Object::dynamic_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 50 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 50 RawClass* Object::void_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 51 RawClass* Object::unresolved_class_class_ = | 51 RawClass* Object::unresolved_class_class_ = |
| 52 reinterpret_cast<RawClass*>(RAW_NULL); | 52 reinterpret_cast<RawClass*>(RAW_NULL); |
| 53 RawClass* Object::parameterized_type_class_ = | 53 RawClass* Object::type_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 54 reinterpret_cast<RawClass*>(RAW_NULL); | |
| 55 RawClass* Object::type_parameter_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 54 RawClass* Object::type_parameter_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 56 RawClass* Object::instantiated_type_class_ = | 55 RawClass* Object::instantiated_type_class_ = |
| 57 reinterpret_cast<RawClass*>(RAW_NULL); | 56 reinterpret_cast<RawClass*>(RAW_NULL); |
| 58 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 57 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 59 RawClass* Object::type_array_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 58 RawClass* Object::type_array_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 60 RawClass* Object::instantiated_type_arguments_class_ = | 59 RawClass* Object::instantiated_type_arguments_class_ = |
| 61 reinterpret_cast<RawClass*>(RAW_NULL); | 60 reinterpret_cast<RawClass*>(RAW_NULL); |
| 62 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 61 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 63 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 62 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 64 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 63 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 80 if (raw_class == class_class()) { | 79 if (raw_class == class_class()) { |
| 81 return kClassClass; | 80 return kClassClass; |
| 82 } else if (raw_class == null_class()) { | 81 } else if (raw_class == null_class()) { |
| 83 return kNullClass; | 82 return kNullClass; |
| 84 } else if (raw_class == dynamic_class()) { | 83 } else if (raw_class == dynamic_class()) { |
| 85 return kDynamicClass; | 84 return kDynamicClass; |
| 86 } else if (raw_class == void_class()) { | 85 } else if (raw_class == void_class()) { |
| 87 return kVoidClass; | 86 return kVoidClass; |
| 88 } else if (raw_class == unresolved_class_class()) { | 87 } else if (raw_class == unresolved_class_class()) { |
| 89 return kUnresolvedClassClass; | 88 return kUnresolvedClassClass; |
| 90 } else if (raw_class == parameterized_type_class()) { | 89 } else if (raw_class == type_class()) { |
| 91 return kParameterizedTypeClass; | 90 return kTypeClass; |
| 92 } else if (raw_class == type_parameter_class()) { | 91 } else if (raw_class == type_parameter_class()) { |
| 93 return kTypeParameterClass; | 92 return kTypeParameterClass; |
| 94 } else if (raw_class == instantiated_type_class()) { | 93 } else if (raw_class == instantiated_type_class()) { |
| 95 return kInstantiatedTypeClass; | 94 return kInstantiatedTypeClass; |
| 96 } else if (raw_class == type_arguments_class()) { | 95 } else if (raw_class == type_arguments_class()) { |
| 97 return kTypeArgumentsClass; | 96 return kTypeArgumentsClass; |
| 98 } else if (raw_class == type_array_class()) { | 97 } else if (raw_class == type_array_class()) { |
| 99 return kTypeArrayClass; | 98 return kTypeArrayClass; |
| 100 } else if (raw_class == instantiated_type_arguments_class()) { | 99 } else if (raw_class == instantiated_type_arguments_class()) { |
| 101 return kInstantiatedTypeArgumentsClass; | 100 return kInstantiatedTypeArgumentsClass; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 130 } | 129 } |
| 131 | 130 |
| 132 | 131 |
| 133 RawClass* Object::GetSingletonClass(int index) { | 132 RawClass* Object::GetSingletonClass(int index) { |
| 134 switch (index) { | 133 switch (index) { |
| 135 case kClassClass: return class_class(); | 134 case kClassClass: return class_class(); |
| 136 case kNullClass: return null_class(); | 135 case kNullClass: return null_class(); |
| 137 case kDynamicClass: return dynamic_class(); | 136 case kDynamicClass: return dynamic_class(); |
| 138 case kVoidClass: return void_class(); | 137 case kVoidClass: return void_class(); |
| 139 case kUnresolvedClassClass: return unresolved_class_class(); | 138 case kUnresolvedClassClass: return unresolved_class_class(); |
| 140 case kParameterizedTypeClass: return parameterized_type_class(); | 139 case kTypeClass: return type_class(); |
| 141 case kTypeParameterClass: return type_parameter_class(); | 140 case kTypeParameterClass: return type_parameter_class(); |
| 142 case kInstantiatedTypeClass: return instantiated_type_class(); | 141 case kInstantiatedTypeClass: return instantiated_type_class(); |
| 143 case kTypeArgumentsClass: return type_arguments_class(); | 142 case kTypeArgumentsClass: return type_arguments_class(); |
| 144 case kTypeArrayClass: return type_array_class(); | 143 case kTypeArrayClass: return type_array_class(); |
| 145 case kInstantiatedTypeArgumentsClass: | 144 case kInstantiatedTypeArgumentsClass: |
| 146 return instantiated_type_arguments_class(); | 145 return instantiated_type_arguments_class(); |
| 147 case kFunctionClass: return function_class(); | 146 case kFunctionClass: return function_class(); |
| 148 case kFieldClass: return field_class(); | 147 case kFieldClass: return field_class(); |
| 149 case kTokenStreamClass: return token_stream_class(); | 148 case kTokenStreamClass: return token_stream_class(); |
| 150 case kScriptClass: return script_class(); | 149 case kScriptClass: return script_class(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 164 } | 163 } |
| 165 | 164 |
| 166 | 165 |
| 167 const char* Object::GetSingletonClassName(int index) { | 166 const char* Object::GetSingletonClassName(int index) { |
| 168 switch (index) { | 167 switch (index) { |
| 169 case kClassClass: return "Class"; | 168 case kClassClass: return "Class"; |
| 170 case kNullClass: return "Null"; | 169 case kNullClass: return "Null"; |
| 171 case kDynamicClass: return "Dynamic"; | 170 case kDynamicClass: return "Dynamic"; |
| 172 case kVoidClass: return "void"; | 171 case kVoidClass: return "void"; |
| 173 case kUnresolvedClassClass: return "UnresolvedClass"; | 172 case kUnresolvedClassClass: return "UnresolvedClass"; |
| 174 case kParameterizedTypeClass: return "ParameterizedType"; | 173 case kTypeClass: return "Type"; |
| 175 case kTypeParameterClass: return "TypeParameter"; | 174 case kTypeParameterClass: return "TypeParameter"; |
| 176 case kInstantiatedTypeClass: return "InstantiatedType"; | 175 case kInstantiatedTypeClass: return "InstantiatedType"; |
| 177 case kTypeArgumentsClass: return "TypeArguments"; | 176 case kTypeArgumentsClass: return "TypeArguments"; |
| 178 case kTypeArrayClass: return "TypeArray"; | 177 case kTypeArrayClass: return "TypeArray"; |
| 179 case kInstantiatedTypeArgumentsClass: return "InstantiatedTypeArguments"; | 178 case kInstantiatedTypeArgumentsClass: return "InstantiatedTypeArguments"; |
| 180 case kFunctionClass: return "Function"; | 179 case kFunctionClass: return "Function"; |
| 181 case kFieldClass: return "Field"; | 180 case kFieldClass: return "Field"; |
| 182 case kTokenStreamClass: return "TokenStream"; | 181 case kTokenStreamClass: return "TokenStream"; |
| 183 case kScriptClass: return "Script"; | 182 case kScriptClass: return "Script"; |
| 184 case kLibraryClass: return "Library"; | 183 case kLibraryClass: return "Library"; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 dynamic_class_ = cls.raw(); | 267 dynamic_class_ = cls.raw(); |
| 269 | 268 |
| 270 // Allocate the remaining VM internal classes. | 269 // Allocate the remaining VM internal classes. |
| 271 cls = Class::New<UnresolvedClass>(); | 270 cls = Class::New<UnresolvedClass>(); |
| 272 unresolved_class_class_ = cls.raw(); | 271 unresolved_class_class_ = cls.raw(); |
| 273 | 272 |
| 274 cls = Class::New<Instance>(); | 273 cls = Class::New<Instance>(); |
| 275 cls.set_is_finalized(); | 274 cls.set_is_finalized(); |
| 276 void_class_ = cls.raw(); | 275 void_class_ = cls.raw(); |
| 277 | 276 |
| 278 cls = Class::New<ParameterizedType>(); | 277 cls = Class::New<Type>(); |
| 279 parameterized_type_class_ = cls.raw(); | 278 type_class_ = cls.raw(); |
| 280 | 279 |
| 281 cls = Class::New<TypeParameter>(); | 280 cls = Class::New<TypeParameter>(); |
| 282 type_parameter_class_ = cls.raw(); | 281 type_parameter_class_ = cls.raw(); |
| 283 | 282 |
| 284 cls = Class::New<InstantiatedType>(); | 283 cls = Class::New<InstantiatedType>(); |
| 285 instantiated_type_class_ = cls.raw(); | 284 instantiated_type_class_ = cls.raw(); |
| 286 | 285 |
| 287 cls = Class::New<TypeArguments>(); | 286 cls = Class::New<TypeArguments>(); |
| 288 type_arguments_class_ = cls.raw(); | 287 type_arguments_class_ = cls.raw(); |
| 289 | 288 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 cls.set_script(script); | 354 cls.set_script(script); |
| 356 lib.AddClass(cls); | 355 lib.AddClass(cls); |
| 357 } | 356 } |
| 358 | 357 |
| 359 | 358 |
| 360 void Object::Init(Isolate* isolate) { | 359 void Object::Init(Isolate* isolate) { |
| 361 TIMERSCOPE(time_bootstrap); | 360 TIMERSCOPE(time_bootstrap); |
| 362 ObjectStore* object_store = isolate->object_store(); | 361 ObjectStore* object_store = isolate->object_store(); |
| 363 | 362 |
| 364 Class& cls = Class::Handle(); | 363 Class& cls = Class::Handle(); |
| 365 ParameterizedType& type = ParameterizedType::Handle(); | 364 Type& type = Type::Handle(); |
| 366 Array& array = Array::Handle(); | 365 Array& array = Array::Handle(); |
| 367 | 366 |
| 368 // All RawArray fields will be initialized to an empty array, therefore | 367 // All RawArray fields will be initialized to an empty array, therefore |
| 369 // initialize array class first. | 368 // initialize array class first. |
| 370 cls = Class::New<Array>(); | 369 cls = Class::New<Array>(); |
| 371 object_store->set_array_class(cls); | 370 object_store->set_array_class(cls); |
| 372 | 371 |
| 373 // Array and ImmutableArray are the only VM classes that are parameterized. | 372 // Array and ImmutableArray are the only VM classes that are parameterized. |
| 374 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we | 373 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we |
| 375 // need to set the offset of their type_arguments_ field, which is explicitly | 374 // need to set the offset of their type_arguments_ field, which is explicitly |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 // Finish the initialization by compiling the bootstrap scripts containing the | 593 // Finish the initialization by compiling the bootstrap scripts containing the |
| 595 // base interfaces and the implementation of the internal classes. | 594 // base interfaces and the implementation of the internal classes. |
| 596 Bootstrap::Compile(core_lib, script); | 595 Bootstrap::Compile(core_lib, script); |
| 597 Bootstrap::Compile(core_impl_lib, impl_script); | 596 Bootstrap::Compile(core_impl_lib, impl_script); |
| 598 | 597 |
| 599 Bootstrap::SetupNativeResolver(); | 598 Bootstrap::SetupNativeResolver(); |
| 600 | 599 |
| 601 // Remove the Object superclass cycle by setting the super type to null (not | 600 // Remove the Object superclass cycle by setting the super type to null (not |
| 602 // to the type of null). | 601 // to the type of null). |
| 603 cls = object_store->object_class(); | 602 cls = object_store->object_class(); |
| 604 cls.set_super_type(Type::Handle()); | 603 cls.set_super_type(AbstractType::Handle()); |
| 605 | 604 |
| 606 ClassFinalizer::VerifyBootstrapClasses(); | 605 ClassFinalizer::VerifyBootstrapClasses(); |
| 607 } | 606 } |
| 608 | 607 |
| 609 | 608 |
| 610 void Object::InitFromSnapshot(Isolate* isolate) { | 609 void Object::InitFromSnapshot(Isolate* isolate) { |
| 611 TIMERSCOPE(time_bootstrap); | 610 TIMERSCOPE(time_bootstrap); |
| 612 ObjectStore* object_store = isolate->object_store(); | 611 ObjectStore* object_store = isolate->object_store(); |
| 613 | 612 |
| 614 Class& cls = Class::Handle(); | 613 Class& cls = Class::Handle(); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 RawString* Class::Name() const { | 717 RawString* Class::Name() const { |
| 719 if (raw_ptr()->name_ != String::null()) { | 718 if (raw_ptr()->name_ != String::null()) { |
| 720 return raw_ptr()->name_; | 719 return raw_ptr()->name_; |
| 721 } | 720 } |
| 722 ASSERT(class_class() != null_); // Or GetSingletonClassIndex will not work. | 721 ASSERT(class_class() != null_); // Or GetSingletonClassIndex will not work. |
| 723 intptr_t index = GetSingletonClassIndex(raw()); | 722 intptr_t index = GetSingletonClassIndex(raw()); |
| 724 return String::NewSymbol(GetSingletonClassName(index)); | 723 return String::NewSymbol(GetSingletonClassName(index)); |
| 725 } | 724 } |
| 726 | 725 |
| 727 | 726 |
| 728 RawType* Class::SignatureType() const { | 727 RawAbstractType* Class::SignatureType() const { |
| 729 // Return the first canonical signature type if already computed. | 728 // Return the first canonical signature type if already computed. |
| 730 const Array& signature_types = Array::Handle(canonical_types()); | 729 const Array& signature_types = Array::Handle(canonical_types()); |
| 731 if (signature_types.Length() > 0) { | 730 if (signature_types.Length() > 0) { |
| 732 Type& signature_type = Type::Handle(); | 731 AbstractType& signature_type = AbstractType::Handle(); |
| 733 signature_type ^= signature_types.At(0); | 732 signature_type ^= signature_types.At(0); |
| 734 if (!signature_type.IsNull()) { | 733 if (!signature_type.IsNull()) { |
| 735 return signature_type.raw(); | 734 return signature_type.raw(); |
| 736 } | 735 } |
| 737 } | 736 } |
| 738 ASSERT(IsSignatureClass()); | 737 ASSERT(IsSignatureClass()); |
| 739 TypeArguments& signature_type_arguments = TypeArguments::Handle(); | 738 TypeArguments& signature_type_arguments = TypeArguments::Handle(); |
| 740 const intptr_t num_type_params = NumTypeParameters(); | 739 const intptr_t num_type_params = NumTypeParameters(); |
| 741 // A signature class extends class Instance and is parameterized in the same | 740 // A signature class extends class Instance and is parameterized in the same |
| 742 // way as the owner class of its non-static signature function. | 741 // way as the owner class of its non-static signature function. |
| 743 // It is not type parameterized if its signature function is static. | 742 // It is not type parameterized if its signature function is static. |
| 744 // See Class::NewSignatureClass() for the setup of its type parameters. | 743 // See Class::NewSignatureClass() for the setup of its type parameters. |
| 745 // During type finalization, the type arguments of the super class of the | 744 // During type finalization, the type arguments of the super class of the |
| 746 // owner class of its signature function will be prepended to the type | 745 // owner class of its signature function will be prepended to the type |
| 747 // argument vector. Therefore, we only need to set the type arguments | 746 // argument vector. Therefore, we only need to set the type arguments |
| 748 // matching the type parameters here. | 747 // matching the type parameters here. |
| 749 if (num_type_params > 0) { | 748 if (num_type_params > 0) { |
| 750 const Array& type_params = Array::Handle(type_parameters()); | 749 const Array& type_params = Array::Handle(type_parameters()); |
| 751 signature_type_arguments = TypeArguments::NewTypeArray(num_type_params); | 750 signature_type_arguments = TypeArguments::NewTypeArray(num_type_params); |
| 752 String& type_param_name = String::Handle(); | 751 String& type_param_name = String::Handle(); |
| 753 Type& type_param = Type::Handle(); | 752 AbstractType& type_param = AbstractType::Handle(); |
| 754 for (int i = 0; i < num_type_params; i++) { | 753 for (int i = 0; i < num_type_params; i++) { |
| 755 type_param_name ^= type_params.At(i); | 754 type_param_name ^= type_params.At(i); |
| 756 type_param = Type::NewTypeParameter(i, type_param_name); | 755 type_param = AbstractType::NewTypeParameter(i, type_param_name); |
| 757 signature_type_arguments.SetTypeAt(i, type_param); | 756 signature_type_arguments.SetTypeAt(i, type_param); |
| 758 } | 757 } |
| 759 } | 758 } |
| 760 const ParameterizedType& signature_type = ParameterizedType::Handle( | 759 const Type& signature_type = Type::Handle( |
| 761 ParameterizedType::New(*this, signature_type_arguments)); | 760 Type::New(*this, signature_type_arguments)); |
| 762 | 761 |
| 763 // Return the still unfinalized signature type. | 762 // Return the still unfinalized signature type. |
| 764 ASSERT(!signature_type.IsFinalized()); | 763 ASSERT(!signature_type.IsFinalized()); |
| 765 return signature_type.raw(); | 764 return signature_type.raw(); |
| 766 } | 765 } |
| 767 | 766 |
| 768 | 767 |
| 769 template <class FakeObject> | 768 template <class FakeObject> |
| 770 RawClass* Class::New() { | 769 RawClass* Class::New() { |
| 771 Class& class_class = Class::Handle(Object::class_class()); | 770 Class& class_class = Class::Handle(Object::class_class()); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 // More efficient than calling NumTypeArguments(). | 894 // More efficient than calling NumTypeArguments(). |
| 896 return type_arguments_instance_field_offset() != kNoTypeArguments; | 895 return type_arguments_instance_field_offset() != kNoTypeArguments; |
| 897 } else { | 896 } else { |
| 898 // No need to check NumTypeArguments() if class has type parameters. | 897 // No need to check NumTypeArguments() if class has type parameters. |
| 899 return (NumTypeParameters() > 0) || (NumTypeArguments() > 0); | 898 return (NumTypeParameters() > 0) || (NumTypeArguments() > 0); |
| 900 } | 899 } |
| 901 } | 900 } |
| 902 | 901 |
| 903 | 902 |
| 904 RawClass* Class::SuperClass() const { | 903 RawClass* Class::SuperClass() const { |
| 905 const Type& sup_type = Type::Handle(super_type()); | 904 const AbstractType& sup_type = AbstractType::Handle(super_type()); |
| 906 if (sup_type.IsNull()) { | 905 if (sup_type.IsNull()) { |
| 907 return Class::null(); | 906 return Class::null(); |
| 908 } | 907 } |
| 909 return sup_type.type_class(); | 908 return sup_type.type_class(); |
| 910 } | 909 } |
| 911 | 910 |
| 912 | 911 |
| 913 void Class::set_super_type(const Type& value) const { | 912 void Class::set_super_type(const AbstractType& value) const { |
| 914 StorePointer(&raw_ptr()->super_type_, value.raw()); | 913 StorePointer(&raw_ptr()->super_type_, value.raw()); |
| 915 } | 914 } |
| 916 | 915 |
| 917 | 916 |
| 918 bool Class::HasFactoryClass() const { | 917 bool Class::HasFactoryClass() const { |
| 919 const Object& factory_class = Object::Handle(raw_ptr()->factory_class_); | 918 const Object& factory_class = Object::Handle(raw_ptr()->factory_class_); |
| 920 return !factory_class.IsNull(); | 919 return !factory_class.IsNull(); |
| 921 } | 920 } |
| 922 | 921 |
| 923 | 922 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 // Unless the signature function already has a signature class, create a | 1116 // Unless the signature function already has a signature class, create a |
| 1118 // canonical signature class by having the signature function point back to | 1117 // canonical signature class by having the signature function point back to |
| 1119 // the signature class. | 1118 // the signature class. |
| 1120 if (signature_function.signature_class() == Object::null()) { | 1119 if (signature_function.signature_class() == Object::null()) { |
| 1121 signature_function.set_signature_class(result); | 1120 signature_function.set_signature_class(result); |
| 1122 } | 1121 } |
| 1123 result.set_is_finalized(); | 1122 result.set_is_finalized(); |
| 1124 // Instances of a signature class can only be closures. | 1123 // Instances of a signature class can only be closures. |
| 1125 ASSERT(result.instance_size() == Closure::InstanceSize()); | 1124 ASSERT(result.instance_size() == Closure::InstanceSize()); |
| 1126 // Cache the signature type as the first canonicalized type in result. | 1125 // Cache the signature type as the first canonicalized type in result. |
| 1127 const Type& signature_type = Type::Handle(result.SignatureType()); | 1126 const AbstractType& signature_type = |
| 1127 AbstractType::Handle(result.SignatureType()); |
| 1128 ASSERT(!signature_type.IsFinalized()); | 1128 ASSERT(!signature_type.IsFinalized()); |
| 1129 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld)); | 1129 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld)); |
| 1130 new_canonical_types.SetAt(0, signature_type); | 1130 new_canonical_types.SetAt(0, signature_type); |
| 1131 result.set_canonical_types(new_canonical_types); | 1131 result.set_canonical_types(new_canonical_types); |
| 1132 return result.raw(); | 1132 return result.raw(); |
| 1133 } | 1133 } |
| 1134 | 1134 |
| 1135 | 1135 |
| 1136 RawClass* Class::GetClass(ObjectKind kind) { | 1136 RawClass* Class::GetClass(ObjectKind kind) { |
| 1137 ObjectStore* object_store = Isolate::Current()->object_store(); | 1137 ObjectStore* object_store = Isolate::Current()->object_store(); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 const Function& fun = Function::Handle(signature_function()); | 1333 const Function& fun = Function::Handle(signature_function()); |
| 1334 const Function& other_fun = Function::Handle(other.signature_function()); | 1334 const Function& other_fun = Function::Handle(other.signature_function()); |
| 1335 return fun.IsSubtypeOf(type_arguments, | 1335 return fun.IsSubtypeOf(type_arguments, |
| 1336 other_fun, | 1336 other_fun, |
| 1337 other_type_arguments); | 1337 other_type_arguments); |
| 1338 } | 1338 } |
| 1339 // Check for 'direct super type' in the case of an interface and check for | 1339 // Check for 'direct super type' in the case of an interface and check for |
| 1340 // transitivity at the same time. | 1340 // transitivity at the same time. |
| 1341 if (other.is_interface()) { | 1341 if (other.is_interface()) { |
| 1342 Array& interfaces = Array::Handle(this->interfaces()); | 1342 Array& interfaces = Array::Handle(this->interfaces()); |
| 1343 Type& interface = Type::Handle(); | 1343 AbstractType& interface = AbstractType::Handle(); |
| 1344 Class& interface_class = Class::Handle(); | 1344 Class& interface_class = Class::Handle(); |
| 1345 TypeArguments& interface_args = TypeArguments::Handle(); | 1345 TypeArguments& interface_args = TypeArguments::Handle(); |
| 1346 for (intptr_t i = 0; i < interfaces.Length(); i++) { | 1346 for (intptr_t i = 0; i < interfaces.Length(); i++) { |
| 1347 interface ^= interfaces.At(i); | 1347 interface ^= interfaces.At(i); |
| 1348 interface_class = interface.type_class(); | 1348 interface_class = interface.type_class(); |
| 1349 interface_args = interface.arguments(); | 1349 interface_args = interface.arguments(); |
| 1350 if (!interface_args.IsNull() && !interface_args.IsInstantiated()) { | 1350 if (!interface_args.IsNull() && !interface_args.IsInstantiated()) { |
| 1351 // This type implements an interface that is parameterized with generic | 1351 // This type implements an interface that is parameterized with generic |
| 1352 // type(s), e.g. it implements Array<T>. | 1352 // type(s), e.g. it implements Array<T>. |
| 1353 // The uninstantiated type T must be instantiated using the type | 1353 // The uninstantiated type T must be instantiated using the type |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1670 return ident(); | 1670 return ident(); |
| 1671 } | 1671 } |
| 1672 } | 1672 } |
| 1673 | 1673 |
| 1674 | 1674 |
| 1675 const char* UnresolvedClass::ToCString() const { | 1675 const char* UnresolvedClass::ToCString() const { |
| 1676 return "UnresolvedClass"; | 1676 return "UnresolvedClass"; |
| 1677 } | 1677 } |
| 1678 | 1678 |
| 1679 | 1679 |
| 1680 bool Type::IsResolved() const { | 1680 bool AbstractType::IsResolved() const { |
| 1681 // Type is an abstract class. | 1681 // AbstractType is an abstract class. |
| 1682 UNREACHABLE(); | 1682 UNREACHABLE(); |
| 1683 return false; | 1683 return false; |
| 1684 } | 1684 } |
| 1685 | 1685 |
| 1686 | 1686 |
| 1687 bool Type::HasResolvedTypeClass() const { | 1687 bool AbstractType::HasResolvedTypeClass() const { |
| 1688 // Type is an abstract class. | 1688 // AbstractType is an abstract class. |
| 1689 UNREACHABLE(); | 1689 UNREACHABLE(); |
| 1690 return false; | 1690 return false; |
| 1691 } | 1691 } |
| 1692 | 1692 |
| 1693 | 1693 |
| 1694 RawClass* Type::type_class() const { | 1694 RawClass* AbstractType::type_class() const { |
| 1695 // Type is an abstract class. | 1695 // AbstractType is an abstract class. |
| 1696 UNREACHABLE(); | 1696 UNREACHABLE(); |
| 1697 return Class::null(); | 1697 return Class::null(); |
| 1698 } | 1698 } |
| 1699 | 1699 |
| 1700 | 1700 |
| 1701 RawUnresolvedClass* Type::unresolved_class() const { | 1701 RawUnresolvedClass* AbstractType::unresolved_class() const { |
| 1702 // Type is an abstract class. | 1702 // AbstractType is an abstract class. |
| 1703 UNREACHABLE(); | 1703 UNREACHABLE(); |
| 1704 return UnresolvedClass::null(); | 1704 return UnresolvedClass::null(); |
| 1705 } | 1705 } |
| 1706 | 1706 |
| 1707 | 1707 |
| 1708 RawTypeArguments* Type::arguments() const { | 1708 RawTypeArguments* AbstractType::arguments() const { |
| 1709 // Type is an abstract class. | 1709 // AbstractType is an abstract class. |
| 1710 UNREACHABLE(); | 1710 UNREACHABLE(); |
| 1711 return NULL; | 1711 return NULL; |
| 1712 } | 1712 } |
| 1713 | 1713 |
| 1714 | 1714 |
| 1715 bool Type::IsInstantiated() const { | 1715 bool AbstractType::IsInstantiated() const { |
| 1716 // Type is an abstract class. | 1716 // AbstractType is an abstract class. |
| 1717 UNREACHABLE(); | 1717 UNREACHABLE(); |
| 1718 return false; | 1718 return false; |
| 1719 } | 1719 } |
| 1720 | 1720 |
| 1721 | 1721 |
| 1722 bool Type::IsFinalized() const { | 1722 bool AbstractType::IsFinalized() const { |
| 1723 // Type is an abstract class. | 1723 // AbstractType is an abstract class. |
| 1724 UNREACHABLE(); | 1724 UNREACHABLE(); |
| 1725 return false; | 1725 return false; |
| 1726 } | 1726 } |
| 1727 | 1727 |
| 1728 | 1728 |
| 1729 bool Type::IsBeingFinalized() const { | 1729 bool AbstractType::IsBeingFinalized() const { |
| 1730 // Type is an abstract class. | 1730 // AbstractType is an abstract class. |
| 1731 UNREACHABLE(); | 1731 UNREACHABLE(); |
| 1732 return false; | 1732 return false; |
| 1733 } | 1733 } |
| 1734 | 1734 |
| 1735 | 1735 |
| 1736 bool Type::Equals(const Type& other) const { | 1736 bool AbstractType::Equals(const AbstractType& other) const { |
| 1737 // Type is an abstract class. | 1737 // AbstractType is an abstract class. |
| 1738 UNREACHABLE(); | 1738 UNREACHABLE(); |
| 1739 return false; | 1739 return false; |
| 1740 } | 1740 } |
| 1741 | 1741 |
| 1742 | 1742 |
| 1743 RawType* Type::InstantiateFrom( | 1743 RawAbstractType* AbstractType::InstantiateFrom( |
| 1744 const TypeArguments& instantiator_type_arguments, | 1744 const TypeArguments& instantiator_type_arguments, |
| 1745 intptr_t offset) const { | 1745 intptr_t offset) const { |
| 1746 // Type is an abstract class. | 1746 // AbstractType is an abstract class. |
| 1747 UNREACHABLE(); | 1747 UNREACHABLE(); |
| 1748 return NULL; | 1748 return NULL; |
| 1749 } | 1749 } |
| 1750 | 1750 |
| 1751 | 1751 |
| 1752 RawType* Type::Canonicalize() const { | 1752 RawAbstractType* AbstractType::Canonicalize() const { |
| 1753 // Type is an abstract class. | 1753 // AbstractType is an abstract class. |
| 1754 UNREACHABLE(); | 1754 UNREACHABLE(); |
| 1755 return NULL; | 1755 return NULL; |
| 1756 } | 1756 } |
| 1757 | 1757 |
| 1758 | 1758 |
| 1759 RawString* Type::Name() const { | 1759 RawString* AbstractType::Name() const { |
| 1760 // If the type is still being finalized, we may be reporting an error about | 1760 // If the type is still being finalized, we may be reporting an error about |
| 1761 // an illformed type, so proceed with caution. | 1761 // an illformed type, so proceed with caution. |
| 1762 const TypeArguments& args = TypeArguments::Handle(arguments()); | 1762 const TypeArguments& args = TypeArguments::Handle(arguments()); |
| 1763 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); | 1763 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); |
| 1764 String& class_name = String::Handle(); | 1764 String& class_name = String::Handle(); |
| 1765 intptr_t first_type_param_index; | 1765 intptr_t first_type_param_index; |
| 1766 intptr_t num_type_params; // Number of type parameters to print. | 1766 intptr_t num_type_params; // Number of type parameters to print. |
| 1767 if (HasResolvedTypeClass()) { | 1767 if (HasResolvedTypeClass()) { |
| 1768 const Class& cls = Class::Handle(type_class()); | 1768 const Class& cls = Class::Handle(type_class()); |
| 1769 class_name = cls.Name(); | 1769 class_name = cls.Name(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1800 String& type_name = String::Handle(); | 1800 String& type_name = String::Handle(); |
| 1801 if (num_type_params == 0) { | 1801 if (num_type_params == 0) { |
| 1802 type_name = class_name.raw(); | 1802 type_name = class_name.raw(); |
| 1803 } else { | 1803 } else { |
| 1804 const intptr_t num_strings = 2*num_type_params + 2; // "C""<""T"", ""T"">". | 1804 const intptr_t num_strings = 2*num_type_params + 2; // "C""<""T"", ""T"">". |
| 1805 const Array& strings = Array::Handle(Array::New(num_strings)); | 1805 const Array& strings = Array::Handle(Array::New(num_strings)); |
| 1806 intptr_t s = 0; | 1806 intptr_t s = 0; |
| 1807 strings.SetAt(s++, class_name); | 1807 strings.SetAt(s++, class_name); |
| 1808 strings.SetAt(s++, String::Handle(String::NewSymbol("<"))); | 1808 strings.SetAt(s++, String::Handle(String::NewSymbol("<"))); |
| 1809 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); | 1809 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); |
| 1810 Type& type = Type::Handle(); | 1810 AbstractType& type = AbstractType::Handle(); |
| 1811 for (intptr_t i = 0; i < num_type_params; i++) { | 1811 for (intptr_t i = 0; i < num_type_params; i++) { |
| 1812 if (first_type_param_index + i >= num_args) { | 1812 if (first_type_param_index + i >= num_args) { |
| 1813 type = DynamicType(); | 1813 type = Type::DynamicType(); |
| 1814 } else { | 1814 } else { |
| 1815 type = args.TypeAt(first_type_param_index + i); | 1815 type = args.TypeAt(first_type_param_index + i); |
| 1816 } | 1816 } |
| 1817 type_name = type.Name(); | 1817 type_name = type.Name(); |
| 1818 strings.SetAt(s++, type_name); | 1818 strings.SetAt(s++, type_name); |
| 1819 if (i < num_type_params - 1) { | 1819 if (i < num_type_params - 1) { |
| 1820 strings.SetAt(s++, kCommaSpace); | 1820 strings.SetAt(s++, kCommaSpace); |
| 1821 } | 1821 } |
| 1822 } | 1822 } |
| 1823 strings.SetAt(s++, String::Handle(String::NewSymbol(">"))); | 1823 strings.SetAt(s++, String::Handle(String::NewSymbol(">"))); |
| 1824 ASSERT(s == num_strings); | 1824 ASSERT(s == num_strings); |
| 1825 type_name = String::ConcatAll(strings); | 1825 type_name = String::ConcatAll(strings); |
| 1826 } | 1826 } |
| 1827 // The name is only used for type checking and debugging purposes. | 1827 // The name is only used for type checking and debugging purposes. |
| 1828 // Unless profiling data shows otherwise, it is not worth caching the name in | 1828 // Unless profiling data shows otherwise, it is not worth caching the name in |
| 1829 // the type. | 1829 // the type. |
| 1830 return String::NewSymbol(type_name); | 1830 return String::NewSymbol(type_name); |
| 1831 } | 1831 } |
| 1832 | 1832 |
| 1833 | 1833 |
| 1834 intptr_t Type::Index() const { | 1834 intptr_t AbstractType::Index() const { |
| 1835 // Type is an abstract class. | 1835 // AbstractType is an abstract class. |
| 1836 UNREACHABLE(); | 1836 UNREACHABLE(); |
| 1837 return -1; | 1837 return -1; |
| 1838 } | 1838 } |
| 1839 | 1839 |
| 1840 | 1840 |
| 1841 RawString* Type::ClassName() const { | 1841 RawString* AbstractType::ClassName() const { |
| 1842 if (HasResolvedTypeClass()) { | 1842 if (HasResolvedTypeClass()) { |
| 1843 return Class::Handle(type_class()).Name(); | 1843 return Class::Handle(type_class()).Name(); |
| 1844 } else { | 1844 } else { |
| 1845 return UnresolvedClass::Handle(unresolved_class()).Name(); | 1845 return UnresolvedClass::Handle(unresolved_class()).Name(); |
| 1846 } | 1846 } |
| 1847 } | 1847 } |
| 1848 | 1848 |
| 1849 | 1849 |
| 1850 bool Type::IsBoolInterface() const { | 1850 bool AbstractType::IsBoolInterface() const { |
| 1851 return HasResolvedTypeClass() && | 1851 return HasResolvedTypeClass() && |
| 1852 (type_class() == Type::Handle(Type::BoolInterface()).type_class()); | 1852 (type_class() == Type::Handle(Type::BoolInterface()).type_class()); |
| 1853 } | 1853 } |
| 1854 | 1854 |
| 1855 | 1855 |
| 1856 bool Type::IsIntInterface() const { | 1856 bool AbstractType::IsIntInterface() const { |
| 1857 return HasResolvedTypeClass() && | 1857 return HasResolvedTypeClass() && |
| 1858 (type_class() == Type::Handle(Type::IntInterface()).type_class()); | 1858 (type_class() == Type::Handle(Type::IntInterface()).type_class()); |
| 1859 } | 1859 } |
| 1860 | 1860 |
| 1861 | 1861 |
| 1862 bool Type::IsDoubleInterface() const { | 1862 bool AbstractType::IsDoubleInterface() const { |
| 1863 return HasResolvedTypeClass() && | 1863 return HasResolvedTypeClass() && |
| 1864 (type_class() == Type::Handle(Type::DoubleInterface()).type_class()); | 1864 (type_class() == Type::Handle(Type::DoubleInterface()).type_class()); |
| 1865 } | 1865 } |
| 1866 | 1866 |
| 1867 | 1867 |
| 1868 bool Type::IsNumberInterface() const { | 1868 bool AbstractType::IsNumberInterface() const { |
| 1869 return HasResolvedTypeClass() && | 1869 return HasResolvedTypeClass() && |
| 1870 (type_class() == Type::Handle(Type::NumberInterface()).type_class()); | 1870 (type_class() == Type::Handle(Type::NumberInterface()).type_class()); |
| 1871 } | 1871 } |
| 1872 | 1872 |
| 1873 | 1873 |
| 1874 bool Type::IsStringInterface() const { | 1874 bool AbstractType::IsStringInterface() const { |
| 1875 return HasResolvedTypeClass() && | 1875 return HasResolvedTypeClass() && |
| 1876 (type_class() == Type::Handle(Type::StringInterface()).type_class()); | 1876 (type_class() == Type::Handle(Type::StringInterface()).type_class()); |
| 1877 } | 1877 } |
| 1878 | 1878 |
| 1879 | 1879 |
| 1880 bool Type::IsFunctionInterface() const { | 1880 bool AbstractType::IsFunctionInterface() const { |
| 1881 return HasResolvedTypeClass() && | 1881 return HasResolvedTypeClass() && |
| 1882 (type_class() == Type::Handle(Type::FunctionInterface()).type_class()); | 1882 (type_class() == Type::Handle(Type::FunctionInterface()).type_class()); |
| 1883 } | 1883 } |
| 1884 | 1884 |
| 1885 | 1885 |
| 1886 bool Type::IsListInterface() const { | 1886 bool AbstractType::IsListInterface() const { |
| 1887 return HasResolvedTypeClass() && | 1887 return HasResolvedTypeClass() && |
| 1888 (type_class() == Type::Handle(Type::ListInterface()).type_class()); | 1888 (type_class() == Type::Handle(Type::ListInterface()).type_class()); |
| 1889 } | 1889 } |
| 1890 | 1890 |
| 1891 | 1891 |
| 1892 bool Type::IsMoreSpecificThan(const Type& other) const { | 1892 bool AbstractType::IsMoreSpecificThan(const AbstractType& other) const { |
| 1893 ASSERT(IsFinalized()); | 1893 ASSERT(IsFinalized()); |
| 1894 ASSERT(other.IsFinalized()); | 1894 ASSERT(other.IsFinalized()); |
| 1895 // Type parameters cannot be handled by Class::IsMoreSpecificThan(). | 1895 // AbstractType parameters cannot be handled by Class::IsMoreSpecificThan(). |
| 1896 if (IsTypeParameter() || other.IsTypeParameter()) { | 1896 if (IsTypeParameter() || other.IsTypeParameter()) { |
| 1897 return IsTypeParameter() && other.IsTypeParameter() && | 1897 return IsTypeParameter() && other.IsTypeParameter() && |
| 1898 (Index() == other.Index()); | 1898 (Index() == other.Index()); |
| 1899 } | 1899 } |
| 1900 const Class& cls = Class::Handle(type_class()); | 1900 const Class& cls = Class::Handle(type_class()); |
| 1901 return cls.IsMoreSpecificThan(TypeArguments::Handle(arguments()), | 1901 return cls.IsMoreSpecificThan(TypeArguments::Handle(arguments()), |
| 1902 Class::Handle(other.type_class()), | 1902 Class::Handle(other.type_class()), |
| 1903 TypeArguments::Handle(other.arguments())); | 1903 TypeArguments::Handle(other.arguments())); |
| 1904 } | 1904 } |
| 1905 | 1905 |
| 1906 | 1906 |
| 1907 bool Type::Test(TypeTestKind test, const Type& other) const { | 1907 bool AbstractType::Test(TypeTestKind test, const AbstractType& other) const { |
| 1908 ASSERT(IsFinalized()); | 1908 ASSERT(IsFinalized()); |
| 1909 ASSERT(other.IsFinalized()); | 1909 ASSERT(other.IsFinalized()); |
| 1910 // Type parameters cannot be handled by Class::TestType(). | 1910 // AbstractType parameters cannot be handled by Class::TestType(). |
| 1911 if (IsTypeParameter() || other.IsTypeParameter()) { | 1911 if (IsTypeParameter() || other.IsTypeParameter()) { |
| 1912 return IsTypeParameter() && other.IsTypeParameter() && | 1912 return IsTypeParameter() && other.IsTypeParameter() && |
| 1913 (Index() == other.Index()); | 1913 (Index() == other.Index()); |
| 1914 } | 1914 } |
| 1915 const Class& cls = Class::Handle(type_class()); | 1915 const Class& cls = Class::Handle(type_class()); |
| 1916 if (test == kIsSubtypeOf) { | 1916 if (test == kIsSubtypeOf) { |
| 1917 return cls.IsSubtypeOf(TypeArguments::Handle(arguments()), | 1917 return cls.IsSubtypeOf(TypeArguments::Handle(arguments()), |
| 1918 Class::Handle(other.type_class()), | 1918 Class::Handle(other.type_class()), |
| 1919 TypeArguments::Handle(other.arguments())); | 1919 TypeArguments::Handle(other.arguments())); |
| 1920 } else { | 1920 } else { |
| 1921 ASSERT(test == kIsAssignableTo); | 1921 ASSERT(test == kIsAssignableTo); |
| 1922 return cls.IsAssignableTo(TypeArguments::Handle(arguments()), | 1922 return cls.IsAssignableTo(TypeArguments::Handle(arguments()), |
| 1923 Class::Handle(other.type_class()), | 1923 Class::Handle(other.type_class()), |
| 1924 TypeArguments::Handle(other.arguments())); | 1924 TypeArguments::Handle(other.arguments())); |
| 1925 } | 1925 } |
| 1926 } | 1926 } |
| 1927 | 1927 |
| 1928 RawAbstractType* AbstractType::NewTypeParameter( |
| 1929 intptr_t index, const String& name) { |
| 1930 return TypeParameter::New(index, name); |
| 1931 } |
| 1928 | 1932 |
| 1929 RawParameterizedType* Type::NullType() { | 1933 |
| 1934 RawAbstractType* AbstractType::NewInstantiatedType( |
| 1935 const AbstractType& uninstantiated_type, |
| 1936 const TypeArguments& instantiator_type_arguments) { |
| 1937 return InstantiatedType::New(uninstantiated_type, |
| 1938 instantiator_type_arguments); |
| 1939 } |
| 1940 |
| 1941 |
| 1942 const char* AbstractType::ToCString() const { |
| 1943 // AbstractType is an abstract class. |
| 1944 UNREACHABLE(); |
| 1945 return "AbstractType"; |
| 1946 } |
| 1947 |
| 1948 |
| 1949 RawType* Type::NullType() { |
| 1930 return Isolate::Current()->object_store()->null_type(); | 1950 return Isolate::Current()->object_store()->null_type(); |
| 1931 } | 1951 } |
| 1932 | 1952 |
| 1933 | 1953 |
| 1934 RawParameterizedType* Type::DynamicType() { | 1954 RawType* Type::DynamicType() { |
| 1935 return Isolate::Current()->object_store()->dynamic_type(); | 1955 return Isolate::Current()->object_store()->dynamic_type(); |
| 1936 } | 1956 } |
| 1937 | 1957 |
| 1938 | 1958 |
| 1939 RawParameterizedType* Type::VoidType() { | 1959 RawType* Type::VoidType() { |
| 1940 return Isolate::Current()->object_store()->void_type(); | 1960 return Isolate::Current()->object_store()->void_type(); |
| 1941 } | 1961 } |
| 1942 | 1962 |
| 1943 | 1963 |
| 1944 RawParameterizedType* Type::ObjectType() { | 1964 RawType* Type::ObjectType() { |
| 1945 return Isolate::Current()->object_store()->object_type(); | 1965 return Isolate::Current()->object_store()->object_type(); |
| 1946 } | 1966 } |
| 1947 | 1967 |
| 1948 | 1968 |
| 1949 RawParameterizedType* Type::BoolInterface() { | 1969 RawType* Type::BoolInterface() { |
| 1950 return Isolate::Current()->object_store()->bool_interface(); | 1970 return Isolate::Current()->object_store()->bool_interface(); |
| 1951 } | 1971 } |
| 1952 | 1972 |
| 1953 | 1973 |
| 1954 RawParameterizedType* Type::IntInterface() { | 1974 RawType* Type::IntInterface() { |
| 1955 return Isolate::Current()->object_store()->int_interface(); | 1975 return Isolate::Current()->object_store()->int_interface(); |
| 1956 } | 1976 } |
| 1957 | 1977 |
| 1958 | 1978 |
| 1959 RawParameterizedType* Type::DoubleInterface() { | 1979 RawType* Type::DoubleInterface() { |
| 1960 return Isolate::Current()->object_store()->double_interface(); | 1980 return Isolate::Current()->object_store()->double_interface(); |
| 1961 } | 1981 } |
| 1962 | 1982 |
| 1963 | 1983 |
| 1964 RawParameterizedType* Type::NumberInterface() { | 1984 RawType* Type::NumberInterface() { |
| 1965 return Isolate::Current()->object_store()->number_interface(); | 1985 return Isolate::Current()->object_store()->number_interface(); |
| 1966 } | 1986 } |
| 1967 | 1987 |
| 1968 | 1988 |
| 1969 RawParameterizedType* Type::StringInterface() { | 1989 RawType* Type::StringInterface() { |
| 1970 return Isolate::Current()->object_store()->string_interface(); | 1990 return Isolate::Current()->object_store()->string_interface(); |
| 1971 } | 1991 } |
| 1972 | 1992 |
| 1973 | 1993 |
| 1974 RawParameterizedType* Type::FunctionInterface() { | 1994 RawType* Type::FunctionInterface() { |
| 1975 return Isolate::Current()->object_store()->function_interface(); | 1995 return Isolate::Current()->object_store()->function_interface(); |
| 1976 } | 1996 } |
| 1977 | 1997 |
| 1978 | 1998 |
| 1979 RawParameterizedType* Type::ListInterface() { | 1999 RawType* Type::ListInterface() { |
| 1980 return Isolate::Current()->object_store()->list_interface(); | 2000 return Isolate::Current()->object_store()->list_interface(); |
| 1981 } | 2001 } |
| 1982 | 2002 |
| 1983 | 2003 |
| 1984 RawParameterizedType* Type::NewRawType(const Class& type_class) { | 2004 RawType* Type::NewRawType(const Class& type_class) { |
| 1985 const TypeArguments& type_arguments = | 2005 const TypeArguments& type_arguments = |
| 1986 TypeArguments::Handle(type_class.type_parameter_extends()); | 2006 TypeArguments::Handle(type_class.type_parameter_extends()); |
| 1987 return NewParameterizedType(Object::Handle(type_class.raw()), type_arguments); | 2007 return NewParameterizedType(Object::Handle(type_class.raw()), type_arguments); |
| 1988 } | 2008 } |
| 1989 | 2009 |
| 1990 | 2010 |
| 1991 RawParameterizedType* Type::NewNonParameterizedType(const Class& type_class) { | 2011 RawType* Type::NewNonParameterizedType( |
| 2012 const Class& type_class) { |
| 1992 ASSERT(!type_class.HasTypeArguments()); | 2013 ASSERT(!type_class.HasTypeArguments()); |
| 1993 const TypeArguments& no_type_arguments = TypeArguments::Handle(); | 2014 const TypeArguments& no_type_arguments = TypeArguments::Handle(); |
| 1994 ParameterizedType& type = ParameterizedType::Handle(); | 2015 Type& type = Type::Handle(); |
| 1995 type ^= ParameterizedType::New( | 2016 type ^= Type::New( |
| 1996 Object::Handle(type_class.raw()), no_type_arguments); | 2017 Object::Handle(type_class.raw()), no_type_arguments); |
| 1997 type.set_is_finalized(); | 2018 type.set_is_finalized(); |
| 1998 type ^= type.Canonicalize(); | 2019 type ^= type.Canonicalize(); |
| 1999 return type.raw(); | 2020 return type.raw(); |
| 2000 } | 2021 } |
| 2001 | 2022 |
| 2002 | 2023 |
| 2003 RawParameterizedType* Type::NewParameterizedType(const Object& clazz, | 2024 RawType* Type::NewParameterizedType(const Object& clazz, |
| 2004 const TypeArguments& arguments) { | 2025 const TypeArguments& arguments) { |
| 2005 return ParameterizedType::New(clazz, arguments); | 2026 return Type::New(clazz, arguments); |
| 2006 } | 2027 } |
| 2007 | 2028 |
| 2008 | 2029 |
| 2009 RawType* Type::NewTypeParameter(intptr_t index, const String& name) { | 2030 void Type::set_is_finalized() const { |
| 2010 return TypeParameter::New(index, name); | 2031 ASSERT(!IsFinalized()); |
| 2032 set_type_state(RawType::kFinalized); |
| 2011 } | 2033 } |
| 2012 | 2034 |
| 2013 | 2035 |
| 2014 RawType* Type::NewInstantiatedType( | 2036 void Type::set_is_being_finalized() const { |
| 2015 const Type& uninstantiated_type, | 2037 ASSERT(!IsFinalized() && !IsBeingFinalized()); |
| 2016 const TypeArguments& instantiator_type_arguments) { | 2038 set_type_state(RawType::kBeingFinalized); |
| 2017 return InstantiatedType::New(uninstantiated_type, | |
| 2018 instantiator_type_arguments); | |
| 2019 } | 2039 } |
| 2020 | 2040 |
| 2021 | 2041 |
| 2022 const char* Type::ToCString() const { | 2042 bool Type::IsResolved() const { |
| 2023 // Type is an abstract class. | |
| 2024 UNREACHABLE(); | |
| 2025 return "Type"; | |
| 2026 } | |
| 2027 | |
| 2028 | |
| 2029 void ParameterizedType::set_is_finalized() const { | |
| 2030 ASSERT(!IsFinalized()); | |
| 2031 set_type_state(RawParameterizedType::kFinalized); | |
| 2032 } | |
| 2033 | |
| 2034 | |
| 2035 void ParameterizedType::set_is_being_finalized() const { | |
| 2036 ASSERT(!IsFinalized() && !IsBeingFinalized()); | |
| 2037 set_type_state(RawParameterizedType::kBeingFinalized); | |
| 2038 } | |
| 2039 | |
| 2040 | |
| 2041 bool ParameterizedType::IsResolved() const { | |
| 2042 if (IsFinalized()) { | 2043 if (IsFinalized()) { |
| 2043 return true; | 2044 return true; |
| 2044 } | 2045 } |
| 2045 if (!HasResolvedTypeClass()) { | 2046 if (!HasResolvedTypeClass()) { |
| 2046 return false; | 2047 return false; |
| 2047 } | 2048 } |
| 2048 const TypeArguments& args = TypeArguments::Handle(arguments()); | 2049 const TypeArguments& args = TypeArguments::Handle(arguments()); |
| 2049 return args.IsNull() || args.IsResolved(); | 2050 return args.IsNull() || args.IsResolved(); |
| 2050 } | 2051 } |
| 2051 | 2052 |
| 2052 | 2053 |
| 2053 bool ParameterizedType::HasResolvedTypeClass() const { | 2054 bool Type::HasResolvedTypeClass() const { |
| 2054 const Object& type_class = Object::Handle(raw_ptr()->type_class_); | 2055 const Object& type_class = Object::Handle(raw_ptr()->type_class_); |
| 2055 return !type_class.IsNull() && type_class.IsClass(); | 2056 return !type_class.IsNull() && type_class.IsClass(); |
| 2056 } | 2057 } |
| 2057 | 2058 |
| 2058 | 2059 |
| 2059 RawClass* ParameterizedType::type_class() const { | 2060 RawClass* Type::type_class() const { |
| 2060 ASSERT(HasResolvedTypeClass()); | 2061 ASSERT(HasResolvedTypeClass()); |
| 2061 Class& type_class = Class::Handle(); | 2062 Class& type_class = Class::Handle(); |
| 2062 type_class ^= raw_ptr()->type_class_; | 2063 type_class ^= raw_ptr()->type_class_; |
| 2063 return type_class.raw(); | 2064 return type_class.raw(); |
| 2064 } | 2065 } |
| 2065 | 2066 |
| 2066 | 2067 |
| 2067 RawUnresolvedClass* ParameterizedType::unresolved_class() const { | 2068 RawUnresolvedClass* Type::unresolved_class() const { |
| 2068 ASSERT(!HasResolvedTypeClass()); | 2069 ASSERT(!HasResolvedTypeClass()); |
| 2069 UnresolvedClass& unresolved_class = UnresolvedClass::Handle(); | 2070 UnresolvedClass& unresolved_class = UnresolvedClass::Handle(); |
| 2070 unresolved_class ^= raw_ptr()->type_class_; | 2071 unresolved_class ^= raw_ptr()->type_class_; |
| 2071 ASSERT(!unresolved_class.IsNull()); | 2072 ASSERT(!unresolved_class.IsNull()); |
| 2072 return unresolved_class.raw(); | 2073 return unresolved_class.raw(); |
| 2073 } | 2074 } |
| 2074 | 2075 |
| 2075 | 2076 |
| 2076 RawTypeArguments* ParameterizedType::arguments() const { | 2077 RawTypeArguments* Type::arguments() const { |
| 2077 return raw_ptr()->arguments_; | 2078 return raw_ptr()->arguments_; |
| 2078 } | 2079 } |
| 2079 | 2080 |
| 2080 | 2081 |
| 2081 bool ParameterizedType::IsInstantiated() const { | 2082 bool Type::IsInstantiated() const { |
| 2082 const TypeArguments& args = TypeArguments::Handle(arguments()); | 2083 const TypeArguments& args = TypeArguments::Handle(arguments()); |
| 2083 return args.IsNull() || args.IsInstantiated(); | 2084 return args.IsNull() || args.IsInstantiated(); |
| 2084 } | 2085 } |
| 2085 | 2086 |
| 2086 | 2087 |
| 2087 RawType* ParameterizedType::InstantiateFrom( | 2088 RawAbstractType* Type::InstantiateFrom( |
| 2088 const TypeArguments& instantiator_type_arguments, | 2089 const TypeArguments& instantiator_type_arguments, |
| 2089 intptr_t offset) const { | 2090 intptr_t offset) const { |
| 2090 ASSERT(IsFinalized()); | 2091 ASSERT(IsFinalized()); |
| 2091 ASSERT(!IsInstantiated()); | 2092 ASSERT(!IsInstantiated()); |
| 2092 TypeArguments& type_arguments = TypeArguments::Handle(arguments()); | 2093 TypeArguments& type_arguments = TypeArguments::Handle(arguments()); |
| 2093 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, | 2094 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, |
| 2094 offset); | 2095 offset); |
| 2095 const Class& cls = Class::Handle(type_class()); | 2096 const Class& cls = Class::Handle(type_class()); |
| 2096 ASSERT(cls.is_finalized()); | 2097 ASSERT(cls.is_finalized()); |
| 2097 ParameterizedType& instantiated_type = ParameterizedType::Handle( | 2098 Type& instantiated_type = Type::Handle(Type::New(cls, type_arguments)); |
| 2098 ParameterizedType::New(cls, type_arguments)); | |
| 2099 ASSERT(type_arguments.IsNull() || | 2099 ASSERT(type_arguments.IsNull() || |
| 2100 (type_arguments.Length() == cls.NumTypeArguments())); | 2100 (type_arguments.Length() == cls.NumTypeArguments())); |
| 2101 instantiated_type.set_is_finalized(); | 2101 instantiated_type.set_is_finalized(); |
| 2102 return instantiated_type.raw(); | 2102 return instantiated_type.raw(); |
| 2103 } | 2103 } |
| 2104 | 2104 |
| 2105 | 2105 |
| 2106 bool ParameterizedType::Equals(const Type& other) const { | 2106 bool Type::Equals(const AbstractType& other) const { |
| 2107 ASSERT(IsFinalized() && other.IsFinalized()); | 2107 ASSERT(IsFinalized() && other.IsFinalized()); |
| 2108 if (raw() == other.raw()) { | 2108 if (raw() == other.raw()) { |
| 2109 return true; | 2109 return true; |
| 2110 } | 2110 } |
| 2111 if (!other.IsParameterizedType()) { | 2111 if (!other.IsType()) { |
| 2112 return false; | 2112 return false; |
| 2113 } | 2113 } |
| 2114 ParameterizedType& other_parameterized_type = ParameterizedType::Handle(); | 2114 Type& other_parameterized_type = Type::Handle(); |
| 2115 other_parameterized_type ^= other.raw(); | 2115 other_parameterized_type ^= other.raw(); |
| 2116 if (type_class() != other_parameterized_type.type_class()) { | 2116 if (type_class() != other_parameterized_type.type_class()) { |
| 2117 return false; | 2117 return false; |
| 2118 } | 2118 } |
| 2119 return TypeArguments::AreEqual(TypeArguments::Handle(arguments()), | 2119 return TypeArguments::AreEqual(TypeArguments::Handle(arguments()), |
| 2120 TypeArguments::Handle(other.arguments())); | 2120 TypeArguments::Handle(other.arguments())); |
| 2121 } | 2121 } |
| 2122 | 2122 |
| 2123 | 2123 |
| 2124 RawType* ParameterizedType::Canonicalize() const { | 2124 RawAbstractType* Type::Canonicalize() const { |
| 2125 ASSERT(IsFinalized()); | 2125 ASSERT(IsFinalized()); |
| 2126 const Class& cls = Class::Handle(type_class()); | 2126 const Class& cls = Class::Handle(type_class()); |
| 2127 Array& canonical_types = Array::Handle(cls.canonical_types()); | 2127 Array& canonical_types = Array::Handle(cls.canonical_types()); |
| 2128 if (canonical_types.IsNull()) { | 2128 if (canonical_types.IsNull()) { |
| 2129 // Types defined in the VM isolate are canonicalized via the object store. | 2129 // Types defined in the VM isolate are canonicalized via the object store. |
| 2130 // TODO(regis): Should we add null_class_, void_class_, dynamic_class_ to | 2130 // TODO(regis): Should we add null_class_, void_class_, dynamic_class_ to |
| 2131 // the object store, remove all types from the object store, and replace | 2131 // the object store, remove all types from the object store, and replace |
| 2132 // the test above by an assert? | 2132 // the test above by an assert? |
| 2133 return this->raw(); | 2133 return this->raw(); |
| 2134 } | 2134 } |
| 2135 const intptr_t canonical_types_len = canonical_types.Length(); | 2135 const intptr_t canonical_types_len = canonical_types.Length(); |
| 2136 // Linear search to see whether this type is already present in the | 2136 // Linear search to see whether this type is already present in the |
| 2137 // list of canonicalized types. | 2137 // list of canonicalized types. |
| 2138 Type& type = Type::Handle(); | 2138 AbstractType& type = AbstractType::Handle(); |
| 2139 intptr_t index = 0; | 2139 intptr_t index = 0; |
| 2140 while (index < canonical_types_len) { | 2140 while (index < canonical_types_len) { |
| 2141 type ^= canonical_types.At(index); | 2141 type ^= canonical_types.At(index); |
| 2142 if (type.IsNull()) { | 2142 if (type.IsNull()) { |
| 2143 break; | 2143 break; |
| 2144 } | 2144 } |
| 2145 if (!type.IsFinalized()) { | 2145 if (!type.IsFinalized()) { |
| 2146 ASSERT((index == 0) && cls.IsSignatureClass()); | 2146 ASSERT((index == 0) && cls.IsSignatureClass()); |
| 2147 index++; | 2147 index++; |
| 2148 continue; | 2148 continue; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2160 Array::Handle(Array::Grow(canonical_types, new_length, Heap::kOld)); | 2160 Array::Handle(Array::Grow(canonical_types, new_length, Heap::kOld)); |
| 2161 cls.set_canonical_types(new_canonical_types); | 2161 cls.set_canonical_types(new_canonical_types); |
| 2162 new_canonical_types.SetAt(index, *this); | 2162 new_canonical_types.SetAt(index, *this); |
| 2163 } else { | 2163 } else { |
| 2164 canonical_types.SetAt(index, *this); | 2164 canonical_types.SetAt(index, *this); |
| 2165 } | 2165 } |
| 2166 return this->raw(); | 2166 return this->raw(); |
| 2167 } | 2167 } |
| 2168 | 2168 |
| 2169 | 2169 |
| 2170 void ParameterizedType::set_type_class(const Object& value) const { | 2170 void Type::set_type_class(const Object& value) const { |
| 2171 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass())); | 2171 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass())); |
| 2172 StorePointer(&raw_ptr()->type_class_, value.raw()); | 2172 StorePointer(&raw_ptr()->type_class_, value.raw()); |
| 2173 } | 2173 } |
| 2174 | 2174 |
| 2175 | 2175 |
| 2176 void ParameterizedType::set_arguments(const TypeArguments& value) const { | 2176 void Type::set_arguments(const TypeArguments& value) const { |
| 2177 StorePointer(&raw_ptr()->arguments_, value.raw()); | 2177 StorePointer(&raw_ptr()->arguments_, value.raw()); |
| 2178 } | 2178 } |
| 2179 | 2179 |
| 2180 | 2180 |
| 2181 RawParameterizedType* ParameterizedType::New() { | 2181 RawType* Type::New() { |
| 2182 const Class& parameterized_type_class = | 2182 const Class& type_class = Class::Handle(Object::type_class()); |
| 2183 Class::Handle(Object::parameterized_type_class()); | 2183 RawObject* raw = Object::Allocate(type_class, |
| 2184 RawObject* raw = Object::Allocate(parameterized_type_class, | 2184 Type::InstanceSize(), |
| 2185 ParameterizedType::InstanceSize(), | |
| 2186 Heap::kOld); | 2185 Heap::kOld); |
| 2187 return reinterpret_cast<RawParameterizedType*>(raw); | 2186 return reinterpret_cast<RawType*>(raw); |
| 2188 } | 2187 } |
| 2189 | 2188 |
| 2190 | 2189 |
| 2191 RawParameterizedType* ParameterizedType::New(const Object& clazz, | 2190 RawType* Type::New(const Object& clazz, |
| 2192 const TypeArguments& arguments) { | 2191 const TypeArguments& arguments) { |
| 2193 const ParameterizedType& result = | 2192 const Type& result = Type::Handle(Type::New()); |
| 2194 ParameterizedType::Handle(ParameterizedType::New()); | |
| 2195 result.set_type_class(clazz); | 2193 result.set_type_class(clazz); |
| 2196 result.set_arguments(arguments); | 2194 result.set_arguments(arguments); |
| 2197 result.raw_ptr()->type_state_ = RawParameterizedType::kAllocated; | 2195 result.raw_ptr()->type_state_ = RawType::kAllocated; |
| 2198 return result.raw(); | 2196 return result.raw(); |
| 2199 } | 2197 } |
| 2200 | 2198 |
| 2201 | 2199 |
| 2202 void ParameterizedType::set_type_state(int8_t state) const { | 2200 void Type::set_type_state(int8_t state) const { |
| 2203 ASSERT(state == RawParameterizedType::kAllocated || | 2201 ASSERT(state == RawType::kAllocated || |
| 2204 state == RawParameterizedType::kBeingFinalized || | 2202 state == RawType::kBeingFinalized || |
| 2205 state == RawParameterizedType::kFinalized); | 2203 state == RawType::kFinalized); |
| 2206 raw_ptr()->type_state_ = state; | 2204 raw_ptr()->type_state_ = state; |
| 2207 } | 2205 } |
| 2208 | 2206 |
| 2209 | 2207 |
| 2210 const char* ParameterizedType::ToCString() const { | 2208 const char* Type::ToCString() const { |
| 2211 if (IsResolved()) { | 2209 if (IsResolved()) { |
| 2212 const TypeArguments& type_arguments = TypeArguments::Handle(arguments()); | 2210 const TypeArguments& type_arguments = TypeArguments::Handle(arguments()); |
| 2213 if (type_arguments.IsNull()) { | 2211 if (type_arguments.IsNull()) { |
| 2214 const char* format = "ParameterizedType: class '%s'"; | 2212 const char* format = "Type: class '%s'"; |
| 2215 const char* class_name = | 2213 const char* class_name = |
| 2216 String::Handle(Class::Handle(type_class()).Name()).ToCString(); | 2214 String::Handle(Class::Handle(type_class()).Name()).ToCString(); |
| 2217 intptr_t len = OS::SNPrint(NULL, 0, format, class_name) + 1; | 2215 intptr_t len = OS::SNPrint(NULL, 0, format, class_name) + 1; |
| 2218 char* chars = reinterpret_cast<char*>( | 2216 char* chars = reinterpret_cast<char*>( |
| 2219 Isolate::Current()->current_zone()->Allocate(len)); | 2217 Isolate::Current()->current_zone()->Allocate(len)); |
| 2220 OS::SNPrint(chars, len, format, class_name); | 2218 OS::SNPrint(chars, len, format, class_name); |
| 2221 return chars; | 2219 return chars; |
| 2222 } else { | 2220 } else { |
| 2223 const char* format = "ParameterizedType: class '%s', args:[%s]"; | 2221 const char* format = "Type: class '%s', args:[%s]"; |
| 2224 const char* class_name = | 2222 const char* class_name = |
| 2225 String::Handle(Class::Handle(type_class()).Name()).ToCString(); | 2223 String::Handle(Class::Handle(type_class()).Name()).ToCString(); |
| 2226 const char* args_cstr = TypeArguments::Handle(arguments()).ToCString(); | 2224 const char* args_cstr = TypeArguments::Handle(arguments()).ToCString(); |
| 2227 intptr_t len = OS::SNPrint(NULL, 0, format, class_name, args_cstr) + 1; | 2225 intptr_t len = OS::SNPrint(NULL, 0, format, class_name, args_cstr) + 1; |
| 2228 char* chars = reinterpret_cast<char*>( | 2226 char* chars = reinterpret_cast<char*>( |
| 2229 Isolate::Current()->current_zone()->Allocate(len)); | 2227 Isolate::Current()->current_zone()->Allocate(len)); |
| 2230 OS::SNPrint(chars, len, format, class_name, args_cstr); | 2228 OS::SNPrint(chars, len, format, class_name, args_cstr); |
| 2231 return chars; | 2229 return chars; |
| 2232 } | 2230 } |
| 2233 } else { | 2231 } else { |
| 2234 return "Unresolved ParameterizedType"; | 2232 return "Unresolved Type"; |
| 2235 } | 2233 } |
| 2236 } | 2234 } |
| 2237 | 2235 |
| 2238 | 2236 |
| 2239 bool TypeParameter::Equals(const Type& other) const { | 2237 bool TypeParameter::Equals(const AbstractType& other) const { |
| 2240 if (raw() == other.raw()) { | 2238 if (raw() == other.raw()) { |
| 2241 return true; | 2239 return true; |
| 2242 } | 2240 } |
| 2243 if (!other.IsTypeParameter()) { | 2241 if (!other.IsTypeParameter()) { |
| 2244 return false; | 2242 return false; |
| 2245 } | 2243 } |
| 2246 TypeParameter& other_type_parameter = TypeParameter::Handle(); | 2244 TypeParameter& other_type_parameter = TypeParameter::Handle(); |
| 2247 other_type_parameter ^= other.raw(); | 2245 other_type_parameter ^= other.raw(); |
| 2248 return Index() == other_type_parameter.Index(); | 2246 return Index() == other_type_parameter.Index(); |
| 2249 } | 2247 } |
| 2250 | 2248 |
| 2251 | 2249 |
| 2252 void TypeParameter::set_index(intptr_t value) const { | 2250 void TypeParameter::set_index(intptr_t value) const { |
| 2253 ASSERT(value >= 0); | 2251 ASSERT(value >= 0); |
| 2254 raw_ptr()->index_ = value; | 2252 raw_ptr()->index_ = value; |
| 2255 } | 2253 } |
| 2256 | 2254 |
| 2257 | 2255 |
| 2258 void TypeParameter::set_name(const String& value) const { | 2256 void TypeParameter::set_name(const String& value) const { |
| 2259 ASSERT(value.IsSymbol()); | 2257 ASSERT(value.IsSymbol()); |
| 2260 StorePointer(&raw_ptr()->name_, value.raw()); | 2258 StorePointer(&raw_ptr()->name_, value.raw()); |
| 2261 } | 2259 } |
| 2262 | 2260 |
| 2263 | 2261 |
| 2264 RawType* TypeParameter::InstantiateFrom( | 2262 RawAbstractType* TypeParameter::InstantiateFrom( |
| 2265 const TypeArguments& instantiator_type_arguments, | 2263 const TypeArguments& instantiator_type_arguments, |
| 2266 intptr_t offset) const { | 2264 intptr_t offset) const { |
| 2267 if (instantiator_type_arguments.IsNull()) { | 2265 if (instantiator_type_arguments.IsNull()) { |
| 2268 return DynamicType(); | 2266 return Type::DynamicType(); |
| 2269 } | 2267 } |
| 2270 return instantiator_type_arguments.TypeAt(Index() + offset); | 2268 return instantiator_type_arguments.TypeAt(Index() + offset); |
| 2271 } | 2269 } |
| 2272 | 2270 |
| 2273 | 2271 |
| 2274 RawTypeParameter* TypeParameter::New() { | 2272 RawTypeParameter* TypeParameter::New() { |
| 2275 const Class& type_parameter_class = | 2273 const Class& type_parameter_class = |
| 2276 Class::Handle(Object::type_parameter_class()); | 2274 Class::Handle(Object::type_parameter_class()); |
| 2277 RawObject* raw = Object::Allocate(type_parameter_class, | 2275 RawObject* raw = Object::Allocate(type_parameter_class, |
| 2278 TypeParameter::InstanceSize(), | 2276 TypeParameter::InstanceSize(), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2294 const char* name_cstr = String::Handle(Name()).ToCString(); | 2292 const char* name_cstr = String::Handle(Name()).ToCString(); |
| 2295 intptr_t len = OS::SNPrint(NULL, 0, format, name_cstr, Index()) + 1; | 2293 intptr_t len = OS::SNPrint(NULL, 0, format, name_cstr, Index()) + 1; |
| 2296 char* chars = reinterpret_cast<char*>( | 2294 char* chars = reinterpret_cast<char*>( |
| 2297 Isolate::Current()->current_zone()->Allocate(len)); | 2295 Isolate::Current()->current_zone()->Allocate(len)); |
| 2298 OS::SNPrint(chars, len, format, name_cstr, Index()); | 2296 OS::SNPrint(chars, len, format, name_cstr, Index()); |
| 2299 return chars; | 2297 return chars; |
| 2300 } | 2298 } |
| 2301 | 2299 |
| 2302 | 2300 |
| 2303 RawClass* InstantiatedType::type_class() const { | 2301 RawClass* InstantiatedType::type_class() const { |
| 2304 return Type::Handle(uninstantiated_type()).type_class(); | 2302 return AbstractType::Handle(uninstantiated_type()).type_class(); |
| 2305 } | 2303 } |
| 2306 | 2304 |
| 2307 | 2305 |
| 2308 RawTypeArguments* InstantiatedType::arguments() const { | 2306 RawTypeArguments* InstantiatedType::arguments() const { |
| 2309 return TypeArguments::NewInstantiatedTypeArguments( | 2307 return TypeArguments::NewInstantiatedTypeArguments( |
| 2310 TypeArguments::Handle(Type::Handle(uninstantiated_type()).arguments()), | 2308 TypeArguments::Handle(AbstractType::Handle( |
| 2309 uninstantiated_type()).arguments()), |
| 2311 TypeArguments::Handle(instantiator_type_arguments())); | 2310 TypeArguments::Handle(instantiator_type_arguments())); |
| 2312 } | 2311 } |
| 2313 | 2312 |
| 2314 | 2313 |
| 2315 void InstantiatedType::set_uninstantiated_type(const Type& value) const { | 2314 void InstantiatedType::set_uninstantiated_type( |
| 2315 const AbstractType& value) const { |
| 2316 StorePointer(&raw_ptr()->uninstantiated_type_, value.raw()); | 2316 StorePointer(&raw_ptr()->uninstantiated_type_, value.raw()); |
| 2317 } | 2317 } |
| 2318 | 2318 |
| 2319 | 2319 |
| 2320 void InstantiatedType::set_instantiator_type_arguments( | 2320 void InstantiatedType::set_instantiator_type_arguments( |
| 2321 const TypeArguments& value) const { | 2321 const TypeArguments& value) const { |
| 2322 StorePointer(&raw_ptr()->instantiator_type_arguments_, value.raw()); | 2322 StorePointer(&raw_ptr()->instantiator_type_arguments_, value.raw()); |
| 2323 } | 2323 } |
| 2324 | 2324 |
| 2325 | 2325 |
| 2326 RawInstantiatedType* InstantiatedType::New() { | 2326 RawInstantiatedType* InstantiatedType::New() { |
| 2327 const Class& instantiated_type_class = | 2327 const Class& instantiated_type_class = |
| 2328 Class::Handle(Object::instantiated_type_class()); | 2328 Class::Handle(Object::instantiated_type_class()); |
| 2329 RawObject* raw = Object::Allocate(instantiated_type_class, | 2329 RawObject* raw = Object::Allocate(instantiated_type_class, |
| 2330 InstantiatedType::InstanceSize(), | 2330 InstantiatedType::InstanceSize(), |
| 2331 Heap::kOld); | 2331 Heap::kOld); |
| 2332 return reinterpret_cast<RawInstantiatedType*>(raw); | 2332 return reinterpret_cast<RawInstantiatedType*>(raw); |
| 2333 } | 2333 } |
| 2334 | 2334 |
| 2335 | 2335 |
| 2336 RawInstantiatedType* InstantiatedType::New( | 2336 RawInstantiatedType* InstantiatedType::New( |
| 2337 const Type& uninstantiated_type, | 2337 const AbstractType& uninstantiated_type, |
| 2338 const TypeArguments& instantiator_type_arguments) { | 2338 const TypeArguments& instantiator_type_arguments) { |
| 2339 const InstantiatedType& result = | 2339 const InstantiatedType& result = |
| 2340 InstantiatedType::Handle(InstantiatedType::New()); | 2340 InstantiatedType::Handle(InstantiatedType::New()); |
| 2341 result.set_uninstantiated_type(uninstantiated_type); | 2341 result.set_uninstantiated_type(uninstantiated_type); |
| 2342 result.set_instantiator_type_arguments(instantiator_type_arguments); | 2342 result.set_instantiator_type_arguments(instantiator_type_arguments); |
| 2343 return result.raw(); | 2343 return result.raw(); |
| 2344 } | 2344 } |
| 2345 | 2345 |
| 2346 | 2346 |
| 2347 const char* InstantiatedType::ToCString() const { | 2347 const char* InstantiatedType::ToCString() const { |
| 2348 return "InstantiatedType"; | 2348 return "InstantiatedType"; |
| 2349 } | 2349 } |
| 2350 | 2350 |
| 2351 | 2351 |
| 2352 intptr_t TypeArguments::Length() const { | 2352 intptr_t TypeArguments::Length() const { |
| 2353 // TypeArguments is an abstract class. | 2353 // TypeArguments is an abstract class. |
| 2354 UNREACHABLE(); | 2354 UNREACHABLE(); |
| 2355 return -1; | 2355 return -1; |
| 2356 } | 2356 } |
| 2357 | 2357 |
| 2358 | 2358 |
| 2359 RawType* TypeArguments::TypeAt(intptr_t index) const { | 2359 RawAbstractType* TypeArguments::TypeAt(intptr_t index) const { |
| 2360 // TypeArguments is an abstract class. | 2360 // TypeArguments is an abstract class. |
| 2361 UNREACHABLE(); | 2361 UNREACHABLE(); |
| 2362 return NULL; | 2362 return NULL; |
| 2363 } | 2363 } |
| 2364 | 2364 |
| 2365 | 2365 |
| 2366 void TypeArguments::SetTypeAt(intptr_t index, const Type& value) const { | 2366 void TypeArguments::SetTypeAt(intptr_t index, const AbstractType& value) const { |
| 2367 // TypeArguments is an abstract class. | 2367 // TypeArguments is an abstract class. |
| 2368 UNREACHABLE(); | 2368 UNREACHABLE(); |
| 2369 } | 2369 } |
| 2370 | 2370 |
| 2371 | 2371 |
| 2372 bool TypeArguments::IsResolved() const { | 2372 bool TypeArguments::IsResolved() const { |
| 2373 // TypeArguments is an abstract class. | 2373 // TypeArguments is an abstract class. |
| 2374 UNREACHABLE(); | 2374 UNREACHABLE(); |
| 2375 return false; | 2375 return false; |
| 2376 } | 2376 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2416 const TypeArguments& instantiator_type_arguments, | 2416 const TypeArguments& instantiator_type_arguments, |
| 2417 intptr_t offset) const { | 2417 intptr_t offset) const { |
| 2418 // TypeArguments is an abstract class. | 2418 // TypeArguments is an abstract class. |
| 2419 UNREACHABLE(); | 2419 UNREACHABLE(); |
| 2420 return NULL; | 2420 return NULL; |
| 2421 } | 2421 } |
| 2422 | 2422 |
| 2423 | 2423 |
| 2424 bool TypeArguments::IsDynamicTypes(intptr_t len) const { | 2424 bool TypeArguments::IsDynamicTypes(intptr_t len) const { |
| 2425 ASSERT(Length() >= len); | 2425 ASSERT(Length() >= len); |
| 2426 Type& type = Type::Handle(); | 2426 AbstractType& type = AbstractType::Handle(); |
| 2427 Class& type_class = Class::Handle(); | 2427 Class& type_class = Class::Handle(); |
| 2428 for (intptr_t i = 0; i < len; i++) { | 2428 for (intptr_t i = 0; i < len; i++) { |
| 2429 type = TypeAt(i); | 2429 type = TypeAt(i); |
| 2430 ASSERT(!type.IsNull()); | 2430 ASSERT(!type.IsNull()); |
| 2431 if (!type.HasResolvedTypeClass()) { | 2431 if (!type.HasResolvedTypeClass()) { |
| 2432 ASSERT(type.IsTypeParameter()); | 2432 ASSERT(type.IsTypeParameter()); |
| 2433 return false; | 2433 return false; |
| 2434 } | 2434 } |
| 2435 type_class = type.type_class(); | 2435 type_class = type.type_class(); |
| 2436 if (!type_class.IsDynamicClass()) { | 2436 if (!type_class.IsDynamicClass()) { |
| 2437 return false; | 2437 return false; |
| 2438 } | 2438 } |
| 2439 } | 2439 } |
| 2440 return true; | 2440 return true; |
| 2441 } | 2441 } |
| 2442 | 2442 |
| 2443 | 2443 |
| 2444 bool TypeArguments::IsMoreSpecificThan(const TypeArguments& other, | 2444 bool TypeArguments::IsMoreSpecificThan(const TypeArguments& other, |
| 2445 intptr_t len) const { | 2445 intptr_t len) const { |
| 2446 ASSERT(Length() >= len); | 2446 ASSERT(Length() >= len); |
| 2447 ASSERT(!other.IsNull()); | 2447 ASSERT(!other.IsNull()); |
| 2448 ASSERT(other.Length() >= len); | 2448 ASSERT(other.Length() >= len); |
| 2449 Type& type = Type::Handle(); | 2449 AbstractType& type = AbstractType::Handle(); |
| 2450 Type& other_type = Type::Handle(); | 2450 AbstractType& other_type = AbstractType::Handle(); |
| 2451 for (intptr_t i = 0; i < len; i++) { | 2451 for (intptr_t i = 0; i < len; i++) { |
| 2452 type = TypeAt(i); | 2452 type = TypeAt(i); |
| 2453 ASSERT(!type.IsNull()); | 2453 ASSERT(!type.IsNull()); |
| 2454 other_type = other.TypeAt(i); | 2454 other_type = other.TypeAt(i); |
| 2455 ASSERT(!other_type.IsNull()); | 2455 ASSERT(!other_type.IsNull()); |
| 2456 if (!type.IsMoreSpecificThan(other_type)) { | 2456 if (!type.IsMoreSpecificThan(other_type)) { |
| 2457 return false; | 2457 return false; |
| 2458 } | 2458 } |
| 2459 } | 2459 } |
| 2460 return true; | 2460 return true; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2480 return "TypeArguments"; | 2480 return "TypeArguments"; |
| 2481 } | 2481 } |
| 2482 | 2482 |
| 2483 | 2483 |
| 2484 intptr_t TypeArray::Length() const { | 2484 intptr_t TypeArray::Length() const { |
| 2485 ASSERT(!IsNull()); | 2485 ASSERT(!IsNull()); |
| 2486 return Smi::Value(raw_ptr()->length_); | 2486 return Smi::Value(raw_ptr()->length_); |
| 2487 } | 2487 } |
| 2488 | 2488 |
| 2489 | 2489 |
| 2490 RawType* TypeArray::TypeAt(intptr_t index) const { | 2490 RawAbstractType* TypeArray::TypeAt(intptr_t index) const { |
| 2491 return *TypeAddr(index); | 2491 return *TypeAddr(index); |
| 2492 } | 2492 } |
| 2493 | 2493 |
| 2494 | 2494 |
| 2495 void TypeArray::SetTypeAt(intptr_t index, const Type& value) const { | 2495 void TypeArray::SetTypeAt(intptr_t index, const AbstractType& value) const { |
| 2496 // TODO(iposva): Add storing NoGCScope. | 2496 // TODO(iposva): Add storing NoGCScope. |
| 2497 *TypeAddr(index) = value.raw(); | 2497 *TypeAddr(index) = value.raw(); |
| 2498 } | 2498 } |
| 2499 | 2499 |
| 2500 | 2500 |
| 2501 bool TypeArray::IsResolved() const { | 2501 bool TypeArray::IsResolved() const { |
| 2502 Type& type = Type::Handle(); | 2502 AbstractType& type = AbstractType::Handle(); |
| 2503 intptr_t num_types = Length(); | 2503 intptr_t num_types = Length(); |
| 2504 for (intptr_t i = 0; i < num_types; i++) { | 2504 for (intptr_t i = 0; i < num_types; i++) { |
| 2505 type = TypeAt(i); | 2505 type = TypeAt(i); |
| 2506 if (!type.IsResolved()) { | 2506 if (!type.IsResolved()) { |
| 2507 return false; | 2507 return false; |
| 2508 } | 2508 } |
| 2509 } | 2509 } |
| 2510 return true; | 2510 return true; |
| 2511 } | 2511 } |
| 2512 | 2512 |
| 2513 | 2513 |
| 2514 bool TypeArray::IsInstantiated() const { | 2514 bool TypeArray::IsInstantiated() const { |
| 2515 Type& type = Type::Handle(); | 2515 AbstractType& type = AbstractType::Handle(); |
| 2516 intptr_t num_types = Length(); | 2516 intptr_t num_types = Length(); |
| 2517 for (intptr_t i = 0; i < num_types; i++) { | 2517 for (intptr_t i = 0; i < num_types; i++) { |
| 2518 type = TypeAt(i); | 2518 type = TypeAt(i); |
| 2519 if (!type.IsInstantiated()) { | 2519 if (!type.IsInstantiated()) { |
| 2520 return false; | 2520 return false; |
| 2521 } | 2521 } |
| 2522 } | 2522 } |
| 2523 return true; | 2523 return true; |
| 2524 } | 2524 } |
| 2525 | 2525 |
| 2526 | 2526 |
| 2527 bool TypeArray::IsUninstantiatedIdentity() const { | 2527 bool TypeArray::IsUninstantiatedIdentity() const { |
| 2528 ASSERT(!IsInstantiated()); | 2528 ASSERT(!IsInstantiated()); |
| 2529 Type& type = Type::Handle(); | 2529 AbstractType& type = AbstractType::Handle(); |
| 2530 intptr_t num_types = Length(); | 2530 intptr_t num_types = Length(); |
| 2531 for (intptr_t i = 0; i < num_types; i++) { | 2531 for (intptr_t i = 0; i < num_types; i++) { |
| 2532 type = TypeAt(i); | 2532 type = TypeAt(i); |
| 2533 if (!type.IsTypeParameter() || (type.Index() != i)) { | 2533 if (!type.IsTypeParameter() || (type.Index() != i)) { |
| 2534 return false; | 2534 return false; |
| 2535 } | 2535 } |
| 2536 } | 2536 } |
| 2537 return true; | 2537 return true; |
| 2538 } | 2538 } |
| 2539 | 2539 |
| 2540 | 2540 |
| 2541 bool TypeArray::Equals(const TypeArguments& other) const { | 2541 bool TypeArray::Equals(const TypeArguments& other) const { |
| 2542 intptr_t num_types = Length(); | 2542 intptr_t num_types = Length(); |
| 2543 if (num_types != other.Length()) { | 2543 if (num_types != other.Length()) { |
| 2544 return false; | 2544 return false; |
| 2545 } | 2545 } |
| 2546 Type& type = Type::Handle(); | 2546 AbstractType& type = AbstractType::Handle(); |
| 2547 Type& other_type = Type::Handle(); | 2547 AbstractType& other_type = AbstractType::Handle(); |
| 2548 for (intptr_t i = 0; i < num_types; i++) { | 2548 for (intptr_t i = 0; i < num_types; i++) { |
| 2549 type = TypeAt(i); | 2549 type = TypeAt(i); |
| 2550 other_type = other.TypeAt(i); | 2550 other_type = other.TypeAt(i); |
| 2551 if (!type.Equals(other_type)) { | 2551 if (!type.Equals(other_type)) { |
| 2552 return false; | 2552 return false; |
| 2553 } | 2553 } |
| 2554 } | 2554 } |
| 2555 return true; | 2555 return true; |
| 2556 } | 2556 } |
| 2557 | 2557 |
| 2558 | 2558 |
| 2559 RawTypeArguments* TypeArray::InstantiateFrom( | 2559 RawTypeArguments* TypeArray::InstantiateFrom( |
| 2560 const TypeArguments& instantiator_type_arguments, | 2560 const TypeArguments& instantiator_type_arguments, |
| 2561 intptr_t offset) const { | 2561 intptr_t offset) const { |
| 2562 ASSERT(!IsInstantiated()); | 2562 ASSERT(!IsInstantiated()); |
| 2563 if ((offset == 0) && | 2563 if ((offset == 0) && |
| 2564 !instantiator_type_arguments.IsNull() && | 2564 !instantiator_type_arguments.IsNull() && |
| 2565 IsUninstantiatedIdentity() && | 2565 IsUninstantiatedIdentity() && |
| 2566 (instantiator_type_arguments.Length() == Length())) { | 2566 (instantiator_type_arguments.Length() == Length())) { |
| 2567 return instantiator_type_arguments.raw(); | 2567 return instantiator_type_arguments.raw(); |
| 2568 } | 2568 } |
| 2569 const intptr_t num_types = Length(); | 2569 const intptr_t num_types = Length(); |
| 2570 TypeArray& instantiated_array = TypeArray::Handle(TypeArray::New(num_types)); | 2570 TypeArray& instantiated_array = TypeArray::Handle(TypeArray::New(num_types)); |
| 2571 Type& type = Type::Handle(); | 2571 AbstractType& type = AbstractType::Handle(); |
| 2572 for (intptr_t i = 0; i < num_types; i++) { | 2572 for (intptr_t i = 0; i < num_types; i++) { |
| 2573 type = TypeAt(i); | 2573 type = TypeAt(i); |
| 2574 if (!type.IsInstantiated()) { | 2574 if (!type.IsInstantiated()) { |
| 2575 type = type.InstantiateFrom(instantiator_type_arguments, offset); | 2575 type = type.InstantiateFrom(instantiator_type_arguments, offset); |
| 2576 } | 2576 } |
| 2577 instantiated_array.SetTypeAt(i, type); | 2577 instantiated_array.SetTypeAt(i, type); |
| 2578 } | 2578 } |
| 2579 return instantiated_array.raw(); | 2579 return instantiated_array.raw(); |
| 2580 } | 2580 } |
| 2581 | 2581 |
| 2582 | 2582 |
| 2583 RawTypeArray* TypeArray::New(intptr_t len) { | 2583 RawTypeArray* TypeArray::New(intptr_t len) { |
| 2584 if ((len < 0) || (len > kMaxTypes)) { | 2584 if ((len < 0) || (len > kMaxTypes)) { |
| 2585 // TODO(iposva): Should we throw an illegal parameter exception? | 2585 // TODO(iposva): Should we throw an illegal parameter exception? |
| 2586 UNIMPLEMENTED(); | 2586 UNIMPLEMENTED(); |
| 2587 return null(); | 2587 return null(); |
| 2588 } | 2588 } |
| 2589 | 2589 |
| 2590 const Class& type_array_class = Class::Handle(Object::type_array_class()); | 2590 const Class& type_array_class = Class::Handle(Object::type_array_class()); |
| 2591 TypeArray& result = TypeArray::Handle(); | 2591 TypeArray& result = TypeArray::Handle(); |
| 2592 { | 2592 { |
| 2593 RawObject* raw = Object::Allocate(type_array_class, | 2593 RawObject* raw = Object::Allocate(type_array_class, |
| 2594 TypeArray::InstanceSize(len), | 2594 TypeArray::InstanceSize(len), |
| 2595 Heap::kOld); | 2595 Heap::kOld); |
| 2596 NoGCScope no_gc; | 2596 NoGCScope no_gc; |
| 2597 result ^= raw; | 2597 result ^= raw; |
| 2598 result.SetLength(len); | 2598 result.SetLength(len); |
| 2599 for (intptr_t i = 0; i < len; i++) { | 2599 for (intptr_t i = 0; i < len; i++) { |
| 2600 *result.TypeAddr(i) = ParameterizedType::null(); | 2600 *result.TypeAddr(i) = Type::null(); |
| 2601 } | 2601 } |
| 2602 } | 2602 } |
| 2603 return result.raw(); | 2603 return result.raw(); |
| 2604 } | 2604 } |
| 2605 | 2605 |
| 2606 | 2606 |
| 2607 RawType** TypeArray::TypeAddr(intptr_t index) const { | 2607 RawAbstractType** TypeArray::TypeAddr(intptr_t index) const { |
| 2608 // TODO(iposva): Determine if we should throw an exception here. | 2608 // TODO(iposva): Determine if we should throw an exception here. |
| 2609 ASSERT((index >= 0) && (index < Length())); | 2609 ASSERT((index >= 0) && (index < Length())); |
| 2610 return &raw_ptr()->types_[index]; | 2610 return &raw_ptr()->types_[index]; |
| 2611 } | 2611 } |
| 2612 | 2612 |
| 2613 | 2613 |
| 2614 void TypeArray::SetLength(intptr_t value) { | 2614 void TypeArray::SetLength(intptr_t value) { |
| 2615 // This is only safe because we create a new Smi, which does not cause | 2615 // This is only safe because we create a new Smi, which does not cause |
| 2616 // heap allocation. | 2616 // heap allocation. |
| 2617 raw_ptr()->length_ = Smi::New(value); | 2617 raw_ptr()->length_ = Smi::New(value); |
| 2618 } | 2618 } |
| 2619 | 2619 |
| 2620 | 2620 |
| 2621 const char* TypeArray::ToCString() const { | 2621 const char* TypeArray::ToCString() const { |
| 2622 if (IsNull()) { | 2622 if (IsNull()) { |
| 2623 return "NULL TypeArray"; | 2623 return "NULL TypeArray"; |
| 2624 } | 2624 } |
| 2625 const char* format = "%s [%s]"; | 2625 const char* format = "%s [%s]"; |
| 2626 const char* prev_cstr = "TypeArray:"; | 2626 const char* prev_cstr = "TypeArray:"; |
| 2627 for (int i = 0; i < Length(); i++) { | 2627 for (int i = 0; i < Length(); i++) { |
| 2628 const char* type_cstr = Type::Handle(TypeAt(i)).ToCString(); | 2628 const char* type_cstr = AbstractType::Handle(TypeAt(i)).ToCString(); |
| 2629 intptr_t len = OS::SNPrint(NULL, 0, format, prev_cstr, type_cstr) + 1; | 2629 intptr_t len = OS::SNPrint(NULL, 0, format, prev_cstr, type_cstr) + 1; |
| 2630 char* chars = reinterpret_cast<char*>( | 2630 char* chars = reinterpret_cast<char*>( |
| 2631 Isolate::Current()->current_zone()->Allocate(len)); | 2631 Isolate::Current()->current_zone()->Allocate(len)); |
| 2632 OS::SNPrint(chars, len, format, prev_cstr, type_cstr); | 2632 OS::SNPrint(chars, len, format, prev_cstr, type_cstr); |
| 2633 prev_cstr = chars; | 2633 prev_cstr = chars; |
| 2634 } | 2634 } |
| 2635 return prev_cstr; | 2635 return prev_cstr; |
| 2636 } | 2636 } |
| 2637 | 2637 |
| 2638 | 2638 |
| 2639 intptr_t InstantiatedTypeArguments::Length() const { | 2639 intptr_t InstantiatedTypeArguments::Length() const { |
| 2640 return TypeArguments::Handle(uninstantiated_type_arguments()).Length(); | 2640 return TypeArguments::Handle(uninstantiated_type_arguments()).Length(); |
| 2641 } | 2641 } |
| 2642 | 2642 |
| 2643 | 2643 |
| 2644 RawType* InstantiatedTypeArguments::TypeAt(intptr_t index) const { | 2644 RawAbstractType* InstantiatedTypeArguments::TypeAt(intptr_t index) const { |
| 2645 const Type& type = Type::Handle( | 2645 const AbstractType& type = AbstractType::Handle( |
| 2646 TypeArguments::Handle(uninstantiated_type_arguments()).TypeAt(index)); | 2646 TypeArguments::Handle(uninstantiated_type_arguments()).TypeAt(index)); |
| 2647 if (type.IsTypeParameter()) { | 2647 if (type.IsTypeParameter()) { |
| 2648 TypeArguments& instantiator = | 2648 TypeArguments& instantiator = |
| 2649 TypeArguments::Handle(instantiator_type_arguments()); | 2649 TypeArguments::Handle(instantiator_type_arguments()); |
| 2650 return instantiator.TypeAt(type.Index()); | 2650 return instantiator.TypeAt(type.Index()); |
| 2651 } | 2651 } |
| 2652 if (!type.IsInstantiated()) { | 2652 if (!type.IsInstantiated()) { |
| 2653 return InstantiatedType::New( | 2653 return InstantiatedType::New( |
| 2654 type, TypeArguments::Handle(instantiator_type_arguments())); | 2654 type, TypeArguments::Handle(instantiator_type_arguments())); |
| 2655 } | 2655 } |
| 2656 return type.raw(); | 2656 return type.raw(); |
| 2657 } | 2657 } |
| 2658 | 2658 |
| 2659 | 2659 |
| 2660 void InstantiatedTypeArguments::SetTypeAt(intptr_t index, | 2660 void InstantiatedTypeArguments::SetTypeAt(intptr_t index, |
| 2661 const Type& value) const { | 2661 const AbstractType& value) const { |
| 2662 // We only replace individual argument types during resolution at compile | 2662 // We only replace individual argument types during resolution at compile |
| 2663 // time, when no type parameters are instantiated yet. | 2663 // time, when no type parameters are instantiated yet. |
| 2664 UNREACHABLE(); | 2664 UNREACHABLE(); |
| 2665 } | 2665 } |
| 2666 | 2666 |
| 2667 | 2667 |
| 2668 void InstantiatedTypeArguments::set_uninstantiated_type_arguments( | 2668 void InstantiatedTypeArguments::set_uninstantiated_type_arguments( |
| 2669 const TypeArguments& value) const { | 2669 const TypeArguments& value) const { |
| 2670 StorePointer(&raw_ptr()->uninstantiated_type_arguments_, value.raw()); | 2670 StorePointer(&raw_ptr()->uninstantiated_type_arguments_, value.raw()); |
| 2671 } | 2671 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2772 StorePointer(&raw_ptr()->name_, value.raw()); | 2772 StorePointer(&raw_ptr()->name_, value.raw()); |
| 2773 } | 2773 } |
| 2774 | 2774 |
| 2775 | 2775 |
| 2776 void Function::set_owner(const Class& value) const { | 2776 void Function::set_owner(const Class& value) const { |
| 2777 ASSERT(!value.IsNull()); | 2777 ASSERT(!value.IsNull()); |
| 2778 StorePointer(&raw_ptr()->owner_, value.raw()); | 2778 StorePointer(&raw_ptr()->owner_, value.raw()); |
| 2779 } | 2779 } |
| 2780 | 2780 |
| 2781 | 2781 |
| 2782 void Function::set_result_type(const Type& value) const { | 2782 void Function::set_result_type(const AbstractType& value) const { |
| 2783 ASSERT(!value.IsNull()); | 2783 ASSERT(!value.IsNull()); |
| 2784 StorePointer(&raw_ptr()->result_type_, value.raw()); | 2784 StorePointer(&raw_ptr()->result_type_, value.raw()); |
| 2785 } | 2785 } |
| 2786 | 2786 |
| 2787 | 2787 |
| 2788 RawType* Function::ParameterTypeAt(intptr_t index) const { | 2788 RawAbstractType* Function::ParameterTypeAt(intptr_t index) const { |
| 2789 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_); | 2789 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_); |
| 2790 Type& parameter_type = Type::Handle(); | 2790 AbstractType& parameter_type = AbstractType::Handle(); |
| 2791 parameter_type ^= parameter_types.At(index); | 2791 parameter_type ^= parameter_types.At(index); |
| 2792 return parameter_type.raw(); | 2792 return parameter_type.raw(); |
| 2793 } | 2793 } |
| 2794 | 2794 |
| 2795 | 2795 |
| 2796 void Function::SetParameterTypeAt(intptr_t index, const Type& value) const { | 2796 void Function::SetParameterTypeAt( |
| 2797 intptr_t index, const AbstractType& value) const { |
| 2797 ASSERT(!value.IsNull()); | 2798 ASSERT(!value.IsNull()); |
| 2798 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_); | 2799 const Array& parameter_types = Array::Handle(raw_ptr()->parameter_types_); |
| 2799 parameter_types.SetAt(index, value); | 2800 parameter_types.SetAt(index, value); |
| 2800 } | 2801 } |
| 2801 | 2802 |
| 2802 | 2803 |
| 2803 void Function::set_parameter_types(const Array& value) const { | 2804 void Function::set_parameter_types(const Array& value) const { |
| 2804 StorePointer(&raw_ptr()->parameter_types_, value.raw()); | 2805 StorePointer(&raw_ptr()->parameter_types_, value.raw()); |
| 2805 } | 2806 } |
| 2806 | 2807 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2993 } | 2994 } |
| 2994 return true; | 2995 return true; |
| 2995 } | 2996 } |
| 2996 | 2997 |
| 2997 | 2998 |
| 2998 bool Function::TestParameterType( | 2999 bool Function::TestParameterType( |
| 2999 intptr_t parameter_position, | 3000 intptr_t parameter_position, |
| 3000 const TypeArguments& type_arguments, | 3001 const TypeArguments& type_arguments, |
| 3001 const Function& other, | 3002 const Function& other, |
| 3002 const TypeArguments& other_type_arguments) const { | 3003 const TypeArguments& other_type_arguments) const { |
| 3003 Type& param_type = Type::Handle(ParameterTypeAt(parameter_position)); | 3004 AbstractType& param_type = |
| 3005 AbstractType::Handle(ParameterTypeAt(parameter_position)); |
| 3004 if (!param_type.IsInstantiated()) { | 3006 if (!param_type.IsInstantiated()) { |
| 3005 param_type = param_type.InstantiateFrom(type_arguments, 0); | 3007 param_type = param_type.InstantiateFrom(type_arguments, 0); |
| 3006 } | 3008 } |
| 3007 if (param_type.IsDynamicType()) { | 3009 if (param_type.IsDynamicType()) { |
| 3008 return true; | 3010 return true; |
| 3009 } | 3011 } |
| 3010 Type& other_param_type = | 3012 AbstractType& other_param_type = |
| 3011 Type::Handle(other.ParameterTypeAt(parameter_position)); | 3013 AbstractType::Handle(other.ParameterTypeAt(parameter_position)); |
| 3012 if (!other_param_type.IsInstantiated()) { | 3014 if (!other_param_type.IsInstantiated()) { |
| 3013 other_param_type = | 3015 other_param_type = |
| 3014 other_param_type.InstantiateFrom(other_type_arguments, 0); | 3016 other_param_type.InstantiateFrom(other_type_arguments, 0); |
| 3015 } | 3017 } |
| 3016 if (other_param_type.IsDynamicType()) { | 3018 if (other_param_type.IsDynamicType()) { |
| 3017 return true; | 3019 return true; |
| 3018 } | 3020 } |
| 3019 if (!param_type.IsSubtypeOf(other_param_type) && | 3021 if (!param_type.IsSubtypeOf(other_param_type) && |
| 3020 !other_param_type.IsSubtypeOf(param_type)) { | 3022 !other_param_type.IsSubtypeOf(param_type)) { |
| 3021 return false; | 3023 return false; |
| 3022 } | 3024 } |
| 3023 return true; | 3025 return true; |
| 3024 } | 3026 } |
| 3025 | 3027 |
| 3026 | 3028 |
| 3027 bool Function::TestType(TypeTestKind test, | 3029 bool Function::TestType(TypeTestKind test, |
| 3028 const TypeArguments& type_arguments, | 3030 const TypeArguments& type_arguments, |
| 3029 const Function& other, | 3031 const Function& other, |
| 3030 const TypeArguments& other_type_arguments) const { | 3032 const TypeArguments& other_type_arguments) const { |
| 3031 const intptr_t num_fixed_params = num_fixed_parameters(); | 3033 const intptr_t num_fixed_params = num_fixed_parameters(); |
| 3032 const intptr_t num_opt_params = num_optional_parameters(); | 3034 const intptr_t num_opt_params = num_optional_parameters(); |
| 3033 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); | 3035 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); |
| 3034 const intptr_t other_num_opt_params = other.num_optional_parameters(); | 3036 const intptr_t other_num_opt_params = other.num_optional_parameters(); |
| 3035 if ((num_fixed_params != other_num_fixed_params) || | 3037 if ((num_fixed_params != other_num_fixed_params) || |
| 3036 ((test == Type::kIsSubtypeOf) && | 3038 ((test == AbstractType::kIsSubtypeOf) && |
| 3037 (num_opt_params < other_num_opt_params))) { | 3039 (num_opt_params < other_num_opt_params))) { |
| 3038 return false; | 3040 return false; |
| 3039 } | 3041 } |
| 3040 // Check the result type. | 3042 // Check the result type. |
| 3041 Type& other_res_type = Type::Handle(other.result_type()); | 3043 AbstractType& other_res_type = AbstractType::Handle(other.result_type()); |
| 3042 if (!other_res_type.IsInstantiated()) { | 3044 if (!other_res_type.IsInstantiated()) { |
| 3043 other_res_type = other_res_type.InstantiateFrom(other_type_arguments, 0); | 3045 other_res_type = other_res_type.InstantiateFrom(other_type_arguments, 0); |
| 3044 } | 3046 } |
| 3045 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) { | 3047 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) { |
| 3046 Type& res_type = Type::Handle(result_type()); | 3048 AbstractType& res_type = AbstractType::Handle(result_type()); |
| 3047 if (!res_type.IsInstantiated()) { | 3049 if (!res_type.IsInstantiated()) { |
| 3048 res_type = res_type.InstantiateFrom(type_arguments, 0); | 3050 res_type = res_type.InstantiateFrom(type_arguments, 0); |
| 3049 } | 3051 } |
| 3050 if (!res_type.IsDynamicType() && | 3052 if (!res_type.IsDynamicType() && |
| 3051 (res_type.IsVoidType() || | 3053 (res_type.IsVoidType() || |
| 3052 !(res_type.IsSubtypeOf(other_res_type) || | 3054 !(res_type.IsSubtypeOf(other_res_type) || |
| 3053 other_res_type.IsSubtypeOf(res_type)))) { | 3055 other_res_type.IsSubtypeOf(res_type)))) { |
| 3054 return false; | 3056 return false; |
| 3055 } | 3057 } |
| 3056 } | 3058 } |
| 3057 // Check the types of fixed parameters. | 3059 // Check the types of fixed parameters. |
| 3058 for (intptr_t i = 0; i < num_fixed_params; i++) { | 3060 for (intptr_t i = 0; i < num_fixed_params; i++) { |
| 3059 if (!TestParameterType(i, type_arguments, other, other_type_arguments)) { | 3061 if (!TestParameterType(i, type_arguments, other, other_type_arguments)) { |
| 3060 return false; | 3062 return false; |
| 3061 } | 3063 } |
| 3062 } | 3064 } |
| 3063 // Check the names and types of optional parameters. | 3065 // Check the names and types of optional parameters. |
| 3064 if (num_opt_params >= other_num_opt_params) { | 3066 if (num_opt_params >= other_num_opt_params) { |
| 3065 // Check that for each optional named parameter of type T of the other | 3067 // Check that for each optional named parameter of type T of the other |
| 3066 // function type, there is a corresponding optional named parameter of this | 3068 // function type, there is a corresponding optional named parameter of this |
| 3067 // function at the same position with an identical name and with a Type S | 3069 // function at the same position with an identical name and with a type S |
| 3068 // that is a subtype or supertype of T. | 3070 // that is a subtype or supertype of T. |
| 3069 // Note that SetParameterNameAt() guarantees that names are symbols, so we | 3071 // Note that SetParameterNameAt() guarantees that names are symbols, so we |
| 3070 // can compare their raw pointers. | 3072 // can compare their raw pointers. |
| 3071 const intptr_t other_num_params = | 3073 const intptr_t other_num_params = |
| 3072 other_num_fixed_params + other_num_opt_params; | 3074 other_num_fixed_params + other_num_opt_params; |
| 3073 String& other_param_name = String::Handle(); | 3075 String& other_param_name = String::Handle(); |
| 3074 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { | 3076 for (intptr_t i = other_num_fixed_params; i < other_num_params; i++) { |
| 3075 other_param_name = other.ParameterNameAt(i); | 3077 other_param_name = other.ParameterNameAt(i); |
| 3076 if ((ParameterNameAt(i) != other_param_name.raw()) || | 3078 if ((ParameterNameAt(i) != other_param_name.raw()) || |
| 3077 !TestParameterType(i, type_arguments, other, other_type_arguments)) { | 3079 !TestParameterType(i, type_arguments, other, other_type_arguments)) { |
| 3078 return false; | 3080 return false; |
| 3079 } | 3081 } |
| 3080 } | 3082 } |
| 3081 return true; | 3083 return true; |
| 3082 } | 3084 } |
| 3083 ASSERT((test == Type::kIsAssignableTo) && | 3085 ASSERT((test == AbstractType::kIsAssignableTo) && |
| 3084 (num_opt_params < other_num_opt_params)); | 3086 (num_opt_params < other_num_opt_params)); |
| 3085 // To verify that this function type is assignable to the other function type, | 3087 // To verify that this function type is assignable to the other function type, |
| 3086 // check that for each optional named parameter of type T of this function | 3088 // check that for each optional named parameter of type T of this function |
| 3087 // type, there is a corresponding optional named parameter of the other | 3089 // type, there is a corresponding optional named parameter of the other |
| 3088 // function at the same position with an identical name and with a Type S that | 3090 // function at the same position with an identical name and with a type S that |
| 3089 // is a subtype or supertype of T. | 3091 // is a subtype or supertype of T. |
| 3090 // Note that SetParameterNameAt() guarantees that names are symbols, so we | 3092 // Note that SetParameterNameAt() guarantees that names are symbols, so we |
| 3091 // can compare their raw pointers. | 3093 // can compare their raw pointers. |
| 3092 const intptr_t num_params = num_fixed_params + num_opt_params; | 3094 const intptr_t num_params = num_fixed_params + num_opt_params; |
| 3093 String& other_param_name = String::Handle(); | 3095 String& other_param_name = String::Handle(); |
| 3094 for (intptr_t i = num_fixed_params; i < num_params; i++) { | 3096 for (intptr_t i = num_fixed_params; i < num_params; i++) { |
| 3095 other_param_name = other.ParameterNameAt(i); | 3097 other_param_name = other.ParameterNameAt(i); |
| 3096 if ((ParameterNameAt(i) != other_param_name.raw()) || | 3098 if ((ParameterNameAt(i) != other_param_name.raw()) || |
| 3097 !TestParameterType(i, type_arguments, other, other_type_arguments)) { | 3099 !TestParameterType(i, type_arguments, other, other_type_arguments)) { |
| 3098 return false; | 3100 return false; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3174 // Set closure function's context scope. | 3176 // Set closure function's context scope. |
| 3175 ContextScope& context_scope = ContextScope::Handle(); | 3177 ContextScope& context_scope = ContextScope::Handle(); |
| 3176 if (is_static()) { | 3178 if (is_static()) { |
| 3177 context_scope ^= ContextScope::New(0); | 3179 context_scope ^= ContextScope::New(0); |
| 3178 } else { | 3180 } else { |
| 3179 context_scope ^= LocalScope::CreateImplicitClosureScope(*this); | 3181 context_scope ^= LocalScope::CreateImplicitClosureScope(*this); |
| 3180 } | 3182 } |
| 3181 closure_function.set_context_scope(context_scope); | 3183 closure_function.set_context_scope(context_scope); |
| 3182 | 3184 |
| 3183 // Set closure function's result type to this result type. | 3185 // Set closure function's result type to this result type. |
| 3184 closure_function.set_result_type(Type::Handle(result_type())); | 3186 closure_function.set_result_type(AbstractType::Handle(result_type())); |
| 3185 | 3187 |
| 3186 // Set closure function's formal parameters to this formal parameters, | 3188 // Set closure function's formal parameters to this formal parameters, |
| 3187 // removing the receiver if this is an instance method. | 3189 // removing the receiver if this is an instance method. |
| 3188 const int has_receiver = is_static() ? 0 : 1; | 3190 const int has_receiver = is_static() ? 0 : 1; |
| 3189 const int num_fixed_params = num_fixed_parameters() - has_receiver; | 3191 const int num_fixed_params = num_fixed_parameters() - has_receiver; |
| 3190 const int num_optional_params = num_optional_parameters(); | 3192 const int num_optional_params = num_optional_parameters(); |
| 3191 const int num_params = num_fixed_params + num_optional_params; | 3193 const int num_params = num_fixed_params + num_optional_params; |
| 3192 closure_function.set_num_fixed_parameters(num_fixed_params); | 3194 closure_function.set_num_fixed_parameters(num_fixed_params); |
| 3193 closure_function.set_num_optional_parameters(num_optional_params); | 3195 closure_function.set_num_optional_parameters(num_optional_params); |
| 3194 closure_function.set_parameter_types(Array::Handle(Array::New(num_params, | 3196 closure_function.set_parameter_types(Array::Handle(Array::New(num_params, |
| 3195 Heap::kOld))); | 3197 Heap::kOld))); |
| 3196 closure_function.set_parameter_names(Array::Handle(Array::New(num_params, | 3198 closure_function.set_parameter_names(Array::Handle(Array::New(num_params, |
| 3197 Heap::kOld))); | 3199 Heap::kOld))); |
| 3198 Type& param_type = Type::Handle(); | 3200 AbstractType& param_type = AbstractType::Handle(); |
| 3199 String& param_name = String::Handle(); | 3201 String& param_name = String::Handle(); |
| 3200 for (int i = 0; i < num_params; i++) { | 3202 for (int i = 0; i < num_params; i++) { |
| 3201 param_type = ParameterTypeAt(i + has_receiver); | 3203 param_type = ParameterTypeAt(i + has_receiver); |
| 3202 closure_function.SetParameterTypeAt(i, param_type); | 3204 closure_function.SetParameterTypeAt(i, param_type); |
| 3203 param_name = ParameterNameAt(i + has_receiver); | 3205 param_name = ParameterNameAt(i + has_receiver); |
| 3204 closure_function.SetParameterNameAt(i, param_name); | 3206 closure_function.SetParameterNameAt(i, param_name); |
| 3205 } | 3207 } |
| 3206 | 3208 |
| 3207 // Lookup or create a new signature class for the closure function in the | 3209 // Lookup or create a new signature class for the closure function in the |
| 3208 // library of the owner class. | 3210 // library of the owner class. |
| 3209 const Class& owner_class = Class::Handle(owner()); | 3211 const Class& owner_class = Class::Handle(owner()); |
| 3210 ASSERT(!owner_class.IsNull() && (owner() == closure_function.owner())); | 3212 ASSERT(!owner_class.IsNull() && (owner() == closure_function.owner())); |
| 3211 const Library& library = Library::Handle(owner_class.library()); | 3213 const Library& library = Library::Handle(owner_class.library()); |
| 3212 ASSERT(!library.IsNull()); | 3214 ASSERT(!library.IsNull()); |
| 3213 const String& signature = String::Handle(closure_function.Signature()); | 3215 const String& signature = String::Handle(closure_function.Signature()); |
| 3214 Class& signature_class = Class::ZoneHandle( | 3216 Class& signature_class = Class::ZoneHandle( |
| 3215 library.LookupLocalClass(signature)); | 3217 library.LookupLocalClass(signature)); |
| 3216 if (signature_class.IsNull()) { | 3218 if (signature_class.IsNull()) { |
| 3217 const Script& script = Script::Handle(owner_class.script()); | 3219 const Script& script = Script::Handle(owner_class.script()); |
| 3218 signature_class = Class::NewSignatureClass(signature, | 3220 signature_class = Class::NewSignatureClass(signature, |
| 3219 closure_function, | 3221 closure_function, |
| 3220 script); | 3222 script); |
| 3221 library.AddClass(signature_class); | 3223 library.AddClass(signature_class); |
| 3222 } else { | 3224 } else { |
| 3223 closure_function.set_signature_class(signature_class); | 3225 closure_function.set_signature_class(signature_class); |
| 3224 } | 3226 } |
| 3225 const Type& signature_type = Type::Handle(signature_class.SignatureType()); | 3227 const AbstractType& signature_type = |
| 3228 AbstractType::Handle(signature_class.SignatureType()); |
| 3226 if (!signature_type.IsFinalized()) { | 3229 if (!signature_type.IsFinalized()) { |
| 3227 String& errmsg = String::Handle(); | 3230 String& errmsg = String::Handle(); |
| 3228 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); | 3231 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); |
| 3229 ASSERT(errmsg.IsNull()); | 3232 ASSERT(errmsg.IsNull()); |
| 3230 } | 3233 } |
| 3231 ASSERT(closure_function.signature_class() == signature_class.raw()); | 3234 ASSERT(closure_function.signature_class() == signature_class.raw()); |
| 3232 set_implicit_closure_function(closure_function); | 3235 set_implicit_closure_function(closure_function); |
| 3233 ASSERT(closure_function.IsImplicitClosureFunction()); | 3236 ASSERT(closure_function.IsImplicitClosureFunction()); |
| 3234 return closure_function.raw(); | 3237 return closure_function.raw(); |
| 3235 } | 3238 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3262 const String& kRAngleBracket = String::Handle(String::NewSymbol(">")); | 3265 const String& kRAngleBracket = String::Handle(String::NewSymbol(">")); |
| 3263 const Class& function_class = Class::Handle(owner()); | 3266 const Class& function_class = Class::Handle(owner()); |
| 3264 ASSERT(!function_class.IsNull()); | 3267 ASSERT(!function_class.IsNull()); |
| 3265 const Array& type_parameters = Array::Handle( | 3268 const Array& type_parameters = Array::Handle( |
| 3266 function_class.type_parameters()); | 3269 function_class.type_parameters()); |
| 3267 if (!type_parameters.IsNull()) { | 3270 if (!type_parameters.IsNull()) { |
| 3268 intptr_t num_type_parameters = type_parameters.Length(); | 3271 intptr_t num_type_parameters = type_parameters.Length(); |
| 3269 pieces.Add(&kLAngleBracket); | 3272 pieces.Add(&kLAngleBracket); |
| 3270 const TypeArray& type_parameter_extends = TypeArray::Handle( | 3273 const TypeArray& type_parameter_extends = TypeArray::Handle( |
| 3271 function_class.type_parameter_extends()); | 3274 function_class.type_parameter_extends()); |
| 3272 Type& parameter_extends = Type::Handle(); | 3275 AbstractType& parameter_extends = AbstractType::Handle(); |
| 3273 for (intptr_t i = 0; i < num_type_parameters; i++) { | 3276 for (intptr_t i = 0; i < num_type_parameters; i++) { |
| 3274 String& type_parameter = String::ZoneHandle(); | 3277 String& type_parameter = String::ZoneHandle(); |
| 3275 type_parameter ^= type_parameters.At(i); | 3278 type_parameter ^= type_parameters.At(i); |
| 3276 pieces.Add(&type_parameter); | 3279 pieces.Add(&type_parameter); |
| 3277 parameter_extends = type_parameter_extends.TypeAt(i); | 3280 parameter_extends = type_parameter_extends.TypeAt(i); |
| 3278 if (!parameter_extends.IsNull() && !parameter_extends.IsDynamicType()) { | 3281 if (!parameter_extends.IsNull() && !parameter_extends.IsDynamicType()) { |
| 3279 pieces.Add(&kSpaceExtendsSpace); | 3282 pieces.Add(&kSpaceExtendsSpace); |
| 3280 pieces.Add(&String::ZoneHandle(parameter_extends.Name())); | 3283 pieces.Add(&String::ZoneHandle(parameter_extends.Name())); |
| 3281 } | 3284 } |
| 3282 if (i < num_type_parameters - 1) { | 3285 if (i < num_type_parameters - 1) { |
| 3283 pieces.Add(&kCommaSpace); | 3286 pieces.Add(&kCommaSpace); |
| 3284 } | 3287 } |
| 3285 } | 3288 } |
| 3286 pieces.Add(&kRAngleBracket); | 3289 pieces.Add(&kRAngleBracket); |
| 3287 } | 3290 } |
| 3288 } | 3291 } |
| 3289 Type& param_type = Type::Handle(); | 3292 AbstractType& param_type = AbstractType::Handle(); |
| 3290 const intptr_t num_params = NumberOfParameters(); | 3293 const intptr_t num_params = NumberOfParameters(); |
| 3291 const intptr_t num_fixed_params = num_fixed_parameters(); | 3294 const intptr_t num_fixed_params = num_fixed_parameters(); |
| 3292 const intptr_t num_opt_params = num_optional_parameters(); | 3295 const intptr_t num_opt_params = num_optional_parameters(); |
| 3293 ASSERT((num_fixed_params + num_opt_params) == num_params); | 3296 ASSERT((num_fixed_params + num_opt_params) == num_params); |
| 3294 pieces.Add(&kLParen); | 3297 pieces.Add(&kLParen); |
| 3295 for (intptr_t i = 0; i < num_fixed_params; i++) { | 3298 for (intptr_t i = 0; i < num_fixed_params; i++) { |
| 3296 param_type = ParameterTypeAt(i); | 3299 param_type = ParameterTypeAt(i); |
| 3297 ASSERT(!param_type.IsNull()); | 3300 ASSERT(!param_type.IsNull()); |
| 3298 if (instantiate && !param_type.IsInstantiated()) { | 3301 if (instantiate && !param_type.IsInstantiated()) { |
| 3299 param_type = param_type.InstantiateFrom(instantiator, offset); | 3302 param_type = param_type.InstantiateFrom(instantiator, offset); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3314 } | 3317 } |
| 3315 ASSERT(!param_type.IsNull()); | 3318 ASSERT(!param_type.IsNull()); |
| 3316 pieces.Add(&String::ZoneHandle(param_type.Name())); | 3319 pieces.Add(&String::ZoneHandle(param_type.Name())); |
| 3317 if (i != (num_params - 1)) { | 3320 if (i != (num_params - 1)) { |
| 3318 pieces.Add(&kCommaSpace); | 3321 pieces.Add(&kCommaSpace); |
| 3319 } | 3322 } |
| 3320 } | 3323 } |
| 3321 pieces.Add(&kRBracket); | 3324 pieces.Add(&kRBracket); |
| 3322 } | 3325 } |
| 3323 pieces.Add(&kRParen); | 3326 pieces.Add(&kRParen); |
| 3324 Type& res_type = Type::Handle(result_type()); | 3327 AbstractType& res_type = AbstractType::Handle(result_type()); |
| 3325 if (instantiate && !res_type.IsInstantiated()) { | 3328 if (instantiate && !res_type.IsInstantiated()) { |
| 3326 res_type = res_type.InstantiateFrom(instantiator, offset); | 3329 res_type = res_type.InstantiateFrom(instantiator, offset); |
| 3327 } | 3330 } |
| 3328 pieces.Add(&String::Handle(res_type.Name())); | 3331 pieces.Add(&String::Handle(res_type.Name())); |
| 3329 const Array& strings = Array::Handle(NewArray<const String>(pieces)); | 3332 const Array& strings = Array::Handle(NewArray<const String>(pieces)); |
| 3330 return String::NewSymbol(String::Handle(String::ConcatAll(strings))); | 3333 return String::NewSymbol(String::Handle(String::ConcatAll(strings))); |
| 3331 } | 3334 } |
| 3332 | 3335 |
| 3333 | 3336 |
| 3334 bool Function::HasInstantiatedSignature() const { | 3337 bool Function::HasInstantiatedSignature() const { |
| 3335 Type& type = Type::Handle(result_type()); | 3338 AbstractType& type = AbstractType::Handle(result_type()); |
| 3336 if (!type.IsInstantiated()) { | 3339 if (!type.IsInstantiated()) { |
| 3337 return false; | 3340 return false; |
| 3338 } | 3341 } |
| 3339 const intptr_t num_parameters = NumberOfParameters(); | 3342 const intptr_t num_parameters = NumberOfParameters(); |
| 3340 for (intptr_t i = 0; i < num_parameters; i++) { | 3343 for (intptr_t i = 0; i < num_parameters; i++) { |
| 3341 type = ParameterTypeAt(i); | 3344 type = ParameterTypeAt(i); |
| 3342 if (!type.IsInstantiated()) { | 3345 if (!type.IsInstantiated()) { |
| 3343 return false; | 3346 return false; |
| 3344 } | 3347 } |
| 3345 } | 3348 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3432 return raw_ptr()->value_; | 3435 return raw_ptr()->value_; |
| 3433 } | 3436 } |
| 3434 | 3437 |
| 3435 | 3438 |
| 3436 void Field::set_value(const Instance& value) const { | 3439 void Field::set_value(const Instance& value) const { |
| 3437 ASSERT(is_static()); // Valid only for static dart fields. | 3440 ASSERT(is_static()); // Valid only for static dart fields. |
| 3438 StorePointer(&raw_ptr()->value_, value.raw()); | 3441 StorePointer(&raw_ptr()->value_, value.raw()); |
| 3439 } | 3442 } |
| 3440 | 3443 |
| 3441 | 3444 |
| 3442 void Field::set_type(const Type& value) const { | 3445 void Field::set_type(const AbstractType& value) const { |
| 3443 ASSERT(!value.IsNull()); | 3446 ASSERT(!value.IsNull()); |
| 3444 StorePointer(&raw_ptr()->type_, value.raw()); | 3447 StorePointer(&raw_ptr()->type_, value.raw()); |
| 3445 } | 3448 } |
| 3446 | 3449 |
| 3447 | 3450 |
| 3448 RawField* Field::New() { | 3451 RawField* Field::New() { |
| 3449 const Class& field_class = Class::Handle(Object::field_class()); | 3452 const Class& field_class = Class::Handle(Object::field_class()); |
| 3450 RawObject* raw = Object::Allocate(field_class, | 3453 RawObject* raw = Object::Allocate(field_class, |
| 3451 Field::InstanceSize(), | 3454 Field::InstanceSize(), |
| 3452 Heap::kOld); | 3455 Heap::kOld); |
| (...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4809 bool ContextScope::IsFinalAt(intptr_t scope_index) const { | 4812 bool ContextScope::IsFinalAt(intptr_t scope_index) const { |
| 4810 return Bool::Handle(VariableDescAddr(scope_index)->is_final).value(); | 4813 return Bool::Handle(VariableDescAddr(scope_index)->is_final).value(); |
| 4811 } | 4814 } |
| 4812 | 4815 |
| 4813 | 4816 |
| 4814 void ContextScope::SetIsFinalAt(intptr_t scope_index, bool is_final) const { | 4817 void ContextScope::SetIsFinalAt(intptr_t scope_index, bool is_final) const { |
| 4815 VariableDescAddr(scope_index)->is_final = Bool::Get(is_final); | 4818 VariableDescAddr(scope_index)->is_final = Bool::Get(is_final); |
| 4816 } | 4819 } |
| 4817 | 4820 |
| 4818 | 4821 |
| 4819 RawType* ContextScope::TypeAt(intptr_t scope_index) const { | 4822 RawAbstractType* ContextScope::TypeAt(intptr_t scope_index) const { |
| 4820 return VariableDescAddr(scope_index)->type; | 4823 return VariableDescAddr(scope_index)->type; |
| 4821 } | 4824 } |
| 4822 | 4825 |
| 4823 | 4826 |
| 4824 void ContextScope::SetTypeAt(intptr_t scope_index, const Type& type) const { | 4827 void ContextScope::SetTypeAt( |
| 4828 intptr_t scope_index, const AbstractType& type) const { |
| 4825 VariableDescAddr(scope_index)->type = type.raw(); | 4829 VariableDescAddr(scope_index)->type = type.raw(); |
| 4826 } | 4830 } |
| 4827 | 4831 |
| 4828 | 4832 |
| 4829 intptr_t ContextScope::ContextIndexAt(intptr_t scope_index) const { | 4833 intptr_t ContextScope::ContextIndexAt(intptr_t scope_index) const { |
| 4830 return Smi::Value(VariableDescAddr(scope_index)->context_index); | 4834 return Smi::Value(VariableDescAddr(scope_index)->context_index); |
| 4831 } | 4835 } |
| 4832 | 4836 |
| 4833 | 4837 |
| 4834 void ContextScope::SetContextIndexAt(intptr_t scope_index, | 4838 void ContextScope::SetContextIndexAt(intptr_t scope_index, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4986 Array::Handle(Array::Grow(constants, new_length, Heap::kOld)); | 4990 Array::Handle(Array::Grow(constants, new_length, Heap::kOld)); |
| 4987 cls.set_constants(new_constants); | 4991 cls.set_constants(new_constants); |
| 4988 new_constants.SetAt(index, *this); | 4992 new_constants.SetAt(index, *this); |
| 4989 } else { | 4993 } else { |
| 4990 constants.SetAt(index, *this); | 4994 constants.SetAt(index, *this); |
| 4991 } | 4995 } |
| 4992 return this->raw(); | 4996 return this->raw(); |
| 4993 } | 4997 } |
| 4994 | 4998 |
| 4995 | 4999 |
| 4996 RawParameterizedType* Instance::GetType() const { | 5000 RawType* Instance::GetType() const { |
| 4997 if (IsNull()) { | 5001 if (IsNull()) { |
| 4998 return ParameterizedType::NullType(); | 5002 return Type::NullType(); |
| 4999 } | 5003 } |
| 5000 const Class& cls = Class::Handle(clazz()); | 5004 const Class& cls = Class::Handle(clazz()); |
| 5001 TypeArguments& type_arguments = TypeArguments::Handle(); | 5005 TypeArguments& type_arguments = TypeArguments::Handle(); |
| 5002 if (cls.HasTypeArguments()) { | 5006 if (cls.HasTypeArguments()) { |
| 5003 type_arguments = GetTypeArguments(); | 5007 type_arguments = GetTypeArguments(); |
| 5004 } | 5008 } |
| 5005 const ParameterizedType& type = ParameterizedType::Handle( | 5009 const Type& type = Type::Handle(Type::New(cls, type_arguments)); |
| 5006 ParameterizedType::New(cls, type_arguments)); | |
| 5007 type.set_is_finalized(); | 5010 type.set_is_finalized(); |
| 5008 return type.raw(); | 5011 return type.raw(); |
| 5009 } | 5012 } |
| 5010 | 5013 |
| 5011 | 5014 |
| 5012 RawTypeArguments* Instance::GetTypeArguments() const { | 5015 RawTypeArguments* Instance::GetTypeArguments() const { |
| 5013 const Class& cls = Class::Handle(clazz()); | 5016 const Class& cls = Class::Handle(clazz()); |
| 5014 intptr_t field_offset = cls.type_arguments_instance_field_offset(); | 5017 intptr_t field_offset = cls.type_arguments_instance_field_offset(); |
| 5015 ASSERT(field_offset != Class::kNoTypeArguments); | 5018 ASSERT(field_offset != Class::kNoTypeArguments); |
| 5016 TypeArguments& type_arguments = TypeArguments::Handle(); | 5019 TypeArguments& type_arguments = TypeArguments::Handle(); |
| 5017 type_arguments ^= *FieldAddrAtOffset(field_offset); | 5020 type_arguments ^= *FieldAddrAtOffset(field_offset); |
| 5018 return type_arguments.raw(); | 5021 return type_arguments.raw(); |
| 5019 } | 5022 } |
| 5020 | 5023 |
| 5021 | 5024 |
| 5022 void Instance::SetTypeArguments(const TypeArguments& value) const { | 5025 void Instance::SetTypeArguments(const TypeArguments& value) const { |
| 5023 const Class& cls = Class::Handle(clazz()); | 5026 const Class& cls = Class::Handle(clazz()); |
| 5024 intptr_t field_offset = cls.type_arguments_instance_field_offset(); | 5027 intptr_t field_offset = cls.type_arguments_instance_field_offset(); |
| 5025 ASSERT(field_offset != Class::kNoTypeArguments); | 5028 ASSERT(field_offset != Class::kNoTypeArguments); |
| 5026 *FieldAddrAtOffset(field_offset) = value.raw(); | 5029 *FieldAddrAtOffset(field_offset) = value.raw(); |
| 5027 } | 5030 } |
| 5028 | 5031 |
| 5029 | 5032 |
| 5030 bool Instance::TestType(TypeTestKind test, | 5033 bool Instance::TestType(TypeTestKind test, |
| 5031 const Type& other, | 5034 const AbstractType& other, |
| 5032 const TypeArguments& other_instantiator) const { | 5035 const TypeArguments& other_instantiator) const { |
| 5033 ASSERT(other.IsFinalized()); | 5036 ASSERT(other.IsFinalized()); |
| 5034 ASSERT(!other.IsDynamicType()); | 5037 ASSERT(!other.IsDynamicType()); |
| 5035 ASSERT(!other.IsVoidType()); | 5038 ASSERT(!other.IsVoidType()); |
| 5036 if (IsNull()) { | 5039 if (IsNull()) { |
| 5037 if (test == Type::kIsSubtypeOf) { | 5040 if (test == AbstractType::kIsSubtypeOf) { |
| 5038 Class& other_class = Class::Handle(); | 5041 Class& other_class = Class::Handle(); |
| 5039 if (other.IsTypeParameter()) { | 5042 if (other.IsTypeParameter()) { |
| 5040 if (other_instantiator.IsNull()) { | 5043 if (other_instantiator.IsNull()) { |
| 5041 return true; // Other type is uninstantiated, i.e. Dynamic. | 5044 return true; // Other type is uninstantiated, i.e. Dynamic. |
| 5042 } | 5045 } |
| 5043 const Type& instantiated_other = | 5046 const AbstractType& instantiated_other = |
| 5044 Type::Handle(other_instantiator.TypeAt(other.Index())); | 5047 AbstractType::Handle(other_instantiator.TypeAt(other.Index())); |
| 5045 ASSERT(instantiated_other.IsInstantiated()); | 5048 ASSERT(instantiated_other.IsInstantiated()); |
| 5046 other_class = instantiated_other.type_class(); | 5049 other_class = instantiated_other.type_class(); |
| 5047 } else { | 5050 } else { |
| 5048 other_class = other.type_class(); | 5051 other_class = other.type_class(); |
| 5049 } | 5052 } |
| 5050 return other_class.IsObjectClass() || other_class.IsDynamicClass(); | 5053 return other_class.IsObjectClass() || other_class.IsDynamicClass(); |
| 5051 } else { | 5054 } else { |
| 5052 ASSERT(test == Type::kIsAssignableTo); | 5055 ASSERT(test == AbstractType::kIsAssignableTo); |
| 5053 return true; | 5056 return true; |
| 5054 } | 5057 } |
| 5055 } | 5058 } |
| 5056 const Class& cls = Class::Handle(clazz()); | 5059 const Class& cls = Class::Handle(clazz()); |
| 5057 TypeArguments& type_arguments = TypeArguments::Handle(); | 5060 TypeArguments& type_arguments = TypeArguments::Handle(); |
| 5058 const intptr_t num_type_arguments = cls.NumTypeArguments(); | 5061 const intptr_t num_type_arguments = cls.NumTypeArguments(); |
| 5059 if (num_type_arguments > 0) { | 5062 if (num_type_arguments > 0) { |
| 5060 type_arguments = GetTypeArguments(); | 5063 type_arguments = GetTypeArguments(); |
| 5061 // Verify that the number of type arguments in the instance matches the | 5064 // Verify that the number of type arguments in the instance matches the |
| 5062 // number of type arguments expected by the instance class. | 5065 // number of type arguments expected by the instance class. |
| 5063 // A discrepancy is allowed for closures, which borrow the type argument | 5066 // A discrepancy is allowed for closures, which borrow the type argument |
| 5064 // vector of their instantiator, which may be of a super class of the class | 5067 // vector of their instantiator, which may be of a super class of the class |
| 5065 // defining the closure. Truncating the vector to the correct length on | 5068 // defining the closure. Truncating the vector to the correct length on |
| 5066 // instantiation is unnecessary. The vector may therefore be longer. | 5069 // instantiation is unnecessary. The vector may therefore be longer. |
| 5067 ASSERT(type_arguments.IsNull() || | 5070 ASSERT(type_arguments.IsNull() || |
| 5068 (type_arguments.Length() == num_type_arguments) || | 5071 (type_arguments.Length() == num_type_arguments) || |
| 5069 (cls.IsSignatureClass() && | 5072 (cls.IsSignatureClass() && |
| 5070 (type_arguments.Length() > num_type_arguments))); | 5073 (type_arguments.Length() > num_type_arguments))); |
| 5071 } | 5074 } |
| 5072 Class& other_class = Class::Handle(); | 5075 Class& other_class = Class::Handle(); |
| 5073 TypeArguments& other_type_arguments = TypeArguments::Handle(); | 5076 TypeArguments& other_type_arguments = TypeArguments::Handle(); |
| 5074 // In case 'other' is not instantiated, we could simply call | 5077 // In case 'other' is not instantiated, we could simply call |
| 5075 // other.InstantiateFrom(other_instantiator, 0), however, we can save the | 5078 // other.InstantiateFrom(other_instantiator, 0), however, we can save the |
| 5076 // allocation of a new Type by inlining the code. | 5079 // allocation of a new AbstractType by inlining the code. |
| 5077 if (other.IsTypeParameter()) { | 5080 if (other.IsTypeParameter()) { |
| 5078 Type& instantiated_other = Type::Handle(); | 5081 AbstractType& instantiated_other = AbstractType::Handle(); |
| 5079 if (!other_instantiator.IsNull()) { | 5082 if (!other_instantiator.IsNull()) { |
| 5080 instantiated_other = other_instantiator.TypeAt(other.Index()); | 5083 instantiated_other = other_instantiator.TypeAt(other.Index()); |
| 5081 ASSERT(instantiated_other.IsInstantiated()); | 5084 ASSERT(instantiated_other.IsInstantiated()); |
| 5082 } else { | 5085 } else { |
| 5083 instantiated_other = Type::DynamicType(); | 5086 instantiated_other = Type::DynamicType(); |
| 5084 } | 5087 } |
| 5085 other_class = instantiated_other.type_class(); | 5088 other_class = instantiated_other.type_class(); |
| 5086 other_type_arguments = instantiated_other.arguments(); | 5089 other_type_arguments = instantiated_other.arguments(); |
| 5087 } else { | 5090 } else { |
| 5088 other_class = other.type_class(); | 5091 other_class = other.type_class(); |
| (...skipping 2180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7269 const String& str = String::Handle(pattern()); | 7272 const String& str = String::Handle(pattern()); |
| 7270 const char* format = "JSRegExp: pattern=%s flags=%s"; | 7273 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 7271 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 7274 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 7272 char* chars = reinterpret_cast<char*>( | 7275 char* chars = reinterpret_cast<char*>( |
| 7273 Isolate::Current()->current_zone()->Allocate(len + 1)); | 7276 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 7274 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 7277 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 7275 return chars; | 7278 return chars; |
| 7276 } | 7279 } |
| 7277 | 7280 |
| 7278 } // namespace dart | 7281 } // namespace dart |
| OLD | NEW |