summaryrefslogtreecommitdiff
path: root/tests/expectations/class_with_inner_struct.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-09-21 04:44:12 -0500
committerGitHub <noreply@github.com>2016-09-21 04:44:12 -0500
commitf318b638a81cf0602ece84fc412f87c7ab3a0b4e (patch)
tree326b031be594e88369d52bea5cd665bc0a9d3bb5 /tests/expectations/class_with_inner_struct.rs
parentbbd6b2c9919e02642a8874e5ceb2ba3b5c76adec (diff)
parentda69afdaf90f091944719edd258ca1bb0c19a82b (diff)
Auto merge of #37 - emilio:v2, r=nox
Rewrite the core of the binding generator. TL;DR: The binding generator is a mess as of right now. At first it was funny (in a "this is challenging" sense) to improve on it, but this is not sustainable. The truth is that the current architecture of the binding generator is a huge pile of hacks, so these few days I've been working on rewriting it with a few goals. 1) Have the hacks as contained and identified as possible. They're sometimes needed because how clang exposes the AST, but ideally those hacks are well identified and don't interact randomly with each others. As an example, in the current bindgen when scanning the parameters of a function that references a struct clones all the struct information, then if the struct name changes (because we mangle it), everything breaks. 2) Support extending the bindgen output without having to deal with clang. The way I'm aiming to do this is separating completely the parsing stage from the code generation one, and providing a single id for each item the binding generator provides. 3) No more random mutation of the internal representation from anywhere. That means no more `Rc<RefCell<T>>`, no more random circular references, no more borrow_state... nothing. 4) No more deduplication of declarations before code generation. Current bindgen has a stage, called `tag_dup_decl`[1], that takes care of deduplicating declarations. That's completely buggy, and for C++ it's a complete mess, since we YOLO modify the world. I've managed to take rid of this using the clang canonical declaration, and the definition, to avoid scanning any type/item twice. 5) Code generation should not modify any internal data structure. It can lookup things, traverse whatever it needs, but not modifying randomly. 6) Each item should have a canonical name, and a single source of mangling logic, and that should be computed from the immutable state, at code generation. I've put a few canonical_name stuff in the code generation phase, but it's still not complete, and should change if I implement namespaces. Improvements pending until this can land: 1) Add support for missing core stuff, mainly generating functions (note that we parse the signatures for types correctly though), bitfields, generating C++ methods. 2) Add support for the necessary features that were added to work around some C++ pitfalls, like opaque types, etc... 3) Add support for the sugar that Manish added recently. 4) Optionally (and I guess this can land without it, because basically nobody uses it since it's so buggy), bring back namespace support. These are not completely trivial, but I think I can do them quite easily with the current architecture. I'm putting the current state of affairs here as a request for comments... Note that there are still a few smells I want to eventually re-redesign, like the ParseError::Recurse thing, but until that happens I'm way happier with this kind of architecture. I'm keeping the old `parser.rs` and `gen.rs` in tree just for reference while I code, but they will go away. [1]: https://github.com/Yamakaky/rust-bindgen/blob/master/src/gen.rs#L448
Diffstat (limited to 'tests/expectations/class_with_inner_struct.rs')
-rw-r--r--tests/expectations/class_with_inner_struct.rs205
1 files changed, 86 insertions, 119 deletions
diff --git a/tests/expectations/class_with_inner_struct.rs b/tests/expectations/class_with_inner_struct.rs
index b465a183..464c622d 100644
--- a/tests/expectations/class_with_inner_struct.rs
+++ b/tests/expectations/class_with_inner_struct.rs
@@ -4,7 +4,7 @@
#![allow(non_snake_case)]
-#[derive(Copy, Debug)]
+#[derive(Debug)]
#[repr(C)]
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
@@ -23,109 +23,94 @@ impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
#[inline]
fn clone(&self) -> Self { Self::new() }
}
+impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
#[repr(C)]
#[derive(Debug, Copy)]
-pub struct Struct_A {
+pub struct A {
pub c: ::std::os::raw::c_uint,
- pub named_union: Union_A_class_with_inner_struct_hpp_unnamed_1,
- pub A_class_with_inner_struct_hpp_unnamed_2: Union_A_class_with_inner_struct_hpp_unnamed_2,
+ pub named_union: A__bindgen_ty_bindgen_id_6,
+ pub __bindgen_anon_1: A__bindgen_ty_bindgen_id_9,
}
#[repr(C)]
#[derive(Debug, Copy)]
-pub struct Struct_A_Segment {
+pub struct A_Segment {
pub begin: ::std::os::raw::c_int,
pub end: ::std::os::raw::c_int,
}
-impl ::std::clone::Clone for Struct_A_Segment {
- fn clone(&self) -> Self { *self }
-}
#[test]
-fn bindgen_test_layout_Struct_A_Segment() {
- assert_eq!(::std::mem::size_of::<Struct_A_Segment>() , 8usize);
- assert_eq!(::std::mem::align_of::<Struct_A_Segment>() , 4usize);
+fn bindgen_test_layout_A_Segment() {
+ assert_eq!(::std::mem::size_of::<A_Segment>() , 8usize);
+ assert_eq!(::std::mem::align_of::<A_Segment>() , 4usize);
+}
+impl Clone for A_Segment {
+ fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy)]
-pub struct Union_A_class_with_inner_struct_hpp_unnamed_1 {
+pub struct A__bindgen_ty_bindgen_id_6 {
pub f: __BindgenUnionField<::std::os::raw::c_int>,
- pub _bindgen_data_: u32,
+ pub bindgen_union_field: u32,
}
-impl Union_A_class_with_inner_struct_hpp_unnamed_1 {
- pub unsafe fn f(&mut self) -> *mut ::std::os::raw::c_int {
- let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
- ::std::mem::transmute(raw.offset(0))
- }
+#[test]
+fn bindgen_test_layout_A__bindgen_ty_bindgen_id_6() {
+ assert_eq!(::std::mem::size_of::<A__bindgen_ty_bindgen_id_6>() , 4usize);
+ assert_eq!(::std::mem::align_of::<A__bindgen_ty_bindgen_id_6>() , 4usize);
}
-impl ::std::clone::Clone for Union_A_class_with_inner_struct_hpp_unnamed_1 {
+impl Clone for A__bindgen_ty_bindgen_id_6 {
fn clone(&self) -> Self { *self }
}
-#[test]
-fn bindgen_test_layout_Union_A_class_with_inner_struct_hpp_unnamed_1() {
- assert_eq!(::std::mem::size_of::<Union_A_class_with_inner_struct_hpp_unnamed_1>()
- , 4usize);
- assert_eq!(::std::mem::align_of::<Union_A_class_with_inner_struct_hpp_unnamed_1>()
- , 4usize);
-}
#[repr(C)]
#[derive(Debug, Copy)]
-pub struct Union_A_class_with_inner_struct_hpp_unnamed_2 {
+pub struct A__bindgen_ty_bindgen_id_9 {
pub d: __BindgenUnionField<::std::os::raw::c_int>,
- pub _bindgen_data_: u32,
+ pub bindgen_union_field: u32,
}
-impl Union_A_class_with_inner_struct_hpp_unnamed_2 {
- pub unsafe fn d(&mut self) -> *mut ::std::os::raw::c_int {
- let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
- ::std::mem::transmute(raw.offset(0))
- }
+#[test]
+fn bindgen_test_layout_A__bindgen_ty_bindgen_id_9() {
+ assert_eq!(::std::mem::size_of::<A__bindgen_ty_bindgen_id_9>() , 4usize);
+ assert_eq!(::std::mem::align_of::<A__bindgen_ty_bindgen_id_9>() , 4usize);
}
-impl ::std::clone::Clone for Union_A_class_with_inner_struct_hpp_unnamed_2 {
+impl Clone for A__bindgen_ty_bindgen_id_9 {
fn clone(&self) -> Self { *self }
}
#[test]
-fn bindgen_test_layout_Union_A_class_with_inner_struct_hpp_unnamed_2() {
- assert_eq!(::std::mem::size_of::<Union_A_class_with_inner_struct_hpp_unnamed_2>()
- , 4usize);
- assert_eq!(::std::mem::align_of::<Union_A_class_with_inner_struct_hpp_unnamed_2>()
- , 4usize);
+fn bindgen_test_layout_A() {
+ assert_eq!(::std::mem::size_of::<A>() , 12usize);
+ assert_eq!(::std::mem::align_of::<A>() , 4usize);
}
-impl ::std::clone::Clone for Struct_A {
+impl Clone for A {
fn clone(&self) -> Self { *self }
}
-#[test]
-fn bindgen_test_layout_Struct_A() {
- assert_eq!(::std::mem::size_of::<Struct_A>() , 12usize);
- assert_eq!(::std::mem::align_of::<Struct_A>() , 4usize);
-}
#[repr(C)]
#[derive(Debug, Copy)]
-pub struct Struct_B {
+pub struct B {
pub d: ::std::os::raw::c_uint,
}
#[repr(C)]
#[derive(Debug, Copy)]
-pub struct Struct_B_Segment {
+pub struct B_Segment {
pub begin: ::std::os::raw::c_int,
pub end: ::std::os::raw::c_int,
}
-impl ::std::clone::Clone for Struct_B_Segment {
- fn clone(&self) -> Self { *self }
-}
#[test]
-fn bindgen_test_layout_Struct_B_Segment() {
- assert_eq!(::std::mem::size_of::<Struct_B_Segment>() , 8usize);
- assert_eq!(::std::mem::align_of::<Struct_B_Segment>() , 4usize);
+fn bindgen_test_layout_B_Segment() {
+ assert_eq!(::std::mem::size_of::<B_Segment>() , 8usize);
+ assert_eq!(::std::mem::align_of::<B_Segment>() , 4usize);
}
-impl ::std::clone::Clone for Struct_B {
+impl Clone for B_Segment {
fn clone(&self) -> Self { *self }
}
#[test]
-fn bindgen_test_layout_Struct_B() {
- assert_eq!(::std::mem::size_of::<Struct_B>() , 4usize);
- assert_eq!(::std::mem::align_of::<Struct_B>() , 4usize);
+fn bindgen_test_layout_B() {
+ assert_eq!(::std::mem::size_of::<B>() , 4usize);
+ assert_eq!(::std::mem::align_of::<B>() , 4usize);
+}
+impl Clone for B {
+ fn clone(&self) -> Self { *self }
}
#[repr(i32)]
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
-pub enum Enum_StepSyntax {
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub enum StepSyntax {
Keyword = 0,
FunctionalWithoutKeyword = 1,
FunctionalWithStartKeyword = 2,
@@ -133,98 +118,80 @@ pub enum Enum_StepSyntax {
}
#[repr(C)]
#[derive(Debug, Copy)]
-pub struct Struct_C {
+pub struct C {
pub d: ::std::os::raw::c_uint,
- pub C_class_with_inner_struct_hpp_unnamed_3: Union_C_class_with_inner_struct_hpp_unnamed_3,
+ pub __bindgen_anon_1: C__bindgen_ty_bindgen_id_21,
}
#[repr(C)]
#[derive(Debug, Copy)]
-pub struct Union_C_class_with_inner_struct_hpp_unnamed_3 {
- pub mFunc: __BindgenUnionField<Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_4>,
- pub C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_5: __BindgenUnionField<Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_5>,
- pub _bindgen_data_: [u32; 4usize],
-}
-impl Union_C_class_with_inner_struct_hpp_unnamed_3 {
- pub unsafe fn mFunc(&mut self)
- ->
- *mut Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_4 {
- let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
- ::std::mem::transmute(raw.offset(0))
- }
- pub unsafe fn C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_5(&mut self)
- ->
- *mut Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_5 {
- let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
- ::std::mem::transmute(raw.offset(0))
- }
-}
-impl ::std::clone::Clone for Union_C_class_with_inner_struct_hpp_unnamed_3 {
- fn clone(&self) -> Self { *self }
-}
-#[test]
-fn bindgen_test_layout_Union_C_class_with_inner_struct_hpp_unnamed_3() {
- assert_eq!(::std::mem::size_of::<Union_C_class_with_inner_struct_hpp_unnamed_3>()
- , 16usize);
- assert_eq!(::std::mem::align_of::<Union_C_class_with_inner_struct_hpp_unnamed_3>()
- , 4usize);
+pub struct C__bindgen_ty_bindgen_id_21 {
+ pub mFunc: __BindgenUnionField<C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_22>,
+ pub __bindgen_anon_1: __BindgenUnionField<C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_28>,
+ pub bindgen_union_field: [u32; 4usize],
}
#[repr(C)]
#[derive(Debug, Copy)]
-pub struct Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_4 {
+pub struct C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_22 {
pub mX1: f32,
pub mY1: f32,
pub mX2: f32,
pub mY2: f32,
}
-impl ::std::clone::Clone for
- Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_4
- {
- fn clone(&self) -> Self { *self }
-}
#[test]
-fn bindgen_test_layout_Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_4() {
- assert_eq!(::std::mem::size_of::<Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_4>()
+fn bindgen_test_layout_C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_22() {
+ assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_22>()
, 16usize);
- assert_eq!(::std::mem::align_of::<Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_4>()
+ assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_22>()
, 4usize);
}
+impl Clone for C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_22 {
+ fn clone(&self) -> Self { *self }
+}
#[repr(C)]
#[derive(Debug, Copy)]
-pub struct Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_5 {
- pub mStepSyntax: Enum_StepSyntax,
+pub struct C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_28 {
+ pub mStepSyntax: StepSyntax,
pub mSteps: ::std::os::raw::c_uint,
}
-impl ::std::clone::Clone for
- Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_5
- {
- fn clone(&self) -> Self { *self }
-}
#[test]
-fn bindgen_test_layout_Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_5() {
- assert_eq!(::std::mem::size_of::<Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_5>()
+fn bindgen_test_layout_C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_28() {
+ assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_28>()
, 8usize);
- assert_eq!(::std::mem::align_of::<Struct_C_class_with_inner_struct_hpp_unnamed_3_class_with_inner_struct_hpp_unnamed_5>()
+ assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_28>()
, 4usize);
}
+impl Clone for C__bindgen_ty_bindgen_id_21__bindgen_ty_bindgen_id_28 {
+ fn clone(&self) -> Self { *self }
+}
+#[test]
+fn bindgen_test_layout_C__bindgen_ty_bindgen_id_21() {
+ assert_eq!(::std::mem::size_of::<C__bindgen_ty_bindgen_id_21>() ,
+ 16usize);
+ assert_eq!(::std::mem::align_of::<C__bindgen_ty_bindgen_id_21>() ,
+ 4usize);
+}
+impl Clone for C__bindgen_ty_bindgen_id_21 {
+ fn clone(&self) -> Self { *self }
+}
#[repr(C)]
#[derive(Debug, Copy)]
-pub struct Struct_C_Segment {
+pub struct C_Segment {
pub begin: ::std::os::raw::c_int,
pub end: ::std::os::raw::c_int,
}
-impl ::std::clone::Clone for Struct_C_Segment {
- fn clone(&self) -> Self { *self }
-}
#[test]
-fn bindgen_test_layout_Struct_C_Segment() {
- assert_eq!(::std::mem::size_of::<Struct_C_Segment>() , 8usize);
- assert_eq!(::std::mem::align_of::<Struct_C_Segment>() , 4usize);
+fn bindgen_test_layout_C_Segment() {
+ assert_eq!(::std::mem::size_of::<C_Segment>() , 8usize);
+ assert_eq!(::std::mem::align_of::<C_Segment>() , 4usize);
}
-impl ::std::clone::Clone for Struct_C {
+impl Clone for C_Segment {
fn clone(&self) -> Self { *self }
}
#[test]
-fn bindgen_test_layout_Struct_C() {
- assert_eq!(::std::mem::size_of::<Struct_C>() , 20usize);
- assert_eq!(::std::mem::align_of::<Struct_C>() , 4usize);
+fn bindgen_test_layout_C() {
+ assert_eq!(::std::mem::size_of::<C>() , 20usize);
+ assert_eq!(::std::mem::align_of::<C>() , 4usize);
+}
+impl Clone for C {
+ fn clone(&self) -> Self { *self }
}