Chromium Code Reviews| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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::type_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 53 RawClass* Object::type_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 54 RawClass* Object::type_parameter_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 54 RawClass* Object::type_parameter_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 55 RawClass* Object::instantiated_type_class_ = | 55 RawClass* Object::instantiated_type_class_ = |
| 56 reinterpret_cast<RawClass*>(RAW_NULL); | 56 reinterpret_cast<RawClass*>(RAW_NULL); |
| 57 RawClass* Object::type_arguments_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 57 RawClass* Object::abstract_type_arguments_class_ = |
| 58 reinterpret_cast<RawClass*>(RAW_NULL); | |
| 58 RawClass* Object::type_array_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 59 RawClass* Object::type_array_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
|
regis
2011/12/01 22:20:16
type_arguments_class_?
srdjan
2011/12/01 22:44:08
Done.
| |
| 59 RawClass* Object::instantiated_type_arguments_class_ = | 60 RawClass* Object::instantiated_type_arguments_class_ = |
| 60 reinterpret_cast<RawClass*>(RAW_NULL); | 61 reinterpret_cast<RawClass*>(RAW_NULL); |
| 61 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 62 RawClass* Object::function_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 62 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 63 RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 63 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 64 RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 64 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 65 RawClass* Object::script_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 65 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 66 RawClass* Object::library_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 66 RawClass* Object::library_prefix_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 67 RawClass* Object::library_prefix_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 67 RawClass* Object::code_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 68 RawClass* Object::code_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| 68 RawClass* Object::instructions_class_ = reinterpret_cast<RawClass*>(RAW_NULL); | 69 RawClass* Object::instructions_class_ = reinterpret_cast<RawClass*>(RAW_NULL); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 85 } else if (raw_class == void_class()) { | 86 } else if (raw_class == void_class()) { |
| 86 return kVoidClass; | 87 return kVoidClass; |
| 87 } else if (raw_class == unresolved_class_class()) { | 88 } else if (raw_class == unresolved_class_class()) { |
| 88 return kUnresolvedClassClass; | 89 return kUnresolvedClassClass; |
| 89 } else if (raw_class == type_class()) { | 90 } else if (raw_class == type_class()) { |
| 90 return kTypeClass; | 91 return kTypeClass; |
| 91 } else if (raw_class == type_parameter_class()) { | 92 } else if (raw_class == type_parameter_class()) { |
| 92 return kTypeParameterClass; | 93 return kTypeParameterClass; |
| 93 } else if (raw_class == instantiated_type_class()) { | 94 } else if (raw_class == instantiated_type_class()) { |
| 94 return kInstantiatedTypeClass; | 95 return kInstantiatedTypeClass; |
| 95 } else if (raw_class == type_arguments_class()) { | 96 } else if (raw_class == abstract_type_arguments_class()) { |
| 97 return kAbstractTypeArgumentsClass; | |
| 98 } else if (raw_class == type_array_class()) { | |
|
regis
2011/12/01 22:20:16
raw_class == type_arguments_class()?
srdjan
2011/12/01 22:44:08
Yes, forgot that one.
| |
| 96 return kTypeArgumentsClass; | 99 return kTypeArgumentsClass; |
| 97 } else if (raw_class == type_array_class()) { | |
| 98 return kTypeArrayClass; | |
| 99 } else if (raw_class == instantiated_type_arguments_class()) { | 100 } else if (raw_class == instantiated_type_arguments_class()) { |
| 100 return kInstantiatedTypeArgumentsClass; | 101 return kInstantiatedTypeArgumentsClass; |
| 101 } else if (raw_class == function_class()) { | 102 } else if (raw_class == function_class()) { |
| 102 return kFunctionClass; | 103 return kFunctionClass; |
| 103 } else if (raw_class == field_class()) { | 104 } else if (raw_class == field_class()) { |
| 104 return kFieldClass; | 105 return kFieldClass; |
| 105 } else if (raw_class == token_stream_class()) { | 106 } else if (raw_class == token_stream_class()) { |
| 106 return kTokenStreamClass; | 107 return kTokenStreamClass; |
| 107 } else if (raw_class == script_class()) { | 108 } else if (raw_class == script_class()) { |
| 108 return kScriptClass; | 109 return kScriptClass; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 132 RawClass* Object::GetSingletonClass(int index) { | 133 RawClass* Object::GetSingletonClass(int index) { |
| 133 switch (index) { | 134 switch (index) { |
| 134 case kClassClass: return class_class(); | 135 case kClassClass: return class_class(); |
| 135 case kNullClass: return null_class(); | 136 case kNullClass: return null_class(); |
| 136 case kDynamicClass: return dynamic_class(); | 137 case kDynamicClass: return dynamic_class(); |
| 137 case kVoidClass: return void_class(); | 138 case kVoidClass: return void_class(); |
| 138 case kUnresolvedClassClass: return unresolved_class_class(); | 139 case kUnresolvedClassClass: return unresolved_class_class(); |
| 139 case kTypeClass: return type_class(); | 140 case kTypeClass: return type_class(); |
| 140 case kTypeParameterClass: return type_parameter_class(); | 141 case kTypeParameterClass: return type_parameter_class(); |
| 141 case kInstantiatedTypeClass: return instantiated_type_class(); | 142 case kInstantiatedTypeClass: return instantiated_type_class(); |
| 142 case kTypeArgumentsClass: return type_arguments_class(); | 143 case kAbstractTypeArgumentsClass: return abstract_type_arguments_class(); |
| 143 case kTypeArrayClass: return type_array_class(); | 144 case kTypeArgumentsClass: return type_array_class(); |
|
regis
2011/12/01 22:20:16
return type_arguments_class()?
srdjan
2011/12/01 22:44:08
Done.
| |
| 144 case kInstantiatedTypeArgumentsClass: | 145 case kInstantiatedTypeArgumentsClass: |
| 145 return instantiated_type_arguments_class(); | 146 return instantiated_type_arguments_class(); |
| 146 case kFunctionClass: return function_class(); | 147 case kFunctionClass: return function_class(); |
| 147 case kFieldClass: return field_class(); | 148 case kFieldClass: return field_class(); |
| 148 case kTokenStreamClass: return token_stream_class(); | 149 case kTokenStreamClass: return token_stream_class(); |
| 149 case kScriptClass: return script_class(); | 150 case kScriptClass: return script_class(); |
| 150 case kLibraryClass: return library_class(); | 151 case kLibraryClass: return library_class(); |
| 151 case kLibraryPrefixClass: return library_prefix_class(); | 152 case kLibraryPrefixClass: return library_prefix_class(); |
| 152 case kCodeClass: return code_class(); | 153 case kCodeClass: return code_class(); |
| 153 case kInstructionsClass: return instructions_class(); | 154 case kInstructionsClass: return instructions_class(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 166 const char* Object::GetSingletonClassName(int index) { | 167 const char* Object::GetSingletonClassName(int index) { |
| 167 switch (index) { | 168 switch (index) { |
| 168 case kClassClass: return "Class"; | 169 case kClassClass: return "Class"; |
| 169 case kNullClass: return "Null"; | 170 case kNullClass: return "Null"; |
| 170 case kDynamicClass: return "Dynamic"; | 171 case kDynamicClass: return "Dynamic"; |
| 171 case kVoidClass: return "void"; | 172 case kVoidClass: return "void"; |
| 172 case kUnresolvedClassClass: return "UnresolvedClass"; | 173 case kUnresolvedClassClass: return "UnresolvedClass"; |
| 173 case kTypeClass: return "Type"; | 174 case kTypeClass: return "Type"; |
| 174 case kTypeParameterClass: return "TypeParameter"; | 175 case kTypeParameterClass: return "TypeParameter"; |
| 175 case kInstantiatedTypeClass: return "InstantiatedType"; | 176 case kInstantiatedTypeClass: return "InstantiatedType"; |
| 177 case kAbstractTypeArgumentsClass: return "AbstractTypeArguments"; | |
| 176 case kTypeArgumentsClass: return "TypeArguments"; | 178 case kTypeArgumentsClass: return "TypeArguments"; |
| 177 case kTypeArrayClass: return "TypeArray"; | |
| 178 case kInstantiatedTypeArgumentsClass: return "InstantiatedTypeArguments"; | 179 case kInstantiatedTypeArgumentsClass: return "InstantiatedTypeArguments"; |
| 179 case kFunctionClass: return "Function"; | 180 case kFunctionClass: return "Function"; |
| 180 case kFieldClass: return "Field"; | 181 case kFieldClass: return "Field"; |
| 181 case kTokenStreamClass: return "TokenStream"; | 182 case kTokenStreamClass: return "TokenStream"; |
| 182 case kScriptClass: return "Script"; | 183 case kScriptClass: return "Script"; |
| 183 case kLibraryClass: return "Library"; | 184 case kLibraryClass: return "Library"; |
| 184 case kLibraryPrefixClass: return "LibraryPrefix"; | 185 case kLibraryPrefixClass: return "LibraryPrefix"; |
| 185 case kCodeClass: return "Code"; | 186 case kCodeClass: return "Code"; |
| 186 case kInstructionsClass: return "Instructions"; | 187 case kInstructionsClass: return "Instructions"; |
| 187 case kPcDescriptorsClass: return "PcDescriptors"; | 188 case kPcDescriptorsClass: return "PcDescriptors"; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 | 277 |
| 277 cls = Class::New<Type>(); | 278 cls = Class::New<Type>(); |
| 278 type_class_ = cls.raw(); | 279 type_class_ = cls.raw(); |
| 279 | 280 |
| 280 cls = Class::New<TypeParameter>(); | 281 cls = Class::New<TypeParameter>(); |
| 281 type_parameter_class_ = cls.raw(); | 282 type_parameter_class_ = cls.raw(); |
| 282 | 283 |
| 283 cls = Class::New<InstantiatedType>(); | 284 cls = Class::New<InstantiatedType>(); |
| 284 instantiated_type_class_ = cls.raw(); | 285 instantiated_type_class_ = cls.raw(); |
| 285 | 286 |
| 287 cls = Class::New<AbstractTypeArguments>(); | |
| 288 abstract_type_arguments_class_ = cls.raw(); | |
| 289 | |
| 286 cls = Class::New<TypeArguments>(); | 290 cls = Class::New<TypeArguments>(); |
| 287 type_arguments_class_ = cls.raw(); | |
| 288 | |
| 289 cls = Class::New<TypeArray>(); | |
| 290 type_array_class_ = cls.raw(); | 291 type_array_class_ = cls.raw(); |
|
regis
2011/12/01 22:20:16
ditto
srdjan
2011/12/01 22:44:08
Done.
| |
| 291 | 292 |
| 292 cls = Class::New<InstantiatedTypeArguments>(); | 293 cls = Class::New<InstantiatedTypeArguments>(); |
| 293 instantiated_type_arguments_class_ = cls.raw(); | 294 instantiated_type_arguments_class_ = cls.raw(); |
| 294 | 295 |
| 295 cls = Class::New<Function>(); | 296 cls = Class::New<Function>(); |
| 296 function_class_ = cls.raw(); | 297 function_class_ = cls.raw(); |
| 297 | 298 |
| 298 cls = Class::New<Field>(); | 299 cls = Class::New<Field>(); |
| 299 field_class_ = cls.raw(); | 300 field_class_ = cls.raw(); |
| 300 | 301 |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 // A signature class extends class Instance and is parameterized in the same | 741 // A signature class extends class Instance and is parameterized in the same |
| 741 // way as the owner class of its non-static signature function. | 742 // way as the owner class of its non-static signature function. |
| 742 // It is not type parameterized if its signature function is static. | 743 // It is not type parameterized if its signature function is static. |
| 743 // See Class::NewSignatureClass() for the setup of its type parameters. | 744 // See Class::NewSignatureClass() for the setup of its type parameters. |
| 744 // During type finalization, the type arguments of the super class of the | 745 // During type finalization, the type arguments of the super class of the |
| 745 // owner class of its signature function will be prepended to the type | 746 // owner class of its signature function will be prepended to the type |
| 746 // argument vector. Therefore, we only need to set the type arguments | 747 // argument vector. Therefore, we only need to set the type arguments |
| 747 // matching the type parameters here. | 748 // matching the type parameters here. |
| 748 if (num_type_params > 0) { | 749 if (num_type_params > 0) { |
| 749 const Array& type_params = Array::Handle(type_parameters()); | 750 const Array& type_params = Array::Handle(type_parameters()); |
| 750 signature_type_arguments = TypeArguments::NewTypeArray(num_type_params); | 751 signature_type_arguments = TypeArguments::New(num_type_params); |
| 751 String& type_param_name = String::Handle(); | 752 String& type_param_name = String::Handle(); |
| 752 AbstractType& type_param = AbstractType::Handle(); | 753 AbstractType& type_param = AbstractType::Handle(); |
| 753 for (int i = 0; i < num_type_params; i++) { | 754 for (int i = 0; i < num_type_params; i++) { |
| 754 type_param_name ^= type_params.At(i); | 755 type_param_name ^= type_params.At(i); |
| 755 type_param = AbstractType::NewTypeParameter(i, type_param_name); | 756 type_param = AbstractType::NewTypeParameter(i, type_param_name); |
| 756 signature_type_arguments.SetTypeAt(i, type_param); | 757 signature_type_arguments.SetTypeAt(i, type_param); |
| 757 } | 758 } |
| 758 } | 759 } |
| 759 const Type& signature_type = Type::Handle( | 760 const Type& signature_type = Type::Handle( |
| 760 Type::New(*this, signature_type_arguments)); | 761 Type::New(*this, signature_type_arguments)); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 846 void Class::set_library(const Library& value) const { | 847 void Class::set_library(const Library& value) const { |
| 847 StorePointer(&raw_ptr()->library_, value.raw()); | 848 StorePointer(&raw_ptr()->library_, value.raw()); |
| 848 } | 849 } |
| 849 | 850 |
| 850 | 851 |
| 851 void Class::set_type_parameters(const Array& value) const { | 852 void Class::set_type_parameters(const Array& value) const { |
| 852 StorePointer(&raw_ptr()->type_parameters_, value.raw()); | 853 StorePointer(&raw_ptr()->type_parameters_, value.raw()); |
| 853 } | 854 } |
| 854 | 855 |
| 855 | 856 |
| 856 void Class::set_type_parameter_extends(const TypeArray& value) const { | 857 void Class::set_type_parameter_extends(const TypeArguments& value) const { |
| 857 StorePointer(&raw_ptr()->type_parameter_extends_, value.raw()); | 858 StorePointer(&raw_ptr()->type_parameter_extends_, value.raw()); |
| 858 } | 859 } |
| 859 | 860 |
| 860 | 861 |
| 861 intptr_t Class::NumTypeParameters() const { | 862 intptr_t Class::NumTypeParameters() const { |
| 862 const Array& type_params = Array::Handle(type_parameters()); | 863 const Array& type_params = Array::Handle(type_parameters()); |
| 863 if (type_params.IsNull()) { | 864 if (type_params.IsNull()) { |
| 864 return 0; | 865 return 0; |
| 865 } else { | 866 } else { |
| 866 return type_params.Length(); | 867 return type_params.Length(); |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1081 } | 1082 } |
| 1082 | 1083 |
| 1083 | 1084 |
| 1084 RawClass* Class::NewSignatureClass(const String& name, | 1085 RawClass* Class::NewSignatureClass(const String& name, |
| 1085 const Function& signature_function, | 1086 const Function& signature_function, |
| 1086 const Script& script) { | 1087 const Script& script) { |
| 1087 ASSERT(!signature_function.IsNull()); | 1088 ASSERT(!signature_function.IsNull()); |
| 1088 const Class& owner_class = Class::Handle(signature_function.owner()); | 1089 const Class& owner_class = Class::Handle(signature_function.owner()); |
| 1089 ASSERT(!owner_class.IsNull()); | 1090 ASSERT(!owner_class.IsNull()); |
| 1090 Array& type_parameters = Array::Handle(); | 1091 Array& type_parameters = Array::Handle(); |
| 1091 TypeArray& type_parameter_extends = TypeArray::Handle(); | 1092 TypeArguments& type_parameter_extends = TypeArguments::Handle(); |
| 1092 // A signature class extends class Instance and is parameterized in the same | 1093 // A signature class extends class Instance and is parameterized in the same |
| 1093 // way as the owner class of its non-static signature function. | 1094 // way as the owner class of its non-static signature function. |
| 1094 // It is not type parameterized if its signature function is static. | 1095 // It is not type parameterized if its signature function is static. |
| 1095 if (!signature_function.is_static()) { | 1096 if (!signature_function.is_static()) { |
| 1096 if ((owner_class.NumTypeParameters() > 0) && | 1097 if ((owner_class.NumTypeParameters() > 0) && |
| 1097 !signature_function.HasInstantiatedSignature()) { | 1098 !signature_function.HasInstantiatedSignature()) { |
| 1098 type_parameters = owner_class.type_parameters(); | 1099 type_parameters = owner_class.type_parameters(); |
| 1099 type_parameter_extends = owner_class.type_parameter_extends(); | 1100 type_parameter_extends = owner_class.type_parameter_extends(); |
| 1100 } | 1101 } |
| 1101 } | 1102 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1293 } | 1294 } |
| 1294 | 1295 |
| 1295 | 1296 |
| 1296 bool Class::IsCanonicalSignatureClass() const { | 1297 bool Class::IsCanonicalSignatureClass() const { |
| 1297 const Function& function = Function::Handle(signature_function()); | 1298 const Function& function = Function::Handle(signature_function()); |
| 1298 return (!function.IsNull() && (function.signature_class() == raw())); | 1299 return (!function.IsNull() && (function.signature_class() == raw())); |
| 1299 } | 1300 } |
| 1300 | 1301 |
| 1301 | 1302 |
| 1302 bool Class::IsMoreSpecificThan( | 1303 bool Class::IsMoreSpecificThan( |
| 1303 const TypeArguments& type_arguments, | 1304 const AbstractTypeArguments& type_arguments, |
| 1304 const Class& other, | 1305 const Class& other, |
| 1305 const TypeArguments& other_type_arguments) const { | 1306 const AbstractTypeArguments& other_type_arguments) const { |
| 1306 // Check for DynamicType. | 1307 // Check for DynamicType. |
| 1307 // The DynamicType on the lefthand side is replaced by the bottom type, which | 1308 // The DynamicType on the lefthand side is replaced by the bottom type, which |
| 1308 // is more specific than any type. | 1309 // is more specific than any type. |
| 1309 // Any type is more specific than the DynamicType on the righthand side. | 1310 // Any type is more specific than the DynamicType on the righthand side. |
| 1310 if (IsDynamicClass() || other.IsDynamicClass()) { | 1311 if (IsDynamicClass() || other.IsDynamicClass()) { |
| 1311 return true; | 1312 return true; |
| 1312 } | 1313 } |
| 1313 // Check for reflexivity. | 1314 // Check for reflexivity. |
| 1314 if (raw() == other.raw()) { | 1315 if (raw() == other.raw()) { |
| 1315 const intptr_t len = NumTypeArguments(); | 1316 const intptr_t len = NumTypeArguments(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1334 return fun.IsSubtypeOf(type_arguments, | 1335 return fun.IsSubtypeOf(type_arguments, |
| 1335 other_fun, | 1336 other_fun, |
| 1336 other_type_arguments); | 1337 other_type_arguments); |
| 1337 } | 1338 } |
| 1338 // 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 |
| 1339 // transitivity at the same time. | 1340 // transitivity at the same time. |
| 1340 if (other.is_interface()) { | 1341 if (other.is_interface()) { |
| 1341 Array& interfaces = Array::Handle(this->interfaces()); | 1342 Array& interfaces = Array::Handle(this->interfaces()); |
| 1342 AbstractType& interface = AbstractType::Handle(); | 1343 AbstractType& interface = AbstractType::Handle(); |
| 1343 Class& interface_class = Class::Handle(); | 1344 Class& interface_class = Class::Handle(); |
| 1344 TypeArguments& interface_args = TypeArguments::Handle(); | 1345 AbstractTypeArguments& interface_args = AbstractTypeArguments::Handle(); |
| 1345 for (intptr_t i = 0; i < interfaces.Length(); i++) { | 1346 for (intptr_t i = 0; i < interfaces.Length(); i++) { |
| 1346 interface ^= interfaces.At(i); | 1347 interface ^= interfaces.At(i); |
| 1347 interface_class = interface.type_class(); | 1348 interface_class = interface.type_class(); |
| 1348 interface_args = interface.arguments(); | 1349 interface_args = interface.arguments(); |
| 1349 if (!interface_args.IsNull() && !interface_args.IsInstantiated()) { | 1350 if (!interface_args.IsNull() && !interface_args.IsInstantiated()) { |
| 1350 // This type implements an interface that is parameterized with generic | 1351 // This type implements an interface that is parameterized with generic |
| 1351 // type(s), e.g. it implements Array<T>. | 1352 // type(s), e.g. it implements Array<T>. |
| 1352 // The uninstantiated type T must be instantiated using the type | 1353 // The uninstantiated type T must be instantiated using the type |
| 1353 // parameters of this type before performing the type test. | 1354 // parameters of this type before performing the type test. |
| 1354 if (type_arguments.IsNull()) { | 1355 if (type_arguments.IsNull()) { |
| 1355 // This type is raw, so the uninstantiated type arguments of the | 1356 // This type is raw, so the uninstantiated type arguments of the |
| 1356 // interface cannot be instantiated and we must check against a raw | 1357 // interface cannot be instantiated and we must check against a raw |
| 1357 // interface. | 1358 // interface. |
| 1358 interface_args = TypeArray::null(); | 1359 interface_args = TypeArguments::null(); |
| 1359 } else { | 1360 } else { |
| 1360 // The type arguments of this type that are referred to by the type | 1361 // The type arguments of this type that are referred to by the type |
| 1361 // parameters of the interface are at the end of the type vector, | 1362 // parameters of the interface are at the end of the type vector, |
| 1362 // after the type arguments of the super type of this type. | 1363 // after the type arguments of the super type of this type. |
| 1363 const intptr_t offset = NumTypeArguments() - NumTypeParameters(); | 1364 const intptr_t offset = NumTypeArguments() - NumTypeParameters(); |
| 1364 interface_args = interface_args.InstantiateFrom(type_arguments, | 1365 interface_args = interface_args.InstantiateFrom(type_arguments, |
| 1365 offset); | 1366 offset); |
| 1366 // TODO(regis): Check the subtyping constraints if any, i.e. if | 1367 // TODO(regis): Check the subtyping constraints if any, i.e. if |
| 1367 // interface.type_parameter_extends() is not an array of DynamicType. | 1368 // interface.type_parameter_extends() is not an array of DynamicType. |
| 1368 // Should we pass the constraints to InstantiateFrom and it would | 1369 // Should we pass the constraints to InstantiateFrom and it would |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1397 other_type_arguments); | 1398 other_type_arguments); |
| 1398 } | 1399 } |
| 1399 | 1400 |
| 1400 | 1401 |
| 1401 bool Class::IsTopLevel() const { | 1402 bool Class::IsTopLevel() const { |
| 1402 return String::Handle(Name()).Length() == 0; | 1403 return String::Handle(Name()).Length() == 0; |
| 1403 } | 1404 } |
| 1404 | 1405 |
| 1405 | 1406 |
| 1406 bool Class::TestType(TypeTestKind test, | 1407 bool Class::TestType(TypeTestKind test, |
| 1407 const TypeArguments& type_arguments, | 1408 const AbstractTypeArguments& type_arguments, |
| 1408 const Class& other, | 1409 const Class& other, |
| 1409 const TypeArguments& other_type_arguments) const { | 1410 const AbstractTypeArguments& other_type_arguments) const { |
| 1410 ASSERT(is_finalized() || !ClassFinalizer::AllClassesFinalized()); | 1411 ASSERT(is_finalized() || !ClassFinalizer::AllClassesFinalized()); |
| 1411 ASSERT(other.is_finalized() || !ClassFinalizer::AllClassesFinalized()); | 1412 ASSERT(other.is_finalized() || !ClassFinalizer::AllClassesFinalized()); |
| 1412 if (test == kIsAssignableTo) { | 1413 if (test == kIsAssignableTo) { |
| 1413 // The spec states that "a type T is assignable to a type S if T is a | 1414 // The spec states that "a type T is assignable to a type S if T is a |
| 1414 // subtype of S or S is a subtype of T". This is from the perspective of a | 1415 // subtype of S or S is a subtype of T". This is from the perspective of a |
| 1415 // static checker, which does not know the actual type of the assigned | 1416 // static checker, which does not know the actual type of the assigned |
| 1416 // value. However, this type information is available at run time in checked | 1417 // value. However, this type information is available at run time in checked |
| 1417 // mode. We therefore apply a more restrictive subtype check, which prevents | 1418 // mode. We therefore apply a more restrictive subtype check, which prevents |
| 1418 // heap pollution. We only keep the assignability check when assigning | 1419 // heap pollution. We only keep the assignability check when assigning |
| 1419 // values of a function type. | 1420 // values of a function type. |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1697 } | 1698 } |
| 1698 | 1699 |
| 1699 | 1700 |
| 1700 RawUnresolvedClass* AbstractType::unresolved_class() const { | 1701 RawUnresolvedClass* AbstractType::unresolved_class() const { |
| 1701 // AbstractType is an abstract class. | 1702 // AbstractType is an abstract class. |
| 1702 UNREACHABLE(); | 1703 UNREACHABLE(); |
| 1703 return UnresolvedClass::null(); | 1704 return UnresolvedClass::null(); |
| 1704 } | 1705 } |
| 1705 | 1706 |
| 1706 | 1707 |
| 1707 RawTypeArguments* AbstractType::arguments() const { | 1708 RawAbstractTypeArguments* AbstractType::arguments() const { |
| 1708 // AbstractType is an abstract class. | 1709 // AbstractType is an abstract class. |
| 1709 UNREACHABLE(); | 1710 UNREACHABLE(); |
| 1710 return NULL; | 1711 return NULL; |
| 1711 } | 1712 } |
| 1712 | 1713 |
| 1713 | 1714 |
| 1714 bool AbstractType::IsInstantiated() const { | 1715 bool AbstractType::IsInstantiated() const { |
| 1715 // AbstractType is an abstract class. | 1716 // AbstractType is an abstract class. |
| 1716 UNREACHABLE(); | 1717 UNREACHABLE(); |
| 1717 return false; | 1718 return false; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1733 | 1734 |
| 1734 | 1735 |
| 1735 bool AbstractType::Equals(const AbstractType& other) const { | 1736 bool AbstractType::Equals(const AbstractType& other) const { |
| 1736 // AbstractType is an abstract class. | 1737 // AbstractType is an abstract class. |
| 1737 UNREACHABLE(); | 1738 UNREACHABLE(); |
| 1738 return false; | 1739 return false; |
| 1739 } | 1740 } |
| 1740 | 1741 |
| 1741 | 1742 |
| 1742 RawAbstractType* AbstractType::InstantiateFrom( | 1743 RawAbstractType* AbstractType::InstantiateFrom( |
| 1743 const TypeArguments& instantiator_type_arguments, | 1744 const AbstractTypeArguments& instantiator_type_arguments, |
| 1744 intptr_t offset) const { | 1745 intptr_t offset) const { |
| 1745 // AbstractType is an abstract class. | 1746 // AbstractType is an abstract class. |
| 1746 UNREACHABLE(); | 1747 UNREACHABLE(); |
| 1747 return NULL; | 1748 return NULL; |
| 1748 } | 1749 } |
| 1749 | 1750 |
| 1750 | 1751 |
| 1751 RawAbstractType* AbstractType::Canonicalize() const { | 1752 RawAbstractType* AbstractType::Canonicalize() const { |
| 1752 // AbstractType is an abstract class. | 1753 // AbstractType is an abstract class. |
| 1753 UNREACHABLE(); | 1754 UNREACHABLE(); |
| 1754 return NULL; | 1755 return NULL; |
| 1755 } | 1756 } |
| 1756 | 1757 |
| 1757 | 1758 |
| 1758 RawString* AbstractType::Name() const { | 1759 RawString* AbstractType::Name() const { |
| 1759 // 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 |
| 1760 // an illformed type, so proceed with caution. | 1761 // an illformed type, so proceed with caution. |
| 1761 const TypeArguments& args = TypeArguments::Handle(arguments()); | 1762 const AbstractTypeArguments& args = |
| 1763 AbstractTypeArguments::Handle(arguments()); | |
| 1762 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); | 1764 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); |
| 1763 String& class_name = String::Handle(); | 1765 String& class_name = String::Handle(); |
| 1764 intptr_t first_type_param_index; | 1766 intptr_t first_type_param_index; |
| 1765 intptr_t num_type_params; // Number of type parameters to print. | 1767 intptr_t num_type_params; // Number of type parameters to print. |
| 1766 if (HasResolvedTypeClass()) { | 1768 if (HasResolvedTypeClass()) { |
| 1767 const Class& cls = Class::Handle(type_class()); | 1769 const Class& cls = Class::Handle(type_class()); |
| 1768 class_name = cls.Name(); | 1770 class_name = cls.Name(); |
| 1769 num_type_params = cls.NumTypeParameters(); // Do not print the full vector. | 1771 num_type_params = cls.NumTypeParameters(); // Do not print the full vector. |
| 1770 if (num_type_params > num_args) { | 1772 if (num_type_params > num_args) { |
| 1771 first_type_param_index = 0; | 1773 first_type_param_index = 0; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1890 | 1892 |
| 1891 bool AbstractType::IsMoreSpecificThan(const AbstractType& other) const { | 1893 bool AbstractType::IsMoreSpecificThan(const AbstractType& other) const { |
| 1892 ASSERT(IsFinalized()); | 1894 ASSERT(IsFinalized()); |
| 1893 ASSERT(other.IsFinalized()); | 1895 ASSERT(other.IsFinalized()); |
| 1894 // AbstractType parameters cannot be handled by Class::IsMoreSpecificThan(). | 1896 // AbstractType parameters cannot be handled by Class::IsMoreSpecificThan(). |
| 1895 if (IsTypeParameter() || other.IsTypeParameter()) { | 1897 if (IsTypeParameter() || other.IsTypeParameter()) { |
| 1896 return IsTypeParameter() && other.IsTypeParameter() && | 1898 return IsTypeParameter() && other.IsTypeParameter() && |
| 1897 (Index() == other.Index()); | 1899 (Index() == other.Index()); |
| 1898 } | 1900 } |
| 1899 const Class& cls = Class::Handle(type_class()); | 1901 const Class& cls = Class::Handle(type_class()); |
| 1900 return cls.IsMoreSpecificThan(TypeArguments::Handle(arguments()), | 1902 return cls.IsMoreSpecificThan( |
| 1901 Class::Handle(other.type_class()), | 1903 AbstractTypeArguments::Handle(arguments()), |
| 1902 TypeArguments::Handle(other.arguments())); | 1904 Class::Handle(other.type_class()), |
| 1905 AbstractTypeArguments::Handle(other.arguments())); | |
| 1903 } | 1906 } |
| 1904 | 1907 |
| 1905 | 1908 |
| 1906 bool AbstractType::Test(TypeTestKind test, const AbstractType& other) const { | 1909 bool AbstractType::Test(TypeTestKind test, const AbstractType& other) const { |
| 1907 ASSERT(IsFinalized()); | 1910 ASSERT(IsFinalized()); |
| 1908 ASSERT(other.IsFinalized()); | 1911 ASSERT(other.IsFinalized()); |
| 1909 // AbstractType parameters cannot be handled by Class::TestType(). | 1912 // AbstractType parameters cannot be handled by Class::TestType(). |
| 1910 if (IsTypeParameter() || other.IsTypeParameter()) { | 1913 if (IsTypeParameter() || other.IsTypeParameter()) { |
| 1911 return IsTypeParameter() && other.IsTypeParameter() && | 1914 return IsTypeParameter() && other.IsTypeParameter() && |
| 1912 (Index() == other.Index()); | 1915 (Index() == other.Index()); |
| 1913 } | 1916 } |
| 1914 const Class& cls = Class::Handle(type_class()); | 1917 const Class& cls = Class::Handle(type_class()); |
| 1915 if (test == kIsSubtypeOf) { | 1918 if (test == kIsSubtypeOf) { |
| 1916 return cls.IsSubtypeOf(TypeArguments::Handle(arguments()), | 1919 return cls.IsSubtypeOf(AbstractTypeArguments::Handle(arguments()), |
| 1917 Class::Handle(other.type_class()), | 1920 Class::Handle(other.type_class()), |
| 1918 TypeArguments::Handle(other.arguments())); | 1921 AbstractTypeArguments::Handle(other.arguments())); |
| 1919 } else { | 1922 } else { |
| 1920 ASSERT(test == kIsAssignableTo); | 1923 ASSERT(test == kIsAssignableTo); |
| 1921 return cls.IsAssignableTo(TypeArguments::Handle(arguments()), | 1924 return cls.IsAssignableTo(AbstractTypeArguments::Handle(arguments()), |
| 1922 Class::Handle(other.type_class()), | 1925 Class::Handle(other.type_class()), |
| 1923 TypeArguments::Handle(other.arguments())); | 1926 AbstractTypeArguments::Handle(other.arguments())); |
| 1924 } | 1927 } |
| 1925 } | 1928 } |
| 1926 | 1929 |
| 1927 RawAbstractType* AbstractType::NewTypeParameter( | 1930 RawAbstractType* AbstractType::NewTypeParameter( |
| 1928 intptr_t index, const String& name) { | 1931 intptr_t index, const String& name) { |
| 1929 return TypeParameter::New(index, name); | 1932 return TypeParameter::New(index, name); |
| 1930 } | 1933 } |
| 1931 | 1934 |
| 1932 | 1935 |
| 1933 RawAbstractType* AbstractType::NewInstantiatedType( | 1936 RawAbstractType* AbstractType::NewInstantiatedType( |
| 1934 const AbstractType& uninstantiated_type, | 1937 const AbstractType& uninstantiated_type, |
| 1935 const TypeArguments& instantiator_type_arguments) { | 1938 const AbstractTypeArguments& instantiator_type_arguments) { |
| 1936 return InstantiatedType::New(uninstantiated_type, | 1939 return InstantiatedType::New(uninstantiated_type, |
| 1937 instantiator_type_arguments); | 1940 instantiator_type_arguments); |
| 1938 } | 1941 } |
| 1939 | 1942 |
| 1940 | 1943 |
| 1941 const char* AbstractType::ToCString() const { | 1944 const char* AbstractType::ToCString() const { |
| 1942 // AbstractType is an abstract class. | 1945 // AbstractType is an abstract class. |
| 1943 UNREACHABLE(); | 1946 UNREACHABLE(); |
| 1944 return "AbstractType"; | 1947 return "AbstractType"; |
| 1945 } | 1948 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1994 return Isolate::Current()->object_store()->function_interface(); | 1997 return Isolate::Current()->object_store()->function_interface(); |
| 1995 } | 1998 } |
| 1996 | 1999 |
| 1997 | 2000 |
| 1998 RawType* Type::ListInterface() { | 2001 RawType* Type::ListInterface() { |
| 1999 return Isolate::Current()->object_store()->list_interface(); | 2002 return Isolate::Current()->object_store()->list_interface(); |
| 2000 } | 2003 } |
| 2001 | 2004 |
| 2002 | 2005 |
| 2003 RawType* Type::NewRawType(const Class& type_class) { | 2006 RawType* Type::NewRawType(const Class& type_class) { |
| 2004 const TypeArguments& type_arguments = | 2007 const AbstractTypeArguments& type_arguments = |
| 2005 TypeArguments::Handle(type_class.type_parameter_extends()); | 2008 AbstractTypeArguments::Handle(type_class.type_parameter_extends()); |
| 2006 return NewParameterizedType(Object::Handle(type_class.raw()), type_arguments); | 2009 return NewParameterizedType(Object::Handle(type_class.raw()), type_arguments); |
| 2007 } | 2010 } |
| 2008 | 2011 |
| 2009 | 2012 |
| 2010 RawType* Type::NewNonParameterizedType( | 2013 RawType* Type::NewNonParameterizedType( |
| 2011 const Class& type_class) { | 2014 const Class& type_class) { |
| 2012 ASSERT(!type_class.HasTypeArguments()); | 2015 ASSERT(!type_class.HasTypeArguments()); |
| 2013 const TypeArguments& no_type_arguments = TypeArguments::Handle(); | 2016 const TypeArguments& no_type_arguments = TypeArguments::Handle(); |
| 2014 Type& type = Type::Handle(); | 2017 Type& type = Type::Handle(); |
| 2015 type ^= Type::New( | 2018 type ^= Type::New( |
| 2016 Object::Handle(type_class.raw()), no_type_arguments); | 2019 Object::Handle(type_class.raw()), no_type_arguments); |
| 2017 type.set_is_finalized(); | 2020 type.set_is_finalized(); |
| 2018 type ^= type.Canonicalize(); | 2021 type ^= type.Canonicalize(); |
| 2019 return type.raw(); | 2022 return type.raw(); |
| 2020 } | 2023 } |
| 2021 | 2024 |
| 2022 | 2025 |
| 2023 RawType* Type::NewParameterizedType(const Object& clazz, | 2026 RawType* Type::NewParameterizedType(const Object& clazz, |
| 2024 const TypeArguments& arguments) { | 2027 const AbstractTypeArguments& arguments) { |
| 2025 return Type::New(clazz, arguments); | 2028 return Type::New(clazz, arguments); |
| 2026 } | 2029 } |
| 2027 | 2030 |
| 2028 | 2031 |
| 2029 void Type::set_is_finalized() const { | 2032 void Type::set_is_finalized() const { |
| 2030 ASSERT(!IsFinalized()); | 2033 ASSERT(!IsFinalized()); |
| 2031 set_type_state(RawType::kFinalized); | 2034 set_type_state(RawType::kFinalized); |
| 2032 } | 2035 } |
| 2033 | 2036 |
| 2034 | 2037 |
| 2035 void Type::set_is_being_finalized() const { | 2038 void Type::set_is_being_finalized() const { |
| 2036 ASSERT(!IsFinalized() && !IsBeingFinalized()); | 2039 ASSERT(!IsFinalized() && !IsBeingFinalized()); |
| 2037 set_type_state(RawType::kBeingFinalized); | 2040 set_type_state(RawType::kBeingFinalized); |
| 2038 } | 2041 } |
| 2039 | 2042 |
| 2040 | 2043 |
| 2041 bool Type::IsResolved() const { | 2044 bool Type::IsResolved() const { |
| 2042 if (IsFinalized()) { | 2045 if (IsFinalized()) { |
| 2043 return true; | 2046 return true; |
| 2044 } | 2047 } |
| 2045 if (!HasResolvedTypeClass()) { | 2048 if (!HasResolvedTypeClass()) { |
| 2046 return false; | 2049 return false; |
| 2047 } | 2050 } |
| 2048 const TypeArguments& args = TypeArguments::Handle(arguments()); | 2051 const AbstractTypeArguments& args = |
| 2052 AbstractTypeArguments::Handle(arguments()); | |
| 2049 return args.IsNull() || args.IsResolved(); | 2053 return args.IsNull() || args.IsResolved(); |
| 2050 } | 2054 } |
| 2051 | 2055 |
| 2052 | 2056 |
| 2053 bool Type::HasResolvedTypeClass() const { | 2057 bool Type::HasResolvedTypeClass() const { |
| 2054 const Object& type_class = Object::Handle(raw_ptr()->type_class_); | 2058 const Object& type_class = Object::Handle(raw_ptr()->type_class_); |
| 2055 return !type_class.IsNull() && type_class.IsClass(); | 2059 return !type_class.IsNull() && type_class.IsClass(); |
| 2056 } | 2060 } |
| 2057 | 2061 |
| 2058 | 2062 |
| 2059 RawClass* Type::type_class() const { | 2063 RawClass* Type::type_class() const { |
| 2060 ASSERT(HasResolvedTypeClass()); | 2064 ASSERT(HasResolvedTypeClass()); |
| 2061 Class& type_class = Class::Handle(); | 2065 Class& type_class = Class::Handle(); |
| 2062 type_class ^= raw_ptr()->type_class_; | 2066 type_class ^= raw_ptr()->type_class_; |
| 2063 return type_class.raw(); | 2067 return type_class.raw(); |
| 2064 } | 2068 } |
| 2065 | 2069 |
| 2066 | 2070 |
| 2067 RawUnresolvedClass* Type::unresolved_class() const { | 2071 RawUnresolvedClass* Type::unresolved_class() const { |
| 2068 ASSERT(!HasResolvedTypeClass()); | 2072 ASSERT(!HasResolvedTypeClass()); |
| 2069 UnresolvedClass& unresolved_class = UnresolvedClass::Handle(); | 2073 UnresolvedClass& unresolved_class = UnresolvedClass::Handle(); |
| 2070 unresolved_class ^= raw_ptr()->type_class_; | 2074 unresolved_class ^= raw_ptr()->type_class_; |
| 2071 ASSERT(!unresolved_class.IsNull()); | 2075 ASSERT(!unresolved_class.IsNull()); |
| 2072 return unresolved_class.raw(); | 2076 return unresolved_class.raw(); |
| 2073 } | 2077 } |
| 2074 | 2078 |
| 2075 | 2079 |
| 2076 RawTypeArguments* Type::arguments() const { | 2080 RawAbstractTypeArguments* Type::arguments() const { |
| 2077 return raw_ptr()->arguments_; | 2081 return raw_ptr()->arguments_; |
| 2078 } | 2082 } |
| 2079 | 2083 |
| 2080 | 2084 |
| 2081 bool Type::IsInstantiated() const { | 2085 bool Type::IsInstantiated() const { |
| 2082 const TypeArguments& args = TypeArguments::Handle(arguments()); | 2086 const AbstractTypeArguments& args = |
| 2087 AbstractTypeArguments::Handle(arguments()); | |
| 2083 return args.IsNull() || args.IsInstantiated(); | 2088 return args.IsNull() || args.IsInstantiated(); |
| 2084 } | 2089 } |
| 2085 | 2090 |
| 2086 | 2091 |
| 2087 RawAbstractType* Type::InstantiateFrom( | 2092 RawAbstractType* Type::InstantiateFrom( |
| 2088 const TypeArguments& instantiator_type_arguments, | 2093 const AbstractTypeArguments& instantiator_type_arguments, |
| 2089 intptr_t offset) const { | 2094 intptr_t offset) const { |
| 2090 ASSERT(IsFinalized()); | 2095 ASSERT(IsFinalized()); |
| 2091 ASSERT(!IsInstantiated()); | 2096 ASSERT(!IsInstantiated()); |
| 2092 TypeArguments& type_arguments = TypeArguments::Handle(arguments()); | 2097 AbstractTypeArguments& type_arguments = |
| 2098 AbstractTypeArguments::Handle(arguments()); | |
| 2093 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, | 2099 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, |
| 2094 offset); | 2100 offset); |
| 2095 const Class& cls = Class::Handle(type_class()); | 2101 const Class& cls = Class::Handle(type_class()); |
| 2096 ASSERT(cls.is_finalized()); | 2102 ASSERT(cls.is_finalized()); |
| 2097 Type& instantiated_type = Type::Handle(Type::New(cls, type_arguments)); | 2103 Type& instantiated_type = Type::Handle(Type::New(cls, type_arguments)); |
| 2098 ASSERT(type_arguments.IsNull() || | 2104 ASSERT(type_arguments.IsNull() || |
| 2099 (type_arguments.Length() == cls.NumTypeArguments())); | 2105 (type_arguments.Length() == cls.NumTypeArguments())); |
| 2100 instantiated_type.set_is_finalized(); | 2106 instantiated_type.set_is_finalized(); |
| 2101 return instantiated_type.raw(); | 2107 return instantiated_type.raw(); |
| 2102 } | 2108 } |
| 2103 | 2109 |
| 2104 | 2110 |
| 2105 bool Type::Equals(const AbstractType& other) const { | 2111 bool Type::Equals(const AbstractType& other) const { |
| 2106 ASSERT(IsFinalized() && other.IsFinalized()); | 2112 ASSERT(IsFinalized() && other.IsFinalized()); |
| 2107 if (raw() == other.raw()) { | 2113 if (raw() == other.raw()) { |
| 2108 return true; | 2114 return true; |
| 2109 } | 2115 } |
| 2110 if (!other.IsType()) { | 2116 if (!other.IsType()) { |
| 2111 return false; | 2117 return false; |
| 2112 } | 2118 } |
| 2113 Type& other_parameterized_type = Type::Handle(); | 2119 Type& other_parameterized_type = Type::Handle(); |
| 2114 other_parameterized_type ^= other.raw(); | 2120 other_parameterized_type ^= other.raw(); |
| 2115 if (type_class() != other_parameterized_type.type_class()) { | 2121 if (type_class() != other_parameterized_type.type_class()) { |
| 2116 return false; | 2122 return false; |
| 2117 } | 2123 } |
| 2118 return TypeArguments::AreEqual(TypeArguments::Handle(arguments()), | 2124 return AbstractTypeArguments::AreEqual( |
| 2119 TypeArguments::Handle(other.arguments())); | 2125 AbstractTypeArguments::Handle(arguments()), |
| 2126 AbstractTypeArguments::Handle(other.arguments())); | |
| 2120 } | 2127 } |
| 2121 | 2128 |
| 2122 | 2129 |
| 2123 RawAbstractType* Type::Canonicalize() const { | 2130 RawAbstractType* Type::Canonicalize() const { |
| 2124 ASSERT(IsFinalized()); | 2131 ASSERT(IsFinalized()); |
| 2125 const Class& cls = Class::Handle(type_class()); | 2132 const Class& cls = Class::Handle(type_class()); |
| 2126 Array& canonical_types = Array::Handle(cls.canonical_types()); | 2133 Array& canonical_types = Array::Handle(cls.canonical_types()); |
| 2127 if (canonical_types.IsNull()) { | 2134 if (canonical_types.IsNull()) { |
| 2128 // Types defined in the VM isolate are canonicalized via the object store. | 2135 // Types defined in the VM isolate are canonicalized via the object store. |
| 2129 // TODO(regis): Should we add null_class_, void_class_, dynamic_class_ to | 2136 // TODO(regis): Should we add null_class_, void_class_, dynamic_class_ to |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2165 return this->raw(); | 2172 return this->raw(); |
| 2166 } | 2173 } |
| 2167 | 2174 |
| 2168 | 2175 |
| 2169 void Type::set_type_class(const Object& value) const { | 2176 void Type::set_type_class(const Object& value) const { |
| 2170 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass())); | 2177 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass())); |
| 2171 StorePointer(&raw_ptr()->type_class_, value.raw()); | 2178 StorePointer(&raw_ptr()->type_class_, value.raw()); |
| 2172 } | 2179 } |
| 2173 | 2180 |
| 2174 | 2181 |
| 2175 void Type::set_arguments(const TypeArguments& value) const { | 2182 void Type::set_arguments(const AbstractTypeArguments& value) const { |
| 2176 StorePointer(&raw_ptr()->arguments_, value.raw()); | 2183 StorePointer(&raw_ptr()->arguments_, value.raw()); |
| 2177 } | 2184 } |
| 2178 | 2185 |
| 2179 | 2186 |
| 2180 RawType* Type::New() { | 2187 RawType* Type::New() { |
| 2181 const Class& type_class = Class::Handle(Object::type_class()); | 2188 const Class& type_class = Class::Handle(Object::type_class()); |
| 2182 RawObject* raw = Object::Allocate(type_class, | 2189 RawObject* raw = Object::Allocate(type_class, |
| 2183 Type::InstanceSize(), | 2190 Type::InstanceSize(), |
| 2184 Heap::kOld); | 2191 Heap::kOld); |
| 2185 return reinterpret_cast<RawType*>(raw); | 2192 return reinterpret_cast<RawType*>(raw); |
| 2186 } | 2193 } |
| 2187 | 2194 |
| 2188 | 2195 |
| 2189 RawType* Type::New(const Object& clazz, | 2196 RawType* Type::New(const Object& clazz, |
| 2190 const TypeArguments& arguments) { | 2197 const AbstractTypeArguments& arguments) { |
| 2191 const Type& result = Type::Handle(Type::New()); | 2198 const Type& result = Type::Handle(Type::New()); |
| 2192 result.set_type_class(clazz); | 2199 result.set_type_class(clazz); |
| 2193 result.set_arguments(arguments); | 2200 result.set_arguments(arguments); |
| 2194 result.raw_ptr()->type_state_ = RawType::kAllocated; | 2201 result.raw_ptr()->type_state_ = RawType::kAllocated; |
| 2195 return result.raw(); | 2202 return result.raw(); |
| 2196 } | 2203 } |
| 2197 | 2204 |
| 2198 | 2205 |
| 2199 void Type::set_type_state(int8_t state) const { | 2206 void Type::set_type_state(int8_t state) const { |
| 2200 ASSERT(state == RawType::kAllocated || | 2207 ASSERT(state == RawType::kAllocated || |
| 2201 state == RawType::kBeingFinalized || | 2208 state == RawType::kBeingFinalized || |
| 2202 state == RawType::kFinalized); | 2209 state == RawType::kFinalized); |
| 2203 raw_ptr()->type_state_ = state; | 2210 raw_ptr()->type_state_ = state; |
| 2204 } | 2211 } |
| 2205 | 2212 |
| 2206 | 2213 |
| 2207 const char* Type::ToCString() const { | 2214 const char* Type::ToCString() const { |
| 2208 if (IsResolved()) { | 2215 if (IsResolved()) { |
| 2209 const TypeArguments& type_arguments = TypeArguments::Handle(arguments()); | 2216 const AbstractTypeArguments& type_arguments = |
| 2217 AbstractTypeArguments::Handle(arguments()); | |
| 2210 if (type_arguments.IsNull()) { | 2218 if (type_arguments.IsNull()) { |
| 2211 const char* format = "Type: class '%s'"; | 2219 const char* format = "Type: class '%s'"; |
| 2212 const char* class_name = | 2220 const char* class_name = |
| 2213 String::Handle(Class::Handle(type_class()).Name()).ToCString(); | 2221 String::Handle(Class::Handle(type_class()).Name()).ToCString(); |
| 2214 intptr_t len = OS::SNPrint(NULL, 0, format, class_name) + 1; | 2222 intptr_t len = OS::SNPrint(NULL, 0, format, class_name) + 1; |
| 2215 char* chars = reinterpret_cast<char*>( | 2223 char* chars = reinterpret_cast<char*>( |
| 2216 Isolate::Current()->current_zone()->Allocate(len)); | 2224 Isolate::Current()->current_zone()->Allocate(len)); |
| 2217 OS::SNPrint(chars, len, format, class_name); | 2225 OS::SNPrint(chars, len, format, class_name); |
| 2218 return chars; | 2226 return chars; |
| 2219 } else { | 2227 } else { |
| 2220 const char* format = "Type: class '%s', args:[%s]"; | 2228 const char* format = "Type: class '%s', args:[%s]"; |
| 2221 const char* class_name = | 2229 const char* class_name = |
| 2222 String::Handle(Class::Handle(type_class()).Name()).ToCString(); | 2230 String::Handle(Class::Handle(type_class()).Name()).ToCString(); |
| 2223 const char* args_cstr = TypeArguments::Handle(arguments()).ToCString(); | 2231 const char* args_cstr = |
| 2232 AbstractTypeArguments::Handle(arguments()).ToCString(); | |
| 2224 intptr_t len = OS::SNPrint(NULL, 0, format, class_name, args_cstr) + 1; | 2233 intptr_t len = OS::SNPrint(NULL, 0, format, class_name, args_cstr) + 1; |
| 2225 char* chars = reinterpret_cast<char*>( | 2234 char* chars = reinterpret_cast<char*>( |
| 2226 Isolate::Current()->current_zone()->Allocate(len)); | 2235 Isolate::Current()->current_zone()->Allocate(len)); |
| 2227 OS::SNPrint(chars, len, format, class_name, args_cstr); | 2236 OS::SNPrint(chars, len, format, class_name, args_cstr); |
| 2228 return chars; | 2237 return chars; |
| 2229 } | 2238 } |
| 2230 } else { | 2239 } else { |
| 2231 return "Unresolved Type"; | 2240 return "Unresolved Type"; |
| 2232 } | 2241 } |
| 2233 } | 2242 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 2252 } | 2261 } |
| 2253 | 2262 |
| 2254 | 2263 |
| 2255 void TypeParameter::set_name(const String& value) const { | 2264 void TypeParameter::set_name(const String& value) const { |
| 2256 ASSERT(value.IsSymbol()); | 2265 ASSERT(value.IsSymbol()); |
| 2257 StorePointer(&raw_ptr()->name_, value.raw()); | 2266 StorePointer(&raw_ptr()->name_, value.raw()); |
| 2258 } | 2267 } |
| 2259 | 2268 |
| 2260 | 2269 |
| 2261 RawAbstractType* TypeParameter::InstantiateFrom( | 2270 RawAbstractType* TypeParameter::InstantiateFrom( |
| 2262 const TypeArguments& instantiator_type_arguments, | 2271 const AbstractTypeArguments& instantiator_type_arguments, |
| 2263 intptr_t offset) const { | 2272 intptr_t offset) const { |
| 2264 if (instantiator_type_arguments.IsNull()) { | 2273 if (instantiator_type_arguments.IsNull()) { |
| 2265 return Type::DynamicType(); | 2274 return Type::DynamicType(); |
| 2266 } | 2275 } |
| 2267 return instantiator_type_arguments.TypeAt(Index() + offset); | 2276 return instantiator_type_arguments.TypeAt(Index() + offset); |
| 2268 } | 2277 } |
| 2269 | 2278 |
| 2270 | 2279 |
| 2271 RawTypeParameter* TypeParameter::New() { | 2280 RawTypeParameter* TypeParameter::New() { |
| 2272 const Class& type_parameter_class = | 2281 const Class& type_parameter_class = |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 2295 OS::SNPrint(chars, len, format, name_cstr, Index()); | 2304 OS::SNPrint(chars, len, format, name_cstr, Index()); |
| 2296 return chars; | 2305 return chars; |
| 2297 } | 2306 } |
| 2298 | 2307 |
| 2299 | 2308 |
| 2300 RawClass* InstantiatedType::type_class() const { | 2309 RawClass* InstantiatedType::type_class() const { |
| 2301 return AbstractType::Handle(uninstantiated_type()).type_class(); | 2310 return AbstractType::Handle(uninstantiated_type()).type_class(); |
| 2302 } | 2311 } |
| 2303 | 2312 |
| 2304 | 2313 |
| 2305 RawTypeArguments* InstantiatedType::arguments() const { | 2314 RawAbstractTypeArguments* InstantiatedType::arguments() const { |
| 2306 return TypeArguments::NewInstantiatedTypeArguments( | 2315 return AbstractTypeArguments::NewInstantiatedTypeArguments( |
| 2307 TypeArguments::Handle(AbstractType::Handle( | 2316 AbstractTypeArguments::Handle(AbstractType::Handle( |
| 2308 uninstantiated_type()).arguments()), | 2317 uninstantiated_type()).arguments()), |
| 2309 TypeArguments::Handle(instantiator_type_arguments())); | 2318 AbstractTypeArguments::Handle(instantiator_type_arguments())); |
| 2310 } | 2319 } |
| 2311 | 2320 |
| 2312 | 2321 |
| 2313 void InstantiatedType::set_uninstantiated_type( | 2322 void InstantiatedType::set_uninstantiated_type( |
| 2314 const AbstractType& value) const { | 2323 const AbstractType& value) const { |
| 2315 StorePointer(&raw_ptr()->uninstantiated_type_, value.raw()); | 2324 StorePointer(&raw_ptr()->uninstantiated_type_, value.raw()); |
| 2316 } | 2325 } |
| 2317 | 2326 |
| 2318 | 2327 |
| 2319 void InstantiatedType::set_instantiator_type_arguments( | 2328 void InstantiatedType::set_instantiator_type_arguments( |
| 2320 const TypeArguments& value) const { | 2329 const AbstractTypeArguments& value) const { |
| 2321 StorePointer(&raw_ptr()->instantiator_type_arguments_, value.raw()); | 2330 StorePointer(&raw_ptr()->instantiator_type_arguments_, value.raw()); |
| 2322 } | 2331 } |
| 2323 | 2332 |
| 2324 | 2333 |
| 2325 RawInstantiatedType* InstantiatedType::New() { | 2334 RawInstantiatedType* InstantiatedType::New() { |
| 2326 const Class& instantiated_type_class = | 2335 const Class& instantiated_type_class = |
| 2327 Class::Handle(Object::instantiated_type_class()); | 2336 Class::Handle(Object::instantiated_type_class()); |
| 2328 RawObject* raw = Object::Allocate(instantiated_type_class, | 2337 RawObject* raw = Object::Allocate(instantiated_type_class, |
| 2329 InstantiatedType::InstanceSize(), | 2338 InstantiatedType::InstanceSize(), |
| 2330 Heap::kOld); | 2339 Heap::kOld); |
| 2331 return reinterpret_cast<RawInstantiatedType*>(raw); | 2340 return reinterpret_cast<RawInstantiatedType*>(raw); |
| 2332 } | 2341 } |
| 2333 | 2342 |
| 2334 | 2343 |
| 2335 RawInstantiatedType* InstantiatedType::New( | 2344 RawInstantiatedType* InstantiatedType::New( |
| 2336 const AbstractType& uninstantiated_type, | 2345 const AbstractType& uninstantiated_type, |
| 2337 const TypeArguments& instantiator_type_arguments) { | 2346 const AbstractTypeArguments& instantiator_type_arguments) { |
| 2338 const InstantiatedType& result = | 2347 const InstantiatedType& result = |
| 2339 InstantiatedType::Handle(InstantiatedType::New()); | 2348 InstantiatedType::Handle(InstantiatedType::New()); |
| 2340 result.set_uninstantiated_type(uninstantiated_type); | 2349 result.set_uninstantiated_type(uninstantiated_type); |
| 2341 result.set_instantiator_type_arguments(instantiator_type_arguments); | 2350 result.set_instantiator_type_arguments(instantiator_type_arguments); |
| 2342 return result.raw(); | 2351 return result.raw(); |
| 2343 } | 2352 } |
| 2344 | 2353 |
| 2345 | 2354 |
| 2346 const char* InstantiatedType::ToCString() const { | 2355 const char* InstantiatedType::ToCString() const { |
| 2347 return "InstantiatedType"; | 2356 return "InstantiatedType"; |
| 2348 } | 2357 } |
| 2349 | 2358 |
| 2350 | 2359 |
| 2351 intptr_t TypeArguments::Length() const { | 2360 intptr_t AbstractTypeArguments::Length() const { |
| 2352 // TypeArguments is an abstract class. | 2361 // AbstractTypeArguments is an abstract class. |
| 2353 UNREACHABLE(); | 2362 UNREACHABLE(); |
| 2354 return -1; | 2363 return -1; |
| 2355 } | 2364 } |
| 2356 | 2365 |
| 2357 | 2366 |
| 2358 RawAbstractType* TypeArguments::TypeAt(intptr_t index) const { | 2367 RawAbstractType* AbstractTypeArguments::TypeAt(intptr_t index) const { |
| 2359 // TypeArguments is an abstract class. | 2368 // AbstractTypeArguments is an abstract class. |
| 2360 UNREACHABLE(); | 2369 UNREACHABLE(); |
| 2361 return NULL; | 2370 return NULL; |
| 2362 } | 2371 } |
| 2363 | 2372 |
| 2364 | 2373 |
| 2365 void TypeArguments::SetTypeAt(intptr_t index, const AbstractType& value) const { | 2374 void AbstractTypeArguments::SetTypeAt(intptr_t index, |
| 2366 // TypeArguments is an abstract class. | 2375 const AbstractType& value) const { |
| 2376 // AbstractTypeArguments is an abstract class. | |
| 2367 UNREACHABLE(); | 2377 UNREACHABLE(); |
| 2368 } | 2378 } |
| 2369 | 2379 |
| 2370 | 2380 |
| 2371 bool TypeArguments::IsResolved() const { | 2381 bool AbstractTypeArguments::IsResolved() const { |
| 2372 // TypeArguments is an abstract class. | 2382 // AbstractTypeArguments is an abstract class. |
| 2373 UNREACHABLE(); | 2383 UNREACHABLE(); |
| 2374 return false; | 2384 return false; |
| 2375 } | 2385 } |
| 2376 | 2386 |
| 2377 | 2387 |
| 2378 bool TypeArguments::IsInstantiated() const { | 2388 bool AbstractTypeArguments::IsInstantiated() const { |
| 2379 // TypeArguments is an abstract class. | 2389 // AbstractTypeArguments is an abstract class. |
| 2380 UNREACHABLE(); | 2390 UNREACHABLE(); |
| 2381 return false; | 2391 return false; |
| 2382 } | 2392 } |
| 2383 | 2393 |
| 2384 | 2394 |
| 2385 bool TypeArguments::IsUninstantiatedIdentity() const { | 2395 bool AbstractTypeArguments::IsUninstantiatedIdentity() const { |
| 2386 // TypeArguments is an abstract class. | 2396 // AbstractTypeArguments is an abstract class. |
| 2387 UNREACHABLE(); | 2397 UNREACHABLE(); |
| 2388 return false; | 2398 return false; |
| 2389 } | 2399 } |
| 2390 | 2400 |
| 2391 | 2401 |
| 2392 bool TypeArguments::Equals(const TypeArguments& other) const { | 2402 bool AbstractTypeArguments::Equals(const AbstractTypeArguments& other) const { |
| 2393 // TypeArguments is an abstract class. | 2403 // AbstractTypeArguments is an abstract class. |
| 2394 UNREACHABLE(); | 2404 UNREACHABLE(); |
| 2395 return false; | 2405 return false; |
| 2396 } | 2406 } |
| 2397 | 2407 |
| 2398 | 2408 |
| 2399 bool TypeArguments::AreEqual(const TypeArguments& arguments, | 2409 bool AbstractTypeArguments::AreEqual( |
| 2400 const TypeArguments& other_arguments) { | 2410 const AbstractTypeArguments& arguments, |
| 2411 const AbstractTypeArguments& other_arguments) { | |
| 2401 if (arguments.raw() == other_arguments.raw()) { | 2412 if (arguments.raw() == other_arguments.raw()) { |
| 2402 return true; | 2413 return true; |
| 2403 } | 2414 } |
| 2404 if (arguments.IsNull()) { | 2415 if (arguments.IsNull()) { |
| 2405 return other_arguments.IsDynamicTypes(other_arguments.Length()); | 2416 return other_arguments.IsDynamicTypes(other_arguments.Length()); |
| 2406 } | 2417 } |
| 2407 if (other_arguments.IsNull()) { | 2418 if (other_arguments.IsNull()) { |
| 2408 return arguments.IsDynamicTypes(arguments.Length()); | 2419 return arguments.IsDynamicTypes(arguments.Length()); |
| 2409 } | 2420 } |
| 2410 return arguments.Equals(other_arguments); | 2421 return arguments.Equals(other_arguments); |
| 2411 } | 2422 } |
| 2412 | 2423 |
| 2413 | 2424 |
| 2414 RawTypeArguments* TypeArguments::InstantiateFrom( | 2425 RawAbstractTypeArguments* AbstractTypeArguments::InstantiateFrom( |
| 2415 const TypeArguments& instantiator_type_arguments, | 2426 const AbstractTypeArguments& instantiator_type_arguments, |
| 2416 intptr_t offset) const { | 2427 intptr_t offset) const { |
| 2417 // TypeArguments is an abstract class. | 2428 // AbstractTypeArguments is an abstract class. |
| 2418 UNREACHABLE(); | 2429 UNREACHABLE(); |
| 2419 return NULL; | 2430 return NULL; |
| 2420 } | 2431 } |
| 2421 | 2432 |
| 2422 | 2433 |
| 2423 bool TypeArguments::IsDynamicTypes(intptr_t len) const { | 2434 bool AbstractTypeArguments::IsDynamicTypes(intptr_t len) const { |
| 2424 ASSERT(Length() >= len); | 2435 ASSERT(Length() >= len); |
| 2425 AbstractType& type = AbstractType::Handle(); | 2436 AbstractType& type = AbstractType::Handle(); |
| 2426 Class& type_class = Class::Handle(); | 2437 Class& type_class = Class::Handle(); |
| 2427 for (intptr_t i = 0; i < len; i++) { | 2438 for (intptr_t i = 0; i < len; i++) { |
| 2428 type = TypeAt(i); | 2439 type = TypeAt(i); |
| 2429 ASSERT(!type.IsNull()); | 2440 ASSERT(!type.IsNull()); |
| 2430 if (!type.HasResolvedTypeClass()) { | 2441 if (!type.HasResolvedTypeClass()) { |
| 2431 ASSERT(type.IsTypeParameter()); | 2442 ASSERT(type.IsTypeParameter()); |
| 2432 return false; | 2443 return false; |
| 2433 } | 2444 } |
| 2434 type_class = type.type_class(); | 2445 type_class = type.type_class(); |
| 2435 if (!type_class.IsDynamicClass()) { | 2446 if (!type_class.IsDynamicClass()) { |
| 2436 return false; | 2447 return false; |
| 2437 } | 2448 } |
| 2438 } | 2449 } |
| 2439 return true; | 2450 return true; |
| 2440 } | 2451 } |
| 2441 | 2452 |
| 2442 | 2453 |
| 2443 bool TypeArguments::IsMoreSpecificThan(const TypeArguments& other, | 2454 bool AbstractTypeArguments::IsMoreSpecificThan( |
| 2444 intptr_t len) const { | 2455 const AbstractTypeArguments& other, |
| 2456 intptr_t len) const { | |
| 2445 ASSERT(Length() >= len); | 2457 ASSERT(Length() >= len); |
| 2446 ASSERT(!other.IsNull()); | 2458 ASSERT(!other.IsNull()); |
| 2447 ASSERT(other.Length() >= len); | 2459 ASSERT(other.Length() >= len); |
| 2448 AbstractType& type = AbstractType::Handle(); | 2460 AbstractType& type = AbstractType::Handle(); |
| 2449 AbstractType& other_type = AbstractType::Handle(); | 2461 AbstractType& other_type = AbstractType::Handle(); |
| 2450 for (intptr_t i = 0; i < len; i++) { | 2462 for (intptr_t i = 0; i < len; i++) { |
| 2451 type = TypeAt(i); | 2463 type = TypeAt(i); |
| 2452 ASSERT(!type.IsNull()); | 2464 ASSERT(!type.IsNull()); |
| 2453 other_type = other.TypeAt(i); | 2465 other_type = other.TypeAt(i); |
| 2454 ASSERT(!other_type.IsNull()); | 2466 ASSERT(!other_type.IsNull()); |
| 2455 if (!type.IsMoreSpecificThan(other_type)) { | 2467 if (!type.IsMoreSpecificThan(other_type)) { |
| 2456 return false; | 2468 return false; |
| 2457 } | 2469 } |
| 2458 } | 2470 } |
| 2459 return true; | 2471 return true; |
| 2460 } | 2472 } |
| 2461 | 2473 |
| 2462 | 2474 |
| 2463 RawTypeArguments* TypeArguments::NewTypeArray(intptr_t len) { | 2475 RawAbstractTypeArguments* AbstractTypeArguments::NewInstantiatedTypeArguments( |
| 2464 return TypeArray::New(len); | 2476 const AbstractTypeArguments& uninstantiated_type_arguments, |
| 2465 } | 2477 const AbstractTypeArguments& instantiator_type_arguments) { |
| 2466 | |
| 2467 | |
| 2468 RawTypeArguments* TypeArguments::NewInstantiatedTypeArguments( | |
| 2469 const TypeArguments& uninstantiated_type_arguments, | |
| 2470 const TypeArguments& instantiator_type_arguments) { | |
| 2471 return InstantiatedTypeArguments::New(uninstantiated_type_arguments, | 2478 return InstantiatedTypeArguments::New(uninstantiated_type_arguments, |
| 2472 instantiator_type_arguments); | 2479 instantiator_type_arguments); |
| 2473 } | 2480 } |
| 2474 | 2481 |
| 2475 | 2482 |
| 2476 const char* TypeArguments::ToCString() const { | 2483 const char* AbstractTypeArguments::ToCString() const { |
| 2477 // TypeArguments is an abstract class. | 2484 // AbstractTypeArguments is an abstract class. |
| 2478 UNREACHABLE(); | 2485 UNREACHABLE(); |
| 2479 return "TypeArguments"; | 2486 return "AbstractTypeArguments"; |
| 2480 } | 2487 } |
| 2481 | 2488 |
| 2482 | 2489 |
| 2483 intptr_t TypeArray::Length() const { | 2490 intptr_t TypeArguments::Length() const { |
| 2484 ASSERT(!IsNull()); | 2491 ASSERT(!IsNull()); |
| 2485 return Smi::Value(raw_ptr()->length_); | 2492 return Smi::Value(raw_ptr()->length_); |
| 2486 } | 2493 } |
| 2487 | 2494 |
| 2488 | 2495 |
| 2489 RawAbstractType* TypeArray::TypeAt(intptr_t index) const { | 2496 RawAbstractType* TypeArguments::TypeAt(intptr_t index) const { |
| 2490 return *TypeAddr(index); | 2497 return *TypeAddr(index); |
| 2491 } | 2498 } |
| 2492 | 2499 |
| 2493 | 2500 |
| 2494 void TypeArray::SetTypeAt(intptr_t index, const AbstractType& value) const { | 2501 void TypeArguments::SetTypeAt(intptr_t index, const AbstractType& value) const { |
| 2495 // TODO(iposva): Add storing NoGCScope. | 2502 // TODO(iposva): Add storing NoGCScope. |
| 2496 *TypeAddr(index) = value.raw(); | 2503 *TypeAddr(index) = value.raw(); |
| 2497 } | 2504 } |
| 2498 | 2505 |
| 2499 | 2506 |
| 2500 bool TypeArray::IsResolved() const { | 2507 bool TypeArguments::IsResolved() const { |
| 2501 AbstractType& type = AbstractType::Handle(); | 2508 AbstractType& type = AbstractType::Handle(); |
| 2502 intptr_t num_types = Length(); | 2509 intptr_t num_types = Length(); |
| 2503 for (intptr_t i = 0; i < num_types; i++) { | 2510 for (intptr_t i = 0; i < num_types; i++) { |
| 2504 type = TypeAt(i); | 2511 type = TypeAt(i); |
| 2505 if (!type.IsResolved()) { | 2512 if (!type.IsResolved()) { |
| 2506 return false; | 2513 return false; |
| 2507 } | 2514 } |
| 2508 } | 2515 } |
| 2509 return true; | 2516 return true; |
| 2510 } | 2517 } |
| 2511 | 2518 |
| 2512 | 2519 |
| 2513 bool TypeArray::IsInstantiated() const { | 2520 bool TypeArguments::IsInstantiated() const { |
| 2514 AbstractType& type = AbstractType::Handle(); | 2521 AbstractType& type = AbstractType::Handle(); |
| 2515 intptr_t num_types = Length(); | 2522 intptr_t num_types = Length(); |
| 2516 for (intptr_t i = 0; i < num_types; i++) { | 2523 for (intptr_t i = 0; i < num_types; i++) { |
| 2517 type = TypeAt(i); | 2524 type = TypeAt(i); |
| 2518 if (!type.IsInstantiated()) { | 2525 if (!type.IsInstantiated()) { |
| 2519 return false; | 2526 return false; |
| 2520 } | 2527 } |
| 2521 } | 2528 } |
| 2522 return true; | 2529 return true; |
| 2523 } | 2530 } |
| 2524 | 2531 |
| 2525 | 2532 |
| 2526 bool TypeArray::IsUninstantiatedIdentity() const { | 2533 bool TypeArguments::IsUninstantiatedIdentity() const { |
| 2527 ASSERT(!IsInstantiated()); | 2534 ASSERT(!IsInstantiated()); |
| 2528 AbstractType& type = AbstractType::Handle(); | 2535 AbstractType& type = AbstractType::Handle(); |
| 2529 intptr_t num_types = Length(); | 2536 intptr_t num_types = Length(); |
| 2530 for (intptr_t i = 0; i < num_types; i++) { | 2537 for (intptr_t i = 0; i < num_types; i++) { |
| 2531 type = TypeAt(i); | 2538 type = TypeAt(i); |
| 2532 if (!type.IsTypeParameter() || (type.Index() != i)) { | 2539 if (!type.IsTypeParameter() || (type.Index() != i)) { |
| 2533 return false; | 2540 return false; |
| 2534 } | 2541 } |
| 2535 } | 2542 } |
| 2536 return true; | 2543 return true; |
| 2537 } | 2544 } |
| 2538 | 2545 |
| 2539 | 2546 |
| 2540 bool TypeArray::Equals(const TypeArguments& other) const { | 2547 bool TypeArguments::Equals(const AbstractTypeArguments& other) const { |
| 2541 intptr_t num_types = Length(); | 2548 intptr_t num_types = Length(); |
| 2542 if (num_types != other.Length()) { | 2549 if (num_types != other.Length()) { |
| 2543 return false; | 2550 return false; |
| 2544 } | 2551 } |
| 2545 AbstractType& type = AbstractType::Handle(); | 2552 AbstractType& type = AbstractType::Handle(); |
| 2546 AbstractType& other_type = AbstractType::Handle(); | 2553 AbstractType& other_type = AbstractType::Handle(); |
| 2547 for (intptr_t i = 0; i < num_types; i++) { | 2554 for (intptr_t i = 0; i < num_types; i++) { |
| 2548 type = TypeAt(i); | 2555 type = TypeAt(i); |
| 2549 other_type = other.TypeAt(i); | 2556 other_type = other.TypeAt(i); |
| 2550 if (!type.Equals(other_type)) { | 2557 if (!type.Equals(other_type)) { |
| 2551 return false; | 2558 return false; |
| 2552 } | 2559 } |
| 2553 } | 2560 } |
| 2554 return true; | 2561 return true; |
| 2555 } | 2562 } |
| 2556 | 2563 |
| 2557 | 2564 |
| 2558 RawTypeArguments* TypeArray::InstantiateFrom( | 2565 RawAbstractTypeArguments* TypeArguments::InstantiateFrom( |
| 2559 const TypeArguments& instantiator_type_arguments, | 2566 const AbstractTypeArguments& instantiator_type_arguments, |
| 2560 intptr_t offset) const { | 2567 intptr_t offset) const { |
| 2561 ASSERT(!IsInstantiated()); | 2568 ASSERT(!IsInstantiated()); |
| 2562 if ((offset == 0) && | 2569 if ((offset == 0) && |
| 2563 !instantiator_type_arguments.IsNull() && | 2570 !instantiator_type_arguments.IsNull() && |
| 2564 IsUninstantiatedIdentity() && | 2571 IsUninstantiatedIdentity() && |
| 2565 (instantiator_type_arguments.Length() == Length())) { | 2572 (instantiator_type_arguments.Length() == Length())) { |
| 2566 return instantiator_type_arguments.raw(); | 2573 return instantiator_type_arguments.raw(); |
| 2567 } | 2574 } |
| 2568 const intptr_t num_types = Length(); | 2575 const intptr_t num_types = Length(); |
| 2569 TypeArray& instantiated_array = TypeArray::Handle(TypeArray::New(num_types)); | 2576 TypeArguments& instantiated_array = |
| 2577 TypeArguments::Handle(TypeArguments::New(num_types)); | |
| 2570 AbstractType& type = AbstractType::Handle(); | 2578 AbstractType& type = AbstractType::Handle(); |
| 2571 for (intptr_t i = 0; i < num_types; i++) { | 2579 for (intptr_t i = 0; i < num_types; i++) { |
| 2572 type = TypeAt(i); | 2580 type = TypeAt(i); |
| 2573 if (!type.IsInstantiated()) { | 2581 if (!type.IsInstantiated()) { |
| 2574 type = type.InstantiateFrom(instantiator_type_arguments, offset); | 2582 type = type.InstantiateFrom(instantiator_type_arguments, offset); |
| 2575 } | 2583 } |
| 2576 instantiated_array.SetTypeAt(i, type); | 2584 instantiated_array.SetTypeAt(i, type); |
| 2577 } | 2585 } |
| 2578 return instantiated_array.raw(); | 2586 return instantiated_array.raw(); |
| 2579 } | 2587 } |
| 2580 | 2588 |
| 2581 | 2589 |
| 2582 RawTypeArray* TypeArray::New(intptr_t len) { | 2590 RawTypeArguments* TypeArguments::New(intptr_t len) { |
| 2583 if ((len < 0) || (len > kMaxTypes)) { | 2591 if ((len < 0) || (len > kMaxTypes)) { |
| 2584 // TODO(iposva): Should we throw an illegal parameter exception? | 2592 // TODO(iposva): Should we throw an illegal parameter exception? |
| 2585 UNIMPLEMENTED(); | 2593 UNIMPLEMENTED(); |
| 2586 return null(); | 2594 return null(); |
| 2587 } | 2595 } |
| 2588 | 2596 |
| 2589 const Class& type_array_class = Class::Handle(Object::type_array_class()); | 2597 const Class& type_array_class = Class::Handle(Object::type_array_class()); |
|
regis
2011/12/01 22:20:16
ditto
| |
| 2590 TypeArray& result = TypeArray::Handle(); | 2598 TypeArguments& result = TypeArguments::Handle(); |
| 2591 { | 2599 { |
| 2592 RawObject* raw = Object::Allocate(type_array_class, | 2600 RawObject* raw = Object::Allocate(type_array_class, |
|
regis
2011/12/01 22:20:16
ditto
| |
| 2593 TypeArray::InstanceSize(len), | 2601 TypeArguments::InstanceSize(len), |
| 2594 Heap::kOld); | 2602 Heap::kOld); |
| 2595 NoGCScope no_gc; | 2603 NoGCScope no_gc; |
| 2596 result ^= raw; | 2604 result ^= raw; |
| 2597 result.SetLength(len); | 2605 result.SetLength(len); |
| 2598 for (intptr_t i = 0; i < len; i++) { | 2606 for (intptr_t i = 0; i < len; i++) { |
| 2599 *result.TypeAddr(i) = Type::null(); | 2607 *result.TypeAddr(i) = Type::null(); |
| 2600 } | 2608 } |
| 2601 } | 2609 } |
| 2602 return result.raw(); | 2610 return result.raw(); |
| 2603 } | 2611 } |
| 2604 | 2612 |
| 2605 | 2613 |
| 2606 RawAbstractType** TypeArray::TypeAddr(intptr_t index) const { | 2614 RawAbstractType** TypeArguments::TypeAddr(intptr_t index) const { |
| 2607 // TODO(iposva): Determine if we should throw an exception here. | 2615 // TODO(iposva): Determine if we should throw an exception here. |
| 2608 ASSERT((index >= 0) && (index < Length())); | 2616 ASSERT((index >= 0) && (index < Length())); |
| 2609 return &raw_ptr()->types_[index]; | 2617 return &raw_ptr()->types_[index]; |
| 2610 } | 2618 } |
| 2611 | 2619 |
| 2612 | 2620 |
| 2613 void TypeArray::SetLength(intptr_t value) { | 2621 void TypeArguments::SetLength(intptr_t value) { |
| 2614 // This is only safe because we create a new Smi, which does not cause | 2622 // This is only safe because we create a new Smi, which does not cause |
| 2615 // heap allocation. | 2623 // heap allocation. |
| 2616 raw_ptr()->length_ = Smi::New(value); | 2624 raw_ptr()->length_ = Smi::New(value); |
| 2617 } | 2625 } |
| 2618 | 2626 |
| 2619 | 2627 |
| 2620 const char* TypeArray::ToCString() const { | 2628 const char* TypeArguments::ToCString() const { |
| 2621 if (IsNull()) { | 2629 if (IsNull()) { |
| 2622 return "NULL TypeArray"; | 2630 return "NULL TypeArguments"; |
| 2623 } | 2631 } |
| 2624 const char* format = "%s [%s]"; | 2632 const char* format = "%s [%s]"; |
| 2625 const char* prev_cstr = "TypeArray:"; | 2633 const char* prev_cstr = "TypeArguments:"; |
| 2626 for (int i = 0; i < Length(); i++) { | 2634 for (int i = 0; i < Length(); i++) { |
| 2627 const char* type_cstr = AbstractType::Handle(TypeAt(i)).ToCString(); | 2635 const char* type_cstr = AbstractType::Handle(TypeAt(i)).ToCString(); |
| 2628 intptr_t len = OS::SNPrint(NULL, 0, format, prev_cstr, type_cstr) + 1; | 2636 intptr_t len = OS::SNPrint(NULL, 0, format, prev_cstr, type_cstr) + 1; |
| 2629 char* chars = reinterpret_cast<char*>( | 2637 char* chars = reinterpret_cast<char*>( |
| 2630 Isolate::Current()->current_zone()->Allocate(len)); | 2638 Isolate::Current()->current_zone()->Allocate(len)); |
| 2631 OS::SNPrint(chars, len, format, prev_cstr, type_cstr); | 2639 OS::SNPrint(chars, len, format, prev_cstr, type_cstr); |
| 2632 prev_cstr = chars; | 2640 prev_cstr = chars; |
| 2633 } | 2641 } |
| 2634 return prev_cstr; | 2642 return prev_cstr; |
| 2635 } | 2643 } |
| 2636 | 2644 |
| 2637 | 2645 |
| 2638 intptr_t InstantiatedTypeArguments::Length() const { | 2646 intptr_t InstantiatedTypeArguments::Length() const { |
| 2639 return TypeArguments::Handle(uninstantiated_type_arguments()).Length(); | 2647 return AbstractTypeArguments::Handle( |
| 2648 uninstantiated_type_arguments()).Length(); | |
| 2640 } | 2649 } |
| 2641 | 2650 |
| 2642 | 2651 |
| 2643 RawAbstractType* InstantiatedTypeArguments::TypeAt(intptr_t index) const { | 2652 RawAbstractType* InstantiatedTypeArguments::TypeAt(intptr_t index) const { |
| 2644 const AbstractType& type = AbstractType::Handle( | 2653 const AbstractType& type = AbstractType::Handle( |
| 2645 TypeArguments::Handle(uninstantiated_type_arguments()).TypeAt(index)); | 2654 AbstractTypeArguments::Handle( |
| 2655 uninstantiated_type_arguments()).TypeAt(index)); | |
| 2646 if (type.IsTypeParameter()) { | 2656 if (type.IsTypeParameter()) { |
| 2647 TypeArguments& instantiator = | 2657 AbstractTypeArguments& instantiator = |
| 2648 TypeArguments::Handle(instantiator_type_arguments()); | 2658 AbstractTypeArguments::Handle(instantiator_type_arguments()); |
| 2649 return instantiator.TypeAt(type.Index()); | 2659 return instantiator.TypeAt(type.Index()); |
| 2650 } | 2660 } |
| 2651 if (!type.IsInstantiated()) { | 2661 if (!type.IsInstantiated()) { |
| 2652 return InstantiatedType::New( | 2662 return InstantiatedType::New( |
| 2653 type, TypeArguments::Handle(instantiator_type_arguments())); | 2663 type, AbstractTypeArguments::Handle(instantiator_type_arguments())); |
| 2654 } | 2664 } |
| 2655 return type.raw(); | 2665 return type.raw(); |
| 2656 } | 2666 } |
| 2657 | 2667 |
| 2658 | 2668 |
| 2659 void InstantiatedTypeArguments::SetTypeAt(intptr_t index, | 2669 void InstantiatedTypeArguments::SetTypeAt(intptr_t index, |
| 2660 const AbstractType& value) const { | 2670 const AbstractType& value) const { |
| 2661 // We only replace individual argument types during resolution at compile | 2671 // We only replace individual argument types during resolution at compile |
| 2662 // time, when no type parameters are instantiated yet. | 2672 // time, when no type parameters are instantiated yet. |
| 2663 UNREACHABLE(); | 2673 UNREACHABLE(); |
| 2664 } | 2674 } |
| 2665 | 2675 |
| 2666 | 2676 |
| 2667 void InstantiatedTypeArguments::set_uninstantiated_type_arguments( | 2677 void InstantiatedTypeArguments::set_uninstantiated_type_arguments( |
| 2668 const TypeArguments& value) const { | 2678 const AbstractTypeArguments& value) const { |
| 2669 StorePointer(&raw_ptr()->uninstantiated_type_arguments_, value.raw()); | 2679 StorePointer(&raw_ptr()->uninstantiated_type_arguments_, value.raw()); |
| 2670 } | 2680 } |
| 2671 | 2681 |
| 2672 | 2682 |
| 2673 void InstantiatedTypeArguments::set_instantiator_type_arguments( | 2683 void InstantiatedTypeArguments::set_instantiator_type_arguments( |
| 2674 const TypeArguments& value) const { | 2684 const AbstractTypeArguments& value) const { |
| 2675 StorePointer(&raw_ptr()->instantiator_type_arguments_, value.raw()); | 2685 StorePointer(&raw_ptr()->instantiator_type_arguments_, value.raw()); |
| 2676 } | 2686 } |
| 2677 | 2687 |
| 2678 | 2688 |
| 2679 RawInstantiatedTypeArguments* InstantiatedTypeArguments::New() { | 2689 RawInstantiatedTypeArguments* InstantiatedTypeArguments::New() { |
| 2680 const Class& instantiated_type_arguments_class = | 2690 const Class& instantiated_type_arguments_class = |
| 2681 Class::Handle(Object::instantiated_type_arguments_class()); | 2691 Class::Handle(Object::instantiated_type_arguments_class()); |
| 2682 RawObject* raw = Object::Allocate(instantiated_type_arguments_class, | 2692 RawObject* raw = Object::Allocate(instantiated_type_arguments_class, |
| 2683 InstantiatedTypeArguments::InstanceSize(), | 2693 InstantiatedTypeArguments::InstanceSize(), |
| 2684 Heap::kNew); | 2694 Heap::kNew); |
| 2685 return reinterpret_cast<RawInstantiatedTypeArguments*>(raw); | 2695 return reinterpret_cast<RawInstantiatedTypeArguments*>(raw); |
| 2686 } | 2696 } |
| 2687 | 2697 |
| 2688 | 2698 |
| 2689 RawInstantiatedTypeArguments* InstantiatedTypeArguments::New( | 2699 RawInstantiatedTypeArguments* InstantiatedTypeArguments::New( |
| 2690 const TypeArguments& uninstantiated_type_arguments, | 2700 const AbstractTypeArguments& uninstantiated_type_arguments, |
| 2691 const TypeArguments& instantiator_type_arguments) { | 2701 const AbstractTypeArguments& instantiator_type_arguments) { |
| 2692 const InstantiatedTypeArguments& result = | 2702 const InstantiatedTypeArguments& result = |
| 2693 InstantiatedTypeArguments::Handle(InstantiatedTypeArguments::New()); | 2703 InstantiatedTypeArguments::Handle(InstantiatedTypeArguments::New()); |
| 2694 result.set_uninstantiated_type_arguments(uninstantiated_type_arguments); | 2704 result.set_uninstantiated_type_arguments(uninstantiated_type_arguments); |
| 2695 result.set_instantiator_type_arguments(instantiator_type_arguments); | 2705 result.set_instantiator_type_arguments(instantiator_type_arguments); |
| 2696 return result.raw(); | 2706 return result.raw(); |
| 2697 } | 2707 } |
| 2698 | 2708 |
| 2699 | 2709 |
| 2700 const char* InstantiatedTypeArguments::ToCString() const { | 2710 const char* InstantiatedTypeArguments::ToCString() const { |
| 2701 if (IsNull()) { | 2711 if (IsNull()) { |
| 2702 return "NULL InstantiatedTypeArguments"; | 2712 return "NULL InstantiatedTypeArguments"; |
| 2703 } | 2713 } |
| 2704 const char* format = "InstantiatedTypeArguments: [%s] instantiator: [%s]\n"; | 2714 const char* format = "InstantiatedTypeArguments: [%s] instantiator: [%s]\n"; |
| 2705 const char* arg_cstr = | 2715 const char* arg_cstr = |
| 2706 TypeArguments::Handle(uninstantiated_type_arguments()).ToCString(); | 2716 AbstractTypeArguments::Handle( |
| 2717 uninstantiated_type_arguments()).ToCString(); | |
| 2707 const char* instantiator_cstr = | 2718 const char* instantiator_cstr = |
| 2708 TypeArguments::Handle(instantiator_type_arguments()).ToCString(); | 2719 AbstractTypeArguments::Handle(instantiator_type_arguments()).ToCString(); |
| 2709 intptr_t len = | 2720 intptr_t len = |
| 2710 OS::SNPrint(NULL, 0, format, arg_cstr, instantiator_cstr) + 1; | 2721 OS::SNPrint(NULL, 0, format, arg_cstr, instantiator_cstr) + 1; |
| 2711 char* chars = reinterpret_cast<char*>( | 2722 char* chars = reinterpret_cast<char*>( |
| 2712 Isolate::Current()->current_zone()->Allocate(len)); | 2723 Isolate::Current()->current_zone()->Allocate(len)); |
| 2713 OS::SNPrint(chars, len, format, arg_cstr, instantiator_cstr); | 2724 OS::SNPrint(chars, len, format, arg_cstr, instantiator_cstr); |
| 2714 return chars; | 2725 return chars; |
| 2715 } | 2726 } |
| 2716 | 2727 |
| 2717 | 2728 |
| 2718 void Function::SetCode(const Code& value) const { | 2729 void Function::SetCode(const Code& value) const { |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2990 if (ParameterNameAt(i) != other_param_name.raw()) { | 3001 if (ParameterNameAt(i) != other_param_name.raw()) { |
| 2991 return false; | 3002 return false; |
| 2992 } | 3003 } |
| 2993 } | 3004 } |
| 2994 return true; | 3005 return true; |
| 2995 } | 3006 } |
| 2996 | 3007 |
| 2997 | 3008 |
| 2998 bool Function::TestParameterType( | 3009 bool Function::TestParameterType( |
| 2999 intptr_t parameter_position, | 3010 intptr_t parameter_position, |
| 3000 const TypeArguments& type_arguments, | 3011 const AbstractTypeArguments& type_arguments, |
| 3001 const Function& other, | 3012 const Function& other, |
| 3002 const TypeArguments& other_type_arguments) const { | 3013 const AbstractTypeArguments& other_type_arguments) const { |
| 3003 AbstractType& param_type = | 3014 AbstractType& param_type = |
| 3004 AbstractType::Handle(ParameterTypeAt(parameter_position)); | 3015 AbstractType::Handle(ParameterTypeAt(parameter_position)); |
| 3005 if (!param_type.IsInstantiated()) { | 3016 if (!param_type.IsInstantiated()) { |
| 3006 param_type = param_type.InstantiateFrom(type_arguments, 0); | 3017 param_type = param_type.InstantiateFrom(type_arguments, 0); |
| 3007 } | 3018 } |
| 3008 if (param_type.IsDynamicType()) { | 3019 if (param_type.IsDynamicType()) { |
| 3009 return true; | 3020 return true; |
| 3010 } | 3021 } |
| 3011 AbstractType& other_param_type = | 3022 AbstractType& other_param_type = |
| 3012 AbstractType::Handle(other.ParameterTypeAt(parameter_position)); | 3023 AbstractType::Handle(other.ParameterTypeAt(parameter_position)); |
| 3013 if (!other_param_type.IsInstantiated()) { | 3024 if (!other_param_type.IsInstantiated()) { |
| 3014 other_param_type = | 3025 other_param_type = |
| 3015 other_param_type.InstantiateFrom(other_type_arguments, 0); | 3026 other_param_type.InstantiateFrom(other_type_arguments, 0); |
| 3016 } | 3027 } |
| 3017 if (other_param_type.IsDynamicType()) { | 3028 if (other_param_type.IsDynamicType()) { |
| 3018 return true; | 3029 return true; |
| 3019 } | 3030 } |
| 3020 if (!param_type.IsSubtypeOf(other_param_type) && | 3031 if (!param_type.IsSubtypeOf(other_param_type) && |
| 3021 !other_param_type.IsSubtypeOf(param_type)) { | 3032 !other_param_type.IsSubtypeOf(param_type)) { |
| 3022 return false; | 3033 return false; |
| 3023 } | 3034 } |
| 3024 return true; | 3035 return true; |
| 3025 } | 3036 } |
| 3026 | 3037 |
| 3027 | 3038 |
| 3028 bool Function::TestType(TypeTestKind test, | 3039 bool Function::TestType( |
| 3029 const TypeArguments& type_arguments, | 3040 TypeTestKind test, |
| 3030 const Function& other, | 3041 const AbstractTypeArguments& type_arguments, |
| 3031 const TypeArguments& other_type_arguments) const { | 3042 const Function& other, |
| 3043 const AbstractTypeArguments& other_type_arguments) const { | |
| 3032 const intptr_t num_fixed_params = num_fixed_parameters(); | 3044 const intptr_t num_fixed_params = num_fixed_parameters(); |
| 3033 const intptr_t num_opt_params = num_optional_parameters(); | 3045 const intptr_t num_opt_params = num_optional_parameters(); |
| 3034 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); | 3046 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); |
| 3035 const intptr_t other_num_opt_params = other.num_optional_parameters(); | 3047 const intptr_t other_num_opt_params = other.num_optional_parameters(); |
| 3036 if ((num_fixed_params != other_num_fixed_params) || | 3048 if ((num_fixed_params != other_num_fixed_params) || |
| 3037 ((test == AbstractType::kIsSubtypeOf) && | 3049 ((test == AbstractType::kIsSubtypeOf) && |
| 3038 (num_opt_params < other_num_opt_params))) { | 3050 (num_opt_params < other_num_opt_params))) { |
| 3039 return false; | 3051 return false; |
| 3040 } | 3052 } |
| 3041 // Check the result type. | 3053 // Check the result type. |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3240 static RawArray* NewArray(const GrowableArray<T*>& objs) { | 3252 static RawArray* NewArray(const GrowableArray<T*>& objs) { |
| 3241 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); | 3253 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); |
| 3242 for (int i = 0; i < objs.length(); i++) { | 3254 for (int i = 0; i < objs.length(); i++) { |
| 3243 a.SetAt(i, *objs[i]); | 3255 a.SetAt(i, *objs[i]); |
| 3244 } | 3256 } |
| 3245 return a.raw(); | 3257 return a.raw(); |
| 3246 } | 3258 } |
| 3247 | 3259 |
| 3248 | 3260 |
| 3249 RawString* Function::BuildSignature(bool instantiate, | 3261 RawString* Function::BuildSignature(bool instantiate, |
| 3250 const TypeArguments& instantiator, | 3262 const AbstractTypeArguments& instantiator, |
| 3251 intptr_t offset) const { | 3263 intptr_t offset) const { |
| 3252 GrowableArray<const String*> pieces; | 3264 GrowableArray<const String*> pieces; |
| 3253 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); | 3265 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); |
| 3254 const String& kColonSpace = String::Handle(String::NewSymbol(": ")); | 3266 const String& kColonSpace = String::Handle(String::NewSymbol(": ")); |
| 3255 const String& kLParen = String::Handle(String::NewSymbol("(")); | 3267 const String& kLParen = String::Handle(String::NewSymbol("(")); |
| 3256 const String& kRParen = String::Handle(String::NewSymbol(") => ")); | 3268 const String& kRParen = String::Handle(String::NewSymbol(") => ")); |
| 3257 const String& kLBracket = String::Handle(String::NewSymbol("[")); | 3269 const String& kLBracket = String::Handle(String::NewSymbol("[")); |
| 3258 const String& kRBracket = String::Handle(String::NewSymbol("]")); | 3270 const String& kRBracket = String::Handle(String::NewSymbol("]")); |
| 3259 if (!instantiate && !is_static()) { | 3271 if (!instantiate && !is_static()) { |
| 3260 const String& kSpaceExtendsSpace = | 3272 const String& kSpaceExtendsSpace = |
| 3261 String::Handle(String::NewSymbol(" extends ")); | 3273 String::Handle(String::NewSymbol(" extends ")); |
| 3262 const String& kLAngleBracket = String::Handle(String::NewSymbol("<")); | 3274 const String& kLAngleBracket = String::Handle(String::NewSymbol("<")); |
| 3263 const String& kRAngleBracket = String::Handle(String::NewSymbol(">")); | 3275 const String& kRAngleBracket = String::Handle(String::NewSymbol(">")); |
| 3264 const Class& function_class = Class::Handle(owner()); | 3276 const Class& function_class = Class::Handle(owner()); |
| 3265 ASSERT(!function_class.IsNull()); | 3277 ASSERT(!function_class.IsNull()); |
| 3266 const Array& type_parameters = Array::Handle( | 3278 const Array& type_parameters = Array::Handle( |
| 3267 function_class.type_parameters()); | 3279 function_class.type_parameters()); |
| 3268 if (!type_parameters.IsNull()) { | 3280 if (!type_parameters.IsNull()) { |
| 3269 intptr_t num_type_parameters = type_parameters.Length(); | 3281 intptr_t num_type_parameters = type_parameters.Length(); |
| 3270 pieces.Add(&kLAngleBracket); | 3282 pieces.Add(&kLAngleBracket); |
| 3271 const TypeArray& type_parameter_extends = TypeArray::Handle( | 3283 const TypeArguments& type_parameter_extends = TypeArguments::Handle( |
| 3272 function_class.type_parameter_extends()); | 3284 function_class.type_parameter_extends()); |
| 3273 AbstractType& parameter_extends = AbstractType::Handle(); | 3285 AbstractType& parameter_extends = AbstractType::Handle(); |
| 3274 for (intptr_t i = 0; i < num_type_parameters; i++) { | 3286 for (intptr_t i = 0; i < num_type_parameters; i++) { |
| 3275 String& type_parameter = String::ZoneHandle(); | 3287 String& type_parameter = String::ZoneHandle(); |
| 3276 type_parameter ^= type_parameters.At(i); | 3288 type_parameter ^= type_parameters.At(i); |
| 3277 pieces.Add(&type_parameter); | 3289 pieces.Add(&type_parameter); |
| 3278 parameter_extends = type_parameter_extends.TypeAt(i); | 3290 parameter_extends = type_parameter_extends.TypeAt(i); |
| 3279 if (!parameter_extends.IsNull() && !parameter_extends.IsDynamicType()) { | 3291 if (!parameter_extends.IsNull() && !parameter_extends.IsDynamicType()) { |
| 3280 pieces.Add(&kSpaceExtendsSpace); | 3292 pieces.Add(&kSpaceExtendsSpace); |
| 3281 pieces.Add(&String::ZoneHandle(parameter_extends.Name())); | 3293 pieces.Add(&String::ZoneHandle(parameter_extends.Name())); |
| (...skipping 1711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4993 } | 5005 } |
| 4994 return this->raw(); | 5006 return this->raw(); |
| 4995 } | 5007 } |
| 4996 | 5008 |
| 4997 | 5009 |
| 4998 RawType* Instance::GetType() const { | 5010 RawType* Instance::GetType() const { |
| 4999 if (IsNull()) { | 5011 if (IsNull()) { |
| 5000 return Type::NullType(); | 5012 return Type::NullType(); |
| 5001 } | 5013 } |
| 5002 const Class& cls = Class::Handle(clazz()); | 5014 const Class& cls = Class::Handle(clazz()); |
| 5003 TypeArguments& type_arguments = TypeArguments::Handle(); | 5015 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); |
| 5004 if (cls.HasTypeArguments()) { | 5016 if (cls.HasTypeArguments()) { |
| 5005 type_arguments = GetTypeArguments(); | 5017 type_arguments = GetTypeArguments(); |
| 5006 } | 5018 } |
| 5007 const Type& type = Type::Handle(Type::New(cls, type_arguments)); | 5019 const Type& type = Type::Handle(Type::New(cls, type_arguments)); |
| 5008 type.set_is_finalized(); | 5020 type.set_is_finalized(); |
| 5009 return type.raw(); | 5021 return type.raw(); |
| 5010 } | 5022 } |
| 5011 | 5023 |
| 5012 | 5024 |
| 5013 RawTypeArguments* Instance::GetTypeArguments() const { | 5025 RawAbstractTypeArguments* Instance::GetTypeArguments() const { |
| 5014 const Class& cls = Class::Handle(clazz()); | 5026 const Class& cls = Class::Handle(clazz()); |
| 5015 intptr_t field_offset = cls.type_arguments_instance_field_offset(); | 5027 intptr_t field_offset = cls.type_arguments_instance_field_offset(); |
| 5016 ASSERT(field_offset != Class::kNoTypeArguments); | 5028 ASSERT(field_offset != Class::kNoTypeArguments); |
| 5017 TypeArguments& type_arguments = TypeArguments::Handle(); | 5029 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); |
| 5018 type_arguments ^= *FieldAddrAtOffset(field_offset); | 5030 type_arguments ^= *FieldAddrAtOffset(field_offset); |
| 5019 return type_arguments.raw(); | 5031 return type_arguments.raw(); |
| 5020 } | 5032 } |
| 5021 | 5033 |
| 5022 | 5034 |
| 5023 void Instance::SetTypeArguments(const TypeArguments& value) const { | 5035 void Instance::SetTypeArguments(const AbstractTypeArguments& value) const { |
| 5024 const Class& cls = Class::Handle(clazz()); | 5036 const Class& cls = Class::Handle(clazz()); |
| 5025 intptr_t field_offset = cls.type_arguments_instance_field_offset(); | 5037 intptr_t field_offset = cls.type_arguments_instance_field_offset(); |
| 5026 ASSERT(field_offset != Class::kNoTypeArguments); | 5038 ASSERT(field_offset != Class::kNoTypeArguments); |
| 5027 *FieldAddrAtOffset(field_offset) = value.raw(); | 5039 *FieldAddrAtOffset(field_offset) = value.raw(); |
| 5028 } | 5040 } |
| 5029 | 5041 |
| 5030 | 5042 |
| 5031 bool Instance::TestType(TypeTestKind test, | 5043 bool Instance::TestType(TypeTestKind test, |
| 5032 const AbstractType& other, | 5044 const AbstractType& other, |
| 5033 const TypeArguments& other_instantiator) const { | 5045 const AbstractTypeArguments& other_instantiator) const { |
| 5034 ASSERT(other.IsFinalized()); | 5046 ASSERT(other.IsFinalized()); |
| 5035 ASSERT(!other.IsDynamicType()); | 5047 ASSERT(!other.IsDynamicType()); |
| 5036 ASSERT(!other.IsVoidType()); | 5048 ASSERT(!other.IsVoidType()); |
| 5037 if (IsNull()) { | 5049 if (IsNull()) { |
| 5038 if (test == AbstractType::kIsSubtypeOf) { | 5050 if (test == AbstractType::kIsSubtypeOf) { |
| 5039 Class& other_class = Class::Handle(); | 5051 Class& other_class = Class::Handle(); |
| 5040 if (other.IsTypeParameter()) { | 5052 if (other.IsTypeParameter()) { |
| 5041 if (other_instantiator.IsNull()) { | 5053 if (other_instantiator.IsNull()) { |
| 5042 return true; // Other type is uninstantiated, i.e. Dynamic. | 5054 return true; // Other type is uninstantiated, i.e. Dynamic. |
| 5043 } | 5055 } |
| 5044 const AbstractType& instantiated_other = | 5056 const AbstractType& instantiated_other = |
| 5045 AbstractType::Handle(other_instantiator.TypeAt(other.Index())); | 5057 AbstractType::Handle(other_instantiator.TypeAt(other.Index())); |
| 5046 ASSERT(instantiated_other.IsInstantiated()); | 5058 ASSERT(instantiated_other.IsInstantiated()); |
| 5047 other_class = instantiated_other.type_class(); | 5059 other_class = instantiated_other.type_class(); |
| 5048 } else { | 5060 } else { |
| 5049 other_class = other.type_class(); | 5061 other_class = other.type_class(); |
| 5050 } | 5062 } |
| 5051 return other_class.IsObjectClass() || other_class.IsDynamicClass(); | 5063 return other_class.IsObjectClass() || other_class.IsDynamicClass(); |
| 5052 } else { | 5064 } else { |
| 5053 ASSERT(test == AbstractType::kIsAssignableTo); | 5065 ASSERT(test == AbstractType::kIsAssignableTo); |
| 5054 return true; | 5066 return true; |
| 5055 } | 5067 } |
| 5056 } | 5068 } |
| 5057 const Class& cls = Class::Handle(clazz()); | 5069 const Class& cls = Class::Handle(clazz()); |
| 5058 TypeArguments& type_arguments = TypeArguments::Handle(); | 5070 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); |
| 5059 const intptr_t num_type_arguments = cls.NumTypeArguments(); | 5071 const intptr_t num_type_arguments = cls.NumTypeArguments(); |
| 5060 if (num_type_arguments > 0) { | 5072 if (num_type_arguments > 0) { |
| 5061 type_arguments = GetTypeArguments(); | 5073 type_arguments = GetTypeArguments(); |
| 5062 // Verify that the number of type arguments in the instance matches the | 5074 // Verify that the number of type arguments in the instance matches the |
| 5063 // number of type arguments expected by the instance class. | 5075 // number of type arguments expected by the instance class. |
| 5064 // A discrepancy is allowed for closures, which borrow the type argument | 5076 // A discrepancy is allowed for closures, which borrow the type argument |
| 5065 // vector of their instantiator, which may be of a super class of the class | 5077 // vector of their instantiator, which may be of a super class of the class |
| 5066 // defining the closure. Truncating the vector to the correct length on | 5078 // defining the closure. Truncating the vector to the correct length on |
| 5067 // instantiation is unnecessary. The vector may therefore be longer. | 5079 // instantiation is unnecessary. The vector may therefore be longer. |
| 5068 ASSERT(type_arguments.IsNull() || | 5080 ASSERT(type_arguments.IsNull() || |
| 5069 (type_arguments.Length() == num_type_arguments) || | 5081 (type_arguments.Length() == num_type_arguments) || |
| 5070 (cls.IsSignatureClass() && | 5082 (cls.IsSignatureClass() && |
| 5071 (type_arguments.Length() > num_type_arguments))); | 5083 (type_arguments.Length() > num_type_arguments))); |
| 5072 } | 5084 } |
| 5073 Class& other_class = Class::Handle(); | 5085 Class& other_class = Class::Handle(); |
| 5074 TypeArguments& other_type_arguments = TypeArguments::Handle(); | 5086 AbstractTypeArguments& other_type_arguments = AbstractTypeArguments::Handle(); |
| 5075 // In case 'other' is not instantiated, we could simply call | 5087 // In case 'other' is not instantiated, we could simply call |
| 5076 // other.InstantiateFrom(other_instantiator, 0), however, we can save the | 5088 // other.InstantiateFrom(other_instantiator, 0), however, we can save the |
| 5077 // allocation of a new AbstractType by inlining the code. | 5089 // allocation of a new AbstractType by inlining the code. |
| 5078 if (other.IsTypeParameter()) { | 5090 if (other.IsTypeParameter()) { |
| 5079 AbstractType& instantiated_other = AbstractType::Handle(); | 5091 AbstractType& instantiated_other = AbstractType::Handle(); |
| 5080 if (!other_instantiator.IsNull()) { | 5092 if (!other_instantiator.IsNull()) { |
| 5081 instantiated_other = other_instantiator.TypeAt(other.Index()); | 5093 instantiated_other = other_instantiator.TypeAt(other.Index()); |
| 5082 ASSERT(instantiated_other.IsInstantiated()); | 5094 ASSERT(instantiated_other.IsInstantiated()); |
| 5083 } else { | 5095 } else { |
| 5084 instantiated_other = Type::DynamicType(); | 5096 instantiated_other = Type::DynamicType(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5138 | 5150 |
| 5139 const char* Instance::ToCString() const { | 5151 const char* Instance::ToCString() const { |
| 5140 if (IsNull()) { | 5152 if (IsNull()) { |
| 5141 return "null"; | 5153 return "null"; |
| 5142 } else if (Isolate::Current()->no_gc_scope_depth() > 0) { | 5154 } else if (Isolate::Current()->no_gc_scope_depth() > 0) { |
| 5143 // Can occur when running disassembler. | 5155 // Can occur when running disassembler. |
| 5144 return "Instance"; | 5156 return "Instance"; |
| 5145 } else { | 5157 } else { |
| 5146 const char* kFormat = "Instance of '%s'"; | 5158 const char* kFormat = "Instance of '%s'"; |
| 5147 Class& cls = Class::Handle(clazz()); | 5159 Class& cls = Class::Handle(clazz()); |
| 5148 TypeArguments& type_arguments = TypeArguments::Handle(); | 5160 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); |
| 5149 const intptr_t num_type_arguments = cls.NumTypeArguments(); | 5161 const intptr_t num_type_arguments = cls.NumTypeArguments(); |
| 5150 if (num_type_arguments > 0) { | 5162 if (num_type_arguments > 0) { |
| 5151 type_arguments = GetTypeArguments(); | 5163 type_arguments = GetTypeArguments(); |
| 5152 } | 5164 } |
| 5153 const Type& type = Type::Handle( | 5165 const Type& type = Type::Handle( |
| 5154 Type::NewParameterizedType(cls, type_arguments)); | 5166 Type::NewParameterizedType(cls, type_arguments)); |
| 5155 const String& type_name = String::Handle(type.Name()); | 5167 const String& type_name = String::Handle(type.Name()); |
| 5156 // Calculate the size of the string. | 5168 // Calculate the size of the string. |
| 5157 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1; | 5169 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1; |
| 5158 char* chars = reinterpret_cast<char*>( | 5170 char* chars = reinterpret_cast<char*>( |
| (...skipping 1667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6826 if (this->raw() == other.raw()) { | 6838 if (this->raw() == other.raw()) { |
| 6827 // Both handles point to the same raw instance. | 6839 // Both handles point to the same raw instance. |
| 6828 return true; | 6840 return true; |
| 6829 } | 6841 } |
| 6830 | 6842 |
| 6831 if (!other.IsArray() || other.IsNull()) { | 6843 if (!other.IsArray() || other.IsNull()) { |
| 6832 return false; | 6844 return false; |
| 6833 } | 6845 } |
| 6834 | 6846 |
| 6835 // Must have the same type arguments. | 6847 // Must have the same type arguments. |
| 6836 if (!TypeArguments::AreEqual( | 6848 if (!AbstractTypeArguments::AreEqual( |
| 6837 TypeArguments::Handle(GetTypeArguments()), | 6849 AbstractTypeArguments::Handle(GetTypeArguments()), |
| 6838 TypeArguments::Handle(other.GetTypeArguments()))) { | 6850 AbstractTypeArguments::Handle(other.GetTypeArguments()))) { |
| 6839 return false; | 6851 return false; |
| 6840 } | 6852 } |
| 6841 | 6853 |
| 6842 Array& other_arr = Array::Handle(); | 6854 Array& other_arr = Array::Handle(); |
| 6843 other_arr ^= other.raw(); | 6855 other_arr ^= other.raw(); |
| 6844 | 6856 |
| 6845 intptr_t len = this->Length(); | 6857 intptr_t len = this->Length(); |
| 6846 if (len != other_arr.Length()) { | 6858 if (len != other_arr.Length()) { |
| 6847 return false; | 6859 return false; |
| 6848 } | 6860 } |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7270 const String& str = String::Handle(pattern()); | 7282 const String& str = String::Handle(pattern()); |
| 7271 const char* format = "JSRegExp: pattern=%s flags=%s"; | 7283 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 7272 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 7284 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 7273 char* chars = reinterpret_cast<char*>( | 7285 char* chars = reinterpret_cast<char*>( |
| 7274 Isolate::Current()->current_zone()->Allocate(len + 1)); | 7286 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 7275 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 7287 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 7276 return chars; | 7288 return chars; |
| 7277 } | 7289 } |
| 7278 | 7290 |
| 7279 } // namespace dart | 7291 } // namespace dart |
| OLD | NEW |