Struct Entity

Source
pub struct Entity<'tu> { /* private fields */ }
Expand description

An AST entity.

Implementations§

Source§

impl<'tu> Entity<'tu>

Source

pub fn evaluate(&self) -> Option<EvaluationResult>

Evaluates this AST entity, if possible.

Source

pub fn get_kind(&self) -> EntityKind

Returns the categorization of this AST entity.

Examples found in repository?
examples/structs.rs (line 17)
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}
Source

pub fn get_display_name(&self) -> Option<String>

Returns the display name of this AST entity, if any.

The display name of an entity contains additional information that helps identify the entity.

Source

pub fn get_pretty_printer(&self) -> PrettyPrinter<'_>

Returns the pretty printer for this declaration.

Source

pub fn get_location(&self) -> Option<SourceLocation<'tu>>

Returns the source location of this AST entity, if any.

Source

pub fn get_range(&self) -> Option<SourceRange<'tu>>

Returns the source range of this AST entity, if any.

Source

pub fn get_accessibility(&self) -> Option<Accessibility>

Returns the accessibility of this declaration or base class specifier, if applicable.

Source

pub fn get_arguments(&self) -> Option<Vec<Entity<'tu>>>

Returns the arguments of this function or method, if applicable.

Source

pub fn get_availability(&self) -> Availability

Returns the availability of this AST entity.

Source

pub fn get_bit_field_width(&self) -> Option<usize>

Returns the width of this bit field, if applicable.

Source

pub fn get_canonical_entity(&self) -> Entity<'tu>

Returns the canonical entity for this AST entity.

In the C family of languages, some types of entities can be declared multiple times. When there are multiple declarations of the same entity, only one will be considered canonical.

Source

pub fn get_comment(&self) -> Option<String>

Returns the comment associated with this AST entity, if any.

Source

pub fn get_parsed_comment(&self) -> Option<Comment<'tu>>

Returns the parsed comment associated with this declaration, if applicable.

Source

pub fn get_comment_brief(&self) -> Option<String>

Returns the brief of the comment associated with this AST entity, if any.

Source

pub fn get_comment_range(&self) -> Option<SourceRange<'tu>>

Returns the source range of the comment associated with this AST entity, if any.

Source

pub fn get_completion_string(&self) -> Option<CompletionString<'_>>

Returns a completion string for this declaration or macro definition, if applicable.

Source

pub fn get_child(&self, index: usize) -> Option<Entity<'tu>>

Returns the child of this AST entity with the supplied index.

Source

pub fn get_children(&self) -> Vec<Entity<'tu>>

Returns the children of this AST entity.

Examples found in repository?
examples/structs.rs (line 16)
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}
Source

pub fn get_definition(&self) -> Option<Entity<'tu>>

Returns the AST entity that describes the definition of this AST entity, if any.

Source

pub fn get_enum_constant_value(&self) -> Option<(i64, u64)>

Returns the value of this enum constant declaration, if applicable.

Source

pub fn get_enum_underlying_type(&self) -> Option<Type<'tu>>

Returns the underlying type of this enum declaration, if applicable.

Source

pub fn get_exception_specification(&self) -> Option<ExceptionSpecification>

Returns the exception specification of this AST entity, if applicable.

Source

pub fn get_external_symbol(&self) -> Option<ExternalSymbol>

Returns the external_source_symbol attribute attached to this AST entity, if any.

Source

pub fn get_file(&self) -> Option<File<'tu>>

Returns the file included by this inclusion directive, if applicable.

Source

pub fn get_language(&self) -> Option<Language>

Returns the language used by this declaration, if applicable.

Source

pub fn get_lexical_parent(&self) -> Option<Entity<'tu>>

Returns the lexical parent of this AST entity, if any.

Source

pub fn get_linkage(&self) -> Option<Linkage>

Returns the linkage of this AST entity, if any.

Source

pub fn get_mangled_name(&self) -> Option<String>

Returns the mangled name of this AST entity, if any.

Source

pub fn get_mangled_names(&self) -> Option<Vec<String>>

Returns the mangled names of this C++ constructor or destructor, if applicable.

Source

pub fn get_mangled_objc_names(&self) -> Option<Vec<String>>

Returns the mangled names of this Objective-C class interface or implementation, if applicable.

Source

pub fn get_module(&self) -> Option<Module<'tu>>

Returns the module imported by this module import declaration, if applicable.

Source

pub fn get_name(&self) -> Option<String>

Returns the name of this AST entity, if any.

Examples found in repository?
examples/structs.rs (line 24)
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}
Source

