summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Finkenauer <tmfinken@gmail.com>2017-06-16 21:20:05 -0700
committerTravis Finkenauer <tmfinken@gmail.com>2017-06-16 21:20:05 -0700
commit5f4b73051ab7895e085e4a8e57fc87e7df0120f7 (patch)
tree2420240fd9a94ea32b14e7ec049d40aad83cee91
parentde155b914d97dd382fa17e56ee9555a012469c5e (diff)
Refactor namespace code and test
-rw-r--r--src/ir/item.rs25
-rw-r--r--tests/expectations/tests/constify-module-enums-types.rs9
-rw-r--r--tests/headers/constify-module-enums-types.hpp3
3 files changed, 24 insertions, 13 deletions
diff --git a/src/ir/item.rs b/src/ir/item.rs
index 61b70673..d0ad9674 100644
--- a/src/ir/item.rs
+++ b/src/ir/item.rs
@@ -826,6 +826,19 @@ impl Item {
_ => None,
}
}
+
+ /// Returns whether the item is a constified module enum
+ fn is_constified_enum_module(&self, ctx: &BindgenContext) -> bool {
+ if let ItemKind::Type(ref type_) = self.kind {
+ if let Some(ref type_) = type_.safe_canonical_type(ctx) {
+ if let TypeKind::Enum(ref enum_) = *type_.kind() {
+ return enum_.is_constified_enum_module(ctx, self);
+ }
+ }
+ }
+
+ return false;
+ }
}
/// A set of items.
@@ -1445,17 +1458,7 @@ impl ItemCanonicalPath for Item {
ctx: &BindgenContext)
-> Vec<String> {
let mut path = self.canonical_path(ctx);
- let mut is_constified_module_enum = false;
- if let ItemKind::Type(ref type_) = self.kind {
- if let Some(ref type_) = type_.safe_canonical_type(ctx) {
- if let TypeKind::Enum(ref enum_) = *type_.kind() {
- if enum_.is_constified_enum_module(ctx, self) {
- // Type alias is inside a module
- is_constified_module_enum = true;
- }
- }
- }
- }
+ let is_constified_module_enum = self.is_constified_enum_module(ctx);
if ctx.options().enable_cxx_namespaces {
if is_constified_module_enum {
path.push(CONSTIFIED_ENUM_MODULE_REPR_NAME.into());
diff --git a/tests/expectations/tests/constify-module-enums-types.rs b/tests/expectations/tests/constify-module-enums-types.rs
index 3effcc12..6f5d1a83 100644
--- a/tests/expectations/tests/constify-module-enums-types.rs
+++ b/tests/expectations/tests/constify-module-enums-types.rs
@@ -15,6 +15,7 @@ pub mod foo {
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ns1_foo2 { THIS = 0, SHOULD_BE = 1, A_CONSTANT = 2, ALSO_THIS = 42, }
+pub use self::ns1_foo2 as ns1_foo;
pub use self::foo::Type as foo_alias1;
pub use self::foo_alias1 as foo_alias2;
#[repr(C)]
@@ -23,10 +24,11 @@ pub struct bar {
pub member1: foo::Type,
pub member2: foo_alias1,
pub member3: foo_alias2,
+ pub member4: ns1_foo,
}
#[test]
fn bindgen_test_layout_bar() {
- assert_eq!(::std::mem::size_of::<bar>() , 12usize , concat ! (
+ assert_eq!(::std::mem::size_of::<bar>() , 16usize , concat ! (
"Size of: " , stringify ! ( bar ) ));
assert_eq! (::std::mem::align_of::<bar>() , 4usize , concat ! (
"Alignment of " , stringify ! ( bar ) ));
@@ -45,6 +47,11 @@ fn bindgen_test_layout_bar() {
, 8usize , concat ! (
"Alignment of field: " , stringify ! ( bar ) , "::" ,
stringify ! ( member3 ) ));
+ assert_eq! (unsafe {
+ & ( * ( 0 as * const bar ) ) . member4 as * const _ as usize }
+ , 12usize , concat ! (
+ "Alignment of field: " , stringify ! ( bar ) , "::" ,
+ stringify ! ( member4 ) ));
}
impl Clone for bar {
fn clone(&self) -> Self { *self }
diff --git a/tests/headers/constify-module-enums-types.hpp b/tests/headers/constify-module-enums-types.hpp
index 1570654f..b49dc038 100644
--- a/tests/headers/constify-module-enums-types.hpp
+++ b/tests/headers/constify-module-enums-types.hpp
@@ -14,7 +14,7 @@ namespace ns1 {
SHOULD_BE,
A_CONSTANT,
ALSO_THIS = 42,
- } foo2;
+ } foo;
}
typedef foo foo_alias1;
@@ -24,6 +24,7 @@ typedef struct bar {
foo member1;
foo_alias1 member2;
foo_alias2 member3;
+ ns1::foo member4;
} bar;
foo *func1(foo arg1, foo *arg2, foo **arg3);