From 89915f9536e4ce385683f0bcbcd9150536f9d975 Mon Sep 17 00:00:00 2001 From: Cldfire Date: Fri, 8 Sep 2017 20:04:33 -0400 Subject: [PATCH] Make bindgen generate enums as constants by default Also simplifies the logic that determines which enum variation gets chosen. --- bindgen-integration/build.rs | 1 + src/codegen/mod.rs | 134 +++++++++++------- src/ir/enum_ty.rs | 24 ++++ src/lib.rs | 31 ++-- src/options.rs | 17 ++- tests/headers/anon_enum.hpp | 2 +- tests/headers/anon_enum_trait.hpp | 2 +- tests/headers/anon_enum_whitelist.h | 2 +- tests/headers/anon_union.hpp | 2 +- tests/headers/anon_union_1_0.hpp | 2 +- tests/headers/bitfield-enum-basic.hpp | 2 +- tests/headers/bitfield_align_2.h | 2 +- tests/headers/class_with_inner_struct.hpp | 2 +- tests/headers/class_with_inner_struct_1_0.hpp | 2 +- tests/headers/const_enum_unnamed.hpp | 1 + tests/headers/constant-evaluate.h | 1 + tests/headers/constify-all-enums.h | 1 - tests/headers/constify-enum.h | 1 + tests/headers/enum.h | 2 + tests/headers/enum_alias.hpp | 2 +- tests/headers/enum_and_vtable_mangling.hpp | 1 + tests/headers/enum_dupe.h | 2 + tests/headers/enum_explicit_type.hpp | 2 +- .../headers/enum_in_template_with_typedef.hpp | 2 +- tests/headers/enum_negative.h | 2 + tests/headers/enum_packed.h | 2 + tests/headers/forward-enum-decl.hpp | 2 +- tests/headers/func_ptr_in_struct.h | 2 +- tests/headers/issue-372.hpp | 2 +- tests/headers/issue-410.hpp | 2 +- tests/headers/issue-493.hpp | 2 +- tests/headers/issue-493_1_0.hpp | 2 +- ...te-params-causing-layout-test-failures.hpp | 2 +- .../headers/issue-888-enum-var-decl-jump.hpp | 2 +- tests/headers/jsval_layout_opaque.hpp | 2 +- tests/headers/jsval_layout_opaque_1_0.hpp | 2 +- tests/headers/layout_array_too_long.h | 2 +- tests/headers/layout_cmdline_token.h | 1 + tests/headers/layout_eth_conf.h | 2 +- tests/headers/layout_eth_conf_1_0.h | 2 +- tests/headers/layout_large_align_field.h | 2 + tests/headers/no-recursive-whitelisting.h | 2 +- tests/headers/no-std.h | 2 +- tests/headers/nsStyleAutoArray.hpp | 1 + tests/headers/overflowed_enum.hpp | 2 +- .../headers/prepend-enum-constified-variant.h | 2 +- tests/headers/prepend_enum_name.hpp | 2 +- tests/headers/short-enums.hpp | 2 +- tests/headers/struct_typedef.h | 2 +- tests/headers/struct_typedef_ns.hpp | 2 +- tests/headers/weird_bitfields.hpp | 2 + 51 files changed, 182 insertions(+), 110 deletions(-) diff --git a/bindgen-integration/build.rs b/bindgen-integration/build.rs index 7107d04b97..54546ab09b 100644 --- a/bindgen-integration/build.rs +++ b/bindgen-integration/build.rs @@ -29,6 +29,7 @@ fn main() { let bindings = Builder::default() .enable_cxx_namespaces() + .rustified_enum(".*") .raw_line("pub use self::root::*;") .header("cpp/Test.h") .clang_args(&["-x", "c++", "-std=c++11"]) diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index f13bd65afb..b841631476 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2072,7 +2072,41 @@ impl MethodCodegen for Method { } } -/// A helper type to construct enums, either bitfield ones or rust-style ones. +/// A helper type that represents different enum variations. +#[derive(Copy, Clone)] +enum EnumVariation { + Rust, + Bitfield, + Consts, + ModuleConsts +} + +impl EnumVariation { + fn is_rust(&self) -> bool { + match *self { + EnumVariation::Rust => true, + _ => false + } + } + + fn is_bitfield(&self) -> bool { + match *self { + EnumVariation::Bitfield => true, + _ => false + } + } + + /// Both the `Const` and `ModuleConsts` variants will cause this to return + /// true. + fn is_const(&self) -> bool { + match *self { + EnumVariation::Consts | EnumVariation::ModuleConsts => true, + _ => false + } + } +} + +/// A helper type to construct different enum variations. enum EnumBuilder<'a> { Rust(quote::Tokens), Bitfield { @@ -2088,26 +2122,44 @@ enum EnumBuilder<'a> { impl<'a> EnumBuilder<'a> { /// Create a new enum given an item builder, a canonical name, a name for - /// the representation, and whether it should be represented as a rust enum. + /// the representation, and which variation it should be generated as. fn new( name: &'a str, attrs: Vec, repr: quote::Tokens, - bitfield_like: bool, - constify: bool, - constify_module: bool, + enum_variation: EnumVariation ) -> Self { let ident = quote::Ident::new(name); - if bitfield_like { - EnumBuilder::Bitfield { - canonical_name: name, - tokens: quote! { + + match enum_variation { + EnumVariation::Bitfield => { + EnumBuilder::Bitfield { + canonical_name: name, + tokens: quote! { + #( #attrs )* + pub struct #ident (pub #repr); + }, + } + } + + EnumVariation::Rust => { + let mut tokens = quote! { #( #attrs )* - pub struct #ident (pub #repr); - }, + pub enum #ident + }; + tokens.append("{"); + EnumBuilder::Rust(tokens) } - } else if constify { - if constify_module { + + EnumVariation::Consts => { + EnumBuilder::Consts(vec![ + quote! { + pub type #ident = #repr; + } + ]) + } + + EnumVariation::ModuleConsts => { let ident = quote::Ident::new(CONSTIFIED_ENUM_MODULE_REPR_NAME); let type_definition = quote! { pub type #ident = #repr; @@ -2117,20 +2169,7 @@ impl<'a> EnumBuilder<'a> { module_name: name, module_items: vec![type_definition], } - } else { - EnumBuilder::Consts(vec![ - quote! { - pub type #ident = #repr; - } - ]) } - } else { - let mut tokens = quote! { - #( #attrs )* - pub enum #ident - }; - tokens.append("{"); - EnumBuilder::Rust(tokens) } } @@ -2342,39 +2381,28 @@ impl CodeGenerator for Enum { // FIXME(emilio): These should probably use the path so it can // disambiguate between namespaces, just like is_opaque etc. - let is_bitfield = { - ctx.options().bitfield_enums.matches(&name) || - (enum_ty.name().is_none() && - self.variants().iter().any(|v| { - ctx.options().bitfield_enums.matches(&v.name()) - })) - }; - - let is_constified_enum_module = - self.is_constified_enum_module(ctx, item); - - let is_constified_enum = { - is_constified_enum_module || - ctx.options().constified_enums.matches(&name) || - (enum_ty.name().is_none() && - self.variants().iter().any(|v| { - ctx.options().constified_enums.matches(&v.name()) - })) + let variation = if self.is_bitfield(ctx, item) { + EnumVariation::Bitfield + } else if self.is_rustified_enum(ctx, item) { + EnumVariation::Rust + } else if self.is_constified_enum_module(ctx, item) { + EnumVariation::ModuleConsts + } else { + // We generate consts by default + EnumVariation::Consts }; - let is_rust_enum = !is_bitfield && !is_constified_enum; - let mut attrs = vec![]; // FIXME: Rust forbids repr with empty enums. Remove this condition when // this is allowed. // // TODO(emilio): Delegate this to the builders? - if is_rust_enum { + if variation.is_rust() { if !self.variants().is_empty() { attrs.push(attributes::repr(repr_name)); } - } else if is_bitfield { + } else if variation.is_bitfield() { attrs.push(attributes::repr("C")); } @@ -2382,7 +2410,7 @@ impl CodeGenerator for Enum { attrs.push(attributes::doc(comment)); } - if !is_constified_enum { + if !variation.is_const() { attrs.push(attributes::derives( &["Debug", "Copy", "Clone", "PartialEq", "Eq", "Hash"], )); @@ -2427,9 +2455,7 @@ impl CodeGenerator for Enum { &name, attrs, repr, - is_bitfield, - is_constified_enum, - is_constified_enum_module, + variation ); // A map where we keep a value -> variant relation. @@ -2475,7 +2501,7 @@ impl CodeGenerator for Enum { match seen_values.entry(variant.val()) { Entry::Occupied(ref entry) => { - if is_rust_enum { + if variation.is_rust() { let variant_name = ctx.rust_mangle(variant.name()); let mangled_name = if is_toplevel || enum_ty.name().is_some() { @@ -2523,7 +2549,7 @@ impl CodeGenerator for Enum { // If it's an unnamed enum, or constification is enforced, // we also generate a constant so it can be properly // accessed. - if (is_rust_enum && enum_ty.name().is_none()) || + if (variation.is_rust() && enum_ty.name().is_none()) || variant.force_constification() { let mangled_name = if is_toplevel { diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index bcd56974ed..dc56f64aa5 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -128,6 +128,18 @@ impl Enum { Ok(Enum::new(repr, variants)) } + /// Whether the enum should be a bitfield + pub fn is_bitfield(&self, ctx: &BindgenContext, item: &Item) -> bool { + let name = item.canonical_name(ctx); + let enum_ty = item.expect_type(); + + ctx.options().bitfield_enums.matches(&name) || + (enum_ty.name().is_none() && + self.variants().iter().any(|v| { + ctx.options().bitfield_enums.matches(&v.name()) + })) + } + /// Whether the enum should be an constified enum module pub fn is_constified_enum_module( &self, @@ -143,6 +155,18 @@ impl Enum { ctx.options().constified_enum_modules.matches(&v.name()) })) } + + /// Whether the enum should be a Rust enum + pub fn is_rustified_enum(&self, ctx: &BindgenContext, item: &Item) -> bool { + let name = item.canonical_name(ctx); + let enum_ty = item.expect_type(); + + ctx.options().rustified_enums.matches(&name) || + (enum_ty.name().is_none() && + self.variants().iter().any(|v| { + ctx.options().rustified_enums.matches(&v.name()) + })) + } } /// A single enum variant, to be contained only in an enum. diff --git a/src/lib.rs b/src/lib.rs index b631071311..dc6409113a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -197,11 +197,11 @@ impl Builder { .count(); self.options - .constified_enums + .rustified_enums .get_items() .iter() .map(|item| { - output_vector.push("--constified-enum".into()); + output_vector.push("--rustified-enum".into()); output_vector.push( item.trim_left_matches("^") .trim_right_matches("$") @@ -666,21 +666,26 @@ impl Builder { self } - /// Mark the given enum (or set of enums, if using a pattern) as a set of - /// constants. + /// Mark the given enum (or set of enums, if using a pattern) as a Rust + /// enum. /// - /// This makes bindgen generate constants instead of enums. Regular + /// This makes bindgen generate enums instead of constants. Regular /// expressions are supported. - pub fn constified_enum>(mut self, arg: T) -> Builder { - self.options.constified_enums.insert(arg); + /// + /// **Use this with caution.** You should not be using Rust enums unless + /// you have complete control of the C/C++ code that you're binding to. + /// Take a look at https://github.com/rust-lang/rust/issues/36927 for + /// more information. + pub fn rustified_enum>(mut self, arg: T) -> Builder { + self.options.rustified_enums.insert(arg); self } /// Mark the given enum (or set of enums, if using a pattern) as a set of /// constants that should be put into a module. /// - /// This makes bindgen generate a modules containing constants instead of - /// enums. Regular expressions are supported. + /// This makes bindgen generate modules containing constants instead of + /// just constants. Regular expressions are supported. pub fn constified_enum_module>(mut self, arg: T) -> Builder { self.options.constified_enum_modules.insert(arg); self @@ -1094,8 +1099,8 @@ pub struct BindgenOptions { /// The enum patterns to mark an enum as bitfield. pub bitfield_enums: RegexSet, - /// The enum patterns to mark an enum as constant. - pub constified_enums: RegexSet, + /// The enum patterns to mark an enum as a Rust enum. + pub rustified_enums: RegexSet, /// The enum patterns to mark an enum as a module of constants. pub constified_enum_modules: RegexSet, @@ -1251,7 +1256,7 @@ impl BindgenOptions { self.opaque_types.build(); self.bitfield_enums.build(); self.constified_enum_modules.build(); - self.constified_enums.build(); + self.rustified_enums.build(); } /// Update rust target version @@ -1286,7 +1291,7 @@ impl Default for BindgenOptions { whitelisted_functions: Default::default(), whitelisted_vars: Default::default(), bitfield_enums: Default::default(), - constified_enums: Default::default(), + rustified_enums: Default::default(), constified_enum_modules: Default::default(), builtins: false, links: vec![], diff --git a/src/options.rs b/src/options.rs index 50238f1cfb..383a88997e 100644 --- a/src/options.rs +++ b/src/options.rs @@ -34,10 +34,10 @@ where .takes_value(true) .multiple(true) .number_of_values(1), - Arg::with_name("constified-enum") - .long("constified-enum") - .help("Mark any enum whose name matches as a set of \ - constants instead of an enumeration.") + Arg::with_name("rustified-enum") + .long("rustified-enum") + .help("Mark any enum whose name matches as a Rust enum \ + instead of a set of constants.") .value_name("regex") .takes_value(true) .multiple(true) @@ -45,8 +45,7 @@ where Arg::with_name("constified-enum-module") .long("constified-enum-module") .help("Mark any enum whose name matches as a module of \ - constants instead of an enumeration. This option \ - implies \"--constified-enum.\"") + constants instead of just constants.") .value_name("regex") .takes_value(true) .multiple(true) @@ -292,9 +291,9 @@ where } } - if let Some(constifieds) = matches.values_of("constified-enum") { - for regex in constifieds { - builder = builder.constified_enum(regex); + if let Some(rustifieds) = matches.values_of("rustified-enum") { + for regex in rustifieds { + builder = builder.rustified_enum(regex); } } diff --git a/tests/headers/anon_enum.hpp b/tests/headers/anon_enum.hpp index 3e8ff3d4ae..23dc5ceb8f 100644 --- a/tests/headers/anon_enum.hpp +++ b/tests/headers/anon_enum.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* struct Test { int foo; float bar; diff --git a/tests/headers/anon_enum_trait.hpp b/tests/headers/anon_enum_trait.hpp index 865411e213..6383c74892 100644 --- a/tests/headers/anon_enum_trait.hpp +++ b/tests/headers/anon_enum_trait.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* template class DataType { diff --git a/tests/headers/anon_enum_whitelist.h b/tests/headers/anon_enum_whitelist.h index 15cda6b1e7..fc4810e044 100644 --- a/tests/headers/anon_enum_whitelist.h +++ b/tests/headers/anon_enum_whitelist.h @@ -1,4 +1,4 @@ -// bindgen-flags: --whitelist-var NODE_.* +// bindgen-flags: --whitelist-var NODE_.* --rustified-enum .* enum { NODE_FLAG_FOO, diff --git a/tests/headers/anon_union.hpp b/tests/headers/anon_union.hpp index 8e649abb5e..19c478d18c 100644 --- a/tests/headers/anon_union.hpp +++ b/tests/headers/anon_union.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* template struct TErrorResult { enum UnionState { diff --git a/tests/headers/anon_union_1_0.hpp b/tests/headers/anon_union_1_0.hpp index 699efa3203..314215bfe5 100644 --- a/tests/headers/anon_union_1_0.hpp +++ b/tests/headers/anon_union_1_0.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* template struct TErrorResult { diff --git a/tests/headers/bitfield-enum-basic.hpp b/tests/headers/bitfield-enum-basic.hpp index 364bebf2d2..c03f0e708a 100644 --- a/tests/headers/bitfield-enum-basic.hpp +++ b/tests/headers/bitfield-enum-basic.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --bitfield-enum "Foo|Buz|NS_.*|DUMMY_.*" -- -std=c++11 +// bindgen-flags: --bitfield-enum "Foo|Buz|NS_.*|DUMMY_.*" --rustified-enum .* -- -std=c++11 enum Foo { Bar = 1 << 1, diff --git a/tests/headers/bitfield_align_2.h b/tests/headers/bitfield_align_2.h index c6e5e5e7f8..31d37f76a7 100644 --- a/tests/headers/bitfield_align_2.h +++ b/tests/headers/bitfield_align_2.h @@ -1,4 +1,4 @@ - +// bindgen-flags: --rustified-enum .* enum MyEnum { ONE, TWO, diff --git a/tests/headers/class_with_inner_struct.hpp b/tests/headers/class_with_inner_struct.hpp index 3cb6cfed8b..66c2bd3f88 100644 --- a/tests/headers/class_with_inner_struct.hpp +++ b/tests/headers/class_with_inner_struct.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* // bindgen-flags: -- -std=c++11 class A { diff --git a/tests/headers/class_with_inner_struct_1_0.hpp b/tests/headers/class_with_inner_struct_1_0.hpp index 0bb8a57fe4..1bae249f8a 100644 --- a/tests/headers/class_with_inner_struct_1_0.hpp +++ b/tests/headers/class_with_inner_struct_1_0.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* // bindgen-flags: -- -std=c++11 class A { diff --git a/tests/headers/const_enum_unnamed.hpp b/tests/headers/const_enum_unnamed.hpp index eb139434ce..bdd9700f87 100644 --- a/tests/headers/const_enum_unnamed.hpp +++ b/tests/headers/const_enum_unnamed.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --rustified-enum .* enum { FOO_BAR, diff --git a/tests/headers/constant-evaluate.h b/tests/headers/constant-evaluate.h index f9f1fa669f..ee9cfaa538 100644 --- a/tests/headers/constant-evaluate.h +++ b/tests/headers/constant-evaluate.h @@ -1,4 +1,5 @@ // bindgen-unstable +// bindgen-flags: --rustified-enum .* enum { foo = 4, diff --git a/tests/headers/constify-all-enums.h b/tests/headers/constify-all-enums.h index 7138bf2018..6f4364e3cc 100644 --- a/tests/headers/constify-all-enums.h +++ b/tests/headers/constify-all-enums.h @@ -1,4 +1,3 @@ -// bindgen-flags: --constified-enum foo enum foo { THIS, diff --git a/tests/headers/constify-enum.h b/tests/headers/constify-enum.h index a5b4052c78..9a9058d38b 100644 --- a/tests/headers/constify-enum.h +++ b/tests/headers/constify-enum.h @@ -1,3 +1,4 @@ +// bindgen-flags: --rustified-enum .* enum nsCSSPropertyID { eCSSProperty_a, diff --git a/tests/headers/enum.h b/tests/headers/enum.h index f2d301e70e..38ce4eee44 100644 --- a/tests/headers/enum.h +++ b/tests/headers/enum.h @@ -1,3 +1,5 @@ +// bindgen-flags: --rustified-enum .* + enum Foo { Bar = 0, Qux diff --git a/tests/headers/enum_alias.hpp b/tests/headers/enum_alias.hpp index 658f8fde9a..c3ecc35159 100644 --- a/tests/headers/enum_alias.hpp +++ b/tests/headers/enum_alias.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- -std=c++11 +// bindgen-flags: --rustified-enum .* -- -std=c++11 typedef unsigned char uint8_t; diff --git a/tests/headers/enum_and_vtable_mangling.hpp b/tests/headers/enum_and_vtable_mangling.hpp index 4c7f4d2be8..e332fc57e6 100644 --- a/tests/headers/enum_and_vtable_mangling.hpp +++ b/tests/headers/enum_and_vtable_mangling.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --rustified-enum .* enum { match, diff --git a/tests/headers/enum_dupe.h b/tests/headers/enum_dupe.h index 6d3591d5cb..826568fb0d 100644 --- a/tests/headers/enum_dupe.h +++ b/tests/headers/enum_dupe.h @@ -1,3 +1,5 @@ +// bindgen-flags: --rustified-enum .* + enum Foo { Bar = 1, Dupe = 1 diff --git a/tests/headers/enum_explicit_type.hpp b/tests/headers/enum_explicit_type.hpp index b2a4307e5e..e611de74bf 100644 --- a/tests/headers/enum_explicit_type.hpp +++ b/tests/headers/enum_explicit_type.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- -std=c++11 +// bindgen-flags: --rustified-enum .* -- -std=c++11 enum Foo: unsigned char { Bar = 0, diff --git a/tests/headers/enum_in_template_with_typedef.hpp b/tests/headers/enum_in_template_with_typedef.hpp index ac19b7813c..244d916c2e 100644 --- a/tests/headers/enum_in_template_with_typedef.hpp +++ b/tests/headers/enum_in_template_with_typedef.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- -std=c++11 +// bindgen-flags: --rustified-enum .* -- -std=c++11 namespace std { template class fbstring_core; diff --git a/tests/headers/enum_negative.h b/tests/headers/enum_negative.h index 6cbdfe044e..267f799f02 100644 --- a/tests/headers/enum_negative.h +++ b/tests/headers/enum_negative.h @@ -1,3 +1,5 @@ +// bindgen-flags: --rustified-enum .* + enum Foo { Bar = -2, Qux = 1, diff --git a/tests/headers/enum_packed.h b/tests/headers/enum_packed.h index 8654d110fd..1c89b992ec 100644 --- a/tests/headers/enum_packed.h +++ b/tests/headers/enum_packed.h @@ -1,3 +1,5 @@ +// bindgen-flags: --rustified-enum .* + enum __attribute__((packed)) Foo { Bar = 0, Qux diff --git a/tests/headers/forward-enum-decl.hpp b/tests/headers/forward-enum-decl.hpp index 2c4316c61d..a3df858428 100644 --- a/tests/headers/forward-enum-decl.hpp +++ b/tests/headers/forward-enum-decl.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- -std=c++11 +// bindgen-flags: --rustified-enum .* -- -std=c++11 enum class CSSPseudoClassType : int; diff --git a/tests/headers/func_ptr_in_struct.h b/tests/headers/func_ptr_in_struct.h index 24e1f44f52..dd608549ae 100644 --- a/tests/headers/func_ptr_in_struct.h +++ b/tests/headers/func_ptr_in_struct.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* // enum baz; diff --git a/tests/headers/issue-372.hpp b/tests/headers/issue-372.hpp index a072f06127..de1447769a 100644 --- a/tests/headers/issue-372.hpp +++ b/tests/headers/issue-372.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces +// bindgen-flags: --enable-cxx-namespaces --rustified-enum .* template class c { a e[b]; }; class d; template class C { c h; }; diff --git a/tests/headers/issue-410.hpp b/tests/headers/issue-410.hpp index a7a834cfc4..c91c83d119 100644 --- a/tests/headers/issue-410.hpp +++ b/tests/headers/issue-410.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces --whitelist-type JS::Value +// bindgen-flags: --enable-cxx-namespaces --whitelist-type JS::Value --rustified-enum .* namespace JS { class Value; diff --git a/tests/headers/issue-493.hpp b/tests/headers/issue-493.hpp index 5d4cb4b8ba..280b873631 100644 --- a/tests/headers/issue-493.hpp +++ b/tests/headers/issue-493.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* template class basic_string { diff --git a/tests/headers/issue-493_1_0.hpp b/tests/headers/issue-493_1_0.hpp index 4e383be334..7406d8936c 100644 --- a/tests/headers/issue-493_1_0.hpp +++ b/tests/headers/issue-493_1_0.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* template class basic_string diff --git a/tests/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp b/tests/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp index 7f8c2d8aa8..964b69cb05 100644 --- a/tests/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp +++ b/tests/headers/issue-569-non-type-template-params-causing-layout-test-failures.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- -std=c++14 +// bindgen-flags: --rustified-enum .* -- -std=c++14 // Generated by C-Reduce, cleaned up and given names for readability. diff --git a/tests/headers/issue-888-enum-var-decl-jump.hpp b/tests/headers/issue-888-enum-var-decl-jump.hpp index d7f31b3e8d..d7182c3c57 100644 --- a/tests/headers/issue-888-enum-var-decl-jump.hpp +++ b/tests/headers/issue-888-enum-var-decl-jump.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --enable-cxx-namespaces +// bindgen-flags: --enable-cxx-namespaces --rustified-enum .* namespace Halide { struct Type; diff --git a/tests/headers/jsval_layout_opaque.hpp b/tests/headers/jsval_layout_opaque.hpp index 09b5bebe4b..7a1957cffd 100644 --- a/tests/headers/jsval_layout_opaque.hpp +++ b/tests/headers/jsval_layout_opaque.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* // bindgen-flags: -- -std=c++11 /** diff --git a/tests/headers/jsval_layout_opaque_1_0.hpp b/tests/headers/jsval_layout_opaque_1_0.hpp index 61eefe1e5a..dcf6274dfb 100644 --- a/tests/headers/jsval_layout_opaque_1_0.hpp +++ b/tests/headers/jsval_layout_opaque_1_0.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* // bindgen-flags: -- -std=c++11 /** diff --git a/tests/headers/layout_array_too_long.h b/tests/headers/layout_array_too_long.h index 5240f0406e..a3ef3d2056 100644 --- a/tests/headers/layout_array_too_long.h +++ b/tests/headers/layout_array_too_long.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; diff --git a/tests/headers/layout_cmdline_token.h b/tests/headers/layout_cmdline_token.h index 34ebd017de..68dd53b837 100644 --- a/tests/headers/layout_cmdline_token.h +++ b/tests/headers/layout_cmdline_token.h @@ -1,3 +1,4 @@ +// bindgen-flags: --rustified-enum .* /** * Stores a pointer to the ops struct, and the offset: the place to diff --git a/tests/headers/layout_eth_conf.h b/tests/headers/layout_eth_conf.h index 637b56961a..71a430bfae 100644 --- a/tests/headers/layout_eth_conf.h +++ b/tests/headers/layout_eth_conf.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; diff --git a/tests/headers/layout_eth_conf_1_0.h b/tests/headers/layout_eth_conf_1_0.h index 285c8c7a25..cf6fa6ad2e 100644 --- a/tests/headers/layout_eth_conf_1_0.h +++ b/tests/headers/layout_eth_conf_1_0.h @@ -1,4 +1,4 @@ -// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --rust-target 1.0 --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* typedef unsigned char uint8_t; typedef unsigned short uint16_t; diff --git a/tests/headers/layout_large_align_field.h b/tests/headers/layout_large_align_field.h index f4f412c6c5..5e87c2a1c4 100644 --- a/tests/headers/layout_large_align_field.h +++ b/tests/headers/layout_large_align_field.h @@ -1,3 +1,5 @@ +// bindgen-flags: --rustified-enum .* + typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned int uint32_t; diff --git a/tests/headers/no-recursive-whitelisting.h b/tests/headers/no-recursive-whitelisting.h index 1d805d9301..8eb8afea14 100644 --- a/tests/headers/no-recursive-whitelisting.h +++ b/tests/headers/no-recursive-whitelisting.h @@ -1,4 +1,4 @@ -// bindgen-flags: --no-recursive-whitelist --whitelist-type "Foo" --raw-line "pub enum Bar {}" +// bindgen-flags: --no-recursive-whitelist --whitelist-type "Foo" --raw-line "pub enum Bar {}" --rustified-enum .* struct Bar; diff --git a/tests/headers/no-std.h b/tests/headers/no-std.h index 7bee9657f8..9248cc3dd5 100644 --- a/tests/headers/no-std.h +++ b/tests/headers/no-std.h @@ -1,4 +1,4 @@ -// bindgen-flags: --ctypes-prefix "libc" --use-core --raw-line "#![no_std]" --raw-line "mod libc { pub type c_int = i32; pub enum c_void {} }" +// bindgen-flags: --ctypes-prefix "libc" --use-core --raw-line "#![no_std]" --raw-line "mod libc { pub type c_int = i32; pub enum c_void {} }" --rustified-enum .* struct foo { int a, b; void* bar; diff --git a/tests/headers/nsStyleAutoArray.hpp b/tests/headers/nsStyleAutoArray.hpp index 950152c0fd..2a0bc21623 100644 --- a/tests/headers/nsStyleAutoArray.hpp +++ b/tests/headers/nsStyleAutoArray.hpp @@ -1,3 +1,4 @@ +// bindgen-flags: --rustified-enum .* template class nsTArray { diff --git a/tests/headers/overflowed_enum.hpp b/tests/headers/overflowed_enum.hpp index 1f2075a57f..53a05ddf82 100644 --- a/tests/headers/overflowed_enum.hpp +++ b/tests/headers/overflowed_enum.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- -std=c++11 -Wno-narrowing +// bindgen-flags: --rustified-enum .* -- -std=c++11 -Wno-narrowing enum Foo { BAP_ARM = 0x93fcb9, diff --git a/tests/headers/prepend-enum-constified-variant.h b/tests/headers/prepend-enum-constified-variant.h index aa526ffb04..06ae264f07 100644 --- a/tests/headers/prepend-enum-constified-variant.h +++ b/tests/headers/prepend-enum-constified-variant.h @@ -1,4 +1,4 @@ -// bindgen-flags: --no-prepend-enum-name +// bindgen-flags: --no-prepend-enum-name --rustified-enum .* enum AVCodecID { AV_CODEC_ID_FIRST_UNKNOWN = 0x18000, diff --git a/tests/headers/prepend_enum_name.hpp b/tests/headers/prepend_enum_name.hpp index df4ecf1fa9..e766036960 100644 --- a/tests/headers/prepend_enum_name.hpp +++ b/tests/headers/prepend_enum_name.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --constified-enum foo --no-prepend-enum-name +// bindgen-flags: --no-prepend-enum-name enum foo { FOO_BAR, diff --git a/tests/headers/short-enums.hpp b/tests/headers/short-enums.hpp index 484c84af3d..0b517d6f7b 100644 --- a/tests/headers/short-enums.hpp +++ b/tests/headers/short-enums.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: -- -std=c++11 -fshort-enums +// bindgen-flags: --rustified-enum .* -- -std=c++11 -fshort-enums typedef enum { SOME_VALUE = 0x1, diff --git a/tests/headers/struct_typedef.h b/tests/headers/struct_typedef.h index de861c5feb..e996b28f0f 100644 --- a/tests/headers/struct_typedef.h +++ b/tests/headers/struct_typedef.h @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --rustified-enum .* // typedef struct { _Bool has_name; diff --git a/tests/headers/struct_typedef_ns.hpp b/tests/headers/struct_typedef_ns.hpp index 07ecc160d2..a5a8f9a64e 100644 --- a/tests/headers/struct_typedef_ns.hpp +++ b/tests/headers/struct_typedef_ns.hpp @@ -1,4 +1,4 @@ -// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --enable-cxx-namespaces +// bindgen-flags: --with-derive-hash --with-derive-partialeq --with-derive-eq --enable-cxx-namespaces --rustified-enum .* namespace whatever { typedef struct { diff --git a/tests/headers/weird_bitfields.hpp b/tests/headers/weird_bitfields.hpp index 68cbf4a56c..7236d60a53 100644 --- a/tests/headers/weird_bitfields.hpp +++ b/tests/headers/weird_bitfields.hpp @@ -1,3 +1,5 @@ +// bindgen-flags: --rustified-enum .* + // You can guess where this is taken from... enum nsStyleSVGOpacitySource { eStyleSVGOpacitySource_Normal,