pub fn get_name_ranges(&self) -> Vec<SourceRange<'tu>>

Returns the source ranges of the name of this AST entity.

Source

pub fn get_objc_attributes(&self) -> Option<ObjCAttributes>

Returns which attributes were applied to this Objective-C property, if applicable.

Source

pub fn get_objc_getter_name(&self) -> Option<String>

Returns the name of the method implementing the getter for this Objective-C property, if applicable

Source

pub fn get_objc_ib_outlet_collection_type(&self) -> Option<Type<'tu>>

Returns the element type for this Objective-C iboutletcollection attribute, if applicable.

Source

pub fn get_objc_receiver_type(&self) -> Option<Type<'tu>>

Returns the type of the receiver of this Objective-C message, if applicable.

Source

pub fn get_objc_selector_index(&self) -> Option<usize>

Returns the selector index for this Objective-C selector identifier, if applicable.

Source

pub fn get_objc_setter_name(&self) -> Option<String>

Returns the name of the method implementing the setter for this Objective-C property, if applicable

Source

pub fn get_objc_type_encoding(&self) -> Option<String>

Returns the type encoding for this Objective-C declaration, if applicable.

Source

pub fn get_objc_qualifiers(&self) -> Option<ObjCQualifiers>

Returns which qualifiers were applied to this Objective-C method return or parameter type, if applicable.

Source

pub fn get_offset_of_field(&self) -> Result<usize, OffsetofError>

Returns the the offset of this field, if applicable.

Source

pub fn get_overloaded_declarations(&self) -> Option<Vec<Entity<'tu>>>

Returns the overloaded declarations referenced by this overloaded declaration reference, if applicable.

Source

pub fn get_overridden_methods(&self) -> Option<Vec<Entity<'tu>>>

Returns the methods that were overridden by this method, if applicable.

Source

pub fn get_platform_availability(&self) -> Option<Vec<PlatformAvailability>>

Returns the availability of this declaration on the platforms where it is known, if applicable.

Source

pub fn get_reference(&self) -> Option<Entity<'tu>>

Returns the AST entity referred to by this AST entity, if any.

Source

pub fn get_semantic_parent(&self) -> Option<Entity<'tu>>

Returns the semantic parent of this AST entity, if any.

Source

pub fn get_storage_class(&self) -> Option<StorageClass>

Returns the storage class of this declaration, if applicable.

Source

pub fn get_template(&self) -> Option<Entity<'tu>>

Returns the template declaration this template specialization was instantiated from, if applicable.

Source

pub fn get_template_arguments(&self) -> Option<Vec<TemplateArgument<'tu>>>

Returns the template arguments for this template function specialization, if applicable.

Source

pub fn get_template_kind(&self) -> Option<EntityKind>

Returns the categorization of the template specialization that would result from instantiating this template declaration, if applicable.

Source

pub fn get_tls_kind(&self) -> Option<TlsKind>

Returns the thread-local storage (TLS) kind of this declaration, if applicable.

Source

pub fn get_translation_unit(&self) -> &'tu TranslationUnit<'tu>

Returns the translation unit which contains this AST entity.

Source

pub fn get_type(&self) -> Option<Type<'tu>>

Returns the type of this AST entity, if any.

Examples found in repository?
examples/structs.rs (line 22)
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}
Source

pub fn get_typedef_underlying_type(&self) -> Option<Type<'tu>>

Returns the underlying type of this typedef declaration, if applicable.

Source

pub fn get_usr(&self) -> Option<Usr>

Returns the USR for this AST entity, if any.

Source

pub fn get_visibility(&self) -> Option<Visibility>

Returns the linker visibility for this AST entity, if any.

Source

pub fn get_result_type(&self) -> Option<Type<'tu>>

Returns the result type of this AST entity, if applicable.

Source

pub fn has_attributes(&self) -> bool

Returns whether this AST entity has any attached attributes.

Source

pub fn is_abstract_record(&self) -> bool

Returns whether this AST entity is an abstract C++ record.

Source

pub fn is_anonymous(&self) -> bool

Returns whether this AST entity is anonymous.

Prior to libclang 9.0, this only returned true if the entity was an anonymous record declaration. As of 9.0, it also returns true for anonymous namespaces. The old behavior is available as is_anonymous_record_decl() for libclang 9.0 and up.

Source

pub fn is_anonymous_record_decl(&self) -> bool

Returns whether this AST entity is an anonymous record declaration.

Source

pub fn is_inline_namespace(&self) -> bool

Returns whether this AST entity is an inline namespace.

Source

pub fn is_bit_field(&self) -> bool

Returns whether this AST entity is a bit field.

