Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
dart::compiler::ffi::NativeType Class Referenceabstract

#include <native_type.h>

Inheritance diagram for dart::compiler::ffi::NativeType:
dart::ZoneAllocated dart::compiler::ffi::NativeArrayType dart::compiler::ffi::NativeCompoundType dart::compiler::ffi::NativePrimitiveType dart::compiler::ffi::NativeStructType dart::compiler::ffi::NativeUnionType

Public Member Functions

virtual bool IsPrimitive () const
 
const NativePrimitiveTypeAsPrimitive () const
 
virtual bool IsArray () const
 
const NativeArrayTypeAsArray () const
 
virtual bool IsCompound () const
 
const NativeCompoundTypeAsCompound () const
 
virtual bool IsStruct () const
 
const NativeStructTypeAsStruct () const
 
virtual bool IsInt () const
 
virtual bool IsFloat () const
 
virtual bool IsVoid () const
 
virtual bool IsSigned () const
 
virtual intptr_t SizeInBytes () const =0
 
virtual intptr_t AlignmentInBytesStack (bool is_vararg=false) const =0
 
virtual intptr_t AlignmentInBytesField () const =0
 
virtual bool ContainsOnlyFloats (Range range) const =0
 
virtual bool ContainsUnalignedMembers (intptr_t offset=0) const =0
 
virtual bool IsExpressibleAsRepresentation () const
 
virtual Representation AsRepresentation () const
 
Representation AsRepresentationOverApprox (Zone *zone_) const
 
virtual bool Equals (const NativeType &other) const
 
virtual NativeTypeSplit (Zone *zone, intptr_t index) const
 
const NativeTypeWidenTo4Bytes (Zone *zone) const
 
const NativeTypeWidenTo8Bytes (Zone *zone) const
 
const NativeTypeExtend (Zone *zone, ExtensionStrategy extension) const
 
virtual void PrintTo (BaseTextBuffer *f, bool multi_line=false, bool verbose=true) const
 
const char * ToCString (Zone *zone, bool multi_line=false, bool verbose=true) const
 
const char * ToCString () const
 
virtual intptr_t NumPrimitiveMembersRecursive () const =0
 
virtual const NativePrimitiveTypeFirstPrimitiveMember () const =0
 
virtual intptr_t PrimitivePairMembers (const NativePrimitiveType **first, const NativePrimitiveType **second, intptr_t offset_in_members=0) const =0
 
virtual ~NativeType ()
 
- Public Member Functions inherited from dart::ZoneAllocated
 ZoneAllocated ()
 
void * operator new (size_t size)
 
void * operator new (size_t size, Zone *zone)
 
void operator delete (void *pointer)
 

Static Public Member Functions

static const NativeTypeFromAbstractType (Zone *zone, const AbstractType &type, const char **error)
 
static const NativeTypeFromTypedDataClassId (Zone *zone, classid_t class_id)
 
static NativePrimitiveTypeFromRepresentation (Zone *zone, Representation rep)
 

Protected Member Functions

 NativeType ()
 

Detailed Description

Definition at line 66 of file native_type.h.

Constructor & Destructor Documentation

◆ ~NativeType()

virtual dart::compiler::ffi::NativeType::~NativeType ( )
inlinevirtual

Definition at line 173 of file native_type.h.

173{}

◆ NativeType()

dart::compiler::ffi::NativeType::NativeType ( )
inlineprotected

Definition at line 176 of file native_type.h.

176{}

Member Function Documentation

◆ AlignmentInBytesField()

virtual intptr_t dart::compiler::ffi::NativeType::AlignmentInBytesField ( ) const
pure virtual

◆ AlignmentInBytesStack()

virtual intptr_t dart::compiler::ffi::NativeType::AlignmentInBytesStack ( bool  is_vararg = false) const
pure virtual

◆ AsArray()

const NativeArrayType & dart::compiler::ffi::NativeType::AsArray ( ) const

Definition at line 51 of file native_type.cc.

51 {
52 ASSERT(IsArray());
53 return static_cast<const NativeArrayType&>(*this);
54}
virtual bool IsArray() const
Definition native_type.h:82
#define ASSERT(E)

◆ AsCompound()

const NativeCompoundType & dart::compiler::ffi::NativeType::AsCompound ( ) const

Definition at line 56 of file native_type.cc.

56 {
58 return static_cast<const NativeCompoundType&>(*this);
59}
virtual bool IsCompound() const
Definition native_type.h:84

◆ AsPrimitive()

const NativePrimitiveType & dart::compiler::ffi::NativeType::AsPrimitive ( ) const

Definition at line 46 of file native_type.cc.

46 {
48 return static_cast<const NativePrimitiveType&>(*this);
49}
virtual bool IsPrimitive() const
Definition native_type.h:80

◆ AsRepresentation()

virtual Representation dart::compiler::ffi::NativeType::AsRepresentation ( ) const
inlinevirtual

Reimplemented in dart::compiler::ffi::NativePrimitiveType.

Definition at line 121 of file native_type.h.

121{ UNREACHABLE_THIS(); }
#define UNREACHABLE_THIS()
Definition native_type.h:25

◆ AsRepresentationOverApprox()

Representation dart::compiler::ffi::NativeType::AsRepresentationOverApprox ( Zone zone_) const

Definition at line 1076 of file native_type.cc.

1076 {
1077 if (IsPrimitive()) {
1078 switch (AsPrimitive().representation()) {
1079 case kInt24:
1080 return kUnboxedInt32;
1081 case kUint24:
1082 return kUnboxedUint32;
1083 case kInt40:
1084 case kUint40:
1085 case kInt48:
1086 case kUint48:
1087 case kInt56:
1088 case kUint56:
1089 return kUnboxedInt64;
1090 default:
1091 break;
1092 }
1093 }
1094 const auto& widened = WidenTo4Bytes(zone_);
1095 return widened.AsRepresentation();
1096}
const NativePrimitiveType & AsPrimitive() const
const NativeType & WidenTo4Bytes(Zone *zone) const

◆ AsStruct()

const NativeStructType & dart::compiler::ffi::NativeType::AsStruct ( ) const

Definition at line 61 of file native_type.cc.

61 {
63 return static_cast<const NativeStructType&>(*this);
64}
virtual bool IsStruct() const
Definition native_type.h:86

◆ ContainsOnlyFloats()

virtual bool dart::compiler::ffi::NativeType::ContainsOnlyFloats ( Range  range) const
pure virtual

◆ ContainsUnalignedMembers()

virtual bool dart::compiler::ffi::NativeType::ContainsUnalignedMembers ( intptr_t  offset = 0) const
pure virtual

◆ Equals()

virtual bool dart::compiler::ffi::NativeType::Equals ( const NativeType other) const
inlinevirtual

◆ Extend()

const NativeType & dart::compiler::ffi::NativeType::Extend ( Zone zone,
ExtensionStrategy  extension 
) const
inline

Definition at line 140 of file native_type.h.

140 {
141 switch (extension) {
142 case kNotExtended:
143 return *this;
144 case kExtendedTo4:
145 return WidenTo4Bytes(zone);
146 case kExtendedTo8:
147 return WidenTo8Bytes(zone);
148 default:
149 UNREACHABLE();
150 }
151 }
#define UNREACHABLE()
Definition assert.h:248
const NativeType & WidenTo8Bytes(Zone *zone) const
@ kExtendedTo4
@ kNotExtended
@ kExtendedTo8

◆ FirstPrimitiveMember()

virtual const NativePrimitiveType & dart::compiler::ffi::NativeType::FirstPrimitiveMember ( ) const
pure virtual

◆ FromAbstractType()

const NativeType * dart::compiler::ffi::NativeType::FromAbstractType ( Zone zone,
const AbstractType type,
const char **  error 
)
static

Definition at line 549 of file native_type.cc.

551 {
552 const classid_t class_id = type.type_class_id();
553 if (IsFfiPredefinedClassId(class_id)) {
554 return &NativeType::FromTypedDataClassId(zone, class_id);
555 }
556
557 // User-defined structs, unions, or Abi-specific integers.
558 const auto& cls = Class::Handle(zone, type.type_class());
559 const auto& superClass = Class::Handle(zone, cls.SuperClass());
560 const bool is_struct = String::Handle(zone, superClass.UserVisibleName())
561 .Equals(Symbols::Struct());
562 const bool is_union = String::Handle(zone, superClass.UserVisibleName())
563 .Equals(Symbols::Union());
564 const bool is_abi_specific_int =
565 String::Handle(zone, superClass.UserVisibleName())
566 .Equals(Symbols::AbiSpecificInteger());
567 RELEASE_ASSERT(is_struct || is_union || is_abi_specific_int);
568
569 auto& pragmas = Object::Handle(zone);
570 String& pragma_name = String::Handle(zone);
571 if (is_struct || is_union) {
572 pragma_name = Symbols::vm_ffi_struct_fields().ptr();
573 } else {
574 ASSERT(is_abi_specific_int);
575 pragma_name = Symbols::vm_ffi_abi_specific_mapping().ptr();
576 }
577 Library::FindPragma(dart::Thread::Current(), /*only_core=*/false, cls,
578 pragma_name, /*multiple=*/true, &pragmas);
579 ASSERT(!pragmas.IsNull());
580 ASSERT(pragmas.IsGrowableObjectArray());
581 const auto& pragmas_array = GrowableObjectArray::Cast(pragmas);
582 auto& pragma = Instance::Handle(zone);
583 auto& clazz = Class::Handle(zone);
584 auto& library = Library::Handle(zone);
585 String& class_symbol = String::Handle(zone);
586 if (is_struct || is_union) {
587 class_symbol = Symbols::FfiStructLayout().ptr();
588 } else {
589 ASSERT(is_abi_specific_int);
590 class_symbol = Symbols::FfiAbiSpecificMapping().ptr();
591 }
592 for (intptr_t i = 0; i < pragmas_array.Length(); i++) {
593 pragma ^= pragmas_array.At(i);
594 clazz ^= pragma.clazz();
595 library ^= clazz.library();
596 if (String::Handle(zone, clazz.UserVisibleName()).Equals(class_symbol) &&
597 String::Handle(zone, library.url()).Equals(Symbols::DartFfi())) {
598 break;
599 }
600 }
601
602 if (is_struct || is_union) {
603 return CompoundFromPragma(zone, pragma, is_struct, error);
604 }
605 ASSERT(is_abi_specific_int);
606 return AbiSpecificFromPragma(zone, pragma, cls, error);
607}
#define RELEASE_ASSERT(cond)
Definition assert.h:327
static bool FindPragma(Thread *T, bool only_core, const Object &object, const String &pragma_name, bool multiple=false, Object *options=nullptr)
Definition object.cc:4201
static Object & Handle()
Definition object.h:407
static Thread * Current()
Definition thread.h:361
static const NativeType & FromTypedDataClassId(Zone *zone, classid_t class_id)
const uint8_t uint32_t uint32_t GError ** error
static const NativeType * CompoundFromPragma(Zone *zone, const Instance &pragma, bool is_struct, const char **error)
static const NativeType * AbiSpecificFromPragma(Zone *zone, const Instance &pragma, const Class &abi_specific_int, const char **error)
bool IsFfiPredefinedClassId(classid_t class_id)
Definition class_id.h:527
int32_t classid_t
Definition globals.h:524

◆ FromRepresentation()

NativePrimitiveType & dart::compiler::ffi::NativeType::FromRepresentation ( Zone zone,
Representation  rep 
)
static

Definition at line 632 of file native_type.cc.

633 {
634 return *new (zone) NativePrimitiveType(fundamental_rep(rep));
635}
static PrimitiveType fundamental_rep(Representation rep)

◆ FromTypedDataClassId()

const NativeType & dart::compiler::ffi::NativeType::FromTypedDataClassId ( Zone zone,
classid_t  class_id 
)
static

Definition at line 435 of file native_type.cc.

436 {
438 const auto fundamental_rep = TypeRepresentation(class_id);
439 return *new (zone) NativePrimitiveType(fundamental_rep);
440}
static PrimitiveType TypeRepresentation(classid_t class_id)

◆ IsArray()

virtual bool dart::compiler::ffi::NativeType::IsArray ( ) const
inlinevirtual

Reimplemented in dart::compiler::ffi::NativeArrayType.

Definition at line 82 of file native_type.h.

82{ return false; }

◆ IsCompound()

virtual bool dart::compiler::ffi::NativeType::IsCompound ( ) const
inlinevirtual

Reimplemented in dart::compiler::ffi::NativeCompoundType.

Definition at line 84 of file native_type.h.

84{ return false; }

◆ IsExpressibleAsRepresentation()

virtual bool dart::compiler::ffi::NativeType::IsExpressibleAsRepresentation ( ) const
inlinevirtual

Reimplemented in dart::compiler::ffi::NativePrimitiveType.

Definition at line 118 of file native_type.h.

118{ return false; }

◆ IsFloat()

virtual bool dart::compiler::ffi::NativeType::IsFloat ( ) const
inlinevirtual

Reimplemented in dart::compiler::ffi::NativePrimitiveType.

Definition at line 90 of file native_type.h.

90{ return false; }

◆ IsInt()

virtual bool dart::compiler::ffi::NativeType::IsInt ( ) const
inlinevirtual

Reimplemented in dart::compiler::ffi::NativePrimitiveType.

Definition at line 89 of file native_type.h.

89{ return false; }

◆ IsPrimitive()

virtual bool dart::compiler::ffi::NativeType::IsPrimitive ( ) const
inlinevirtual

Reimplemented in dart::compiler::ffi::NativePrimitiveType.

Definition at line 80 of file native_type.h.

80{ return false; }

◆ IsSigned()

virtual bool dart::compiler::ffi::NativeType::IsSigned ( ) const
inlinevirtual

Reimplemented in dart::compiler::ffi::NativePrimitiveType.

Definition at line 93 of file native_type.h.

93{ return false; }

◆ IsStruct()

virtual bool dart::compiler::ffi::NativeType::IsStruct ( ) const
inlinevirtual

Reimplemented in dart::compiler::ffi::NativeStructType.

Definition at line 86 of file native_type.h.

86{ return false; }

◆ IsVoid()

virtual bool dart::compiler::ffi::NativeType::IsVoid ( ) const
inlinevirtual

Reimplemented in dart::compiler::ffi::NativePrimitiveType.

Definition at line 91 of file native_type.h.

91{ return false; }

◆ NumPrimitiveMembersRecursive()

virtual intptr_t dart::compiler::ffi::NativeType::NumPrimitiveMembersRecursive ( ) const
pure virtual

◆ PrimitivePairMembers()

virtual intptr_t dart::compiler::ffi::NativeType::PrimitivePairMembers ( const NativePrimitiveType **  first,
const NativePrimitiveType **  second,
intptr_t  offset_in_members = 0 
) const
pure virtual

◆ PrintTo()

void dart::compiler::ffi::NativeType::PrintTo ( BaseTextBuffer f,
bool  multi_line = false,
bool  verbose = true 
) const
virtual

◆ SizeInBytes()

virtual intptr_t dart::compiler::ffi::NativeType::SizeInBytes ( ) const
pure virtual

◆ Split()

virtual NativeType & dart::compiler::ffi::NativeType::Split ( Zone zone,
intptr_t  index 
) const
inlinevirtual

Reimplemented in dart::compiler::ffi::NativePrimitiveType.

Definition at line 130 of file native_type.h.

130 {
132 }

◆ ToCString() [1/2]

const char * dart::compiler::ffi::NativeType::ToCString ( ) const

Definition at line 663 of file native_type.cc.

663 {
664 return ToCString(Thread::Current()->zone());
665}
const char * ToCString() const

◆ ToCString() [2/2]

const char * dart::compiler::ffi::NativeType::ToCString ( Zone zone,
bool  multi_line = false,
bool  verbose = true 
) const

Definition at line 654 of file native_type.cc.

656 {
657 ZoneTextBuffer textBuffer(zone);
658 PrintTo(&textBuffer, multi_line, verbose);
659 return textBuffer.buffer();
660}
virtual void PrintTo(BaseTextBuffer *f, bool multi_line=false, bool verbose=true) const

◆ WidenTo4Bytes()

const NativeType & dart::compiler::ffi::NativeType::WidenTo4Bytes ( Zone zone) const

Definition at line 1099 of file native_type.cc.

1099 {
1100 if (IsInt() && SizeInBytes() <= 2) {
1101 if (IsSigned()) {
1102 return *new (zone) NativePrimitiveType(kInt32);
1103 } else {
1104 return *new (zone) NativePrimitiveType(kUint32);
1105 }
1106 }
1107 return *this;
1108}
virtual bool IsInt() const
Definition native_type.h:89
virtual bool IsSigned() const
Definition native_type.h:93
virtual intptr_t SizeInBytes() const =0

◆ WidenTo8Bytes()

const NativeType & dart::compiler::ffi::NativeType::WidenTo8Bytes ( Zone zone) const

Definition at line 1110 of file native_type.cc.

1110 {
1111 if (IsInt() && SizeInBytes() <= 4) {
1112 if (IsSigned()) {
1113 return *new (zone) NativePrimitiveType(kInt64);
1114 } else {
1115 return *new (zone) NativePrimitiveType(kUint64);
1116 }
1117 }
1118 return *this;
1119}

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