extern crate clang;
use clang::*;
fn main() {
let clang = Clang::new().unwrap();
let index = Index::new(&clang, false, false);
let tu = TranslationUnit::from_source(
&index, "examples/structs.c", &[], &[], ParseOptions::default()
).unwrap();
let structs = tu.get_entity().get_children().into_iter().filter(|e| {
e.get_kind() == EntityKind::StructDecl
}).collect::<Vec<_>>();
for struct_ in structs {
let type_ = struct_.get_type().unwrap();
let size = type_.get_sizeof().unwrap();
println!("struct: {:?} (size: {} bytes)", struct_.get_name().unwrap(), size);
for field in struct_.get_children() {
let name = field.get_name().unwrap();
let offset = type_.get_offsetof(&name).unwrap();
println!(" field: {:?} (offset: {} bits)", name, offset);
}
}
}