Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Friends | List of all members
dart::kernel::TypeTranslator Class Reference

#include <kernel_translation_helper.h>

Public Member Functions

 TypeTranslator (KernelReaderHelper *helper, ConstantReader *constant_reader, ActiveClass *active_class, bool finalize=false, bool in_constant_context=false)
 
AbstractTypeBuildType ()
 
AbstractTypeBuildTypeWithoutFinalization ()
 
const TypeArgumentsBuildTypeArguments (intptr_t length)
 
const TypeArgumentsBuildInstantiatedTypeArguments (const Class &receiver_class, intptr_t length)
 
void LoadAndSetupTypeParameters (ActiveClass *active_class, const Function &function, const Class &parameterized_class, const FunctionType &parameterized_signature, intptr_t type_parameter_count)
 
void LoadAndSetupBounds (ActiveClass *active_class, const Function &function, const Class &parameterized_class, const FunctionType &parameterized_signature, intptr_t type_parameter_count)
 
const TypeReceiverType (const Class &klass)
 
void SetupFunctionParameters (const Class &klass, const Function &function, bool is_method, bool is_closure, FunctionNodeHelper *function_node_helper)
 

Friends

class ScopeBuilder
 
class KernelLoader
 

Detailed Description

Definition at line 1541 of file kernel_translation_helper.h.

Constructor & Destructor Documentation

◆ TypeTranslator()

dart::kernel::TypeTranslator::TypeTranslator ( KernelReaderHelper helper,
ConstantReader constant_reader,
ActiveClass active_class,
bool  finalize = false,
bool  in_constant_context = false 
)

Definition at line 3289 of file kernel_translation_helper.cc.

3294 : helper_(helper),
3295 constant_reader_(constant_reader),
3296 translation_helper_(helper->translation_helper_),
3297 active_class_(active_class),
3298 type_parameter_scope_(nullptr),
3299 inferred_type_metadata_helper_(helper_, constant_reader_),
3300 unboxing_info_metadata_helper_(helper_),
3301 zone_(translation_helper_.zone()),
3302 result_(AbstractType::Handle(translation_helper_.zone())),
3303 finalize_(finalize),
3304 in_constant_context_(in_constant_context) {}
static Object & Handle()
Definition object.h:407

Member Function Documentation

◆ BuildInstantiatedTypeArguments()

const TypeArguments & dart::kernel::TypeTranslator::BuildInstantiatedTypeArguments ( const Class receiver_class,
intptr_t  length 
)

Definition at line 3706 of file kernel_translation_helper.cc.

3708 {
3709 const TypeArguments& type_arguments = BuildTypeArguments(length);
3710
3711 // If type_arguments is null all arguments are dynamic.
3712 // If, however, this class doesn't specify all the type arguments directly we
3713 // still need to finalize the type below in order to get any non-dynamic types
3714 // from any super. See http://www.dartbug.com/29537.
3715 if (type_arguments.IsNull() && receiver_class.NumTypeArguments() == length) {
3716 return type_arguments;
3717 }
3718
3719 const TypeArguments& instantiated_type_arguments = TypeArguments::ZoneHandle(
3720 Z, receiver_class.GetInstanceTypeArguments(H.thread(), type_arguments));
3721 return instantiated_type_arguments;
3722}
#define Z
static Object & ZoneHandle()
Definition object.h:419
const TypeArguments & BuildTypeArguments(intptr_t length)
size_t length
Definition SkMD5.cpp:130

◆ BuildType()

AbstractType & dart::kernel::TypeTranslator::BuildType ( )

Definition at line 3306 of file kernel_translation_helper.cc.

3306 {
3307 BuildTypeInternal();
3308
3309 // We return a new `ZoneHandle` here on purpose: The intermediate language
3310 // instructions do not make a copy of the handle, so we do it.
3311 return AbstractType::ZoneHandle(Z, result_.ptr());
3312}
ObjectPtr ptr() const
Definition object.h:332

◆ BuildTypeArguments()

const TypeArguments & dart::kernel::TypeTranslator::BuildTypeArguments ( intptr_t  length)

Definition at line 3681 of file kernel_translation_helper.cc.

3681 {
3682 bool only_dynamic = true;
3683 intptr_t offset = helper_->ReaderOffset();
3684 for (intptr_t i = 0; i < length; ++i) {
3685 if (helper_->ReadTag() != kDynamicType) { // Read the ith types tag.
3686 only_dynamic = false;
3687 helper_->SetOffset(offset);
3688 break;
3689 }
3690 }
3691 TypeArguments& type_arguments = TypeArguments::ZoneHandle(Z);
3692 if (!only_dynamic) {
3693 type_arguments = TypeArguments::New(length);
3694 for (intptr_t i = 0; i < length; ++i) {
3695 BuildTypeInternal(); // read ith type.
3696 type_arguments.SetTypeAt(i, result_);
3697 }
3698
3699 if (finalize_) {
3700 type_arguments = type_arguments.Canonicalize(Thread::Current());
3701 }
3702 }
3703 return type_arguments;
3704}
static Thread * Current()
Definition thread.h:361
static TypeArgumentsPtr New(intptr_t len, Heap::Space space=Heap::kOld)
Definition object.cc:7733
Tag ReadTag(uint8_t *payload=nullptr)
Point offset

