From c1639f708aa3c45be1623e51615b688d7b7061e2 Mon Sep 17 00:00:00 2001 From: Emilio Cobos Álvarez Date: Sun, 2 Oct 2016 17:19:04 +0200 Subject: Be able to represent Complex types with the correct layout. --- src/ir/ty.rs | 7 ++++ tests/expectations/complex.rs | 84 +++++++++++++++++++++++++++++++++++++++++++ tests/headers/complex.h | 13 +++++++ 3 files changed, 104 insertions(+) create mode 100644 tests/expectations/complex.rs create mode 100644 tests/headers/complex.h diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 8227a786..89ef893c 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -549,6 +549,13 @@ impl Type { .expect("Not able to resolve array element?"); TypeKind::Array(inner, ty.num_elements()) } + // A complex number is always a real and an imaginary part, so + // represent that as a two-item array. + CXType_Complex => { + let inner = Item::from_ty(&ty.elem_type(), location, parent_id, ctx) + .expect("Not able to resolve array element?"); + TypeKind::Array(inner, 2) + } #[cfg(not(feature="llvm_stable"))] CXType_Elaborated => { return Self::from_clang_ty(potential_id, &ty.named(), diff --git a/tests/expectations/complex.rs b/tests/expectations/complex.rs new file mode 100644 index 00000000..e11a049e --- /dev/null +++ b/tests/expectations/complex.rs @@ -0,0 +1,84 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy)] +pub struct Testdouble { + pub mMember: [f64; 2usize], +} +#[test] +fn bindgen_test_layout_Testdouble() { + assert_eq!(::std::mem::size_of::() , 16usize); + assert_eq!(::std::mem::align_of::() , 8usize); +} +impl Clone for Testdouble { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct TestdoublePtr { + pub mMember: *mut [f64; 2usize], +} +#[test] +fn bindgen_test_layout_TestdoublePtr() { + assert_eq!(::std::mem::size_of::() , 8usize); + assert_eq!(::std::mem::align_of::() , 8usize); +} +impl Clone for TestdoublePtr { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct Testfloat { + pub mMember: [f32; 2usize], +} +#[test] +fn bindgen_test_layout_Testfloat() { + assert_eq!(::std::mem::size_of::() , 8usize); + assert_eq!(::std::mem::align_of::() , 4usize); +} +impl Clone for Testfloat { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct TestfloatPtr { + pub mMember: *mut [f32; 2usize], +} +#[test] +fn bindgen_test_layout_TestfloatPtr() { + assert_eq!(::std::mem::size_of::() , 8usize); + assert_eq!(::std::mem::align_of::() , 8usize); +} +impl Clone for TestfloatPtr { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct Testint { + pub mMember: [::std::os::raw::c_int; 2usize], +} +#[test] +fn bindgen_test_layout_Testint() { + assert_eq!(::std::mem::size_of::() , 8usize); + assert_eq!(::std::mem::align_of::() , 4usize); +} +impl Clone for Testint { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct TestintPtr { + pub mMember: *mut [::std::os::raw::c_int; 2usize], +} +#[test] +fn bindgen_test_layout_TestintPtr() { + assert_eq!(::std::mem::size_of::() , 8usize); + assert_eq!(::std::mem::align_of::() , 8usize); +} +impl Clone for TestintPtr { + fn clone(&self) -> Self { *self } +} diff --git a/tests/headers/complex.h b/tests/headers/complex.h new file mode 100644 index 00000000..ad7af59f --- /dev/null +++ b/tests/headers/complex.h @@ -0,0 +1,13 @@ + +#define COMPLEX_TEST(ty_) \ + struct Test##ty_ { \ + ty_ _Complex mMember; \ + \ + }; \ + struct Test##ty_##Ptr { \ + ty_ _Complex* mMember; \ + }; + +COMPLEX_TEST(double) +COMPLEX_TEST(float) +COMPLEX_TEST(int) -- cgit v1.2.3