Skip to content

Add a Builder::blacklist_type #991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl CodeGenerator for Item {
return;
}

if self.is_hidden(ctx) || result.seen(self.id()) {
if self.is_blacklisted(ctx) || result.seen(self.id()) {
debug!(
"<Item as CodeGenerator>::codegen: Ignoring hidden or seen: \
self = {:?}",
Expand Down
12 changes: 6 additions & 6 deletions src/ir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl<'ctx> Iterator for WhitelistedItemsTraversal<'ctx> {
loop {
match self.traversal.next() {
None => return None,
Some(id) if self.ctx.resolve_item(id).is_hidden(self.ctx) => {
Some(id) if self.ctx.resolve_item(id).is_blacklisted(self.ctx) => {
continue
}
Some(id) => return Some(id),
Expand Down Expand Up @@ -1103,7 +1103,7 @@ impl BindgenContext {
"We only compute template parameter usage as we enter codegen"
);

if self.resolve_item(item).is_hidden(self) {
if self.resolve_item(item).is_blacklisted(self) {
return true;
}

Expand Down Expand Up @@ -1765,14 +1765,14 @@ impl BindgenContext {
}
}

/// Is the item with the given `name` hidden? Or is the item with the given
/// `name` and `id` replaced by another type, and effectively hidden?
pub fn hidden_by_name(&self, path: &[String], id: ItemId) -> bool {
/// Is the item with the given `name` blacklisted? Or is the item with the given
/// `name` and `id` replaced by another type, and effectively blacklisted?
pub fn blacklisted_by_name(&self, path: &[String], id: ItemId) -> bool {
debug_assert!(
self.in_codegen_phase(),
"You're not supposed to call this yet"
);
self.options.hidden_types.matches(&path[1..].join("::")) ||
self.options.blacklisted_types.matches(&path[1..].join("::")) ||
self.is_replaced_type(path, id)
}

Expand Down
6 changes: 3 additions & 3 deletions src/ir/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,16 +603,16 @@ impl Item {
&self.annotations
}

/// Whether this item should be hidden.
/// Whether this item should be blacklisted.
///
/// This may be due to either annotations or to other kind of configuration.
pub fn is_hidden(&self, ctx: &BindgenContext) -> bool {
pub fn is_blacklisted(&self, ctx: &BindgenContext) -> bool {
debug_assert!(
ctx.in_codegen_phase(),
"You're not supposed to call this yet"
);
self.annotations.hide() ||
ctx.hidden_by_name(&self.canonical_path(ctx), self.id)
ctx.blacklisted_by_name(&self.canonical_path(ctx), self.id)
}

/// Is this a reference to another type?
Expand Down
19 changes: 13 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl Builder {
.count();

self.options
.hidden_types
.blacklisted_types
.get_items()
.iter()
.map(|item| {
Expand Down Expand Up @@ -620,8 +620,15 @@ impl Builder {

/// Hide the given type from the generated bindings. Regular expressions are
/// supported.
pub fn hide_type<T: AsRef<str>>(mut self, arg: T) -> Builder {
self.options.hidden_types.insert(arg);
#[deprecated = "Use blacklist_type instead"]
pub fn hide_type<T: AsRef<str>>(self, arg: T) -> Builder {
self.blacklist_type(arg)
}

/// Hide the given type from the generated bindings. Regular expressions are
/// supported.
pub fn blacklist_type<T: AsRef<str>>(mut self, arg: T) -> Builder {
self.options.blacklisted_types.insert(arg);
self
}

Expand Down Expand Up @@ -1085,7 +1092,7 @@ impl Builder {
pub struct BindgenOptions {
/// The set of types that have been blacklisted and should not appear
/// anywhere in the generated code.
pub hidden_types: RegexSet,
pub blacklisted_types: RegexSet,

/// The set of types that should be treated as opaque structures in the
/// generated code.
Expand Down Expand Up @@ -1261,7 +1268,7 @@ impl BindgenOptions {
self.whitelisted_vars.build();
self.whitelisted_types.build();
self.whitelisted_functions.build();
self.hidden_types.build();
self.blacklisted_types.build();
self.opaque_types.build();
self.bitfield_enums.build();
self.constified_enum_modules.build();
Expand Down Expand Up @@ -1294,7 +1301,7 @@ impl Default for BindgenOptions {
BindgenOptions {
rust_target: rust_target,
rust_features: rust_target.into(),
hidden_types: Default::default(),
blacklisted_types: Default::default(),
opaque_types: Default::default(),
whitelisted_types: Default::default(),
whitelisted_functions: Default::default(),
Expand Down