◆ BuildTypeWithoutFinalization()

AbstractType & dart::kernel::TypeTranslator::BuildTypeWithoutFinalization ( )

Definition at line 3314 of file kernel_translation_helper.cc.

3314 {
3315 bool saved_finalize = finalize_;
3316 finalize_ = false;
3317 BuildTypeInternal();
3318 finalize_ = saved_finalize;
3319
3320 // We return a new `ZoneHandle` here on purpose: The intermediate language
3321 // instructions do not make a copy of the handle, so we do it.
3322 return AbstractType::ZoneHandle(Z, result_.ptr());
3323}

◆ LoadAndSetupBounds()

void dart::kernel::TypeTranslator::LoadAndSetupBounds ( ActiveClass active_class,
const Function function,
const Class parameterized_class,
const FunctionType parameterized_signature,
intptr_t  type_parameter_count 
)

Definition at line 3779 of file kernel_translation_helper.cc.

3784 {
3785 ASSERT(parameterized_class.IsNull() != parameterized_signature.IsNull());
3786 ASSERT(type_parameter_count >= 0);
3787 if (type_parameter_count == 0) {
3788 return;
3789 }
3790
3791 const TypeParameters& type_parameters = TypeParameters::Handle(
3792 Z, !parameterized_class.IsNull()
3793 ? parameterized_class.type_parameters()
3794 : parameterized_signature.type_parameters());
3795
3796 // Fill in the bounds and default arguments of all [TypeParameter]s.
3797 for (intptr_t i = 0; i < type_parameter_count; i++) {
3798 TypeParameterHelper helper(helper_);
3799 helper.ReadUntilExcludingAndSetJustRead(TypeParameterHelper::kBound);
3800
3801 AbstractType& bound = BuildTypeWithoutFinalization(); // read ith bound.
3802 ASSERT(!bound.IsNull());
3803 type_parameters.SetBoundAt(i, bound);
3804 helper.ReadUntilExcludingAndSetJustRead(TypeParameterHelper::kDefaultType);
3805 AbstractType& default_arg = BuildTypeWithoutFinalization();
3806 ASSERT(!default_arg.IsNull());
3807 type_parameters.SetDefaultAt(i, default_arg);
3808 helper.Finish();
3809 }
3810}
#define ASSERT(E)

◆ LoadAndSetupTypeParameters()

void dart::kernel::TypeTranslator::LoadAndSetupTypeParameters ( ActiveClass active_class,
const Function function,
const Class parameterized_class,
const FunctionType parameterized_signature,
intptr_t  type_parameter_count 
)

Definition at line 3724 of file kernel_translation_helper.cc.

3729 {
3730 ASSERT(parameterized_class.IsNull() != parameterized_signature.IsNull());
3731 ASSERT(type_parameter_count >= 0);
3732 if (type_parameter_count == 0) {
3733 ASSERT(parameterized_class.IsNull() ||
3734 parameterized_class.type_parameters() == TypeParameters::null());
3735 ASSERT(parameterized_signature.IsNull() ||
3736 parameterized_signature.type_parameters() == TypeParameters::null());
3737 return;
3738 }
3739
3740 // The finalized index of a type parameter can only be determined if the
3741 // length of the flattened type argument vector is known, which in turn can
3742 // only be determined after the super type and its class have been loaded.
3743 // Due to the added complexity of loading classes out of order from the kernel
3744 // file, class type parameter indices are not finalized during class loading.
3745 // However, function type parameter indices can be immediately finalized.
3746
3747 // First setup the type parameters, so if any of the following code uses it
3748 // (in a recursive way) we're fine.
3749
3750 // - Create a [ TypeParameters ] object.
3751 const TypeParameters& type_parameters =
3752 TypeParameters::Handle(Z, TypeParameters::New(type_parameter_count));
3753 const Type& null_bound = Type::Handle(Z);
3754
3755 if (!parameterized_class.IsNull()) {
3756 ASSERT(parameterized_class.type_parameters() == TypeParameters::null());
3757 parameterized_class.set_type_parameters(type_parameters);
3758 } else {
3759 ASSERT(parameterized_signature.type_parameters() == TypeParameters::null());
3760 parameterized_signature.SetTypeParameters(type_parameters);
3761 }
3762
3763 const Library& lib = Library::Handle(Z, active_class->klass->library());
3764 {
3765 AlternativeReadingScope alt(&helper_->reader_);
3766 for (intptr_t i = 0; i < type_parameter_count; i++) {
3767 TypeParameterHelper helper(helper_);
3768 helper.Finish();
3769 type_parameters.SetNameAt(i, H.DartIdentifier(lib, helper.name_index_));
3770 type_parameters.SetIsGenericCovariantImplAt(
3771 i, helper.IsGenericCovariantImpl());
3772 // Bounds are filled later in LoadAndSetupBounds as bound types may
3773 // reference type parameters which are not created yet.
3774 type_parameters.SetBoundAt(i, null_bound);
3775 }
3776 }
3777}
static ObjectPtr null()
Definition object.h:433
static TypeParametersPtr New(Heap::Space space=Heap::kOld)
Definition object.cc:6778

