pub struct Index<'c> { /* private fields */ }
Expand description
A collection of translation units.
Implementations§
Source§impl<'c> Index<'c>
impl<'c> Index<'c>
Sourcepub fn new(_: &'c Clang, exclude: bool, diagnostics: bool) -> Index<'c>
pub fn new(_: &'c Clang, exclude: bool, diagnostics: bool) -> Index<'c>
Constructs a new Index
.
exclude
determines whether declarations from precompiled headers are excluded and
diagnostics
determines whether diagnostics are printed while parsing source files.
Examples found in repository?
examples/structs.rs (line 10)
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 parser<F: Into<PathBuf>>(&'c self, f: F) -> Parser<'c>
pub fn parser<F: Into<PathBuf>>(&'c self, f: F) -> Parser<'c>
Returns a parser for the supplied file.
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}
Sourcepub fn set_invocation_emission_path<P: AsRef<Path>>(&'c self, path: P)
pub fn set_invocation_emission_path<P: AsRef<Path>>(&'c self, path: P)
Sets the invocation emission path for this index.
Sourcepub fn get_thread_options(&self) -> ThreadOptions
pub fn get_thread_options(&self) -> ThreadOptions
Returns the thread options for this index.
Sourcepub fn set_thread_options(&mut self, options: ThreadOptions)
pub fn set_thread_options(&mut self, options: ThreadOptions)
Sets the thread options for this index.
Trait Implementations§
Auto Trait Implementations§
impl<'c> Freeze for Index<'c>
impl<'c> RefUnwindSafe for Index<'c>
impl<'c> !Send for Index<'c>
impl<'c> !Sync for Index<'c>
impl<'c> Unpin for Index<'c>
impl<'c> UnwindSafe for Index<'c>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more