OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 // canonical_type_arguments_ are Smi terminated. | 1143 // canonical_type_arguments_ are Smi terminated. |
1144 // Last element contains the count of used slots. | 1144 // Last element contains the count of used slots. |
1145 const intptr_t kInitialCanonicalTypeArgumentsSize = 4; | 1145 const intptr_t kInitialCanonicalTypeArgumentsSize = 4; |
1146 array = Array::New(kInitialCanonicalTypeArgumentsSize + 1); | 1146 array = Array::New(kInitialCanonicalTypeArgumentsSize + 1); |
1147 array.SetAt(kInitialCanonicalTypeArgumentsSize, | 1147 array.SetAt(kInitialCanonicalTypeArgumentsSize, |
1148 Smi::Handle(zone, Smi::New(0))); | 1148 Smi::Handle(zone, Smi::New(0))); |
1149 object_store->set_canonical_type_arguments(array); | 1149 object_store->set_canonical_type_arguments(array); |
1150 | 1150 |
1151 // Setup type class early in the process. | 1151 // Setup type class early in the process. |
1152 const Class& type_cls = Class::Handle(zone, Class::New<Type>()); | 1152 const Class& type_cls = Class::Handle(zone, Class::New<Type>()); |
1153 const Class& function_type_cls = Class::Handle(zone, | |
1154 Class::New<FunctionType>()); | |
1155 const Class& type_ref_cls = Class::Handle(zone, Class::New<TypeRef>()); | 1153 const Class& type_ref_cls = Class::Handle(zone, Class::New<TypeRef>()); |
1156 const Class& type_parameter_cls = Class::Handle(zone, | 1154 const Class& type_parameter_cls = Class::Handle(zone, |
1157 Class::New<TypeParameter>()); | 1155 Class::New<TypeParameter>()); |
1158 const Class& bounded_type_cls = Class::Handle(zone, | 1156 const Class& bounded_type_cls = Class::Handle(zone, |
1159 Class::New<BoundedType>()); | 1157 Class::New<BoundedType>()); |
1160 const Class& mixin_app_type_cls = Class::Handle(zone, | 1158 const Class& mixin_app_type_cls = Class::Handle(zone, |
1161 Class::New<MixinAppType>()); | 1159 Class::New<MixinAppType>()); |
1162 const Class& library_prefix_cls = Class::Handle(zone, | 1160 const Class& library_prefix_cls = Class::Handle(zone, |
1163 Class::New<LibraryPrefix>()); | 1161 Class::New<LibraryPrefix>()); |
1164 | 1162 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1307 RegisterClass(cls, Symbols::Null(), core_lib); | 1305 RegisterClass(cls, Symbols::Null(), core_lib); |
1308 pending_classes.Add(cls); | 1306 pending_classes.Add(cls); |
1309 | 1307 |
1310 ASSERT(!library_prefix_cls.IsNull()); | 1308 ASSERT(!library_prefix_cls.IsNull()); |
1311 RegisterPrivateClass(library_prefix_cls, Symbols::_LibraryPrefix(), core_lib); | 1309 RegisterPrivateClass(library_prefix_cls, Symbols::_LibraryPrefix(), core_lib); |
1312 pending_classes.Add(library_prefix_cls); | 1310 pending_classes.Add(library_prefix_cls); |
1313 | 1311 |
1314 RegisterPrivateClass(type_cls, Symbols::Type(), core_lib); | 1312 RegisterPrivateClass(type_cls, Symbols::Type(), core_lib); |
1315 pending_classes.Add(type_cls); | 1313 pending_classes.Add(type_cls); |
1316 | 1314 |
1317 RegisterPrivateClass(function_type_cls, Symbols::FunctionType(), core_lib); | |
1318 pending_classes.Add(function_type_cls); | |
1319 | |
1320 RegisterPrivateClass(type_ref_cls, Symbols::TypeRef(), core_lib); | 1315 RegisterPrivateClass(type_ref_cls, Symbols::TypeRef(), core_lib); |
1321 pending_classes.Add(type_ref_cls); | 1316 pending_classes.Add(type_ref_cls); |
1322 | 1317 |
1323 RegisterPrivateClass(type_parameter_cls, Symbols::TypeParameter(), core_lib); | 1318 RegisterPrivateClass(type_parameter_cls, Symbols::TypeParameter(), core_lib); |
1324 pending_classes.Add(type_parameter_cls); | 1319 pending_classes.Add(type_parameter_cls); |
1325 | 1320 |
1326 RegisterPrivateClass(bounded_type_cls, Symbols::BoundedType(), core_lib); | 1321 RegisterPrivateClass(bounded_type_cls, Symbols::BoundedType(), core_lib); |
1327 pending_classes.Add(bounded_type_cls); | 1322 pending_classes.Add(bounded_type_cls); |
1328 | 1323 |
1329 RegisterPrivateClass(mixin_app_type_cls, Symbols::MixinAppType(), core_lib); | 1324 RegisterPrivateClass(mixin_app_type_cls, Symbols::MixinAppType(), core_lib); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1626 // This is done to allow bootstrapping of reading classes from the snapshot. | 1621 // This is done to allow bootstrapping of reading classes from the snapshot. |
1627 // Some classes are not stored in the object store. Yet we still need to | 1622 // Some classes are not stored in the object store. Yet we still need to |
1628 // create their Class object so that they get put into the class_table | 1623 // create their Class object so that they get put into the class_table |
1629 // (as a side effect of Class::New()). | 1624 // (as a side effect of Class::New()). |
1630 | 1625 |
1631 cls = Class::New<Instance>(kInstanceCid); | 1626 cls = Class::New<Instance>(kInstanceCid); |
1632 object_store->set_object_class(cls); | 1627 object_store->set_object_class(cls); |
1633 | 1628 |
1634 cls = Class::New<LibraryPrefix>(); | 1629 cls = Class::New<LibraryPrefix>(); |
1635 cls = Class::New<Type>(); | 1630 cls = Class::New<Type>(); |
1636 cls = Class::New<FunctionType>(); | |
1637 cls = Class::New<TypeRef>(); | 1631 cls = Class::New<TypeRef>(); |
1638 cls = Class::New<TypeParameter>(); | 1632 cls = Class::New<TypeParameter>(); |
1639 cls = Class::New<BoundedType>(); | 1633 cls = Class::New<BoundedType>(); |
1640 cls = Class::New<MixinAppType>(); | 1634 cls = Class::New<MixinAppType>(); |
1641 | 1635 |
1642 cls = Class::New<Array>(); | 1636 cls = Class::New<Array>(); |
1643 object_store->set_array_class(cls); | 1637 object_store->set_array_class(cls); |
1644 | 1638 |
1645 cls = Class::New<Array>(kImmutableArrayCid); | 1639 cls = Class::New<Array>(kImmutableArrayCid); |
1646 object_store->set_immutable_array_class(cls); | 1640 object_store->set_immutable_array_class(cls); |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2419 do { | 2413 do { |
2420 // Calling NumOwnTypeArguments() on a mixin application class will setup the | 2414 // Calling NumOwnTypeArguments() on a mixin application class will setup the |
2421 // type parameters if not already done. | 2415 // type parameters if not already done. |
2422 num_type_args += cls.NumOwnTypeArguments(); | 2416 num_type_args += cls.NumOwnTypeArguments(); |
2423 // Super type of Object class is null. | 2417 // Super type of Object class is null. |
2424 if ((cls.super_type() == AbstractType::null()) || | 2418 if ((cls.super_type() == AbstractType::null()) || |
2425 (cls.super_type() == isolate->object_store()->object_type())) { | 2419 (cls.super_type() == isolate->object_store()->object_type())) { |
2426 break; | 2420 break; |
2427 } | 2421 } |
2428 sup_type = cls.super_type(); | 2422 sup_type = cls.super_type(); |
2429 // A BoundedType, TypeRef, or FunctionType can appear as type argument of | 2423 // A BoundedType, TypeRef, or function type can appear as type argument of |
2430 // sup_type, but not as sup_type itself. | 2424 // sup_type, but not as sup_type itself. |
2431 ASSERT(sup_type.IsType()); | 2425 ASSERT(sup_type.IsType()); |
2432 sup_type = ClassFinalizer::ResolveTypeClass(cls, Type::Cast(sup_type)); | 2426 ClassFinalizer::ResolveTypeClass(cls, Type::Cast(sup_type)); |
2433 cls = sup_type.type_class(); | 2427 cls = sup_type.type_class(); |
2434 ASSERT(!cls.IsTypedefClass()); | 2428 ASSERT(!cls.IsTypedefClass()); |
2435 } while (true); | 2429 } while (true); |
2436 set_num_type_arguments(num_type_args); | 2430 set_num_type_arguments(num_type_args); |
2437 return num_type_args; | 2431 return num_type_args; |
2438 } | 2432 } |
2439 | 2433 |
2440 | 2434 |
2441 RawClass* Class::SuperClass() const { | 2435 RawClass* Class::SuperClass() const { |
2442 if (super_type() == AbstractType::null()) { | 2436 if (super_type() == AbstractType::null()) { |
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3624 return; | 3618 return; |
3625 } | 3619 } |
3626 ASSERT(!existing_stub.IsDisabled()); | 3620 ASSERT(!existing_stub.IsDisabled()); |
3627 // Change the stub so that the next caller will regenerate the stub. | 3621 // Change the stub so that the next caller will regenerate the stub. |
3628 existing_stub.DisableStubCode(); | 3622 existing_stub.DisableStubCode(); |
3629 // Disassociate the existing stub from class. | 3623 // Disassociate the existing stub from class. |
3630 StorePointer(&raw_ptr()->allocation_stub_, Code::null()); | 3624 StorePointer(&raw_ptr()->allocation_stub_, Code::null()); |
3631 } | 3625 } |
3632 | 3626 |
3633 | 3627 |
3634 bool Class::IsFunctionClass() const { | 3628 bool Class::IsDartFunctionClass() const { |
3635 return raw() == Type::Handle(Type::Function()).type_class(); | 3629 return raw() == Type::Handle(Type::DartFunctionType()).type_class(); |
3636 } | 3630 } |
3637 | 3631 |
3638 | 3632 |
3639 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T. | 3633 // If test_kind == kIsSubtypeOf, checks if type S is a subtype of type T. |
3640 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T. | 3634 // If test_kind == kIsMoreSpecificThan, checks if S is more specific than T. |
3641 // Type S is specified by this class parameterized with 'type_arguments', and | 3635 // Type S is specified by this class parameterized with 'type_arguments', and |
3642 // type T by class 'other' parameterized with 'other_type_arguments'. | 3636 // type T by class 'other' parameterized with 'other_type_arguments'. |
3643 // This class and class 'other' do not need to be finalized, however, they must | 3637 // This class and class 'other' do not need to be finalized, however, they must |
3644 // be resolved as well as their interfaces. | 3638 // be resolved as well as their interfaces. |
3645 bool Class::TypeTestNonRecursive(const Class& cls, | 3639 bool Class::TypeTestNonRecursive(const Class& cls, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3703 return test_kind == Class::kIsSubtypeOf; | 3697 return test_kind == Class::kIsSubtypeOf; |
3704 } | 3698 } |
3705 return type_arguments.TypeTest(test_kind, | 3699 return type_arguments.TypeTest(test_kind, |
3706 other_type_arguments, | 3700 other_type_arguments, |
3707 from_index, | 3701 from_index, |
3708 num_type_params, | 3702 num_type_params, |
3709 bound_error, | 3703 bound_error, |
3710 bound_trail, | 3704 bound_trail, |
3711 space); | 3705 space); |
3712 } | 3706 } |
3713 if (other.IsFunctionClass()) { | 3707 if (other.IsDartFunctionClass()) { |
3714 // Check if type S has a call() method. | 3708 // Check if type S has a call() method. |
3715 Function& function = Function::Handle(zone, | 3709 Function& function = Function::Handle(zone, |
3716 thsi.LookupDynamicFunctionAllowAbstract(Symbols::Call())); | 3710 thsi.LookupDynamicFunctionAllowAbstract(Symbols::Call())); |
3717 if (function.IsNull()) { | 3711 if (function.IsNull()) { |
3718 // Walk up the super_class chain. | 3712 // Walk up the super_class chain. |
3719 Class& cls = Class::Handle(zone, thsi.SuperClass()); | 3713 Class& cls = Class::Handle(zone, thsi.SuperClass()); |
3720 while (!cls.IsNull() && function.IsNull()) { | 3714 while (!cls.IsNull() && function.IsNull()) { |
3721 function = cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); | 3715 function = cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); |
3722 cls = cls.SuperClass(); | 3716 cls = cls.SuperClass(); |
3723 } | 3717 } |
(...skipping 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5425 ASSERT(obj.IsArray()); | 5419 ASSERT(obj.IsArray()); |
5426 ASSERT((Array::Cast(obj).At(1) == Object::null()) || value.IsNull()); | 5420 ASSERT((Array::Cast(obj).At(1) == Object::null()) || value.IsNull()); |
5427 Array::Cast(obj).SetAt(1, value); | 5421 Array::Cast(obj).SetAt(1, value); |
5428 } else { | 5422 } else { |
5429 ASSERT((raw_ptr()->data_ == Object::null()) || value.IsNull()); | 5423 ASSERT((raw_ptr()->data_ == Object::null()) || value.IsNull()); |
5430 set_data(value); | 5424 set_data(value); |
5431 } | 5425 } |
5432 } | 5426 } |
5433 | 5427 |
5434 | 5428 |
5435 RawFunctionType* Function::SignatureType() const { | 5429 RawType* Function::SignatureType() const { |
5436 FunctionType& type = FunctionType::Handle(); | 5430 Type& type = Type::Handle(); |
5437 const Object& obj = Object::Handle(raw_ptr()->data_); | 5431 const Object& obj = Object::Handle(raw_ptr()->data_); |
5438 if (IsSignatureFunction()) { | 5432 if (IsSignatureFunction()) { |
5439 ASSERT(obj.IsNull() || obj.IsFunctionType()); | 5433 ASSERT(obj.IsNull() || Type::Cast(obj).IsFunctionType()); |
5440 type = obj.IsNull() ? FunctionType::null() : FunctionType::Cast(obj).raw(); | 5434 type = obj.IsNull() ? Type::null() : Type::Cast(obj).raw(); |
5441 } else { | 5435 } else { |
5442 ASSERT(IsClosureFunction()); | 5436 ASSERT(IsClosureFunction()); |
5443 ASSERT(!obj.IsNull()); | 5437 ASSERT(!obj.IsNull()); |
5444 type = ClosureData::Cast(obj).signature_type(); | 5438 type = ClosureData::Cast(obj).signature_type(); |
5445 } | 5439 } |
5446 if (type.IsNull()) { | 5440 if (type.IsNull()) { |
5447 // A function type is parameterized in the same way as the owner class of | 5441 // A function type is parameterized in the same way as the owner class of |
5448 // its non-static signature function. | 5442 // its non-static signature function. |
5449 // It is not type parameterized if its signature function is static. | 5443 // It is not type parameterized if its signature function is static. |
5450 // During type finalization, the type arguments of the super class of the | 5444 // During type finalization, the type arguments of the super class of the |
(...skipping 15 matching lines...) Expand all Loading... |
5466 HasInstantiatedSignature())) { | 5460 HasInstantiatedSignature())) { |
5467 scope_class = Isolate::Current()->object_store()->closure_class(); | 5461 scope_class = Isolate::Current()->object_store()->closure_class(); |
5468 if (IsSignatureFunction()) { | 5462 if (IsSignatureFunction()) { |
5469 set_owner(scope_class); | 5463 set_owner(scope_class); |
5470 set_token_pos(TokenPosition::kNoSource); | 5464 set_token_pos(TokenPosition::kNoSource); |
5471 } | 5465 } |
5472 } | 5466 } |
5473 const TypeArguments& signature_type_arguments = | 5467 const TypeArguments& signature_type_arguments = |
5474 TypeArguments::Handle(scope_class.type_parameters()); | 5468 TypeArguments::Handle(scope_class.type_parameters()); |
5475 // Return the still unfinalized signature type. | 5469 // Return the still unfinalized signature type. |
5476 type = FunctionType::New(scope_class, | 5470 type = Type::New(scope_class, signature_type_arguments, token_pos()); |
5477 signature_type_arguments, | 5471 type.set_signature(*this); |
5478 *this, | |
5479 token_pos()); | |
5480 | |
5481 SetSignatureType(type); | 5472 SetSignatureType(type); |
5482 } | 5473 } |
5483 return type.raw(); | 5474 return type.raw(); |
5484 } | 5475 } |
5485 | 5476 |
5486 | 5477 |
5487 void Function::SetSignatureType(const FunctionType& value) const { | 5478 void Function::SetSignatureType(const Type& value) const { |
5488 if (IsSignatureFunction()) { | 5479 if (IsSignatureFunction()) { |
5489 set_data(value); | 5480 set_data(value); |
5490 } else { | 5481 } else { |
5491 ASSERT(IsClosureFunction()); | 5482 ASSERT(IsClosureFunction()); |
5492 const Object& obj = Object::Handle(raw_ptr()->data_); | 5483 const Object& obj = Object::Handle(raw_ptr()->data_); |
5493 ASSERT(!obj.IsNull()); | 5484 ASSERT(!obj.IsNull()); |
5494 ClosureData::Cast(obj).set_signature_type(value); | 5485 ClosureData::Cast(obj).set_signature_type(value); |
5495 } | 5486 } |
5496 } | 5487 } |
5497 | 5488 |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6146 other.token_pos(), | 6137 other.token_pos(), |
6147 Report::AtLocation, | 6138 Report::AtLocation, |
6148 Report::kError, | 6139 Report::kError, |
6149 Heap::kNew, | 6140 Heap::kNew, |
6150 "signature type '%s' of function '%s' is not a subtype of signature " | 6141 "signature type '%s' of function '%s' is not a subtype of signature " |
6151 "type '%s' of function '%s' where\n%s%s", | 6142 "type '%s' of function '%s' where\n%s%s", |
6152 String::Handle(UserVisibleSignature()).ToCString(), | 6143 String::Handle(UserVisibleSignature()).ToCString(), |
6153 String::Handle(UserVisibleName()).ToCString(), | 6144 String::Handle(UserVisibleName()).ToCString(), |
6154 String::Handle(other.UserVisibleSignature()).ToCString(), | 6145 String::Handle(other.UserVisibleSignature()).ToCString(), |
6155 String::Handle(other.UserVisibleName()).ToCString(), | 6146 String::Handle(other.UserVisibleName()).ToCString(), |
6156 String::Handle(FunctionType::Handle( | 6147 String::Handle(Type::Handle( |
6157 SignatureType()).EnumerateURIs()).ToCString(), | 6148 SignatureType()).EnumerateURIs()).ToCString(), |
6158 String::Handle(FunctionType::Handle( | 6149 String::Handle(Type::Handle( |
6159 other.SignatureType()).EnumerateURIs()).ToCString()); | 6150 other.SignatureType()).EnumerateURIs()).ToCString()); |
6160 return false; | 6151 return false; |
6161 } | 6152 } |
6162 // We should also check that if the other function explicitly specifies a | 6153 // We should also check that if the other function explicitly specifies a |
6163 // default value for a formal parameter, this function does not specify a | 6154 // default value for a formal parameter, this function does not specify a |
6164 // different default value for the same parameter. However, this check is not | 6155 // different default value for the same parameter. However, this check is not |
6165 // possible in the current implementation, because the default parameter | 6156 // possible in the current implementation, because the default parameter |
6166 // values are not stored in the Function object, but discarded after a | 6157 // values are not stored in the Function object, but discarded after a |
6167 // function is compiled. | 6158 // function is compiled. |
6168 return true; | 6159 return true; |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6584 // Add implicit closure object parameter. | 6575 // Add implicit closure object parameter. |
6585 param_type = Type::DynamicType(); | 6576 param_type = Type::DynamicType(); |
6586 closure_function.SetParameterTypeAt(0, param_type); | 6577 closure_function.SetParameterTypeAt(0, param_type); |
6587 closure_function.SetParameterNameAt(0, Symbols::ClosureParameter()); | 6578 closure_function.SetParameterNameAt(0, Symbols::ClosureParameter()); |
6588 for (int i = kClosure; i < num_params; i++) { | 6579 for (int i = kClosure; i < num_params; i++) { |
6589 param_type = ParameterTypeAt(has_receiver - kClosure + i); | 6580 param_type = ParameterTypeAt(has_receiver - kClosure + i); |
6590 closure_function.SetParameterTypeAt(i, param_type); | 6581 closure_function.SetParameterTypeAt(i, param_type); |
6591 param_name = ParameterNameAt(has_receiver - kClosure + i); | 6582 param_name = ParameterNameAt(has_receiver - kClosure + i); |
6592 closure_function.SetParameterNameAt(i, param_name); | 6583 closure_function.SetParameterNameAt(i, param_name); |
6593 } | 6584 } |
6594 const FunctionType& signature_type = | 6585 const Type& signature_type = Type::Handle(closure_function.SignatureType()); |
6595 FunctionType::Handle(closure_function.SignatureType()); | |
6596 if (!signature_type.IsFinalized()) { | 6586 if (!signature_type.IsFinalized()) { |
6597 ClassFinalizer::FinalizeType( | 6587 ClassFinalizer::FinalizeType( |
6598 Class::Handle(Owner()), signature_type, ClassFinalizer::kCanonicalize); | 6588 Class::Handle(Owner()), signature_type, ClassFinalizer::kCanonicalize); |
6599 } | 6589 } |
6600 set_implicit_closure_function(closure_function); | 6590 set_implicit_closure_function(closure_function); |
6601 ASSERT(closure_function.IsImplicitClosureFunction()); | 6591 ASSERT(closure_function.IsImplicitClosureFunction()); |
6602 return closure_function.raw(); | 6592 return closure_function.raw(); |
6603 } | 6593 } |
6604 | 6594 |
6605 | 6595 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6660 } | 6650 } |
6661 i++; | 6651 i++; |
6662 } | 6652 } |
6663 if (num_opt_params > 0) { | 6653 if (num_opt_params > 0) { |
6664 if (num_opt_pos_params > 0) { | 6654 if (num_opt_pos_params > 0) { |
6665 pieces->Add(Symbols::LBracket()); | 6655 pieces->Add(Symbols::LBracket()); |
6666 } else { | 6656 } else { |
6667 pieces->Add(Symbols::LBrace()); | 6657 pieces->Add(Symbols::LBrace()); |
6668 } | 6658 } |
6669 for (intptr_t i = num_fixed_params; i < num_params; i++) { | 6659 for (intptr_t i = num_fixed_params; i < num_params; i++) { |
6670 // The parameter name of an optional positional parameter does not need | |
6671 // to be part of the signature, since it is not used. | |
6672 if (num_opt_named_params > 0) { | |
6673 name = ParameterNameAt(i); | |
6674 pieces->Add(name); | |
6675 pieces->Add(Symbols::ColonSpace()); | |
6676 } | |
6677 param_type = ParameterTypeAt(i); | 6660 param_type = ParameterTypeAt(i); |
6678 if (instantiate && | 6661 if (instantiate && |
6679 param_type.IsFinalized() && | 6662 param_type.IsFinalized() && |
6680 !param_type.IsInstantiated()) { | 6663 !param_type.IsInstantiated()) { |
6681 param_type = param_type.InstantiateFrom(instantiator, NULL, | 6664 param_type = param_type.InstantiateFrom(instantiator, NULL, |
6682 NULL, NULL, Heap::kNew); | 6665 NULL, NULL, Heap::kNew); |
6683 } | 6666 } |
6684 ASSERT(!param_type.IsNull()); | 6667 ASSERT(!param_type.IsNull()); |
6685 name = param_type.BuildName(name_visibility); | 6668 name = param_type.BuildName(name_visibility); |
6686 pieces->Add(name); | 6669 pieces->Add(name); |
| 6670 // The parameter name of an optional positional parameter does not need |
| 6671 // to be part of the signature, since it is not used. |
| 6672 if (num_opt_named_params > 0) { |
| 6673 name = ParameterNameAt(i); |
| 6674 pieces->Add(Symbols::Blank()); |
| 6675 pieces->Add(name); |
| 6676 } |
6687 if (i != (num_params - 1)) { | 6677 if (i != (num_params - 1)) { |
6688 pieces->Add(Symbols::CommaSpace()); | 6678 pieces->Add(Symbols::CommaSpace()); |
6689 } | 6679 } |
6690 } | 6680 } |
6691 if (num_opt_pos_params > 0) { | 6681 if (num_opt_pos_params > 0) { |
6692 pieces->Add(Symbols::RBracket()); | 6682 pieces->Add(Symbols::RBracket()); |
6693 } else { | 6683 } else { |
6694 pieces->Add(Symbols::RBrace()); | 6684 pieces->Add(Symbols::RBrace()); |
6695 } | 6685 } |
6696 } | 6686 } |
(...skipping 11 matching lines...) Expand all Loading... |
6708 Instance& closure = | 6698 Instance& closure = |
6709 Instance::Handle(zone, Closure::New(*this, context, Heap::kOld)); | 6699 Instance::Handle(zone, Closure::New(*this, context, Heap::kOld)); |
6710 set_implicit_static_closure(closure); | 6700 set_implicit_static_closure(closure); |
6711 } | 6701 } |
6712 return implicit_static_closure(); | 6702 return implicit_static_closure(); |
6713 } | 6703 } |
6714 | 6704 |
6715 | 6705 |
6716 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const { | 6706 RawInstance* Function::ImplicitInstanceClosure(const Instance& receiver) const { |
6717 ASSERT(IsImplicitClosureFunction()); | 6707 ASSERT(IsImplicitClosureFunction()); |
6718 const FunctionType& signature_type = FunctionType::Handle(SignatureType()); | 6708 const Type& signature_type = Type::Handle(SignatureType()); |
6719 const Class& cls = Class::Handle(signature_type.type_class()); | 6709 const Class& cls = Class::Handle(signature_type.type_class()); |
6720 const Context& context = Context::Handle(Context::New(1)); | 6710 const Context& context = Context::Handle(Context::New(1)); |
6721 context.SetAt(0, receiver); | 6711 context.SetAt(0, receiver); |
6722 const Instance& result = Instance::Handle(Closure::New(*this, context)); | 6712 const Instance& result = Instance::Handle(Closure::New(*this, context)); |
6723 if (cls.IsGeneric()) { | 6713 if (cls.IsGeneric()) { |
6724 const TypeArguments& type_arguments = | 6714 const TypeArguments& type_arguments = |
6725 TypeArguments::Handle(receiver.GetTypeArguments()); | 6715 TypeArguments::Handle(receiver.GetTypeArguments()); |
6726 result.SetTypeArguments(type_arguments); | 6716 result.SetTypeArguments(type_arguments); |
6727 } | 6717 } |
6728 return result.raw(); | 6718 return result.raw(); |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7119 ASSERT(raw_ptr()->closure_ == Instance::null()); | 7109 ASSERT(raw_ptr()->closure_ == Instance::null()); |
7120 StorePointer(&raw_ptr()->closure_, closure.raw()); | 7110 StorePointer(&raw_ptr()->closure_, closure.raw()); |
7121 } | 7111 } |
7122 | 7112 |
7123 | 7113 |
7124 void ClosureData::set_parent_function(const Function& value) const { | 7114 void ClosureData::set_parent_function(const Function& value) const { |
7125 StorePointer(&raw_ptr()->parent_function_, value.raw()); | 7115 StorePointer(&raw_ptr()->parent_function_, value.raw()); |
7126 } | 7116 } |
7127 | 7117 |
7128 | 7118 |
7129 void ClosureData::set_signature_type(const FunctionType& value) const { | 7119 void ClosureData::set_signature_type(const Type& value) const { |
7130 StorePointer(&raw_ptr()->signature_type_, value.raw()); | 7120 StorePointer(&raw_ptr()->signature_type_, value.raw()); |
7131 } | 7121 } |
7132 | 7122 |
7133 | 7123 |
7134 RawClosureData* ClosureData::New() { | 7124 RawClosureData* ClosureData::New() { |
7135 ASSERT(Object::closure_data_class() != Class::null()); | 7125 ASSERT(Object::closure_data_class() != Class::null()); |
7136 RawObject* raw = Object::Allocate(ClosureData::kClassId, | 7126 RawObject* raw = Object::Allocate(ClosureData::kClassId, |
7137 ClosureData::InstanceSize(), | 7127 ClosureData::InstanceSize(), |
7138 Heap::kOld); | 7128 Heap::kOld); |
7139 return reinterpret_cast<RawClosureData*>(raw); | 7129 return reinterpret_cast<RawClosureData*>(raw); |
(...skipping 4945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12085 ASSERT(!value.IsNull()); | 12075 ASSERT(!value.IsNull()); |
12086 StorePointer(&raw_ptr()->target_name_, value.raw()); | 12076 StorePointer(&raw_ptr()->target_name_, value.raw()); |
12087 } | 12077 } |
12088 | 12078 |
12089 | 12079 |
12090 void ICData::set_arguments_descriptor(const Array& value) const { | 12080 void ICData::set_arguments_descriptor(const Array& value) const { |
12091 ASSERT(!value.IsNull()); | 12081 ASSERT(!value.IsNull()); |
12092 StorePointer(&raw_ptr()->args_descriptor_, value.raw()); | 12082 StorePointer(&raw_ptr()->args_descriptor_, value.raw()); |
12093 } | 12083 } |
12094 | 12084 |
| 12085 |
12095 void ICData::set_deopt_id(intptr_t value) const { | 12086 void ICData::set_deopt_id(intptr_t value) const { |
12096 ASSERT(value <= kMaxInt32); | 12087 ASSERT(value <= kMaxInt32); |
12097 StoreNonPointer(&raw_ptr()->deopt_id_, value); | 12088 StoreNonPointer(&raw_ptr()->deopt_id_, value); |
12098 } | 12089 } |
12099 | 12090 |
12100 | 12091 |
12101 void ICData::set_ic_data_array(const Array& value) const { | 12092 void ICData::set_ic_data_array(const Array& value) const { |
12102 ASSERT(!value.IsNull()); | 12093 ASSERT(!value.IsNull()); |
12103 StorePointer(&raw_ptr()->ic_data_, value.raw()); | 12094 StorePointer(&raw_ptr()->ic_data_, value.raw()); |
12104 } | 12095 } |
(...skipping 2499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14604 | 14595 |
14605 | 14596 |
14606 RawAbstractType* Instance::GetType() const { | 14597 RawAbstractType* Instance::GetType() const { |
14607 if (IsNull()) { | 14598 if (IsNull()) { |
14608 return Type::NullType(); | 14599 return Type::NullType(); |
14609 } | 14600 } |
14610 const Class& cls = Class::Handle(clazz()); | 14601 const Class& cls = Class::Handle(clazz()); |
14611 if (cls.IsClosureClass()) { | 14602 if (cls.IsClosureClass()) { |
14612 const Function& signature = | 14603 const Function& signature = |
14613 Function::Handle(Closure::Cast(*this).function()); | 14604 Function::Handle(Closure::Cast(*this).function()); |
14614 FunctionType& type = FunctionType::Handle(signature.SignatureType()); | 14605 Type& type = Type::Handle(signature.SignatureType()); |
14615 if (type.scope_class() == cls.raw()) { | 14606 if (type.type_class() == cls.raw()) { |
14616 // Type is not parameterized. | 14607 // Type is not parameterized. |
14617 if (!type.IsCanonical()) { | 14608 if (!type.IsCanonical()) { |
14618 type ^= type.Canonicalize(); | 14609 type ^= type.Canonicalize(); |
14619 signature.SetSignatureType(type); | 14610 signature.SetSignatureType(type); |
14620 } | 14611 } |
14621 return type.raw(); | 14612 return type.raw(); |
14622 } | 14613 } |
14623 const Class& scope_cls = Class::Handle(type.scope_class()); | 14614 const Class& scope_cls = Class::Handle(type.type_class()); |
14624 ASSERT(scope_cls.NumTypeArguments() > 0); | 14615 ASSERT(scope_cls.NumTypeArguments() > 0); |
14625 TypeArguments& type_arguments = TypeArguments::Handle(GetTypeArguments()); | 14616 TypeArguments& type_arguments = TypeArguments::Handle(GetTypeArguments()); |
14626 type = FunctionType::New( | 14617 type = Type::New(scope_cls, type_arguments, TokenPosition::kNoSource); |
14627 scope_cls, type_arguments, signature, TokenPosition::kNoSource); | 14618 type.set_signature(signature); |
14628 type.SetIsFinalized(); | 14619 type.SetIsFinalized(); |
14629 type ^= type.Canonicalize(); | 14620 type ^= type.Canonicalize(); |
14630 return type.raw(); | 14621 return type.raw(); |
14631 } | 14622 } |
14632 Type& type = Type::Handle(); | 14623 Type& type = Type::Handle(); |
14633 if (!cls.IsGeneric()) { | 14624 if (!cls.IsGeneric()) { |
14634 type = cls.CanonicalType(); | 14625 type = cls.CanonicalType(); |
14635 } | 14626 } |
14636 if (type.IsNull()) { | 14627 if (type.IsNull()) { |
14637 TypeArguments& type_arguments = TypeArguments::Handle(); | 14628 TypeArguments& type_arguments = TypeArguments::Handle(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14697 instantiated_other = TypeRef::Cast(instantiated_other).type(); | 14688 instantiated_other = TypeRef::Cast(instantiated_other).type(); |
14698 } | 14689 } |
14699 if (instantiated_other.IsDynamicType() || | 14690 if (instantiated_other.IsDynamicType() || |
14700 instantiated_other.IsObjectType() || | 14691 instantiated_other.IsObjectType() || |
14701 instantiated_other.IsDartFunctionType()) { | 14692 instantiated_other.IsDartFunctionType()) { |
14702 return true; | 14693 return true; |
14703 } | 14694 } |
14704 if (!instantiated_other.IsFunctionType()) { | 14695 if (!instantiated_other.IsFunctionType()) { |
14705 return false; | 14696 return false; |
14706 } | 14697 } |
14707 other_signature = FunctionType::Cast(instantiated_other).signature(); | 14698 other_signature = Type::Cast(instantiated_other).signature(); |
14708 other_type_arguments = instantiated_other.arguments(); | 14699 other_type_arguments = instantiated_other.arguments(); |
14709 } else { | 14700 } else { |
14710 if (!other.IsFunctionType()) { | 14701 if (!other.IsFunctionType()) { |
14711 return false; | 14702 return false; |
14712 } | 14703 } |
14713 other_signature = FunctionType::Cast(other).signature(); | 14704 other_signature = Type::Cast(other).signature(); |
14714 other_type_arguments = other.arguments(); | 14705 other_type_arguments = other.arguments(); |
14715 } | 14706 } |
14716 const Function& signature = | 14707 const Function& signature = |
14717 Function::Handle(zone, Closure::Cast(*this).function()); | 14708 Function::Handle(zone, Closure::Cast(*this).function()); |
14718 const TypeArguments& type_arguments = | 14709 const TypeArguments& type_arguments = |
14719 TypeArguments::Handle(zone, GetTypeArguments()); | 14710 TypeArguments::Handle(zone, GetTypeArguments()); |
14720 return signature.IsSubtypeOf(type_arguments, | 14711 return signature.IsSubtypeOf(type_arguments, |
14721 other_signature, | 14712 other_signature, |
14722 other_type_arguments, | 14713 other_type_arguments, |
14723 bound_error, | 14714 bound_error, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14768 while (!super_cls.IsNull() && call.IsNull()) { | 14759 while (!super_cls.IsNull() && call.IsNull()) { |
14769 call = super_cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); | 14760 call = super_cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); |
14770 super_cls = super_cls.SuperClass(); | 14761 super_cls = super_cls.SuperClass(); |
14771 } | 14762 } |
14772 } | 14763 } |
14773 if (!call.IsNull()) { | 14764 if (!call.IsNull()) { |
14774 if (other_is_dart_function) { | 14765 if (other_is_dart_function) { |
14775 return true; | 14766 return true; |
14776 } | 14767 } |
14777 const Function& other_signature = Function::Handle( | 14768 const Function& other_signature = Function::Handle( |
14778 zone, FunctionType::Cast(instantiated_other).signature()); | 14769 zone, Type::Cast(instantiated_other).signature()); |
14779 if (call.IsSubtypeOf(type_arguments, | 14770 if (call.IsSubtypeOf(type_arguments, |
14780 other_signature, | 14771 other_signature, |
14781 other_type_arguments, | 14772 other_type_arguments, |
14782 bound_error, | 14773 bound_error, |
14783 Heap::kOld)) { | 14774 Heap::kOld)) { |
14784 return true; | 14775 return true; |
14785 } | 14776 } |
14786 } | 14777 } |
14787 } | 14778 } |
14788 if (!instantiated_other.IsType()) { | 14779 if (!instantiated_other.IsType()) { |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15265 // a malformed type, so proceed with caution. | 15256 // a malformed type, so proceed with caution. |
15266 const TypeArguments& args = TypeArguments::Handle(zone, arguments()); | 15257 const TypeArguments& args = TypeArguments::Handle(zone, arguments()); |
15267 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); | 15258 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); |
15268 String& class_name = String::Handle(zone); | 15259 String& class_name = String::Handle(zone); |
15269 intptr_t first_type_param_index; | 15260 intptr_t first_type_param_index; |
15270 intptr_t num_type_params; // Number of type parameters to print. | 15261 intptr_t num_type_params; // Number of type parameters to print. |
15271 Class& cls = Class::Handle(zone); | 15262 Class& cls = Class::Handle(zone); |
15272 if (IsFunctionType()) { | 15263 if (IsFunctionType()) { |
15273 cls = type_class(); | 15264 cls = type_class(); |
15274 const Function& signature_function = Function::Handle( | 15265 const Function& signature_function = Function::Handle( |
15275 zone, FunctionType::Cast(*this).signature()); | 15266 zone, Type::Cast(*this).signature()); |
15276 if (!cls.IsTypedefClass() || | 15267 if (!cls.IsTypedefClass() || |
15277 (cls.signature_function() != signature_function.raw())) { | 15268 (cls.signature_function() != signature_function.raw())) { |
15278 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { | 15269 if (!IsFinalized() || IsBeingFinalized() || IsMalformed()) { |
15279 return signature_function.UserVisibleSignature(); | 15270 return signature_function.UserVisibleSignature(); |
15280 } | 15271 } |
15281 return signature_function.InstantiatedSignatureFrom(args, | 15272 return signature_function.InstantiatedSignatureFrom(args, |
15282 name_visibility); | 15273 name_visibility); |
15283 } | 15274 } |
15284 class_name = cls.Name(); // Typedef name. | 15275 class_name = cls.Name(); // Typedef name. |
15285 // We may be reporting an error about a malformed function type. In that | 15276 // We may be reporting an error about a malformed function type. In that |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15370 pieces.Add(String::Handle(zone, BuildName(kUserVisibleName))); | 15361 pieces.Add(String::Handle(zone, BuildName(kUserVisibleName))); |
15371 if (!IsDynamicType() && !IsVoidType()) { | 15362 if (!IsDynamicType() && !IsVoidType()) { |
15372 pieces.Add(Symbols::SpaceWhereNewLine()); | 15363 pieces.Add(Symbols::SpaceWhereNewLine()); |
15373 pieces.Add(String::Handle(zone, EnumerateURIs())); | 15364 pieces.Add(String::Handle(zone, EnumerateURIs())); |
15374 } | 15365 } |
15375 return Symbols::FromConcatAll(pieces); | 15366 return Symbols::FromConcatAll(pieces); |
15376 } | 15367 } |
15377 | 15368 |
15378 | 15369 |
15379 RawString* AbstractType::ClassName() const { | 15370 RawString* AbstractType::ClassName() const { |
| 15371 ASSERT(!IsFunctionType()); |
15380 if (HasResolvedTypeClass()) { | 15372 if (HasResolvedTypeClass()) { |
15381 return Class::Handle(type_class()).Name(); | 15373 return Class::Handle(type_class()).Name(); |
15382 } else { | 15374 } else { |
15383 return UnresolvedClass::Handle(unresolved_class()).Name(); | 15375 return UnresolvedClass::Handle(unresolved_class()).Name(); |
15384 } | 15376 } |
15385 } | 15377 } |
15386 | 15378 |
15387 | 15379 |
15388 bool AbstractType::IsNullType() const { | 15380 bool AbstractType::IsNullType() const { |
15389 return HasResolvedTypeClass() && | 15381 return !IsFunctionType() && |
| 15382 HasResolvedTypeClass() && |
15390 (type_class() == Isolate::Current()->object_store()->null_class()); | 15383 (type_class() == Isolate::Current()->object_store()->null_class()); |
15391 } | 15384 } |
15392 | 15385 |
15393 | 15386 |
15394 bool AbstractType::IsBoolType() const { | 15387 bool AbstractType::IsBoolType() const { |
15395 return HasResolvedTypeClass() && | 15388 return !IsFunctionType() && |
| 15389 HasResolvedTypeClass() && |
15396 (type_class() == Isolate::Current()->object_store()->bool_class()); | 15390 (type_class() == Isolate::Current()->object_store()->bool_class()); |
15397 } | 15391 } |
15398 | 15392 |
15399 | 15393 |
15400 bool AbstractType::IsIntType() const { | 15394 bool AbstractType::IsIntType() const { |
15401 return HasResolvedTypeClass() && | 15395 return !IsFunctionType() && |
| 15396 HasResolvedTypeClass() && |
15402 (type_class() == Type::Handle(Type::IntType()).type_class()); | 15397 (type_class() == Type::Handle(Type::IntType()).type_class()); |
15403 } | 15398 } |
15404 | 15399 |
15405 | 15400 |
15406 bool AbstractType::IsDoubleType() const { | 15401 bool AbstractType::IsDoubleType() const { |
15407 return HasResolvedTypeClass() && | 15402 return !IsFunctionType() && |
| 15403 HasResolvedTypeClass() && |
15408 (type_class() == Type::Handle(Type::Double()).type_class()); | 15404 (type_class() == Type::Handle(Type::Double()).type_class()); |
15409 } | 15405 } |
15410 | 15406 |
15411 | 15407 |
15412 bool AbstractType::IsFloat32x4Type() const { | 15408 bool AbstractType::IsFloat32x4Type() const { |
15413 return HasResolvedTypeClass() && | 15409 return !IsFunctionType() && |
| 15410 HasResolvedTypeClass() && |
15414 (type_class() == Type::Handle(Type::Float32x4()).type_class()); | 15411 (type_class() == Type::Handle(Type::Float32x4()).type_class()); |
15415 } | 15412 } |
15416 | 15413 |
15417 | 15414 |
15418 bool AbstractType::IsFloat64x2Type() const { | 15415 bool AbstractType::IsFloat64x2Type() const { |
15419 return HasResolvedTypeClass() && | 15416 return !IsFunctionType() && |
| 15417 HasResolvedTypeClass() && |
15420 (type_class() == Type::Handle(Type::Float64x2()).type_class()); | 15418 (type_class() == Type::Handle(Type::Float64x2()).type_class()); |
15421 } | 15419 } |
15422 | 15420 |
15423 | 15421 |
15424 bool AbstractType::IsInt32x4Type() const { | 15422 bool AbstractType::IsInt32x4Type() const { |
15425 return HasResolvedTypeClass() && | 15423 return !IsFunctionType() && |
| 15424 HasResolvedTypeClass() && |
15426 (type_class() == Type::Handle(Type::Int32x4()).type_class()); | 15425 (type_class() == Type::Handle(Type::Int32x4()).type_class()); |
15427 } | 15426 } |
15428 | 15427 |
15429 | 15428 |
15430 bool AbstractType::IsNumberType() const { | 15429 bool AbstractType::IsNumberType() const { |
15431 return HasResolvedTypeClass() && | 15430 return !IsFunctionType() && |
| 15431 HasResolvedTypeClass() && |
15432 (type_class() == Type::Handle(Type::Number()).type_class()); | 15432 (type_class() == Type::Handle(Type::Number()).type_class()); |
15433 } | 15433 } |
15434 | 15434 |
15435 | 15435 |
15436 bool AbstractType::IsSmiType() const { | 15436 bool AbstractType::IsSmiType() const { |
15437 return HasResolvedTypeClass() && | 15437 return !IsFunctionType() && |
| 15438 HasResolvedTypeClass() && |
15438 (type_class() == Type::Handle(Type::SmiType()).type_class()); | 15439 (type_class() == Type::Handle(Type::SmiType()).type_class()); |
15439 } | 15440 } |
15440 | 15441 |
15441 | 15442 |
15442 bool AbstractType::IsStringType() const { | 15443 bool AbstractType::IsStringType() const { |
15443 return HasResolvedTypeClass() && | 15444 return !IsFunctionType() && |
| 15445 HasResolvedTypeClass() && |
15444 (type_class() == Type::Handle(Type::StringType()).type_class()); | 15446 (type_class() == Type::Handle(Type::StringType()).type_class()); |
15445 } | 15447 } |
15446 | 15448 |
15447 | 15449 |
15448 bool AbstractType::IsDartFunctionType() const { | 15450 bool AbstractType::IsDartFunctionType() const { |
15449 return HasResolvedTypeClass() && | 15451 return !IsFunctionType() && |
15450 (type_class() == Type::Handle(Type::Function()).type_class()); | 15452 HasResolvedTypeClass() && |
| 15453 (type_class() == Type::Handle(Type::DartFunctionType()).type_class()); |
15451 } | 15454 } |
15452 | 15455 |
15453 | 15456 |
15454 bool AbstractType::TypeTest(TypeTestKind test_kind, | 15457 bool AbstractType::TypeTest(TypeTestKind test_kind, |
15455 const AbstractType& other, | 15458 const AbstractType& other, |
15456 Error* bound_error, | 15459 Error* bound_error, |
15457 TrailPtr bound_trail, | 15460 TrailPtr bound_trail, |
15458 Heap::Space space) const { | 15461 Heap::Space space) const { |
15459 ASSERT(IsFinalized()); | 15462 ASSERT(IsFinalized()); |
15460 ASSERT(other.IsFinalized()); | 15463 ASSERT(other.IsFinalized()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15538 if (other.IsTypeParameter()) { | 15541 if (other.IsTypeParameter()) { |
15539 const TypeParameter& other_type_param = TypeParameter::Cast(other); | 15542 const TypeParameter& other_type_param = TypeParameter::Cast(other); |
15540 if (type_param.Equals(other_type_param)) { | 15543 if (type_param.Equals(other_type_param)) { |
15541 return true; | 15544 return true; |
15542 } | 15545 } |
15543 } | 15546 } |
15544 const AbstractType& bound = AbstractType::Handle(zone, type_param.bound()); | 15547 const AbstractType& bound = AbstractType::Handle(zone, type_param.bound()); |
15545 // We may be checking bounds at finalization time and can encounter | 15548 // We may be checking bounds at finalization time and can encounter |
15546 // a still unfinalized bound. Finalizing the bound here may lead to cycles. | 15549 // a still unfinalized bound. Finalizing the bound here may lead to cycles. |
15547 if (!bound.IsFinalized()) { | 15550 if (!bound.IsFinalized()) { |
15548 return false; // TODO(regis): Return "maybe after instantiation". | 15551 return false; // TODO(regis): Return "maybe after instantiation". |
15549 } | 15552 } |
15550 // The current bound_trail cannot be used, because operands are swapped and | 15553 // The current bound_trail cannot be used, because operands are swapped and |
15551 // the test is different anyway (more specific vs. subtype). | 15554 // the test is different anyway (more specific vs. subtype). |
15552 if (bound.IsMoreSpecificThan(other, bound_error, NULL, space)) { | 15555 if (bound.IsMoreSpecificThan(other, bound_error, NULL, space)) { |
15553 return true; | 15556 return true; |
15554 } | 15557 } |
15555 return false; // TODO(regis): We should return "maybe after instantiation". | 15558 return false; // TODO(regis): We should return "maybe after instantiation". |
15556 } | 15559 } |
15557 if (other.IsTypeParameter()) { | 15560 if (other.IsTypeParameter()) { |
15558 return false; // TODO(regis): We should return "maybe after instantiation". | 15561 return false; // TODO(regis): We should return "maybe after instantiation". |
15559 } | 15562 } |
15560 const Class& type_cls = Class::Handle(zone, type_class()); | 15563 const Class& type_cls = Class::Handle(zone, type_class()); |
15561 // Function types cannot be handled by Class::TypeTest(). | 15564 // Function types cannot be handled by Class::TypeTest(). |
15562 const bool other_is_dart_function_type = other.IsDartFunctionType(); | 15565 const bool other_is_dart_function_type = other.IsDartFunctionType(); |
15563 if (other_is_dart_function_type || other.IsFunctionType()) { | 15566 if (other_is_dart_function_type || other.IsFunctionType()) { |
15564 if (IsFunctionType()) { | 15567 if (IsFunctionType()) { |
15565 if (other_is_dart_function_type) { | 15568 if (other_is_dart_function_type) { |
15566 return true; | 15569 return true; |
15567 } | 15570 } |
15568 const Function& other_fun = | 15571 const Function& other_fun = |
15569 Function::Handle(zone, FunctionType::Cast(other).signature()); | 15572 Function::Handle(zone, Type::Cast(other).signature()); |
15570 // Check for two function types. | 15573 // Check for two function types. |
15571 const Function& fun = | 15574 const Function& fun = |
15572 Function::Handle(zone, FunctionType::Cast(*this).signature()); | 15575 Function::Handle(zone, Type::Cast(*this).signature()); |
15573 return fun.TypeTest(test_kind, | 15576 return fun.TypeTest(test_kind, |
15574 TypeArguments::Handle(zone, arguments()), | 15577 TypeArguments::Handle(zone, arguments()), |
15575 other_fun, | 15578 other_fun, |
15576 TypeArguments::Handle(zone, other.arguments()), | 15579 TypeArguments::Handle(zone, other.arguments()), |
15577 bound_error, | 15580 bound_error, |
15578 space); | 15581 space); |
15579 } | 15582 } |
15580 // Check if type S has a call() method of function type T. | 15583 // Check if type S has a call() method of function type T. |
15581 Function& function = Function::Handle(zone, | 15584 Function& function = Function::Handle(zone, |
15582 type_cls.LookupDynamicFunctionAllowAbstract(Symbols::Call())); | 15585 type_cls.LookupDynamicFunctionAllowAbstract(Symbols::Call())); |
15583 if (function.IsNull()) { | 15586 if (function.IsNull()) { |
15584 // Walk up the super_class chain. | 15587 // Walk up the super_class chain. |
15585 Class& cls = Class::Handle(zone, type_cls.SuperClass()); | 15588 Class& cls = Class::Handle(zone, type_cls.SuperClass()); |
15586 while (!cls.IsNull() && function.IsNull()) { | 15589 while (!cls.IsNull() && function.IsNull()) { |
15587 function = cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); | 15590 function = cls.LookupDynamicFunctionAllowAbstract(Symbols::Call()); |
15588 cls = cls.SuperClass(); | 15591 cls = cls.SuperClass(); |
15589 } | 15592 } |
15590 } | 15593 } |
15591 if (!function.IsNull()) { | 15594 if (!function.IsNull()) { |
15592 if (other_is_dart_function_type || | 15595 if (other_is_dart_function_type || |
15593 function.TypeTest(test_kind, | 15596 function.TypeTest(test_kind, |
15594 TypeArguments::Handle(zone, arguments()), | 15597 TypeArguments::Handle(zone, arguments()), |
15595 Function::Handle( | 15598 Function::Handle( |
15596 zone, FunctionType::Cast(other).signature()), | 15599 zone, Type::Cast(other).signature()), |
15597 TypeArguments::Handle(zone, other.arguments()), | 15600 TypeArguments::Handle(zone, other.arguments()), |
15598 bound_error, | 15601 bound_error, |
15599 space)) { | 15602 space)) { |
15600 return true; | 15603 return true; |
15601 } | 15604 } |
15602 } | 15605 } |
15603 } | 15606 } |
15604 if (IsFunctionType()) { | 15607 if (IsFunctionType()) { |
15605 return false; | 15608 return false; |
15606 } | 15609 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15696 RawType* Type::StringType() { | 15699 RawType* Type::StringType() { |
15697 return Isolate::Current()->object_store()->string_type(); | 15700 return Isolate::Current()->object_store()->string_type(); |
15698 } | 15701 } |
15699 | 15702 |
15700 | 15703 |
15701 RawType* Type::ArrayType() { | 15704 RawType* Type::ArrayType() { |
15702 return Isolate::Current()->object_store()->array_type(); | 15705 return Isolate::Current()->object_store()->array_type(); |
15703 } | 15706 } |
15704 | 15707 |
15705 | 15708 |
15706 RawType* Type::Function() { | 15709 RawType* Type::DartFunctionType() { |
15707 return Isolate::Current()->object_store()->function_type(); | 15710 return Isolate::Current()->object_store()->function_type(); |
15708 } | 15711 } |
15709 | 15712 |
15710 | 15713 |
15711 RawType* Type::NewNonParameterizedType(const Class& type_class) { | 15714 RawType* Type::NewNonParameterizedType(const Class& type_class) { |
15712 ASSERT(type_class.NumTypeArguments() == 0); | 15715 ASSERT(type_class.NumTypeArguments() == 0); |
15713 Type& type = Type::Handle(type_class.CanonicalType()); | 15716 Type& type = Type::Handle(type_class.CanonicalType()); |
15714 if (type.IsNull()) { | 15717 if (type.IsNull()) { |
15715 const TypeArguments& no_type_arguments = TypeArguments::Handle(); | 15718 const TypeArguments& no_type_arguments = TypeArguments::Handle(); |
15716 type ^= Type::New(Object::Handle(type_class.raw()), | 15719 type ^= Type::New(Object::Handle(type_class.raw()), |
(...skipping 11 matching lines...) Expand all Loading... |
15728 ASSERT(!IsFinalized()); | 15731 ASSERT(!IsFinalized()); |
15729 if (IsInstantiated()) { | 15732 if (IsInstantiated()) { |
15730 ASSERT(HasResolvedTypeClass()); | 15733 ASSERT(HasResolvedTypeClass()); |
15731 set_type_state(RawType::kFinalizedInstantiated); | 15734 set_type_state(RawType::kFinalizedInstantiated); |
15732 } else { | 15735 } else { |
15733 set_type_state(RawType::kFinalizedUninstantiated); | 15736 set_type_state(RawType::kFinalizedUninstantiated); |
15734 } | 15737 } |
15735 } | 15738 } |
15736 | 15739 |
15737 | 15740 |
| 15741 void Type::ResetIsFinalized() const { |
| 15742 ASSERT(IsFinalized()); |
| 15743 set_type_state(RawType::kBeingFinalized); |
| 15744 SetIsFinalized(); |
| 15745 } |
| 15746 |
| 15747 |
15738 void Type::SetIsBeingFinalized() const { | 15748 void Type::SetIsBeingFinalized() const { |
15739 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized()); | 15749 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized()); |
15740 set_type_state(RawType::kBeingFinalized); | 15750 set_type_state(RawType::kBeingFinalized); |
15741 } | 15751 } |
15742 | 15752 |
15743 | 15753 |
15744 bool Type::IsMalformed() const { | 15754 bool Type::IsMalformed() const { |
15745 if (raw_ptr()->error_ == LanguageError::null()) { | 15755 if (raw_ptr()->sig_or_err_.error_ == LanguageError::null()) { |
15746 return false; | 15756 return false; // Valid type, but not a function type. |
15747 } | 15757 } |
15748 const LanguageError& type_error = LanguageError::Handle(error()); | 15758 const LanguageError& type_error = LanguageError::Handle(error()); |
| 15759 if (type_error.IsNull()) { |
| 15760 return false; // Valid function type. |
| 15761 } |
15749 return type_error.kind() == Report::kMalformedType; | 15762 return type_error.kind() == Report::kMalformedType; |
15750 } | 15763 } |
15751 | 15764 |
15752 | 15765 |
15753 bool Type::IsMalbounded() const { | 15766 bool Type::IsMalbounded() const { |
| 15767 if (raw_ptr()->sig_or_err_.error_ == LanguageError::null()) { |
| 15768 return false; // Valid type, but not a function type. |
| 15769 } |
15754 if (!Isolate::Current()->type_checks()) { | 15770 if (!Isolate::Current()->type_checks()) { |
15755 return false; | 15771 return false; |
15756 } | 15772 } |
15757 if (raw_ptr()->error_ == LanguageError::null()) { | 15773 const LanguageError& type_error = LanguageError::Handle(error()); |
15758 return false; | 15774 if (type_error.IsNull()) { |
| 15775 return false; // Valid function type. |
15759 } | 15776 } |
15760 const LanguageError& type_error = LanguageError::Handle(error()); | |
15761 return type_error.kind() == Report::kMalboundedType; | 15777 return type_error.kind() == Report::kMalboundedType; |
15762 } | 15778 } |
15763 | 15779 |
15764 | 15780 |
15765 bool Type::IsMalformedOrMalbounded() const { | 15781 bool Type::IsMalformedOrMalbounded() const { |
15766 if (raw_ptr()->error_ == LanguageError::null()) { | 15782 if (raw_ptr()->sig_or_err_.error_ == LanguageError::null()) { |
15767 return false; | 15783 return false; // Valid type, but not a function type. |
15768 } | 15784 } |
15769 const LanguageError& type_error = LanguageError::Handle(error()); | 15785 const LanguageError& type_error = LanguageError::Handle(error()); |
| 15786 if (type_error.IsNull()) { |
| 15787 return false; // Valid function type. |
| 15788 } |
15770 if (type_error.kind() == Report::kMalformedType) { | 15789 if (type_error.kind() == Report::kMalformedType) { |
15771 return true; | 15790 return true; |
15772 } | 15791 } |
15773 ASSERT(type_error.kind() == Report::kMalboundedType); | 15792 ASSERT(type_error.kind() == Report::kMalboundedType); |
15774 return Isolate::Current()->type_checks(); | 15793 return Isolate::Current()->type_checks(); |
15775 } | 15794 } |
15776 | 15795 |
15777 | 15796 |
| 15797 RawLanguageError* Type::error() const { |
| 15798 const Object& type_error = Object::Handle(raw_ptr()->sig_or_err_.error_); |
| 15799 if (type_error.IsLanguageError()) { |
| 15800 return LanguageError::RawCast(type_error.raw()); |
| 15801 } |
| 15802 return LanguageError::null(); |
| 15803 } |
| 15804 |
| 15805 |
15778 void Type::set_error(const LanguageError& value) const { | 15806 void Type::set_error(const LanguageError& value) const { |
15779 StorePointer(&raw_ptr()->error_, value.raw()); | 15807 StorePointer(&raw_ptr()->sig_or_err_.error_, value.raw()); |
| 15808 } |
| 15809 |
| 15810 |
| 15811 RawFunction* Type::signature() const { |
| 15812 if (raw_ptr()->sig_or_err_.signature_ == Function::null()) { |
| 15813 return Function::null(); |
| 15814 } |
| 15815 const Object& obj = Object::Handle(raw_ptr()->sig_or_err_.signature_); |
| 15816 if (obj.IsFunction()) { |
| 15817 return Function::RawCast(obj.raw()); |
| 15818 } |
| 15819 ASSERT(obj.IsLanguageError()); // Type is malformed or malbounded. |
| 15820 return Function::null(); |
| 15821 } |
| 15822 |
| 15823 |
| 15824 void Type::set_signature(const Function& value) const { |
| 15825 StorePointer(&raw_ptr()->sig_or_err_.signature_, value.raw()); |
15780 } | 15826 } |
15781 | 15827 |
15782 | 15828 |
15783 void Type::SetIsResolved() const { | 15829 void Type::SetIsResolved() const { |
15784 ASSERT(!IsResolved()); | 15830 ASSERT(!IsResolved()); |
15785 // A Typedef is a FunctionType, not a type. | |
15786 ASSERT(!Class::Handle(type_class()).IsTypedefClass()); | |
15787 set_type_state(RawType::kResolved); | 15831 set_type_state(RawType::kResolved); |
15788 } | 15832 } |
15789 | 15833 |
15790 | 15834 |
15791 bool Type::HasResolvedTypeClass() const { | 15835 bool Type::HasResolvedTypeClass() const { |
15792 const Object& type_class = Object::Handle(raw_ptr()->type_class_); | 15836 const Object& type_class = Object::Handle(raw_ptr()->type_class_); |
15793 return !type_class.IsNull() && type_class.IsClass(); | 15837 return !type_class.IsNull() && type_class.IsClass(); |
15794 } | 15838 } |
15795 | 15839 |
15796 | 15840 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15877 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); | 15921 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); |
15878 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, | 15922 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, |
15879 bound_error, | 15923 bound_error, |
15880 instantiation_trail, | 15924 instantiation_trail, |
15881 bound_trail, | 15925 bound_trail, |
15882 space); | 15926 space); |
15883 // This uninstantiated type is not modified, as it can be instantiated | 15927 // This uninstantiated type is not modified, as it can be instantiated |
15884 // with different instantiators. Allocate a new instantiated version of it. | 15928 // with different instantiators. Allocate a new instantiated version of it. |
15885 const Type& instantiated_type = | 15929 const Type& instantiated_type = |
15886 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space)); | 15930 Type::Handle(zone, Type::New(cls, type_arguments, token_pos(), space)); |
| 15931 // Preserve the bound error if any. |
| 15932 if (IsMalbounded()) { |
| 15933 const LanguageError& bound_error = LanguageError::Handle(zone, error()); |
| 15934 instantiated_type.set_error(bound_error); |
| 15935 } |
| 15936 // Preserve the signature if this type represents a function type. |
| 15937 // Note that the types in the signature remain unchanged. They get indirectly |
| 15938 // instantiated by instantiating the type arguments above. |
| 15939 const Function& sig_fun = Function::Handle(zone, signature()); |
| 15940 if (!sig_fun.IsNull()) { |
| 15941 instantiated_type.set_signature(sig_fun); |
| 15942 } |
15887 if (IsFinalized()) { | 15943 if (IsFinalized()) { |
15888 instantiated_type.SetIsFinalized(); | 15944 instantiated_type.SetIsFinalized(); |
15889 } else { | 15945 } else { |
15890 instantiated_type.SetIsResolved(); | 15946 instantiated_type.SetIsResolved(); |
15891 } | 15947 } |
15892 // Canonicalization is not part of instantiation. | 15948 // Canonicalization is not part of instantiation. |
15893 return instantiated_type.raw(); | 15949 return instantiated_type.raw(); |
15894 } | 15950 } |
15895 | 15951 |
15896 | 15952 |
15897 bool Type::IsEquivalent(const Instance& other, TrailPtr trail) const { | 15953 bool Type::IsEquivalent(const Instance& other, TrailPtr trail) const { |
15898 ASSERT(!IsNull()); | 15954 ASSERT(!IsNull()); |
15899 if (raw() == other.raw()) { | 15955 if (raw() == other.raw()) { |
15900 return true; | 15956 return true; |
15901 } | 15957 } |
15902 if (other.IsTypeRef()) { | 15958 if (other.IsTypeRef()) { |
15903 // Unfold right hand type. Divergence is controlled by left hand type. | 15959 // Unfold right hand type. Divergence is controlled by left hand type. |
15904 const AbstractType& other_ref_type = AbstractType::Handle( | 15960 const AbstractType& other_ref_type = AbstractType::Handle( |
15905 TypeRef::Cast(other).type()); | 15961 TypeRef::Cast(other).type()); |
15906 ASSERT(!other_ref_type.IsTypeRef()); | 15962 ASSERT(!other_ref_type.IsTypeRef()); |
15907 return IsEquivalent(other_ref_type, trail); | 15963 return IsEquivalent(other_ref_type, trail); |
15908 } | 15964 } |
15909 if (!other.IsType()) { | 15965 if (!other.IsType()) { |
15910 return false; | 15966 return false; |
15911 } | 15967 } |
15912 const Type& other_type = Type::Cast(other); | 15968 const Type& other_type = Type::Cast(other); |
| 15969 if (IsFunctionType() != other_type.IsFunctionType()) { |
| 15970 return false; |
| 15971 } |
15913 ASSERT(IsResolved() && other_type.IsResolved()); | 15972 ASSERT(IsResolved() && other_type.IsResolved()); |
15914 if (IsMalformed() || other_type.IsMalformed()) { | 15973 if (IsMalformed() || other_type.IsMalformed()) { |
15915 return false; | 15974 return false; // Malformed types do not get canonicalized. |
| 15975 } |
| 15976 if (IsMalbounded() != other_type.IsMalbounded()) { |
| 15977 return false; // Do not drop bound error. |
15916 } | 15978 } |
15917 if (type_class() != other_type.type_class()) { | 15979 if (type_class() != other_type.type_class()) { |
15918 return false; | 15980 return false; |
15919 } | 15981 } |
15920 if (!IsFinalized() || !other_type.IsFinalized()) { | 15982 if (!IsFinalized() || !other_type.IsFinalized()) { |
15921 return false; | 15983 return false; // Too early to decide if equal. |
15922 } | 15984 } |
15923 if (arguments() == other_type.arguments()) { | 15985 if ((arguments() == other_type.arguments()) && |
| 15986 (signature() == other_type.signature())) { |
15924 return true; | 15987 return true; |
15925 } | 15988 } |
15926 Thread* thread = Thread::Current(); | 15989 Thread* thread = Thread::Current(); |
15927 Zone* zone = thread->zone(); | 15990 Zone* zone = thread->zone(); |
| 15991 if (arguments() != other_type.arguments()) { |
15928 const Class& cls = Class::Handle(zone, type_class()); | 15992 const Class& cls = Class::Handle(zone, type_class()); |
15929 const intptr_t num_type_params = cls.NumTypeParameters(thread); | 15993 const intptr_t num_type_params = cls.NumTypeParameters(thread); |
15930 if (num_type_params == 0) { | 15994 // Shortcut unnecessary handle allocation below if non-generic. |
15931 // Shortcut unnecessary handle allocation below. | 15995 if (num_type_params > 0) { |
| 15996 const intptr_t num_type_args = cls.NumTypeArguments(); |
| 15997 const intptr_t from_index = num_type_args - num_type_params; |
| 15998 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
| 15999 const TypeArguments& other_type_args = TypeArguments::Handle( |
| 16000 zone, other_type.arguments()); |
| 16001 if (type_args.IsNull()) { |
| 16002 // Ignore from_index. |
| 16003 if (!other_type_args.IsRaw(0, num_type_args)) { |
| 16004 return false; |
| 16005 } |
| 16006 } else if (other_type_args.IsNull()) { |
| 16007 // Ignore from_index. |
| 16008 if (!type_args.IsRaw(0, num_type_args)) { |
| 16009 return false; |
| 16010 } |
| 16011 } else if (!type_args.IsSubvectorEquivalent(other_type_args, |
| 16012 from_index, |
| 16013 num_type_params)) { |
| 16014 return false; |
| 16015 } |
| 16016 #ifdef DEBUG |
| 16017 if (from_index > 0) { |
| 16018 // Verify that the type arguments of the super class match, since they |
| 16019 // depend solely on the type parameters that were just verified to |
| 16020 // match. |
| 16021 ASSERT(type_args.Length() >= (from_index + num_type_params)); |
| 16022 ASSERT(other_type_args.Length() >= (from_index + num_type_params)); |
| 16023 AbstractType& type_arg = AbstractType::Handle(zone); |
| 16024 AbstractType& other_type_arg = AbstractType::Handle(zone); |
| 16025 for (intptr_t i = 0; i < from_index; i++) { |
| 16026 type_arg = type_args.TypeAt(i); |
| 16027 other_type_arg = other_type_args.TypeAt(i); |
| 16028 // Ignore bounds of bounded types. |
| 16029 while (type_arg.IsBoundedType()) { |
| 16030 type_arg = BoundedType::Cast(type_arg).type(); |
| 16031 } |
| 16032 while (other_type_arg.IsBoundedType()) { |
| 16033 other_type_arg = BoundedType::Cast(other_type_arg).type(); |
| 16034 } |
| 16035 ASSERT(type_arg.IsEquivalent(other_type_arg, trail)); |
| 16036 } |
| 16037 } |
| 16038 #endif |
| 16039 } |
| 16040 } |
| 16041 if (!IsFunctionType()) { |
15932 return true; | 16042 return true; |
15933 } | 16043 } |
15934 const intptr_t num_type_args = cls.NumTypeArguments(); | 16044 ASSERT(Type::Cast(other).IsFunctionType()); |
15935 const intptr_t from_index = num_type_args - num_type_params; | 16045 // Equal function types must have equal signature types and equal optional |
15936 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); | 16046 // named arguments. |
15937 const TypeArguments& other_type_args = TypeArguments::Handle( | 16047 if (signature() == other_type.signature()) { |
15938 zone, other_type.arguments()); | 16048 return true; |
15939 if (type_args.IsNull()) { | |
15940 // Ignore from_index. | |
15941 return other_type_args.IsRaw(0, num_type_args); | |
15942 } | 16049 } |
15943 if (other_type_args.IsNull()) { | 16050 const Function& sig_fun = Function::Handle(zone, signature()); |
15944 // Ignore from_index. | 16051 const Function& other_sig_fun = Function::Handle( |
15945 return type_args.IsRaw(0, num_type_args); | 16052 zone, other_type.signature()); |
15946 } | 16053 |
15947 if (!type_args.IsSubvectorEquivalent(other_type_args, | 16054 // Compare number of function parameters. |
15948 from_index, | 16055 const intptr_t num_fixed_params = sig_fun.num_fixed_parameters(); |
15949 num_type_params)) { | 16056 const intptr_t other_num_fixed_params = other_sig_fun.num_fixed_parameters(); |
| 16057 if (num_fixed_params != other_num_fixed_params) { |
15950 return false; | 16058 return false; |
15951 } | 16059 } |
15952 #ifdef DEBUG | 16060 const intptr_t num_opt_pos_params = sig_fun.NumOptionalPositionalParameters(); |
15953 if (from_index > 0) { | 16061 const intptr_t other_num_opt_pos_params = |
15954 // Verify that the type arguments of the super class match, since they | 16062 other_sig_fun.NumOptionalPositionalParameters(); |
15955 // depend solely on the type parameters that were just verified to match. | 16063 if (num_opt_pos_params != other_num_opt_pos_params) { |
15956 ASSERT(type_args.Length() >= (from_index + num_type_params)); | 16064 return false; |
15957 ASSERT(other_type_args.Length() >= (from_index + num_type_params)); | 16065 } |
15958 AbstractType& type_arg = AbstractType::Handle(zone); | 16066 const intptr_t num_opt_named_params = sig_fun.NumOptionalNamedParameters(); |
15959 AbstractType& other_type_arg = AbstractType::Handle(zone); | 16067 const intptr_t other_num_opt_named_params = |
15960 for (intptr_t i = 0; i < from_index; i++) { | 16068 other_sig_fun.NumOptionalNamedParameters(); |
15961 type_arg = type_args.TypeAt(i); | 16069 if (num_opt_named_params != other_num_opt_named_params) { |
15962 other_type_arg = other_type_args.TypeAt(i); | 16070 return false; |
15963 // Ignore bounds of bounded types. | 16071 } |
15964 while (type_arg.IsBoundedType()) { | 16072 const intptr_t num_ignored_params = sig_fun.NumImplicitParameters(); |
15965 type_arg = BoundedType::Cast(type_arg).type(); | 16073 const intptr_t other_num_ignored_params = |
15966 } | 16074 other_sig_fun.NumImplicitParameters(); |
15967 while (other_type_arg.IsBoundedType()) { | 16075 if (num_ignored_params != other_num_ignored_params) { |
15968 other_type_arg = BoundedType::Cast(other_type_arg).type(); | 16076 return false; |
15969 } | 16077 } |
15970 ASSERT(type_arg.IsEquivalent(other_type_arg, trail)); | 16078 AbstractType& param_type = Type::Handle(zone); |
| 16079 AbstractType& other_param_type = Type::Handle(zone); |
| 16080 // Check the result type. |
| 16081 param_type = sig_fun.result_type(); |
| 16082 other_param_type = other_sig_fun.result_type(); |
| 16083 if (!param_type.Equals(other_param_type)) { |
| 16084 return false; |
| 16085 } |
| 16086 // Check the types of all parameters. |
| 16087 const intptr_t num_params = sig_fun.NumParameters(); |
| 16088 ASSERT(other_sig_fun.NumParameters() == num_params); |
| 16089 for (intptr_t i = 0; i < num_params; i++) { |
| 16090 param_type = sig_fun.ParameterTypeAt(i); |
| 16091 other_param_type = other_sig_fun.ParameterTypeAt(i); |
| 16092 if (!param_type.Equals(other_param_type)) { |
| 16093 return false; |
15971 } | 16094 } |
15972 } | 16095 } |
15973 #endif | 16096 // Check the names and types of optional named parameters. |
| 16097 if (num_opt_named_params == 0) { |
| 16098 return true; |
| 16099 } |
| 16100 for (intptr_t i = num_fixed_params; i < num_params; i++) { |
| 16101 if (sig_fun.ParameterNameAt(i) != other_sig_fun.ParameterNameAt(i)) { |
| 16102 return false; |
| 16103 } |
| 16104 } |
15974 return true; | 16105 return true; |
15975 } | 16106 } |
15976 | 16107 |
15977 | 16108 |
15978 bool Type::IsRecursive() const { | 16109 bool Type::IsRecursive() const { |
15979 return TypeArguments::Handle(arguments()).IsRecursive(); | 16110 return TypeArguments::Handle(arguments()).IsRecursive(); |
15980 } | 16111 } |
15981 | 16112 |
15982 | 16113 |
15983 RawAbstractType* Type::CloneUnfinalized() const { | 16114 RawAbstractType* Type::CloneUnfinalized() const { |
15984 ASSERT(IsResolved()); | 16115 ASSERT(IsResolved()); |
15985 if (IsFinalized()) { | 16116 if (IsFinalized()) { |
15986 return raw(); | 16117 return raw(); |
15987 } | 16118 } |
15988 ASSERT(!IsMalformed()); // Malformed types are finalized. | 16119 ASSERT(!IsMalformed()); // Malformed types are finalized. |
15989 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. | 16120 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. |
15990 TypeArguments& type_args = TypeArguments::Handle(arguments()); | 16121 Zone* zone = Thread::Current()->zone(); |
15991 type_args = type_args.CloneUnfinalized(); | 16122 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
15992 const Type& clone = Type::Handle( | 16123 const TypeArguments& type_args_clone = |
15993 Type::New(Class::Handle(type_class()), type_args, token_pos())); | 16124 TypeArguments::Handle(zone, type_args.CloneUnfinalized()); |
| 16125 if (type_args_clone.raw() == type_args.raw()) { |
| 16126 return raw(); |
| 16127 } |
| 16128 const Type& clone = Type::Handle(zone, |
| 16129 Type::New(Class::Handle(zone, type_class()), type_args, token_pos())); |
| 16130 // Preserve the bound error if any. |
| 16131 if (IsMalbounded()) { |
| 16132 const LanguageError& bound_error = LanguageError::Handle(zone, error()); |
| 16133 clone.set_error(bound_error); |
| 16134 } |
| 16135 // Clone the signature if this type represents a function type. |
| 16136 Function& fun = Function::Handle(zone, signature()); |
| 16137 if (!fun.IsNull()) { |
| 16138 const Class& owner = Class::Handle(zone, fun.Owner()); |
| 16139 Function& fun_clone = Function::Handle(zone, |
| 16140 Function::NewSignatureFunction(owner, TokenPosition::kNoSource)); |
| 16141 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); |
| 16142 type = type.CloneUnfinalized(); |
| 16143 fun_clone.set_result_type(type); |
| 16144 const intptr_t num_params = fun.NumParameters(); |
| 16145 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); |
| 16146 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), |
| 16147 fun.HasOptionalPositionalParameters()); |
| 16148 fun_clone.set_parameter_types(Array::Handle(Array::New(num_params, |
| 16149 Heap::kOld))); |
| 16150 for (intptr_t i = 0; i < num_params; i++) { |
| 16151 type = fun.ParameterTypeAt(i); |
| 16152 type = type.CloneUnfinalized(); |
| 16153 fun_clone.SetParameterTypeAt(i, type); |
| 16154 } |
| 16155 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names())); |
| 16156 clone.set_signature(fun_clone); |
| 16157 } |
15994 clone.SetIsResolved(); | 16158 clone.SetIsResolved(); |
15995 return clone.raw(); | 16159 return clone.raw(); |
15996 } | 16160 } |
15997 | 16161 |
15998 | 16162 |
15999 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner, | 16163 RawAbstractType* Type::CloneUninstantiated(const Class& new_owner, |
16000 TrailPtr trail) const { | 16164 TrailPtr trail) const { |
16001 ASSERT(IsFinalized()); | 16165 ASSERT(IsFinalized()); |
16002 ASSERT(!IsMalformed()); | 16166 ASSERT(!IsMalformed()); |
16003 if (IsInstantiated()) { | 16167 if (IsInstantiated()) { |
16004 return raw(); | 16168 return raw(); |
16005 } | 16169 } |
16006 // We may recursively encounter a type already being cloned, because we clone | 16170 // We may recursively encounter a type already being cloned, because we clone |
16007 // the upper bounds of its uninstantiated type arguments in the same pass. | 16171 // the upper bounds of its uninstantiated type arguments in the same pass. |
16008 Type& clone = Type::Handle(); | 16172 Zone* zone = Thread::Current()->zone(); |
| 16173 Type& clone = Type::Handle(zone); |
16009 clone ^= OnlyBuddyInTrail(trail); | 16174 clone ^= OnlyBuddyInTrail(trail); |
16010 if (!clone.IsNull()) { | 16175 if (!clone.IsNull()) { |
16011 return clone.raw(); | 16176 return clone.raw(); |
16012 } | 16177 } |
16013 const Class& type_cls = Class::Handle(type_class()); | 16178 const Class& type_cls = Class::Handle(zone, type_class()); |
16014 clone = Type::New(type_cls, TypeArguments::Handle(), token_pos()); | 16179 clone = Type::New(type_cls, TypeArguments::Handle(zone), token_pos()); |
16015 TypeArguments& type_args = TypeArguments::Handle(arguments()); | 16180 // Preserve the bound error if any. |
| 16181 if (IsMalbounded()) { |
| 16182 const LanguageError& bound_error = LanguageError::Handle(zone, error()); |
| 16183 clone.set_error(bound_error); |
| 16184 } |
| 16185 // Clone the signature if this type represents a function type. |
| 16186 const Function& fun = Function::Handle(zone, signature()); |
| 16187 if (!fun.IsNull()) { |
| 16188 Function& fun_clone = Function::Handle(zone, |
| 16189 Function::NewSignatureFunction(new_owner, TokenPosition::kNoSource)); |
| 16190 AbstractType& type = AbstractType::Handle(zone, fun.result_type()); |
| 16191 type = type.CloneUninstantiated(new_owner, trail); |
| 16192 fun_clone.set_result_type(type); |
| 16193 const intptr_t num_params = fun.NumParameters(); |
| 16194 fun_clone.set_num_fixed_parameters(fun.num_fixed_parameters()); |
| 16195 fun_clone.SetNumOptionalParameters(fun.NumOptionalParameters(), |
| 16196 fun.HasOptionalPositionalParameters()); |
| 16197 fun_clone.set_parameter_types(Array::Handle(Array::New(num_params, |
| 16198 Heap::kOld))); |
| 16199 for (intptr_t i = 0; i < num_params; i++) { |
| 16200 type = fun.ParameterTypeAt(i); |
| 16201 type = type.CloneUninstantiated(new_owner, trail); |
| 16202 fun_clone.SetParameterTypeAt(i, type); |
| 16203 } |
| 16204 fun_clone.set_parameter_names(Array::Handle(zone, fun.parameter_names())); |
| 16205 clone.set_signature(fun_clone); |
| 16206 } |
| 16207 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
16016 // Upper bounds of uninstantiated type arguments may form a cycle. | 16208 // Upper bounds of uninstantiated type arguments may form a cycle. |
16017 if (type_args.IsRecursive() || !type_args.IsInstantiated()) { | 16209 if (type_args.IsRecursive() || !type_args.IsInstantiated()) { |
16018 AddOnlyBuddyToTrail(&trail, clone); | 16210 AddOnlyBuddyToTrail(&trail, clone); |
16019 } | 16211 } |
16020 type_args = type_args.CloneUninstantiated(new_owner, trail); | 16212 type_args = type_args.CloneUninstantiated(new_owner, trail); |
16021 clone.set_arguments(type_args); | 16213 clone.set_arguments(type_args); |
16022 clone.SetIsFinalized(); | 16214 clone.SetIsFinalized(); |
16023 return clone.raw(); | 16215 return clone.raw(); |
16024 } | 16216 } |
16025 | 16217 |
16026 | 16218 |
16027 RawAbstractType* Type::Canonicalize(TrailPtr trail) const { | 16219 RawAbstractType* Type::Canonicalize(TrailPtr trail) const { |
16028 ASSERT(IsFinalized()); | 16220 ASSERT(IsFinalized()); |
16029 if (IsCanonical() || IsMalformed()) { | 16221 if (IsCanonical() || IsMalformed()) { |
16030 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld()); | 16222 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld()); |
16031 return this->raw(); | 16223 return this->raw(); |
16032 } | 16224 } |
16033 Thread* thread = Thread::Current(); | 16225 Thread* thread = Thread::Current(); |
16034 Zone* zone = thread->zone(); | 16226 Zone* zone = thread->zone(); |
16035 Isolate* isolate = thread->isolate(); | 16227 Isolate* isolate = thread->isolate(); |
16036 AbstractType& type = Type::Handle(zone); | 16228 AbstractType& type = Type::Handle(zone); |
16037 const Class& cls = Class::Handle(zone, type_class()); | 16229 const Class& cls = Class::Handle(zone, type_class()); |
16038 ASSERT(!cls.IsTypedefClass()); // This type should be a FunctionType. | |
16039 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) { | 16230 if (cls.raw() == Object::dynamic_class() && (isolate != Dart::vm_isolate())) { |
16040 return Object::dynamic_type().raw(); | 16231 return Object::dynamic_type().raw(); |
16041 } | 16232 } |
16042 // Fast canonical lookup/registry for simple types. | 16233 // Fast canonical lookup/registry for simple types. |
16043 if (!cls.IsGeneric() && !cls.IsClosureClass()) { | 16234 if (!cls.IsGeneric() && !cls.IsClosureClass()) { |
| 16235 ASSERT(!IsFunctionType() || cls.IsTypedefClass()); |
16044 type = cls.CanonicalType(); | 16236 type = cls.CanonicalType(); |
16045 if (type.IsNull()) { | 16237 if (type.IsNull()) { |
16046 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate())); | 16238 ASSERT(!cls.raw()->IsVMHeapObject() || (isolate == Dart::vm_isolate())); |
16047 // Canonicalize the type arguments of the supertype, if any. | 16239 // Canonicalize the type arguments of the supertype, if any. |
16048 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); | 16240 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
16049 type_args = type_args.Canonicalize(trail); | 16241 type_args = type_args.Canonicalize(trail); |
16050 if (IsCanonical()) { | 16242 if (IsCanonical()) { |
16051 // Canonicalizing type_args canonicalized this type. | 16243 // Canonicalizing type_args canonicalized this type. |
16052 ASSERT(IsRecursive()); | 16244 ASSERT(IsRecursive()); |
16053 return this->raw(); | 16245 return this->raw(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16097 | 16289 |
16098 // Canonicalize the type arguments. | 16290 // Canonicalize the type arguments. |
16099 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); | 16291 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
16100 // In case the type is first canonicalized at runtime, its type argument | 16292 // In case the type is first canonicalized at runtime, its type argument |
16101 // vector may be longer than necessary. This is not an issue. | 16293 // vector may be longer than necessary. This is not an issue. |
16102 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments())); | 16294 ASSERT(type_args.IsNull() || (type_args.Length() >= cls.NumTypeArguments())); |
16103 type_args = type_args.Canonicalize(trail); | 16295 type_args = type_args.Canonicalize(trail); |
16104 if (IsCanonical()) { | 16296 if (IsCanonical()) { |
16105 // Canonicalizing type_args canonicalized this type as a side effect. | 16297 // Canonicalizing type_args canonicalized this type as a side effect. |
16106 ASSERT(IsRecursive()); | 16298 ASSERT(IsRecursive()); |
| 16299 // Cycles via typedefs are detected and disallowed, but a function type can |
| 16300 // be recursive due to a cycle in its type arguments. |
16107 return this->raw(); | 16301 return this->raw(); |
16108 } | 16302 } |
16109 set_arguments(type_args); | 16303 set_arguments(type_args); |
16110 ASSERT(type_args.IsNull() || type_args.IsOld()); | 16304 ASSERT(type_args.IsNull() || type_args.IsOld()); |
16111 | 16305 |
| 16306 // In case of a function type, replace the actual function by a signature |
| 16307 // function. |
| 16308 if (IsFunctionType()) { |
| 16309 const Function& fun = Function::Handle(zone, signature()); |
| 16310 if (!fun.IsSignatureFunction()) { |
| 16311 Function& sig_fun = Function::Handle(zone, |
| 16312 Function::NewSignatureFunction(cls, TokenPosition::kNoSource)); |
| 16313 type = fun.result_type(); |
| 16314 type = type.Canonicalize(trail); |
| 16315 sig_fun.set_result_type(type); |
| 16316 const intptr_t num_params = fun.NumParameters(); |
| 16317 sig_fun.set_num_fixed_parameters(fun.num_fixed_parameters()); |
| 16318 sig_fun.SetNumOptionalParameters(fun.NumOptionalParameters(), |
| 16319 fun.HasOptionalPositionalParameters()); |
| 16320 sig_fun.set_parameter_types(Array::Handle(Array::New(num_params, |
| 16321 Heap::kOld))); |
| 16322 for (intptr_t i = 0; i < num_params; i++) { |
| 16323 type = fun.ParameterTypeAt(i); |
| 16324 type = type.Canonicalize(trail); |
| 16325 sig_fun.SetParameterTypeAt(i, type); |
| 16326 } |
| 16327 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names())); |
| 16328 set_signature(sig_fun); |
| 16329 } |
| 16330 } |
16112 return cls.LookupOrAddCanonicalType(*this, index); | 16331 return cls.LookupOrAddCanonicalType(*this, index); |
16113 } | 16332 } |
16114 | 16333 |
16115 | 16334 |
16116 RawString* Type::EnumerateURIs() const { | 16335 RawString* Type::EnumerateURIs() const { |
16117 if (IsDynamicType() || IsVoidType()) { | 16336 if (IsDynamicType() || IsVoidType()) { |
16118 return Symbols::Empty().raw(); | 16337 return Symbols::Empty().raw(); |
16119 } | 16338 } |
16120 Zone* zone = Thread::Current()->zone(); | 16339 Zone* zone = Thread::Current()->zone(); |
16121 GrowableHandlePtrArray<const String> pieces(zone, 6); | 16340 GrowableHandlePtrArray<const String> pieces(zone, 6); |
16122 const Class& cls = Class::Handle(zone, type_class()); | 16341 if (IsFunctionType()) { |
16123 pieces.Add(Symbols::TwoSpaces()); | 16342 // The scope class and type arguments do not appear explicitly in the user |
16124 pieces.Add(String::Handle(zone, cls.UserVisibleName())); | 16343 // visible name. The type arguments were used to instantiate the function |
16125 pieces.Add(Symbols::SpaceIsFromSpace()); | 16344 // type prior to this call. |
16126 const Library& library = Library::Handle(zone, cls.library()); | 16345 const Function& sig_fun = Function::Handle(zone, signature()); |
16127 pieces.Add(String::Handle(zone, library.url())); | 16346 AbstractType& type = AbstractType::Handle(zone); |
16128 pieces.Add(Symbols::NewLine()); | 16347 const intptr_t num_params = sig_fun.NumParameters(); |
16129 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); | 16348 GrowableHandlePtrArray<const String> pieces(zone, num_params + 1); |
16130 pieces.Add(String::Handle(zone, type_args.EnumerateURIs())); | 16349 for (intptr_t i = 0; i < num_params; i++) { |
| 16350 type = sig_fun.ParameterTypeAt(i); |
| 16351 pieces.Add(String::Handle(zone, type.EnumerateURIs())); |
| 16352 } |
| 16353 // Handle result type last, since it appears last in the user visible name. |
| 16354 type = sig_fun.result_type(); |
| 16355 pieces.Add(String::Handle(zone, type.EnumerateURIs())); |
| 16356 } else { |
| 16357 const Class& cls = Class::Handle(zone, type_class()); |
| 16358 pieces.Add(Symbols::TwoSpaces()); |
| 16359 pieces.Add(String::Handle(zone, cls.UserVisibleName())); |
| 16360 pieces.Add(Symbols::SpaceIsFromSpace()); |
| 16361 const Library& library = Library::Handle(zone, cls.library()); |
| 16362 pieces.Add(String::Handle(zone, library.url())); |
| 16363 pieces.Add(Symbols::NewLine()); |
| 16364 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
| 16365 pieces.Add(String::Handle(zone, type_args.EnumerateURIs())); |
| 16366 } |
16131 return Symbols::FromConcatAll(pieces); | 16367 return Symbols::FromConcatAll(pieces); |
16132 } | 16368 } |
16133 | 16369 |
16134 | 16370 |
16135 intptr_t Type::Hash() const { | 16371 intptr_t Type::Hash() const { |
16136 ASSERT(IsFinalized()); | 16372 ASSERT(IsFinalized()); |
16137 uint32_t result = 1; | 16373 uint32_t result = 1; |
16138 if (IsMalformed()) return result; | 16374 if (IsMalformed()) return result; |
16139 result = CombineHashes(result, Class::Handle(type_class()).id()); | 16375 result = CombineHashes(result, Class::Handle(type_class()).id()); |
16140 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash()); | 16376 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash()); |
| 16377 if (IsFunctionType()) { |
| 16378 const Function& sig_fun = Function::Handle(signature()); |
| 16379 AbstractType& type = AbstractType::Handle(sig_fun.result_type()); |
| 16380 result = CombineHashes(result, type.Hash()); |
| 16381 result = CombineHashes(result, sig_fun.NumOptionalPositionalParameters()); |
| 16382 const intptr_t num_params = sig_fun.NumParameters(); |
| 16383 for (intptr_t i = 0; i < num_params; i++) { |
| 16384 type = sig_fun.ParameterTypeAt(i); |
| 16385 result = CombineHashes(result, type.Hash()); |
| 16386 } |
| 16387 if (sig_fun.NumOptionalNamedParameters() > 0) { |
| 16388 String& param_name = String::Handle(); |
| 16389 for (intptr_t i = sig_fun.num_fixed_parameters(); i < num_params; i++) { |
| 16390 param_name = sig_fun.ParameterNameAt(i); |
| 16391 result = CombineHashes(result, param_name.Hash()); |
| 16392 } |
| 16393 } |
| 16394 } |
16141 return FinalizeHash(result); | 16395 return FinalizeHash(result); |
16142 } | 16396 } |
16143 | 16397 |
16144 | 16398 |
16145 void Type::set_type_class(const Object& value) const { | 16399 void Type::set_type_class(const Object& value) const { |
16146 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass())); | 16400 ASSERT(!value.IsNull() && (value.IsClass() || value.IsUnresolvedClass())); |
16147 StorePointer(&raw_ptr()->type_class_, value.raw()); | 16401 StorePointer(&raw_ptr()->type_class_, value.raw()); |
16148 } | 16402 } |
16149 | 16403 |
16150 | 16404 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16182 | 16436 |
16183 | 16437 |
16184 void Type::set_type_state(int8_t state) const { | 16438 void Type::set_type_state(int8_t state) const { |
16185 ASSERT((state >= RawType::kAllocated) && | 16439 ASSERT((state >= RawType::kAllocated) && |
16186 (state <= RawType::kFinalizedUninstantiated)); | 16440 (state <= RawType::kFinalizedUninstantiated)); |
16187 StoreNonPointer(&raw_ptr()->type_state_, state); | 16441 StoreNonPointer(&raw_ptr()->type_state_, state); |
16188 } | 16442 } |
16189 | 16443 |
16190 | 16444 |
16191 const char* Type::ToCString() const { | 16445 const char* Type::ToCString() const { |
| 16446 Zone* zone = Thread::Current()->zone(); |
16192 const char* unresolved = IsResolved() ? "" : "Unresolved "; | 16447 const char* unresolved = IsResolved() ? "" : "Unresolved "; |
16193 const TypeArguments& type_arguments = TypeArguments::Handle(arguments()); | 16448 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); |
| 16449 const char* args_cstr = type_args.IsNull() ? "null" : type_args.ToCString(); |
| 16450 Class& cls = Class::Handle(zone); |
16194 const char* class_name; | 16451 const char* class_name; |
16195 if (HasResolvedTypeClass()) { | 16452 if (HasResolvedTypeClass()) { |
16196 class_name = String::Handle( | 16453 cls = type_class(); |
16197 Class::Handle(type_class()).Name()).ToCString(); | 16454 class_name = String::Handle(zone, cls.Name()).ToCString(); |
16198 } else { | 16455 } else { |
16199 class_name = UnresolvedClass::Handle(unresolved_class()).ToCString(); | 16456 class_name = UnresolvedClass::Handle(zone, unresolved_class()).ToCString(); |
16200 } | 16457 } |
16201 if (type_arguments.IsNull()) { | 16458 if (IsFunctionType()) { |
16202 return OS::SCreate(Thread::Current()->zone(), | 16459 const Function& sig_fun = Function::Handle(zone, signature()); |
16203 "%sType: class '%s'", unresolved, class_name); | 16460 const String& sig = IsFinalized() ? |
| 16461 String::Handle(zone, sig_fun.InstantiatedSignatureFrom(type_args, |
| 16462 kInternalName)) : |
| 16463 String::Handle(zone, sig_fun.Signature()); |
| 16464 if (cls.IsClosureClass()) { |
| 16465 ASSERT(type_args.IsNull()); |
| 16466 return OS::SCreate(zone, "%sFunction Type: %s", |
| 16467 unresolved, sig.ToCString()); |
| 16468 } |
| 16469 return OS::SCreate(zone, "%s Function Type: %s (class: %s, args: %s)", |
| 16470 unresolved, |
| 16471 sig.ToCString(), |
| 16472 class_name, |
| 16473 args_cstr); |
| 16474 } |
| 16475 if (type_args.IsNull()) { |
| 16476 return OS::SCreate(zone, "%sType: class '%s'", unresolved, class_name); |
16204 } else if (IsResolved() && IsFinalized() && IsRecursive()) { | 16477 } else if (IsResolved() && IsFinalized() && IsRecursive()) { |
16205 const intptr_t hash = Hash(); | 16478 const intptr_t hash = Hash(); |
16206 const char* args_cstr = TypeArguments::Handle(arguments()).ToCString(); | 16479 return OS::SCreate(zone, "Type: (@%p H%" Px ") class '%s', args:[%s]", |
16207 return OS::SCreate(Thread::Current()->zone(), | 16480 raw(), hash, class_name, args_cstr); |
16208 "Type: (@%p H%" Px ") class '%s', args:[%s]", | |
16209 raw(), hash, class_name, args_cstr); | |
16210 } else { | 16481 } else { |
16211 const char* args_cstr = TypeArguments::Handle(arguments()).ToCString(); | 16482 return OS::SCreate(zone, "%sType: class '%s', args:[%s]", |
16212 return OS::SCreate(Thread::Current()->zone(), | 16483 unresolved, class_name, args_cstr); |
16213 "%sType: class '%s', args:[%s]", unresolved, class_name, args_cstr); | |
16214 } | 16484 } |
16215 } | 16485 } |
16216 | 16486 |
16217 | 16487 |
16218 void FunctionType::SetIsFinalized() const { | |
16219 ASSERT(!IsFinalized()); | |
16220 if (IsInstantiated()) { | |
16221 set_type_state(RawFunctionType::kFinalizedInstantiated); | |
16222 } else { | |
16223 set_type_state(RawFunctionType::kFinalizedUninstantiated); | |
16224 } | |
16225 } | |
16226 | |
16227 | |
16228 void FunctionType::ResetIsFinalized() const { | |
16229 ASSERT(IsFinalized()); | |
16230 set_type_state(RawFunctionType::kBeingFinalized); | |
16231 SetIsFinalized(); | |
16232 } | |
16233 | |
16234 | |
16235 void FunctionType::SetIsBeingFinalized() const { | |
16236 ASSERT(IsResolved() && !IsFinalized() && !IsBeingFinalized()); | |
16237 set_type_state(RawFunctionType::kBeingFinalized); | |
16238 } | |
16239 | |
16240 | |
16241 bool FunctionType::IsMalformed() const { | |
16242 if (raw_ptr()->error_ == LanguageError::null()) { | |
16243 return false; | |
16244 } | |
16245 const LanguageError& type_error = LanguageError::Handle(error()); | |
16246 return type_error.kind() == Report::kMalformedType; | |
16247 } | |
16248 | |
16249 | |
16250 bool FunctionType::IsMalbounded() const { | |
16251 if (!Isolate::Current()->type_checks()) { | |
16252 return false; | |
16253 } | |
16254 if (raw_ptr()->error_ == LanguageError::null()) { | |
16255 return false; | |
16256 } | |
16257 const LanguageError& type_error = LanguageError::Handle(error()); | |
16258 return type_error.kind() == Report::kMalboundedType; | |
16259 } | |
16260 | |
16261 | |
16262 bool FunctionType::IsMalformedOrMalbounded() const { | |
16263 if (raw_ptr()->error_ == LanguageError::null()) { | |
16264 return false; | |
16265 } | |
16266 const LanguageError& type_error = LanguageError::Handle(error()); | |
16267 if (type_error.kind() == Report::kMalformedType) { | |
16268 return true; | |
16269 } | |
16270 ASSERT(type_error.kind() == Report::kMalboundedType); | |
16271 return Isolate::Current()->type_checks(); | |
16272 } | |
16273 | |
16274 | |
16275 void FunctionType::set_error(const LanguageError& value) const { | |
16276 StorePointer(&raw_ptr()->error_, value.raw()); | |
16277 } | |
16278 | |
16279 | |
16280 void FunctionType::SetIsResolved() const { | |
16281 ASSERT(!IsResolved()); | |
16282 set_type_state(RawFunctionType::kResolved); | |
16283 } | |
16284 | |
16285 | |
16286 bool FunctionType::IsInstantiated(TrailPtr trail) const { | |
16287 if (raw_ptr()->type_state_ == RawFunctionType::kFinalizedInstantiated) { | |
16288 return true; | |
16289 } | |
16290 if (raw_ptr()->type_state_ == RawFunctionType::kFinalizedUninstantiated) { | |
16291 return false; | |
16292 } | |
16293 if (arguments() == TypeArguments::null()) { | |
16294 return true; | |
16295 } | |
16296 const Class& scope_cls = Class::Handle(scope_class()); | |
16297 if (!scope_cls.IsGeneric()) { | |
16298 ASSERT(scope_cls.IsClosureClass() || scope_cls.IsTypedefClass()); | |
16299 ASSERT(arguments() == TypeArguments::null()); | |
16300 return true; | |
16301 } | |
16302 const TypeArguments& type_arguments = TypeArguments::Handle(arguments()); | |
16303 const intptr_t num_type_args = scope_cls.NumTypeArguments(); | |
16304 const intptr_t num_type_params = scope_cls.NumTypeParameters(); | |
16305 // The vector may be longer than necessary. An empty vector is handled above. | |
16306 ASSERT(type_arguments.Length() >= num_type_args); | |
16307 return | |
16308 (num_type_params == 0) || | |
16309 type_arguments.IsSubvectorInstantiated(num_type_args - num_type_params, | |
16310 num_type_params); | |
16311 } | |
16312 | |
16313 | |
16314 RawAbstractType* FunctionType::InstantiateFrom( | |
16315 const TypeArguments& instantiator_type_arguments, | |
16316 Error* bound_error, | |
16317 TrailPtr instantiation_trail, | |
16318 TrailPtr bound_trail, | |
16319 Heap::Space space) const { | |
16320 Zone* zone = Thread::Current()->zone(); | |
16321 ASSERT(IsFinalized() || IsBeingFinalized()); | |
16322 ASSERT(!IsInstantiated()); | |
16323 ASSERT(!IsMalformed()); // FunctionType cannot be malformed. | |
16324 // Instantiating this type with its own type arguments as instantiator can | |
16325 // occur during finalization and bounds checking. Return the type unchanged. | |
16326 if (arguments() == instantiator_type_arguments.raw()) { | |
16327 return raw(); | |
16328 } | |
16329 // Note that the scope class has to be resolved at this time, but not | |
16330 // necessarily finalized yet. We may be checking bounds at compile time or | |
16331 // finalizing the type argument vector of a recursive type. | |
16332 const Class& cls = Class::Handle(zone, scope_class()); | |
16333 TypeArguments& type_arguments = TypeArguments::Handle(zone, arguments()); | |
16334 ASSERT(type_arguments.Length() == cls.NumTypeArguments()); | |
16335 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, | |
16336 bound_error, | |
16337 instantiation_trail, | |
16338 bound_trail, | |
16339 space); | |
16340 // This uninstantiated type is not modified, as it can be instantiated | |
16341 // with different instantiators. Allocate a new instantiated version of it. | |
16342 const FunctionType& instantiated_type = FunctionType::Handle(zone, | |
16343 FunctionType::New(cls, | |
16344 type_arguments, | |
16345 Function::Handle(zone, signature()), | |
16346 token_pos(), | |
16347 space)); | |
16348 if (IsFinalized()) { | |
16349 instantiated_type.SetIsFinalized(); | |
16350 } else { | |
16351 instantiated_type.SetIsResolved(); | |
16352 } | |
16353 // Canonicalization is not part of instantiation. | |
16354 return instantiated_type.raw(); | |
16355 } | |
16356 | |
16357 | |
16358 bool FunctionType::IsEquivalent(const Instance& other, TrailPtr trail) const { | |
16359 ASSERT(!IsNull()); | |
16360 if (raw() == other.raw()) { | |
16361 return true; | |
16362 } | |
16363 if (!other.IsFunctionType()) { | |
16364 return false; | |
16365 } | |
16366 const FunctionType& other_type = FunctionType::Cast(other); | |
16367 ASSERT(IsResolved() && other_type.IsResolved()); | |
16368 if (IsMalformed() || other_type.IsMalformed()) { | |
16369 return false; | |
16370 } | |
16371 if (scope_class() != other_type.scope_class()) { | |
16372 return false; | |
16373 } | |
16374 if ((arguments() == other_type.arguments()) && | |
16375 (signature() == other_type.signature())) { | |
16376 return true; | |
16377 } | |
16378 if (!IsFinalized() || !other_type.IsFinalized()) { | |
16379 return false; | |
16380 } | |
16381 | |
16382 // We do not instantiate the types of the signature. This happens on demand | |
16383 // at runtime during a type test. | |
16384 // Therefore, equal function types must have equal type arguments. | |
16385 Thread* thread = Thread::Current(); | |
16386 Zone* zone = thread->zone(); | |
16387 const TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); | |
16388 const TypeArguments& other_type_args = TypeArguments::Handle( | |
16389 zone, other_type.arguments()); | |
16390 if (!type_args.Equals(other_type_args)) { | |
16391 return false; | |
16392 } | |
16393 | |
16394 // Type arguments are equal. | |
16395 // Equal function types must have equal signature types and equal optional | |
16396 // named arguments. | |
16397 if (signature() == other_type.signature()) { | |
16398 return true; | |
16399 } | |
16400 const Function& sig_fun = Function::Handle(zone, signature()); | |
16401 const Function& other_sig_fun = Function::Handle( | |
16402 zone, other_type.signature()); | |
16403 | |
16404 // Compare number of function parameters. | |
16405 const intptr_t num_fixed_params = sig_fun.num_fixed_parameters(); | |
16406 const intptr_t other_num_fixed_params = other_sig_fun.num_fixed_parameters(); | |
16407 if (num_fixed_params != other_num_fixed_params) { | |
16408 return false; | |
16409 } | |
16410 const intptr_t num_opt_pos_params = sig_fun.NumOptionalPositionalParameters(); | |
16411 const intptr_t other_num_opt_pos_params = | |
16412 other_sig_fun.NumOptionalPositionalParameters(); | |
16413 if (num_opt_pos_params != other_num_opt_pos_params) { | |
16414 return false; | |
16415 } | |
16416 const intptr_t num_opt_named_params = sig_fun.NumOptionalNamedParameters(); | |
16417 const intptr_t other_num_opt_named_params = | |
16418 other_sig_fun.NumOptionalNamedParameters(); | |
16419 if (num_opt_named_params != other_num_opt_named_params) { | |
16420 return false; | |
16421 } | |
16422 const intptr_t num_ignored_params = sig_fun.NumImplicitParameters(); | |
16423 const intptr_t other_num_ignored_params = | |
16424 other_sig_fun.NumImplicitParameters(); | |
16425 if (num_ignored_params != other_num_ignored_params) { | |
16426 return false; | |
16427 } | |
16428 AbstractType& param_type = Type::Handle(zone); | |
16429 AbstractType& other_param_type = Type::Handle(zone); | |
16430 // Check the result type. | |
16431 param_type = sig_fun.result_type(); | |
16432 other_param_type = other_sig_fun.result_type(); | |
16433 if (!param_type.Equals(other_param_type)) { | |
16434 return false; | |
16435 } | |
16436 // Check the types of all parameters. | |
16437 const intptr_t num_params = sig_fun.NumParameters(); | |
16438 ASSERT(other_sig_fun.NumParameters() == num_params); | |
16439 for (intptr_t i = 0; i < num_params; i++) { | |
16440 param_type = sig_fun.ParameterTypeAt(i); | |
16441 other_param_type = other_sig_fun.ParameterTypeAt(i); | |
16442 if (!param_type.Equals(other_param_type)) { | |
16443 return false; | |
16444 } | |
16445 } | |
16446 // Check the names and types of optional named parameters. | |
16447 if (num_opt_named_params == 0) { | |
16448 return true; | |
16449 } | |
16450 for (intptr_t i = num_fixed_params; i < num_params; i++) { | |
16451 if (sig_fun.ParameterNameAt(i) != other_sig_fun.ParameterNameAt(i)) { | |
16452 return false; | |
16453 } | |
16454 } | |
16455 return true; | |
16456 } | |
16457 | |
16458 | |
16459 bool FunctionType::IsRecursive() const { | |
16460 return TypeArguments::Handle(arguments()).IsRecursive(); | |
16461 } | |
16462 | |
16463 | |
16464 RawAbstractType* FunctionType::CloneUnfinalized() const { | |
16465 ASSERT(IsResolved()); | |
16466 if (IsFinalized()) { | |
16467 return raw(); | |
16468 } | |
16469 ASSERT(!IsMalformed()); // Malformed types are finalized. | |
16470 ASSERT(!IsBeingFinalized()); // Cloning must occur prior to finalization. | |
16471 TypeArguments& type_args = TypeArguments::Handle(arguments()); | |
16472 type_args = type_args.CloneUnfinalized(); | |
16473 const FunctionType& clone = FunctionType::Handle( | |
16474 FunctionType::New(Class::Handle(scope_class()), | |
16475 type_args, | |
16476 Function::Handle(signature()), | |
16477 token_pos())); | |
16478 clone.SetIsResolved(); | |
16479 return clone.raw(); | |
16480 } | |
16481 | |
16482 | |
16483 RawAbstractType* FunctionType::CloneUninstantiated(const Class& new_owner, | |
16484 TrailPtr trail) const { | |
16485 ASSERT(IsFinalized()); | |
16486 ASSERT(!IsMalformed()); | |
16487 if (IsInstantiated()) { | |
16488 return raw(); | |
16489 } | |
16490 // We may recursively encounter a type already being cloned, because we clone | |
16491 // the upper bounds of its uninstantiated type arguments in the same pass. | |
16492 FunctionType& clone = FunctionType::Handle(); | |
16493 clone ^= OnlyBuddyInTrail(trail); | |
16494 if (!clone.IsNull()) { | |
16495 return clone.raw(); | |
16496 } | |
16497 clone = FunctionType::New(Class::Handle(scope_class()), | |
16498 TypeArguments::Handle(), | |
16499 Function::Handle(signature()), | |
16500 token_pos()); | |
16501 TypeArguments& type_args = TypeArguments::Handle(arguments()); | |
16502 // Upper bounds of uninstantiated type arguments may form a cycle. | |
16503 if (type_args.IsRecursive() || !type_args.IsInstantiated()) { | |
16504 AddOnlyBuddyToTrail(&trail, clone); | |
16505 } | |
16506 type_args = type_args.CloneUninstantiated(new_owner, trail); | |
16507 clone.set_arguments(type_args); | |
16508 clone.SetIsFinalized(); | |
16509 return clone.raw(); | |
16510 } | |
16511 | |
16512 | |
16513 RawAbstractType* FunctionType::Canonicalize(TrailPtr trail) const { | |
16514 ASSERT(IsFinalized()); | |
16515 if (IsCanonical() || IsMalformed()) { | |
16516 ASSERT(IsMalformed() || TypeArguments::Handle(arguments()).IsOld()); | |
16517 return this->raw(); | |
16518 } | |
16519 Thread* thread = Thread::Current(); | |
16520 Zone* zone = thread->zone(); | |
16521 AbstractType& type = Type::Handle(zone); | |
16522 const Class& scope_cls = Class::Handle(zone, type_class()); | |
16523 Array& canonical_types = Array::Handle(zone); | |
16524 canonical_types ^= scope_cls.canonical_types(); | |
16525 if (canonical_types.IsNull()) { | |
16526 canonical_types = empty_array().raw(); | |
16527 } | |
16528 intptr_t length = canonical_types.Length(); | |
16529 // Linear search to see whether this type is already present in the | |
16530 // list of canonicalized types. | |
16531 // TODO(asiva): Try to re-factor this lookup code to make sharing | |
16532 // easy between the 4 versions of this loop. | |
16533 intptr_t index = 1; // Slot 0 is reserved for CanonicalType(). | |
16534 while (index < length) { | |
16535 type ^= canonical_types.At(index); | |
16536 if (type.IsNull()) { | |
16537 break; | |
16538 } | |
16539 ASSERT(type.IsFinalized()); | |
16540 if (this->Equals(type)) { | |
16541 ASSERT(type.IsCanonical()); | |
16542 return type.raw(); | |
16543 } | |
16544 index++; | |
16545 } | |
16546 // The type was not found in the table. It is not canonical yet. | |
16547 | |
16548 // Canonicalize the type arguments. | |
16549 TypeArguments& type_args = TypeArguments::Handle(zone, arguments()); | |
16550 // In case the type is first canonicalized at runtime, its type argument | |
16551 // vector may be longer than necessary. This is not an issue. | |
16552 ASSERT(type_args.IsNull() || | |
16553 (type_args.Length() >= scope_cls.NumTypeArguments())); | |
16554 type_args = type_args.Canonicalize(trail); | |
16555 if (IsCanonical()) { | |
16556 // Canonicalizing type_args canonicalized this type as a side effect. | |
16557 ASSERT(IsRecursive()); | |
16558 // Cycles via typedefs are detected and disallowed, but a function type can | |
16559 // be recursive due to a cycle in its type arguments. | |
16560 return this->raw(); | |
16561 } | |
16562 set_arguments(type_args); | |
16563 | |
16564 // Replace the actual function by a signature function. | |
16565 const Function& fun = Function::Handle(zone, signature()); | |
16566 if (!fun.IsSignatureFunction()) { | |
16567 Function& sig_fun = Function::Handle(zone, | |
16568 Function::NewSignatureFunction(scope_cls, TokenPosition::kNoSource)); | |
16569 type = fun.result_type(); | |
16570 type = type.Canonicalize(trail); | |
16571 sig_fun.set_result_type(type); | |
16572 const intptr_t num_params = fun.NumParameters(); | |
16573 sig_fun.set_num_fixed_parameters(fun.num_fixed_parameters()); | |
16574 sig_fun.SetNumOptionalParameters(fun.NumOptionalParameters(), | |
16575 fun.HasOptionalPositionalParameters()); | |
16576 sig_fun.set_parameter_types(Array::Handle(Array::New(num_params, | |
16577 Heap::kOld))); | |
16578 for (intptr_t i = 0; i < num_params; i++) { | |
16579 type = fun.ParameterTypeAt(i); | |
16580 type = type.Canonicalize(trail); | |
16581 sig_fun.SetParameterTypeAt(i, type); | |
16582 } | |
16583 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names())); | |
16584 set_signature(sig_fun); | |
16585 } | |
16586 ASSERT(type_args.IsNull() || type_args.IsOld()); | |
16587 | |
16588 return scope_cls.LookupOrAddCanonicalType(*this, index); | |
16589 } | |
16590 | |
16591 | |
16592 RawString* FunctionType::EnumerateURIs() const { | |
16593 Zone* zone = Thread::Current()->zone(); | |
16594 // The scope class and type arguments do not appear explicitly in the user | |
16595 // visible name. The type arguments were used to instantiate the function type | |
16596 // prior to this call. | |
16597 const Function& sig_fun = Function::Handle(zone, signature()); | |
16598 AbstractType& type = AbstractType::Handle(zone); | |
16599 const intptr_t num_params = sig_fun.NumParameters(); | |
16600 GrowableHandlePtrArray<const String> pieces(zone, num_params + 1); | |
16601 for (intptr_t i = 0; i < num_params; i++) { | |
16602 type = sig_fun.ParameterTypeAt(i); | |
16603 pieces.Add(String::Handle(zone, type.EnumerateURIs())); | |
16604 } | |
16605 // Handle result type last, since it appears last in the user visible name. | |
16606 type = sig_fun.result_type(); | |
16607 pieces.Add(String::Handle(zone, type.EnumerateURIs())); | |
16608 return Symbols::FromConcatAll(pieces); | |
16609 } | |
16610 | |
16611 | |
16612 intptr_t FunctionType::Hash() const { | |
16613 ASSERT(IsFinalized()); | |
16614 uint32_t result = 1; | |
16615 if (IsMalformed()) return result; | |
16616 result = CombineHashes(result, Class::Handle(scope_class()).id()); | |
16617 result = CombineHashes(result, TypeArguments::Handle(arguments()).Hash()); | |
16618 const Function& sig_fun = Function::Handle(signature()); | |
16619 AbstractType& type = AbstractType::Handle(sig_fun.result_type()); | |
16620 result = CombineHashes(result, type.Hash()); | |
16621 result = CombineHashes(result, sig_fun.NumOptionalPositionalParameters()); | |
16622 const intptr_t num_params = sig_fun.NumParameters(); | |
16623 for (intptr_t i = 0; i < num_params; i++) { | |
16624 type = sig_fun.ParameterTypeAt(i); | |
16625 result = CombineHashes(result, type.Hash()); | |
16626 } | |
16627 if (sig_fun.NumOptionalNamedParameters() > 0) { | |
16628 String& param_name = String::Handle(); | |
16629 for (intptr_t i = sig_fun.num_fixed_parameters(); i < num_params; i++) { | |
16630 param_name = sig_fun.ParameterNameAt(i); | |
16631 result = CombineHashes(result, param_name.Hash()); | |
16632 } | |
16633 } | |
16634 return FinalizeHash(result); | |
16635 } | |
16636 | |
16637 | |
16638 void FunctionType::set_scope_class(const Class& value) const { | |
16639 ASSERT(!value.IsNull()); | |
16640 StorePointer(&raw_ptr()->scope_class_, value.raw()); | |
16641 } | |
16642 | |
16643 | |
16644 void FunctionType::set_arguments(const TypeArguments& value) const { | |
16645 ASSERT(!IsCanonical()); | |
16646 StorePointer(&raw_ptr()->arguments_, value.raw()); | |
16647 } | |
16648 | |
16649 | |
16650 void FunctionType::set_signature(const Function& value) const { | |
16651 StorePointer(&raw_ptr()->signature_, value.raw()); | |
16652 } | |
16653 | |
16654 | |
16655 RawFunctionType* FunctionType::New(Heap::Space space) { | |
16656 RawObject* raw = Object::Allocate(FunctionType::kClassId, | |
16657 FunctionType::InstanceSize(), | |
16658 space); | |
16659 return reinterpret_cast<RawFunctionType*>(raw); | |
16660 } | |
16661 | |
16662 | |
16663 RawFunctionType* FunctionType::New(const Class& clazz, | |
16664 const TypeArguments& arguments, | |
16665 const Function& signature, | |
16666 TokenPosition token_pos, | |
16667 Heap::Space space) { | |
16668 const FunctionType& result = FunctionType::Handle(FunctionType::New(space)); | |
16669 result.set_scope_class(clazz); | |
16670 result.set_arguments(arguments); | |
16671 result.set_signature(signature); | |
16672 result.set_token_pos(token_pos); | |
16673 result.StoreNonPointer(&result.raw_ptr()->type_state_, | |
16674 RawFunctionType::kAllocated); | |
16675 return result.raw(); | |
16676 } | |
16677 | |
16678 | |
16679 void FunctionType::set_token_pos(TokenPosition token_pos) const { | |
16680 ASSERT(!token_pos.IsClassifying()); | |
16681 StoreNonPointer(&raw_ptr()->token_pos_, token_pos); | |
16682 } | |
16683 | |
16684 | |
16685 void FunctionType::set_type_state(int8_t state) const { | |
16686 ASSERT((state >= RawFunctionType::kAllocated) && | |
16687 (state <= RawFunctionType::kFinalizedUninstantiated)); | |
16688 StoreNonPointer(&raw_ptr()->type_state_, state); | |
16689 } | |
16690 | |
16691 | |
16692 const char* FunctionType::ToCString() const { | |
16693 const char* unresolved = IsResolved() ? "" : "Unresolved "; | |
16694 const Class& scope_cls = Class::Handle(scope_class()); | |
16695 const TypeArguments& type_arguments = TypeArguments::Handle(arguments()); | |
16696 const Function& signature_function = Function::Handle(signature()); | |
16697 const String& signature_string = IsFinalized() ? | |
16698 String::Handle( | |
16699 signature_function.InstantiatedSignatureFrom(type_arguments, | |
16700 kInternalName)) : | |
16701 String::Handle(signature_function.Signature()); | |
16702 if (scope_cls.IsClosureClass()) { | |
16703 ASSERT(arguments() == TypeArguments::null()); | |
16704 return OS::SCreate( | |
16705 Thread::Current()->zone(), | |
16706 "%sFunctionType: %s", unresolved, signature_string.ToCString()); | |
16707 } | |
16708 const char* class_name = String::Handle(scope_cls.Name()).ToCString(); | |
16709 const char* args_cstr = | |
16710 type_arguments.IsNull() ? "null" : type_arguments.ToCString(); | |
16711 return OS::SCreate( | |
16712 Thread::Current()->zone(), | |
16713 "%s FunctionType: %s (scope_cls: %s, args: %s)", | |
16714 unresolved, | |
16715 signature_string.ToCString(), | |
16716 class_name, | |
16717 args_cstr); | |
16718 } | |
16719 | |
16720 | |
16721 bool TypeRef::IsInstantiated(TrailPtr trail) const { | 16488 bool TypeRef::IsInstantiated(TrailPtr trail) const { |
16722 if (TestAndAddToTrail(&trail)) { | 16489 if (TestAndAddToTrail(&trail)) { |
16723 return true; | 16490 return true; |
16724 } | 16491 } |
16725 return AbstractType::Handle(type()).IsInstantiated(trail); | 16492 return AbstractType::Handle(type()).IsInstantiated(trail); |
16726 } | 16493 } |
16727 | 16494 |
16728 | 16495 |
16729 bool TypeRef::IsEquivalent(const Instance& other, TrailPtr trail) const { | 16496 bool TypeRef::IsEquivalent(const Instance& other, TrailPtr trail) const { |
16730 if (raw() == other.raw()) { | 16497 if (raw() == other.raw()) { |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17282 } | 17049 } |
17283 } | 17050 } |
17284 return instantiated_bounded_type.raw(); | 17051 return instantiated_bounded_type.raw(); |
17285 } | 17052 } |
17286 | 17053 |
17287 | 17054 |
17288 RawAbstractType* BoundedType::CloneUnfinalized() const { | 17055 RawAbstractType* BoundedType::CloneUnfinalized() const { |
17289 if (IsFinalized()) { | 17056 if (IsFinalized()) { |
17290 return raw(); | 17057 return raw(); |
17291 } | 17058 } |
17292 AbstractType& bounded_type = AbstractType::Handle(type()); | 17059 const AbstractType& bounded_type = AbstractType::Handle(type()); |
17293 | 17060 const AbstractType& bounded_type_clone = |
17294 bounded_type = bounded_type.CloneUnfinalized(); | 17061 AbstractType::Handle(bounded_type.CloneUnfinalized()); |
| 17062 if (bounded_type_clone.raw() == bounded_type.raw()) { |
| 17063 return raw(); |
| 17064 } |
17295 // No need to clone bound or type parameter, as they are not part of the | 17065 // No need to clone bound or type parameter, as they are not part of the |
17296 // finalization state of this bounded type. | 17066 // finalization state of this bounded type. |
17297 return BoundedType::New(bounded_type, | 17067 return BoundedType::New(bounded_type, |
17298 AbstractType::Handle(bound()), | 17068 AbstractType::Handle(bound()), |
17299 TypeParameter::Handle(type_parameter())); | 17069 TypeParameter::Handle(type_parameter())); |
17300 } | 17070 } |
17301 | 17071 |
17302 | 17072 |
17303 RawAbstractType* BoundedType::CloneUninstantiated( | 17073 RawAbstractType* BoundedType::CloneUninstantiated( |
17304 const Class& new_owner, TrailPtr trail) const { | 17074 const Class& new_owner, TrailPtr trail) const { |
(...skipping 4648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21953 return UserTag::null(); | 21723 return UserTag::null(); |
21954 } | 21724 } |
21955 | 21725 |
21956 | 21726 |
21957 const char* UserTag::ToCString() const { | 21727 const char* UserTag::ToCString() const { |
21958 const String& tag_label = String::Handle(label()); | 21728 const String& tag_label = String::Handle(label()); |
21959 return tag_label.ToCString(); | 21729 return tag_label.ToCString(); |
21960 } | 21730 } |
21961 | 21731 |
21962 } // namespace dart | 21732 } // namespace dart |
OLD | NEW |