diff options
author | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2016-11-22 10:27:47 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <ecoal95@gmail.com> | 2016-11-22 10:33:50 +0100 |
commit | b1736b936e6c8a5fd8885c3ea79e38a2be689d24 (patch) | |
tree | 4b70bfbcff59a06f9898f1c0d162ed49b50db1fe | |
parent | d4a66485a1438b5c3502fc1dd633ce42d9e04405 (diff) |
ir: Deduplicate namespaces.
6 files changed, 96 insertions, 13 deletions
diff --git a/libbindgen/src/ir/context.rs b/libbindgen/src/ir/context.rs index 7c643f04..76e27841 100644 --- a/libbindgen/src/ir/context.rs +++ b/libbindgen/src/ir/context.rs @@ -888,6 +888,8 @@ impl<'ctx> BindgenContext<'ctx> { self.current_module, ItemKind::Module(module)); + self.modules.insert(cursor, module.id()); + self.add_item(module, None, None); module_id diff --git a/libbindgen/tests/expectations/tests/duplicated-namespaces-definitions.rs b/libbindgen/tests/expectations/tests/duplicated-namespaces-definitions.rs new file mode 100644 index 00000000..314a24a3 --- /dev/null +++ b/libbindgen/tests/expectations/tests/duplicated-namespaces-definitions.rs @@ -0,0 +1,45 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +pub mod root { + #[allow(unused_imports)] + use root; + pub mod foo { + #[allow(unused_imports)] + use root; + #[repr(C)] + #[derive(Debug, Copy)] + pub struct Bar { + pub foo: ::std::os::raw::c_int, + pub baz: bool, + } + #[test] + fn bindgen_test_layout_Bar() { + assert_eq!(::std::mem::size_of::<Bar>() , 8usize); + assert_eq!(::std::mem::align_of::<Bar>() , 4usize); + } + impl Clone for Bar { + fn clone(&self) -> Self { *self } + } + } + pub mod bar { + #[allow(unused_imports)] + use root; + #[repr(C)] + #[derive(Debug, Copy)] + pub struct Foo { + pub ptr: *mut root::foo::Bar, + } + #[test] + fn bindgen_test_layout_Foo() { + assert_eq!(::std::mem::size_of::<Foo>() , 8usize); + assert_eq!(::std::mem::align_of::<Foo>() , 8usize); + } + impl Clone for Foo { + fn clone(&self) -> Self { *self } + } + } +} diff --git a/libbindgen/tests/expectations/tests/duplicated-namespaces.rs b/libbindgen/tests/expectations/tests/duplicated-namespaces.rs new file mode 100644 index 00000000..786fe1a5 --- /dev/null +++ b/libbindgen/tests/expectations/tests/duplicated-namespaces.rs @@ -0,0 +1,14 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +pub mod root { + #[allow(unused_imports)] + use root; + pub mod std { + #[allow(unused_imports)] + use root; + } +} diff --git a/libbindgen/tests/expectations/tests/typeref.rs b/libbindgen/tests/expectations/tests/typeref.rs index 21217ced..1188393d 100644 --- a/libbindgen/tests/expectations/tests/typeref.rs +++ b/libbindgen/tests/expectations/tests/typeref.rs @@ -68,19 +68,6 @@ impl Clone for mozilla_Position { fn clone(&self) -> Self { *self } } #[repr(C)] -#[derive(Debug, Copy)] -pub struct Bar { - pub mFoo: *mut nsFoo, -} -#[test] -fn bindgen_test_layout_Bar() { - assert_eq!(::std::mem::size_of::<Bar>() , 8usize); - assert_eq!(::std::mem::align_of::<Bar>() , 8usize); -} -impl Clone for Bar { - fn clone(&self) -> Self { *self } -} -#[repr(C)] #[derive(Debug, Copy, Clone)] pub struct mozilla_StyleShapeSource<ReferenceBox> { pub __bindgen_anon_1: mozilla_StyleShapeSource__bindgen_ty_1<ReferenceBox>, @@ -94,3 +81,16 @@ pub struct mozilla_StyleShapeSource__bindgen_ty_1<ReferenceBox> { pub bindgen_union_field: u64, pub _phantom_0: ::std::marker::PhantomData<ReferenceBox>, } +#[repr(C)] +#[derive(Debug, Copy)] +pub struct Bar { + pub mFoo: *mut nsFoo, +} +#[test] +fn bindgen_test_layout_Bar() { + assert_eq!(::std::mem::size_of::<Bar>() , 8usize); + assert_eq!(::std::mem::align_of::<Bar>() , 8usize); +} +impl Clone for Bar { + fn clone(&self) -> Self { *self } +} diff --git a/libbindgen/tests/headers/duplicated-namespaces-definitions.hpp b/libbindgen/tests/headers/duplicated-namespaces-definitions.hpp new file mode 100644 index 00000000..7c8888de --- /dev/null +++ b/libbindgen/tests/headers/duplicated-namespaces-definitions.hpp @@ -0,0 +1,18 @@ +// bindgen-flags: --enable-cxx-namespaces + +namespace foo { + class Bar; +} + +namespace bar { + struct Foo { + foo::Bar* ptr; + }; +}; + +namespace foo { + class Bar { + int foo; + bool baz; + }; +} diff --git a/libbindgen/tests/headers/duplicated-namespaces.hpp b/libbindgen/tests/headers/duplicated-namespaces.hpp new file mode 100644 index 00000000..10e1933f --- /dev/null +++ b/libbindgen/tests/headers/duplicated-namespaces.hpp @@ -0,0 +1,4 @@ +// bindgen-flags: --enable-cxx-namespaces + +namespace std {} +namespace std {} |