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/become.h" | 10 #include "vm/become.h" |
(...skipping 5713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5724 ASSERT(!obj.IsNull()); | 5724 ASSERT(!obj.IsNull()); |
5725 if (IsSignatureFunction()) { | 5725 if (IsSignatureFunction()) { |
5726 return SignatureData::Cast(obj).signature_type(); | 5726 return SignatureData::Cast(obj).signature_type(); |
5727 } else { | 5727 } else { |
5728 ASSERT(IsClosureFunction()); | 5728 ASSERT(IsClosureFunction()); |
5729 return ClosureData::Cast(obj).signature_type(); | 5729 return ClosureData::Cast(obj).signature_type(); |
5730 } | 5730 } |
5731 } | 5731 } |
5732 | 5732 |
5733 | 5733 |
| 5734 RawFunction* Function::CanonicalSignatureFunction(TrailPtr trail) const { |
| 5735 ASSERT(!IsSignatureFunction()); |
| 5736 Zone* zone = Thread::Current()->zone(); |
| 5737 Function& parent = Function::Handle(zone, parent_function()); |
| 5738 if (!parent.IsNull() && !parent.IsSignatureFunction()) { |
| 5739 // Make sure the parent function is also a signature function. |
| 5740 parent = parent.CanonicalSignatureFunction(trail); |
| 5741 } |
| 5742 const Class& owner = Class::Handle(zone, Owner()); |
| 5743 const Function& sig_fun = Function::Handle( |
| 5744 zone, |
| 5745 Function::NewSignatureFunction(owner, parent, TokenPosition::kNoSource)); |
| 5746 // In case of a generic function, the function type parameters in the |
| 5747 // signature will still refer to the original function. This should not |
| 5748 // be a problem, since once finalized the indices will be identical. |
| 5749 sig_fun.set_type_parameters(TypeArguments::Handle(zone, type_parameters())); |
| 5750 ASSERT(HasGenericParent() == sig_fun.HasGenericParent()); |
| 5751 ASSERT(IsGeneric() == sig_fun.IsGeneric()); |
| 5752 AbstractType& type = AbstractType::Handle(zone); |
| 5753 type = result_type(); |
| 5754 type = type.Canonicalize(trail); |
| 5755 sig_fun.set_result_type(type); |
| 5756 const intptr_t num_params = NumParameters(); |
| 5757 sig_fun.set_num_fixed_parameters(num_fixed_parameters()); |
| 5758 sig_fun.SetNumOptionalParameters(NumOptionalParameters(), |
| 5759 HasOptionalPositionalParameters()); |
| 5760 sig_fun.set_parameter_types( |
| 5761 Array::Handle(Array::New(num_params, Heap::kOld))); |
| 5762 for (intptr_t i = 0; i < num_params; i++) { |
| 5763 type = ParameterTypeAt(i); |
| 5764 type = type.Canonicalize(trail); |
| 5765 sig_fun.SetParameterTypeAt(i, type); |
| 5766 } |
| 5767 sig_fun.set_parameter_names(Array::Handle(zone, parameter_names())); |
| 5768 return sig_fun.raw(); |
| 5769 } |
| 5770 |
| 5771 |
5734 RawType* Function::SignatureType() const { | 5772 RawType* Function::SignatureType() const { |
5735 Type& type = Type::Handle(ExistingSignatureType()); | 5773 Type& type = Type::Handle(ExistingSignatureType()); |
5736 if (type.IsNull()) { | 5774 if (type.IsNull()) { |
5737 // The function type of this function is not yet cached and needs to be | 5775 // The function type of this function is not yet cached and needs to be |
5738 // constructed and cached here. | 5776 // constructed and cached here. |
5739 // A function type is type parameterized in the same way as the owner class | 5777 // A function type is type parameterized in the same way as the owner class |
5740 // of its non-static signature function. | 5778 // of its non-static signature function. |
5741 // It is not type parameterized if its signature function is static, or if | 5779 // It is not type parameterized if its signature function is static, or if |
5742 // none of its result type or formal parameter types are type parameterized. | 5780 // none of its result type or formal parameter types are type parameterized. |
5743 // Unless the function type is a generic typedef, the type arguments of the | 5781 // Unless the function type is a generic typedef, the type arguments of the |
(...skipping 11965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17709 // Cycles via typedefs are detected and disallowed, but a function type | 17747 // Cycles via typedefs are detected and disallowed, but a function type |
17710 // can be recursive due to a cycle in its type arguments. | 17748 // can be recursive due to a cycle in its type arguments. |
17711 return this->raw(); | 17749 return this->raw(); |
17712 } | 17750 } |
17713 set_arguments(type_args); | 17751 set_arguments(type_args); |
17714 ASSERT(type_args.IsNull() || type_args.IsOld()); | 17752 ASSERT(type_args.IsNull() || type_args.IsOld()); |
17715 | 17753 |
17716 // In case of a function type, replace the actual function by a signature | 17754 // In case of a function type, replace the actual function by a signature |
17717 // function. | 17755 // function. |
17718 if (IsFunctionType()) { | 17756 if (IsFunctionType()) { |
17719 const Function& fun = Function::Handle(zone, signature()); | 17757 Function& sig_fun = Function::Handle(zone, signature()); |
17720 if (!fun.IsSignatureFunction()) { | 17758 if (!sig_fun.IsSignatureFunction()) { |
17721 // In case of a generic function, the function type parameters in the | 17759 sig_fun = sig_fun.CanonicalSignatureFunction(trail); |
17722 // signature will still refer to the original function. This should not | |
17723 // be a problem, since they are finalized and the indices remain | |
17724 // unchanged. | |
17725 const Function& parent = Function::Handle(zone, fun.parent_function()); | |
17726 Function& sig_fun = | |
17727 Function::Handle(zone, Function::NewSignatureFunction( | |
17728 cls, parent, TokenPosition::kNoSource)); | |
17729 sig_fun.set_type_parameters( | |
17730 TypeArguments::Handle(zone, fun.type_parameters())); | |
17731 ASSERT(fun.HasGenericParent() == sig_fun.HasGenericParent()); | |
17732 ASSERT(fun.IsGeneric() == sig_fun.IsGeneric()); | |
17733 type = fun.result_type(); | |
17734 type = type.Canonicalize(trail); | |
17735 sig_fun.set_result_type(type); | |
17736 const intptr_t num_params = fun.NumParameters(); | |
17737 sig_fun.set_num_fixed_parameters(fun.num_fixed_parameters()); | |
17738 sig_fun.SetNumOptionalParameters(fun.NumOptionalParameters(), | |
17739 fun.HasOptionalPositionalParameters()); | |
17740 sig_fun.set_parameter_types( | |
17741 Array::Handle(Array::New(num_params, Heap::kOld))); | |
17742 for (intptr_t i = 0; i < num_params; i++) { | |
17743 type = fun.ParameterTypeAt(i); | |
17744 type = type.Canonicalize(trail); | |
17745 sig_fun.SetParameterTypeAt(i, type); | |
17746 } | |
17747 sig_fun.set_parameter_names(Array::Handle(zone, fun.parameter_names())); | |
17748 set_signature(sig_fun); | 17760 set_signature(sig_fun); |
17749 // Note that the signature type of the signature function may be | 17761 // Note that the signature type of the signature function may be |
17750 // different than the type being canonicalized. | 17762 // different than the type being canonicalized. |
17751 // Consider F<int> being canonicalized, with F being a typedef and F<T> | 17763 // Consider F<int> being canonicalized, with F being a typedef and F<T> |
17752 // being its signature type. | 17764 // being its signature type. |
17753 } | 17765 } |
17754 } | 17766 } |
17755 | 17767 |
17756 // Check to see if the type got added to canonical list as part of the | 17768 // Check to see if the type got added to canonical list as part of the |
17757 // type arguments canonicalization. | 17769 // type arguments canonicalization. |
(...skipping 5800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
23558 return UserTag::null(); | 23570 return UserTag::null(); |
23559 } | 23571 } |
23560 | 23572 |
23561 | 23573 |
23562 const char* UserTag::ToCString() const { | 23574 const char* UserTag::ToCString() const { |
23563 const String& tag_label = String::Handle(label()); | 23575 const String& tag_label = String::Handle(label()); |
23564 return tag_label.ToCString(); | 23576 return tag_label.ToCString(); |
23565 } | 23577 } |
23566 | 23578 |
23567 } // namespace dart | 23579 } // namespace dart |
OLD | NEW |