Struct Parser

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

Parses translation units.

Implementations§

Source§

impl<'tu> Parser<'tu>

Source

pub fn cache_completion_results( &mut self, cache_completion_results: bool, ) -> &mut Parser<'tu>

Sets whether certain code completion results will be cached when the translation unit is reparsed.

This option increases the time it takes to reparse the translation unit but improves code completion performance.

Source

pub fn detailed_preprocessing_record( &mut self, detailed_preprocessing_record: bool, ) -> &mut Parser<'tu>

Sets whether a detailed preprocessing record will be constructed which tracks all macro definitions and instantiations.

Source

pub fn briefs_in_completion_results( &mut self, briefs_in_completion_results: bool, ) -> &mut Parser<'tu>

Sets whether documentation comment briefs will be included in code completion results.

Source

pub fn incomplete(&mut self, incomplete: bool) -> &mut Parser<'tu>

Sets whether the translation unit will be considered incomplete.

This option suppresses certain semantic analyses and is typically used when parsing headers with the intent of creating a precompiled header.

Source

pub fn skip_function_bodies( &mut self, skip_function_bodies: bool, ) -> &mut Parser<'tu>

Sets whether function and method bodies will be skipped.

Source

pub fn keep_going(&mut self, keep_going: bool) -> &mut Parser<'tu>

Sets whether processing will continue after a fatal error is encountered.

Source

pub fn single_file_parse(&mut self, single_file_parse: bool) -> &mut Parser<'tu>

Sets whether incremental processing will be used.

Source

pub fn limit_skip_function_bodies_to_preamble( &mut self, limit_skip_function_bodies_to_preamble: bool, ) -> &mut Parser<'tu>

Sets whether function bodies will only be skipped in the preamble.

Used in conjunction with skip_function_bodies.

Source

pub fn include_attributed_types( &mut self, include_attributed_types: bool, ) -> &mut Parser<'tu>

Sets whether attributed types should be included.

Source

pub fn visit_implicit_attributes( &mut self, visit_implicit_attributes: bool, ) -> &mut Parser<'tu>

Sets whether implicit attributes should be visited.

Source

pub fn ignore_non_errors_from_included_files( &mut self, ignore_non_errors_from_included_files: bool, ) -> &mut Parser<'tu>

Indicates that non-errors (e.g. warnings) from included files should be ignored.

Source

pub fn retain_excluded_conditional_blocks( &mut self, retain_excluded_conditional_blocks: bool, ) -> &mut Parser<'tu>

Sets whether the preprocessor will retain excluded conditional blocks.

Source§

impl<'tu> Parser<'tu>

Source

pub fn arguments<S: AsRef<str>>(&mut self, arguments: &[S]) -> &mut Parser<'tu>

Sets the compiler arguments to provide to libclang.

Any compiler argument that could be supplied to clang may be supplied to this function. However, the following arguments are ignored:

  • -c
  • -emit-ast
  • -fsyntax-only
  • -o and the following <output>
Source

pub fn unsaved(&mut self, unsaved: &[Unsaved]) -> &mut Parser<'tu>

Sets the unsaved files to use.

Source

pub fn parse(&self) -> Result<TranslationUnit<'tu>, SourceError>

Parses a translation unit.

§Failures
  • an error occurs while deserializing an AST file
  • libclang crashes
  • an unknown error occurs
Examples found in repository?
examples/structs.rs (line 13)
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}

Trait Implementations§

Source§

impl<'tu> Clone for Parser<'tu>

Source§

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

Returns a copy 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 Parser<'tu>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'tu> Freeze for Parser<'tu>

§

impl<'tu> RefUnwindSafe for Parser<'tu>

§

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

§

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

§

impl<'tu> Unpin for Parser<'tu>

§

impl<'tu> UnwindSafe for Parser<'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.