◆ ReceiverType()

const Type & dart::kernel::TypeTranslator::ReceiverType ( const Class klass)

Definition at line 3812 of file kernel_translation_helper.cc.

3812 {
3813 ASSERT(!klass.IsNull());
3814 // Forward expression evaluation class to a real class when
3815 // creating types.
3816 if (translation_helper_.GetExpressionEvaluationClass().ptr() == klass.ptr()) {
3817 ASSERT(translation_helper_.GetExpressionEvaluationRealClass().ptr() !=
3818 klass.ptr());
3819 return ReceiverType(translation_helper_.GetExpressionEvaluationRealClass());
3820 }
3821 ASSERT(klass.id() != kIllegalCid);
3822 // Note that if klass is _Closure, the returned type will be _Closure,
3823 // and not the signature type.
3825 if (finalize_ || klass.is_type_finalized()) {
3826 type = klass.DeclarationType();
3827 } else {
3828 TypeArguments& type_args = TypeArguments::Handle(Z);
3829 const intptr_t num_type_params = klass.NumTypeParameters();
3830 if (num_type_params > 0) {
3831 type_args = TypeArguments::New(num_type_params);
3832 TypeParameter& type_param = TypeParameter::Handle();
3833 for (intptr_t i = 0; i < num_type_params; i++) {
3834 type_param = klass.TypeParameterAt(i);
3835 type_args.SetTypeAt(i, type_param);
3836 }
3837 }
3838 type = Type::New(klass, type_args, Nullability::kNonNullable);
3839 }
3840 return type;
3841}
static TypePtr New(const Class &clazz, const TypeArguments &arguments, Nullability nullability=Nullability::kLegacy, Heap::Space space=Heap::kOld)
Definition object.cc:22492
const Type & ReceiverType(const Class &klass)
@ kIllegalCid
Definition class_id.h:214

◆ SetupFunctionParameters()

void dart::kernel::TypeTranslator::SetupFunctionParameters ( const Class klass,
const Function function,
bool  is_method,
bool  is_closure,
FunctionNodeHelper function_node_helper 
)

Definition at line 3930 of file kernel_translation_helper.cc.

