summaryrefslogtreecommitdiff
path: root/libbindgen/src
diff options
context:
space:
mode:
Diffstat (limited to 'libbindgen/src')
-rw-r--r--libbindgen/src/codegen/mod.rs13
-rw-r--r--libbindgen/src/ir/context.rs24
-rw-r--r--libbindgen/src/ir/module.rs4
-rw-r--r--libbindgen/src/lib.rs11
4 files changed, 24 insertions, 28 deletions
diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs
index ba52fa83..ad9ac2de 100644
--- a/libbindgen/src/codegen/mod.rs
+++ b/libbindgen/src/codegen/mod.rs
@@ -270,16 +270,11 @@ impl CodeGenerator for Module {
debug!("<Module as CodeGenerator>::codegen: item = {:?}", item);
let codegen_self = |result: &mut CodegenResult, found_any: &mut bool| {
- // FIXME: This could be less expensive, I guess.
- for &whitelisted_item in whitelisted_items {
- if whitelisted_item == item.id() {
- continue;
- }
-
- let child = ctx.resolve_item(whitelisted_item);
- if child.parent_id() == item.id() {
+ for child in self.children() {
+ if whitelisted_items.contains(child) {
*found_any = true;
- child.codegen(ctx, result, whitelisted_items, &());
+ ctx.resolve_item(*child)
+ .codegen(ctx, result, whitelisted_items, &());
}
}
};
diff --git a/libbindgen/src/ir/context.rs b/libbindgen/src/ir/context.rs
index e599160e..67db2a59 100644
--- a/libbindgen/src/ir/context.rs
+++ b/libbindgen/src/ir/context.rs
@@ -184,6 +184,17 @@ impl<'ctx> BindgenContext<'ctx> {
let id = item.id();
let is_type = item.kind().is_type();
let is_unnamed = is_type && item.expect_type().name().is_none();
+
+ // Be sure to track all the generated children under namespace, even
+ // those generated after resolving typerefs, etc.
+ if item.id() != item.parent_id() {
+ if let Some(mut parent) = self.items.get_mut(&item.parent_id()) {
+ if let Some(mut module) = parent.as_module_mut() {
+ module.children_mut().push(item.id());
+ }
+ }
+ }
+
let old_item = self.items.insert(id, item);
assert!(old_item.is_none(), "Inserted type twice?");
@@ -898,23 +909,14 @@ impl<'ctx> BindgenContext<'ctx> {
/// Start traversing the module with the given `module_id`, invoke the
/// callback `cb`, and then return to traversing the original module.
pub fn with_module<F>(&mut self, module_id: ItemId, cb: F)
- where F: FnOnce(&mut Self, &mut Vec<ItemId>),
+ where F: FnOnce(&mut Self),
{
debug_assert!(self.resolve_item(module_id).kind().is_module(), "Wat");
let previous_id = self.current_module;
self.current_module = module_id;
- let mut children = vec![];
- cb(self, &mut children);
-
- self.items
- .get_mut(&module_id)
- .unwrap()
- .as_module_mut()
- .expect("Not a module?")
- .children_mut()
- .extend(children.into_iter());
+ cb(self);
self.current_module = previous_id;
}
diff --git a/libbindgen/src/ir/module.rs b/libbindgen/src/ir/module.rs
index c5d8cfa7..7546a63c 100644
--- a/libbindgen/src/ir/module.rs
+++ b/libbindgen/src/ir/module.rs
@@ -47,9 +47,9 @@ impl ClangSubItemParser for Module {
match cursor.kind() {
CXCursor_Namespace => {
let module_id = ctx.module(cursor);
- ctx.with_module(module_id, |ctx, children| {
+ ctx.with_module(module_id, |ctx| {
cursor.visit(|cursor| {
- parse_one(ctx, cursor, Some(module_id), children)
+ parse_one(ctx, cursor, Some(module_id))
})
});
diff --git a/libbindgen/src/lib.rs b/libbindgen/src/lib.rs
index 84c69310..10961e36 100644
--- a/libbindgen/src/lib.rs
+++ b/libbindgen/src/lib.rs
@@ -544,8 +544,7 @@ fn filter_builtins(ctx: &BindgenContext, cursor: &clang::Cursor) -> bool {
/// Parse one `Item` from the Clang cursor.
pub fn parse_one(ctx: &mut BindgenContext,
cursor: clang::Cursor,
- parent: Option<ItemId>,
- children: &mut Vec<ItemId>)
+ parent: Option<ItemId>)
-> clangll::Enum_CXVisitorResult {
if !filter_builtins(ctx, &cursor) {
return CXChildVisit_Continue;
@@ -553,10 +552,10 @@ pub fn parse_one(ctx: &mut BindgenContext,
use clangll::CXChildVisit_Continue;
match Item::parse(cursor, parent, ctx) {
- Ok(id) => children.push(id),
+ Ok(..) => {},
Err(ParseError::Continue) => {}
Err(ParseError::Recurse) => {
- cursor.visit(|child| parse_one(ctx, child, parent, children));
+ cursor.visit(|child| parse_one(ctx, child, parent));
}
}
CXChildVisit_Continue
@@ -579,8 +578,8 @@ fn parse(context: &mut BindgenContext) {
}
let root = context.root_module();
- context.with_module(root, |context, children| {
- cursor.visit(|cursor| parse_one(context, cursor, None, children))
+ context.with_module(root, |context| {
+ cursor.visit(|cursor| parse_one(context, cursor, None))
});
assert!(context.current_module() == context.root_module(),