diff options
Diffstat (limited to 'src/ir/enum_ty.rs')
-rw-r--r-- | src/ir/enum_ty.rs | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index 6d1e7214..f3da2199 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -143,46 +143,29 @@ impl Enum { let path = item.canonical_path(ctx); let enum_ty = item.expect_type(); - let path_matches = enums.matches(&path[1..].join("::")); - let enum_is_anon = enum_ty.name().is_none(); - let a_variant_matches = self.variants().iter().any(|v| { - enums.matches(&v.name()) - }); - path_matches || (enum_is_anon && a_variant_matches) - } - - /// Whether the enum was explicitly specified to be a bitfield. - fn is_bitfield(&self, ctx: &BindgenContext, item: &Item) -> bool { - self.is_matching_enum(ctx, &ctx.options().bitfield_enums, item) - } - - /// Whether the enum was explicitly specified to be an constified enum - /// module. - fn is_constified_enum_module(&self, ctx: &BindgenContext, item: &Item) -> bool { - self.is_matching_enum(ctx, &ctx.options().constified_enum_modules, item) - } + if enums.matches(&path[1..].join("::")) { + return true; + } - /// Whether the enum was explicitly specified to be an set of constants. - fn is_constified_enum(&self, ctx: &BindgenContext, item: &Item) -> bool { - self.is_matching_enum(ctx, &ctx.options().constified_enums, item) - } + // Test the variants if the enum is anonymous. + if enum_ty.name().is_some() { + return false; + } - /// Whether the enum was explicitly specified to be a Rust enum. - fn is_rustified_enum(&self, ctx: &BindgenContext, item: &Item) -> bool { - self.is_matching_enum(ctx, &ctx.options().rustified_enums, item) + self.variants().iter().any(|v| enums.matches(&v.name())) } /// Returns the final representation of the enum. pub fn computed_enum_variation(&self, ctx: &BindgenContext, item: &Item) -> EnumVariation { // ModuleConsts has higher precedence before Rust in order to avoid // problems with overlapping match patterns. - if self.is_constified_enum_module(ctx, item) { + if self.is_matching_enum(ctx, &ctx.options().constified_enum_modules, item) { EnumVariation::ModuleConsts - } else if self.is_bitfield(ctx, item) { + } else if self.is_matching_enum(ctx, &ctx.options().bitfield_enums, item) { EnumVariation::Bitfield - } else if self.is_rustified_enum(ctx, item) { + } else if self.is_matching_enum(ctx, &ctx.options().rustified_enums, item) { EnumVariation::Rust - } else if self.is_constified_enum(ctx, item) { + } else if self.is_matching_enum(ctx, &ctx.options().constified_enums, item) { EnumVariation::Consts } else { ctx.options().default_enum_style |