Flutter Engine
The Flutter Engine
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 1539 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 3288 of file kernel_translation_helper.cc.

3293 : helper_(helper),
3294 constant_reader_(constant_reader),
3295 translation_helper_(helper->translation_helper_),
3296 active_class_(active_class),
3297 type_parameter_scope_(nullptr),
3298 inferred_type_metadata_helper_(helper_, constant_reader_),
3299 unboxing_info_metadata_helper_(helper_),
3300 zone_(translation_helper_.zone()),
3301 result_(AbstractType::Handle(translation_helper_.zone())),
3302 finalize_(finalize),
3303 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 3705 of file kernel_translation_helper.cc.

3707 {
3708 const TypeArguments& type_arguments = BuildTypeArguments(length);
3709
3710 // If type_arguments is null all arguments are dynamic.
3711 // If, however, this class doesn't specify all the type arguments directly we
3712 // still need to finalize the type below in order to get any non-dynamic types
3713 // from any super. See http://www.dartbug.com/29537.
3714 if (type_arguments.IsNull() && receiver_class.NumTypeArguments() == length) {
3715 return type_arguments;
3716 }
3717
3718 const TypeArguments& instantiated_type_arguments = TypeArguments::ZoneHandle(
3719 Z, receiver_class.GetInstanceTypeArguments(H.thread(), type_arguments));
3720 return instantiated_type_arguments;
3721}
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 3305 of file kernel_translation_helper.cc.

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

◆ BuildTypeArguments()

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

Definition at line 3680 of file kernel_translation_helper.cc.

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

◆ BuildTypeWithoutFinalization()

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

Definition at line 3313 of file kernel_translation_helper.cc.

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

◆ 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 3778 of file kernel_translation_helper.cc.

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

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

◆ ReceiverType()

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

Definition at line 3811 of file kernel_translation_helper.cc.

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

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

◆ KernelLoader

friend class KernelLoader
friend

Definition at line 1638 of file kernel_translation_helper.h.

◆ ScopeBuilder

friend class ScopeBuilder
friend

Definition at line 1637 of file kernel_translation_helper.h.


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