3935 {
3936 ASSERT(!(is_method && is_closure));
3937 bool is_factory = function.IsFactory();
3938 intptr_t extra_parameters = (is_method || is_closure || is_factory) ? 1 : 0;
3939
3940 const FunctionType& signature = FunctionType::Handle(Z, function.signature());
3941 ASSERT(!signature.IsNull());
3942 intptr_t type_parameter_count = 0;
3943 if (!is_factory) {
3944 type_parameter_count = helper_->ReadListLength();
3946 signature, type_parameter_count);
3947 function_node_helper->SetJustRead(FunctionNodeHelper::kTypeParameters);
3948 }
3949
3950 ActiveTypeParametersScope scope(active_class_, function, &signature, Z);
3951
3952 if (!is_factory) {
3953 LoadAndSetupBounds(active_class_, function, Class::Handle(Z), signature,
3954 type_parameter_count);
3955 function_node_helper->SetJustRead(FunctionNodeHelper::kTypeParameters);
3956 }
3957
3958 function_node_helper->ReadUntilExcluding(
3960
3961 intptr_t required_parameter_count =
3962 function_node_helper->required_parameter_count_;
3963 intptr_t total_parameter_count = function_node_helper->total_parameter_count_;
3964
3965 intptr_t positional_parameter_count =
3966 helper_->ReadListLength(); // read list length.
3967
3968 intptr_t named_parameter_count =
3969 total_parameter_count - positional_parameter_count;
3970
3971 signature.set_num_fixed_parameters(extra_parameters +
3972 required_parameter_count);
3973 if (named_parameter_count > 0) {
3974 signature.SetNumOptionalParameters(named_parameter_count, false);
3975 } else {
3976 signature.SetNumOptionalParameters(
3977 positional_parameter_count - required_parameter_count, true);
3978 }
3979 intptr_t parameter_count = extra_parameters + total_parameter_count;
3980
3981 intptr_t pos = 0;
3982 if (parameter_count > 0) {
3983 signature.set_parameter_types(
3984 Array::Handle(Z, Array::New(parameter_count, Heap::kOld)));
3985 function.CreateNameArray();
3986 signature.CreateNameArrayIncludingFlags();
3987 if (is_method) {
3988 ASSERT(!klass.IsNull());
3989 signature.SetParameterTypeAt(pos, H.GetDeclarationType(klass));
3990 function.SetParameterNameAt(pos, Symbols::This());
3991 pos++;
3992 } else if (is_closure) {
3993 signature.SetParameterTypeAt(pos, AbstractType::dynamic_type());
3994 function.SetParameterNameAt(pos, Symbols::ClosureParameter());
3995 pos++;
3996 } else if (is_factory) {
3997 signature.SetParameterTypeAt(pos, AbstractType::dynamic_type());
3998 function.SetParameterNameAt(pos, Symbols::TypeArgumentsParameter());
3999 pos++;
4000 }
4001 } else {
4002 ASSERT(!is_method && !is_closure && !is_factory);
4003 }
4004
4005 const Library& lib = Library::Handle(Z, active_class_->klass->library());
4006 for (intptr_t i = 0; i < positional_parameter_count; ++i, ++pos) {
4007 // Read ith variable declaration.
4008 VariableDeclarationHelper helper(helper_);
4009 helper.ReadUntilExcluding(VariableDeclarationHelper::kType);
4010 // The required flag should only be set on named parameters.
4011 ASSERT(!helper.IsRequired());
4012 const AbstractType& type = BuildTypeWithoutFinalization(); // read type.
4013 Tag tag = helper_->ReadTag(); // read (first part of) initializer.
4014 if (tag == kSomething) {
4015 helper_->SkipExpression(); // read (actual) initializer.
4016 }
4017
4018 signature.SetParameterTypeAt(pos, type);
4019 function.SetParameterNameAt(pos, H.DartIdentifier(lib, helper.name_index_));
4020 }
4021
4022 intptr_t named_parameter_count_check =
4023 helper_->ReadListLength(); // read list length.
4024 ASSERT(named_parameter_count_check == named_parameter_count);
4025 for (intptr_t i = 0; i < named_parameter_count; ++i, ++pos) {
4026 // Read ith variable declaration.
4027 VariableDeclarationHelper helper(helper_);
4028 helper.ReadUntilExcluding(VariableDeclarationHelper::kType);
4029 const AbstractType& type = BuildTypeWithoutFinalization(); // read type.
4030 Tag tag = helper_->ReadTag(); // read (first part of) initializer.
4031 if (tag == kSomething) {
4032 helper_->SkipExpression(); // read (actual) initializer.
4033 }
4034
4035 signature.SetParameterTypeAt(pos, type);
4036 signature.SetParameterNameAt(pos,
4037 H.DartIdentifier(lib, helper.name_index_));
4038 if (helper.IsRequired()) {
4039 signature.SetIsRequiredAt(pos);
4040 }
4041 }
4042 signature.FinalizeNameArray();
4043
4044 function_node_helper->SetJustRead(FunctionNodeHelper::kNamedParameters);
4045
4046 // The result type for generative constructors has already been set.
4047 if (!function.IsGenerativeConstructor()) {
4048 const AbstractType& return_type =
4049 BuildTypeWithoutFinalization(); // read return type.
4050 signature.set_result_type(return_type);
4051 function_node_helper->SetJustRead(FunctionNodeHelper::kReturnType);
4052 }
4053}
SkPoint pos
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition object.h:10933
LibraryPtr library() const
Definition object.h:1335
@ kOld
Definition heap.h:39
static const String & This()
Definition symbols.h:691
void LoadAndSetupTypeParameters(ActiveClass *active_class, const Function &function, const Class &parameterized_class, const FunctionType &parameterized_signature, intptr_t type_parameter_count)
void LoadAndSetupBounds(ActiveClass *active_class, const Function &function, const Class &parameterized_class, const FunctionType &parameterized_signature, intptr_t type_parameter_count)
Dart_NativeFunction function
Definition fuchsia.cc:51

Friends And Related Symbol Documentation

◆ KernelLoader

friend class KernelLoader
friend

Definition at line 1640 of file kernel_translation_helper.h.

◆ ScopeBuilder

friend class ScopeBuilder
friend

Definition at line 1639 of file kernel_translation_helper.h.


The documentation for this class was generated from the following files: