pub struct Type<'tu> { /* private fields */ }
Expand description
The type of an AST entity.
Implementations§
Source§impl<'tu> Type<'tu>
impl<'tu> Type<'tu>
Sourcepub fn get_display_name(&self) -> String
pub fn get_display_name(&self) -> String
Returns the display name of this type.
Sourcepub fn get_alignof(&self) -> Result<usize, AlignofError>
pub fn get_alignof(&self) -> Result<usize, AlignofError>
Returns the alignment of this type in bytes.
§Failures
- this type is a dependent type
- this type is an incomplete type
Sourcepub fn get_offsetof<F: AsRef<str>>(
&self,
field: F,
) -> Result<usize, OffsetofError>
pub fn get_offsetof<F: AsRef<str>>( &self, field: F, ) -> Result<usize, OffsetofError>
Returns the offset of the field with the supplied name in this record type in bits.
§Failures
- this record type is a dependent type
- this record record type is an incomplete type
- this record type does not contain a field with the supplied name
Examples found in repository?
5fn main() {
6 // Acquire an instance of `Clang`
7 let clang = Clang::new().unwrap();
8
9 // Create a new `Index`
10 let index = Index::new(&clang, false, false);
11
12 // Parse a source file into a translation unit
13 let tu = index.parser("examples/structs.c").parse().unwrap();
14
15 // Get the structs in this translation unit
16 let structs = tu.get_entity().get_children().into_iter().filter(|e| {
17 e.get_kind() == EntityKind::StructDecl
18 }).collect::<Vec<_>>();
19
20 // Print information about the structs
21 for struct_ in structs {
22 let type_ = struct_.get_type().unwrap();
23 let size = type_.get_sizeof().unwrap();
24 println!("struct: {:?} (size: {} bytes)", struct_.get_name().unwrap(), size);
25
26 for field in struct_.get_children() {
27 let name = field.get_name().unwrap();
28 let offset = type_.get_offsetof(&name).unwrap();
29 println!(" field: {:?} (offset: {} bits)", name, offset);
30 }
31 }
32}
Sourcepub fn get_sizeof(&self) -> Result<usize, SizeofError>
pub fn get_sizeof(&self) -> Result<usize, SizeofError>
Returns the size of this type in bytes.
§Failures
- this type is a dependent type
- this type is an incomplete type
- this type is a variable size type
Examples found in repository?
5fn main() {
6 // Acquire an instance of `Clang`
7 let clang = Clang::new().unwrap();
8
9 // Create a new `Index`
10 let index = Index::new(&clang, false, false);
11
12 // Parse a source file into a translation unit
13 let tu = index.parser("examples/structs.c").parse().unwrap();
14
15 // Get the structs in this translation unit
16 let structs = tu.get_entity().get_children().into_iter().filter(|e| {
17 e.get_kind() == EntityKind::StructDecl
18 }).collect::<Vec<_>>();
19
20 // Print information about the structs
21 for struct_ in structs {
22 let type_ = struct_.get_type().unwrap();
23 let size = type_.get_sizeof().unwrap();
24 println!("struct: {:?} (size: {} bytes)", struct_.get_name().unwrap(), size);
25
26 for field in struct_.get_children() {
27 let name = field.get_name().unwrap();
28 let offset = type_.get_offsetof(&name).unwrap();
29 println!(" field: {:?} (offset: {} bits)", name, offset);
30 }
31 }
32}
Sourcepub fn get_address_space(&self) -> usize
pub fn get_address_space(&self) -> usize
Returns the address space of this type.
Sourcepub fn get_argument_types(&self) -> Option<Vec<Type<'tu>>>
pub fn get_argument_types(&self) -> Option<Vec<Type<'tu>>>
Returns the argument types for this function or method type, if applicable.
Sourcepub fn get_calling_convention(&self) -> Option<CallingConvention>
pub fn get_calling_convention(&self) -> Option<CallingConvention>
Returns the calling convention specified for this function type, if applicable.
Sourcepub fn get_canonical_type(&self) -> Type<'tu>
pub fn get_canonical_type(&self) -> Type<'tu>
Returns the canonical type for this type.
The canonical type is the underlying type with all “sugar” removed (e.g., typedefs).
Sourcepub fn get_class_type(&self) -> Option<Type<'tu>>
pub fn get_class_type(&self) -> Option<Type<'tu>>
Returns the class type for this member pointer type, if applicable.
Sourcepub fn get_declaration(&self) -> Option<Entity<'tu>>
pub fn get_declaration(&self) -> Option<Entity<'tu>>
Returns the AST entity that declared this type, if any.
Sourcepub fn get_elaborated_type(&self) -> Option<Type<'tu>>
pub fn get_elaborated_type(&self) -> Option<Type<'tu>>
Returns the type named by this elaborated type, if applicable.
Sourcepub fn get_element_type(&self) -> Option<Type<'tu>>
pub fn get_element_type(&self) -> Option<Type<'tu>>
Returns the element type for this array, complex, or vector type, if applicable.
Sourcepub fn get_exception_specification(&self) -> Option<ExceptionSpecification>
pub fn get_exception_specification(&self) -> Option<ExceptionSpecification>
Returns the exception specification of this type, if applicable.
Sourcepub fn get_fields(&self) -> Option<Vec<Entity<'tu>>>
pub fn get_fields(&self) -> Option<Vec<Entity<'tu>>>
Returns the fields in this record type, if applicable.
Sourcepub fn get_modified_type(&self) -> Option<Type<'tu>>
pub fn get_modified_type(&self) -> Option<Type<'tu>>
Return the type that was modified by this attributed type.
Sourcepub fn get_nullability(&self) -> Option<Nullability>
pub fn get_nullability(&self) -> Option<Nullability>
Returns the nullability of this pointer type, if applicable.
Sourcepub fn get_objc_encoding(&self) -> Option<String>
pub fn get_objc_encoding(&self) -> Option<String>
Returns the encoding of this Objective-C type, if applicable.
Sourcepub fn get_objc_object_base_type(&self) -> Option<Type<'_>>
pub fn get_objc_object_base_type(&self) -> Option<Type<'_>>
Returns the base type of this Objective-C type, if applicable.
Sourcepub fn get_objc_protocol_declarations(&self) -> Vec<Entity<'tu>>
pub fn get_objc_protocol_declarations(&self) -> Vec<Entity<'tu>>
Returns the declarations for all protocol references for this Objective-C type, if applicable.
Sourcepub fn get_objc_type_arguments(&self) -> Vec<Type<'tu>>
pub fn get_objc_type_arguments(&self) -> Vec<Type<'tu>>
Returns the type arguments for this Objective-C type, if applicable.
Sourcepub fn get_pointee_type(&self) -> Option<Type<'tu>>
pub fn get_pointee_type(&self) -> Option<Type<'tu>>
Returns the pointee type for this pointer type, if applicable.
Sourcepub fn get_ref_qualifier(&self) -> Option<RefQualifier>
pub fn get_ref_qualifier(&self) -> Option<RefQualifier>
Returns the ref qualifier for this C++ function or method type, if applicable.
Sourcepub fn get_result_type(&self) -> Option<Type<'tu>>
pub fn get_result_type(&self) -> Option<Type<'tu>>
Returns the result type for this function or method type, if applicable.
Sourcepub fn get_size(&self) -> Option<usize>
pub fn get_size(&self) -> Option<usize>
Returns the size of this constant array or vector type, if applicable.
Sourcepub fn get_template_argument_types(&self) -> Option<Vec<Option<Type<'tu>>>>
pub fn get_template_argument_types(&self) -> Option<Vec<Option<Type<'tu>>>>
Returns the template argument types for this template class specialization type, if applicable.
Sourcepub fn get_typedef_name(&self) -> Option<String>
pub fn get_typedef_name(&self) -> Option<String>
Returns the typedef name of this type, if applicable.
Sourcepub fn is_const_qualified(&self) -> bool
pub fn is_const_qualified(&self) -> bool
Returns whether this type is qualified with const.
Sourcepub fn is_elaborated(&self) -> Option<bool>
pub fn is_elaborated(&self) -> Option<bool>
Returns whether this type is an elaborated type, if it can be determined for certain.
Sourcepub fn is_restrict_qualified(&self) -> bool
pub fn is_restrict_qualified(&self) -> bool
Returns whether this type is qualified with restrict.
Sourcepub fn is_transparent_tag(&self) -> bool
pub fn is_transparent_tag(&self) -> bool
Returns whether this type is a transparent tag typedef.
Sourcepub fn is_variadic(&self) -> bool
pub fn is_variadic(&self) -> bool
Returns whether this type is a variadic function type.
Sourcepub fn is_volatile_qualified(&self) -> bool
pub fn is_volatile_qualified(&self) -> bool
Returns whether this type is qualified with volatile.
Sourcepub fn visit_fields<F: FnMut(Entity<'tu>) -> bool>(&self, f: F) -> Option<bool>
pub fn visit_fields<F: FnMut(Entity<'tu>) -> bool>(&self, f: F) -> Option<bool>
Visits the fields in this record type, returning None
if this type is not a record type
and returning Some(b)
otherwise where b
indicates whether visitation was ended by the
callback returning false
.
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns whether this type is an integer type.
Sourcepub fn is_signed_integer(&self) -> bool
pub fn is_signed_integer(&self) -> bool
Returns whether this type is a signed integer type.
Sourcepub fn is_unsigned_integer(&self) -> bool
pub fn is_unsigned_integer(&self) -> bool
Returns whether this type is an unsigned integer type.