From 8d897009a217be80d9a9133915f30e51812f18c1 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 15 Nov 2016 13:31:59 -0800 Subject: [PATCH 1/2] 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. --- libbindgen/src/clang.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libbindgen/src/clang.rs b/libbindgen/src/clang.rs index 7da755eaba..d10457b3b0 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 } From 60b1c83009c721ec7f6214d16a5035b62304afe9 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 15 Nov 2016 13:35:00 -0800 Subject: [PATCH 2/2] Add `debug!` logging in code generation This instruments each `CodeGenerator` implementation with a `debug!` logging macro. --- libbindgen/src/codegen/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs index 8e04fd7c05..65bc28d53a 100644 --- a/libbindgen/src/codegen/mod.rs +++ b/libbindgen/src/codegen/mod.rs @@ -228,9 +228,12 @@ impl CodeGenerator for Item { result: &mut CodegenResult, _extra: &()) { if self.is_hidden(ctx) || result.seen(self.id()) { + debug!("::codegen: Ignoring hidden or seen: self = {:?}", self); return; } + debug!("::codegen: self = {:?}", self); + result.set_seen(self.id()); match *self.kind() { @@ -264,6 +267,8 @@ impl CodeGenerator for Module { ctx: &BindgenContext, result: &mut CodegenResult, item: &Item) { + debug!("::codegen: item = {:?}", item); + if !ctx.options().enable_cxx_namespaces { for child in self.children() { ctx.resolve_item(*child).codegen(ctx, result, &()); @@ -299,6 +304,8 @@ impl CodeGenerator for Var { ctx: &BindgenContext, result: &mut CodegenResult, item: &Item) { + debug!("::codegen: item = {:?}", item); + let canonical_name = item.canonical_name(ctx); if result.seen_var(&canonical_name) { @@ -349,6 +356,8 @@ impl CodeGenerator for Type { ctx: &BindgenContext, result: &mut CodegenResult, item: &Item) { + debug!("::codegen: item = {:?}", item); + match *self.kind() { TypeKind::Void | TypeKind::NullPtr | @@ -600,6 +609,9 @@ impl CodeGenerator for CompInfo { result: &mut CodegenResult, item: &Item) { use aster::struct_field::StructFieldBuilder; + + debug!("::codegen: item = {:?}", item); + // Don't output classes with template parameters that aren't types, and // also don't output template specializations, neither total or partial. // @@ -1361,6 +1373,8 @@ impl CodeGenerator for Enum { ctx: &BindgenContext, result: &mut CodegenResult, item: &Item) { + debug!("::codegen: item = {:?}", item); + let name = item.canonical_name(ctx); let enum_ty = item.expect_type(); let layout = enum_ty.layout(ctx); @@ -1800,6 +1814,8 @@ impl CodeGenerator for Function { ctx: &BindgenContext, result: &mut CodegenResult, item: &Item) { + debug!("::codegen: item = {:?}", item); + let name = self.name(); let mut canonical_name = item.canonical_name(ctx); let mangled_name = self.mangled_name();