Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
--------------------------------------------------------------------------------
# Unreleased
## Added
- Added `--bitfield-global-enum` for parity with `--newtype-global-enum`
## Changed
## Removed
- Removed support for generating code for rustc versions < 1.51.
Expand Down
139 changes: 139 additions & 0 deletions bindgen-tests/tests/expectations/tests/bitfield-global-enum-basic.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions bindgen-tests/tests/headers/bitfield-global-enum-basic.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// bindgen-flags: --bitfield-global-enum "Foo|Buz|NS_.*|DUMMY_.*" --rustified-enum ".*" -- -std=c++11

enum Foo {
Bar = 1 << 1,
Baz = 1 << 2,
Duplicated = 1 << 2,
Negative = -3,
};

enum class Buz : signed char {
Bar = 1 << 1,
Baz = 1 << 2,
Duplicated = 1 << 2,
Negative = -3,
};

enum {
NS_FOO = 1 << 0,
NS_BAR = 1 << 1,
};

class Dummy {
enum {
DUMMY_FOO = 1 << 0,
DUMMY_BAR = 1 << 1,
};
};
9 changes: 9 additions & 0 deletions bindgen/ir/enum_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ impl Enum {
is_bitfield: true,
is_global: false,
}
} else if self.is_matching_enum(
ctx,
&ctx.options().bitfield_global_enums,
item,
) {
EnumVariation::NewType {
is_bitfield: true,
is_global: true,
}
} else if self.is_matching_enum(ctx, &ctx.options().newtype_enums, item)
{
EnumVariation::NewType {
Expand Down
4 changes: 3 additions & 1 deletion bindgen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ impl Builder {

impl BindgenOptions {
fn build(&mut self) {
const REGEX_SETS_LEN: usize = 29;
const REGEX_SETS_LEN: usize = 30;

let regex_sets: [_; REGEX_SETS_LEN] = [
&mut self.blocklisted_types,
Expand All @@ -478,6 +478,7 @@ impl BindgenOptions {
&mut self.allowlisted_files,
&mut self.allowlisted_items,
&mut self.bitfield_enums,
&mut self.bitfield_global_enums,
&mut self.constified_enums,
&mut self.constified_enum_modules,
&mut self.newtype_enums,
Expand Down Expand Up @@ -515,6 +516,7 @@ impl BindgenOptions {
"--allowlist-file",
"--allowlist-item",
"--bitfield-enum",
"--bitfield-global-enum",
"--newtype-enum",
"--newtype-global-enum",
"--rustified-enum",
Expand Down
5 changes: 5 additions & 0 deletions bindgen/options/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ struct BindgenCommand {
/// Mark any enum whose name matches REGEX as a set of bitfield flags.
#[arg(long, value_name = "REGEX")]
bitfield_enum: Vec<String>,
/// Mark any enum whose name matches REGEX as a set of global bitfield flags.
#[arg(long, value_name = "REGEX")]
bitfield_global_enum: Vec<String>,
/// Mark any enum whose name matches REGEX as a newtype.
#[arg(long, value_name = "REGEX")]
newtype_enum: Vec<String>,
Expand Down Expand Up @@ -590,6 +593,7 @@ where
depfile,
default_enum_style,
bitfield_enum,
bitfield_global_enum,
newtype_enum,
newtype_global_enum,
rustified_enum,
Expand Down Expand Up @@ -902,6 +906,7 @@ where
rust_edition,
default_enum_style,
bitfield_enum,
bitfield_global_enum,
newtype_enum,
newtype_global_enum,
rustified_enum,
Expand Down
16 changes: 16 additions & 0 deletions bindgen/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,22 @@ options! {
},
as_args: "--bitfield-enum",
},
/// `enum`s marked as bitfield-like. This is, global newtypes with bitwise operations.
bitfield_global_enums: RegexSet {
methods: {
regex_option! {
/// Mark the given `enum` as being bitfield-like.
///
/// This is similar to the [`Builder::newtype_global_enum`] style, but with the bitwise
/// operators implemented.
pub fn bitfield_global_enum<T: AsRef<str>>(mut self, arg: T) -> Builder {
self.options.bitfield_global_enums.insert(arg);
self
}
}
},
as_args: "--bitfield-global-enum",
},
/// `enum`s marked as newtypes.
newtype_enums: RegexSet {
methods: {
Expand Down
Loading