diff options
author | Nick Fitzgerald <fitzgen@gmail.com> | 2016-11-15 13:31:59 -0800 |
---|---|---|
committer | Nick Fitzgerald <fitzgen@gmail.com> | 2016-11-15 13:36:27 -0800 |
commit | 8d897009a217be80d9a9133915f30e51812f18c1 (patch) | |
tree | 8bbee9f86921421b6d63e03dcffe27f7ffe7f81c | |
parent | 6b285e617ede6d3dbd6d2d0129ac81bc992a1593 (diff) |
Clean up AST dumping
This adds labels to each thing that gets printed for each AST node, and
uses a range for indent iteration rather than an index variable.
-rw-r--r-- | libbindgen/src/clang.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/libbindgen/src/clang.rs b/libbindgen/src/clang.rs index 7da755ea..d10457b3 100644 --- a/libbindgen/src/clang.rs +++ b/libbindgen/src/clang.rs @@ -1235,21 +1235,23 @@ pub fn type_to_str(x: Enum_CXTypeKind) -> String { /// Dump the Clang AST to stdout for debugging purposes. pub fn ast_dump(c: &Cursor, depth: isize) -> Enum_CXVisitorResult { fn print_indent(depth: isize, s: &str) { - let mut i = 0; - while i < depth { + for _ in 0..depth { print!("\t"); - i += 1; } println!("{}", s); } - let ct = c.cur_type().kind(); + print_indent(depth, - &format!("({} {} {}", + &format!("(kind: {}, spelling: {}, type: {}", kind_to_str(c.kind()), c.spelling(), - type_to_str(ct))); + type_to_str(c.cur_type().kind()))); + + // Recurse. c.visit(|s| ast_dump(&s, depth + 1)); + print_indent(depth, ")"); + CXChildVisit_Continue } |