Source

pub fn is_builtin_macro(&self) -> bool

Returns whether this AST entity is a builtin macro.

Source

pub fn is_const_method(&self) -> bool

Returns whether this AST entity is a const method.

Source

pub fn is_converting_constructor(&self) -> bool

Returns whether this AST entity is a C++ converting constructor.

Source

pub fn is_copy_constructor(&self) -> bool

Returns whether this AST entity is a C++ copy constructor.

Source

pub fn is_default_constructor(&self) -> bool

Returns whether this AST entity is a C++ default constructor.

Source

pub fn is_defaulted(&self) -> bool

Returns whether this AST entity is a C++ defaulted constructor or method.

Source

pub fn is_definition(&self) -> bool

Returns whether this AST entity is a declaration and also the definition of that declaration.

Source

pub fn is_dynamic_call(&self) -> bool

Returns whether this AST entity is a dynamic call.

A dynamic call is either a call to a C++ virtual method or an Objective-C message where the receiver is an object instance, not super or a specific class.

Source

pub fn is_function_like_macro(&self) -> bool

Returns whether this AST entity is a function-like macro.

Source

pub fn is_inline_function(&self) -> bool

Returns whether this AST entity is an inline function.

Source

pub fn is_invalid_declaration(&self) -> bool

Returns whether this AST entity is an invalid declaration.

Source

pub fn is_move_constructor(&self) -> bool

Returns whether this AST entity is a C++ default constructor.

Source

pub fn is_mutable(&self) -> bool

Returns whether this AST entity is a mutable field in a C++ struct or class.

Source

pub fn is_objc_optional(&self) -> bool

Returns whether this AST entity is an Objective-C method or property declaration with the @optional attribute applied to it.

Source

pub fn is_pure_virtual_method(&self) -> bool

Returns whether this AST entity is a pure virtual method.

Source

pub fn is_scoped(&self) -> bool

Returns whether this AST entity is a scoped enum.

Source

pub fn is_static_method(&self) -> bool

Returns whether this AST entity is a static method.

Source

pub fn is_variadic(&self) -> bool

Returns whether this AST entity is a variadic function or method.

Source

pub fn is_virtual_base(&self) -> bool

Returns whether this AST entity is a virtual base class specifier.

Source

pub fn is_virtual_method(&self) -> bool

Returns whether this AST entity is a virtual method.

Source

pub fn visit_children<F: FnMut(Entity<'tu>, Entity<'tu>) -> EntityVisitResult>( &self, f: F, ) -> bool

Visits the children of this AST entity recursively and returns whether visitation was ended by the callback returning EntityVisitResult::Break.

The first argument of the callback is the AST entity being visited and the second argument is the parent of that AST entity. The return value of the callback determines how visitation will proceed.

Source

pub fn is_attribute(&self) -> bool

Returns whether this AST entity is categorized as an attribute.

Source

pub fn is_declaration(&self) -> bool

Returns whether this AST entity is categorized as a declaration.

Source

pub fn is_expression(&self) -> bool

Returns whether this AST entity is categorized as an expression.

Source

pub fn is_preprocessing(&self) -> bool

Returns whether this AST entity is categorized as a preprocessing entity.

Source

pub fn is_reference(&self) -> bool

Returns whether this AST entity is categorized as a reference.

Source

pub fn is_statement(&self) -> bool

Returns whether this AST entity is categorized as a statement.

Source

pub fn is_unexposed(&self) -> bool

Returns whether the categorization of this AST entity is unexposed.

Source

pub fn is_in_main_file(&self) -> bool

Returns whether this AST entity is in a main file.

Source

pub fn is_in_system_header(&self) -> bool

Returns whether this AST entity is in a system header.

Trait Implementations§

Source§

impl<'tu> Clone for Entity<'tu>

Source§

fn clone(&self) -> Entity<'tu>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'tu> Debug for Entity<'tu>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'tu> Hash for Entity<'tu>

Source§

fn hash<H: Hasher>(&self, hasher: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'tu> PartialEq for Entity<'tu>

Source§

fn eq(&self, other: &Entity<'tu>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'tu> Copy for Entity<'tu>

Source§

impl<'tu> Eq for Entity<'tu>

Auto Trait Implementations§

§

impl<'tu> Freeze for Entity<'tu>

§

impl<'tu> RefUnwindSafe for Entity<'tu>

§

impl<'tu> !Send for Entity<'tu>

§

impl<'tu> !Sync for Entity<'tu>

§

impl<'tu> Unpin for Entity<'tu>

§

impl<'tu> UnwindSafe for Entity<'tu>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.