Created
July 31, 2016 11:07
-
-
Save VictorKoenders/9e7ee2f40bc1063f9865b682bc01a10e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate clang; | |
use clang::*; | |
fn main() { | |
// Acquire an instance of `Clang` | |
let clang = Clang::new().unwrap(); | |
// Create a new `Index` | |
let index = Index::new(&clang, false, false); | |
// Parse a source file into a translation unit | |
let tu = index.parser("examples/test.cpp").parse().unwrap(); | |
tu.save("output.txt"); | |
// Get the structs in this translation unit | |
let classes = tu.get_entity().get_children().into_iter().filter(|e| { | |
e.get_kind() == EntityKind::ClassDecl | |
}).collect::<Vec<_>>(); | |
// Print information about the structs | |
for class in classes { | |
let type_ = class.get_type().unwrap(); | |
let size = type_.get_sizeof().unwrap(); | |
println!("class: {:?} (size: {} bytes)", class.get_name().unwrap(), size); | |
for child in class.get_children().into_iter().filter(|e| e.get_kind() == EntityKind::FieldDecl) | |
{ | |
let name = child.get_name().unwrap(); | |
let type_ = child.get_type().unwrap(); | |
println!("\t{} {}", type_.get_display_name(), child.get_name().unwrap()); | |
} | |
} | |
} | |
/* Outputs: | |
class: "Test" (size: 16 bytes) | |
int _a | |
bool _b | |
Test * _c | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "test.hpp" | |
Test::Test(Test* test){ | |
} | |
Test::Test(void){ | |
} | |
void Test::TestMe(void){ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
class Test { | |
private: | |
int _a; | |
bool _b; | |
Test* _c; | |
public: | |
Test(Test* test); | |
Test(void); | |
void TestMe(void); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment