diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-03-23 11:18:37 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-03-23 11:18:37 +0100 |
commit | 217cf285d452d3004f584fbe841da725f9063af9 (patch) | |
tree | a826f413c5977b301f75525882fe1d768f9c33d4 | |
parent | 15a18fa820d1b9d7e97bd317eb210d0363f95ee3 (diff) |
ir: Prefer the enum definition instead of the declaration when looking for variants.
-rw-r--r-- | src/ir/enum_ty.rs | 7 | ||||
-rw-r--r-- | tests/expectations/tests/forward-enum-decl.rs | 9 | ||||
-rw-r--r-- | tests/headers/forward-enum-decl.hpp | 8 |
3 files changed, 22 insertions, 2 deletions
diff --git a/src/ir/enum_ty.rs b/src/ir/enum_ty.rs index 175af691..e64354fb 100644 --- a/src/ir/enum_ty.rs +++ b/src/ir/enum_ty.rs @@ -54,6 +54,8 @@ impl Enum { ctx: &mut BindgenContext) -> Result<Self, ParseError> { use clang_sys::*; + debug!("Enum::from_ty {:?}", ty); + if ty.kind() != CXType_Enum { return Err(ParseError::Continue); } @@ -82,7 +84,8 @@ impl Enum { }; let type_name = type_name.as_ref().map(String::as_str); - declaration.visit(|cursor| { + let definition = declaration.definition().unwrap_or(declaration); + definition.visit(|cursor| { if cursor.kind() == CXCursor_EnumConstantDecl { let value = if is_signed { cursor.enum_val_signed().map(EnumVariantValue::Signed) @@ -99,7 +102,7 @@ impl Enum { Annotations::new(&cursor) .and_then(|anno| if anno.hide() { Some(EnumVariantCustomBehavior::Hide) - } else if + } else if anno.constify_enum_variant() { Some(EnumVariantCustomBehavior::Constify) } else { diff --git a/tests/expectations/tests/forward-enum-decl.rs b/tests/expectations/tests/forward-enum-decl.rs new file mode 100644 index 00000000..7f2d937a --- /dev/null +++ b/tests/expectations/tests/forward-enum-decl.rs @@ -0,0 +1,9 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(i32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum CSSPseudoClassType { empty = 0, link = 1, } diff --git a/tests/headers/forward-enum-decl.hpp b/tests/headers/forward-enum-decl.hpp new file mode 100644 index 00000000..2c4316c6 --- /dev/null +++ b/tests/headers/forward-enum-decl.hpp @@ -0,0 +1,8 @@ +// bindgen-flags: -- -std=c++11 + +enum class CSSPseudoClassType : int; + +enum class CSSPseudoClassType : int { + empty, + link, +}; |