From a91f18574615720c09dcea9d5f27d4a06fdc6563 Mon Sep 17 00:00:00 2001 From: Weston Carvalho Date: Tue, 12 Jan 2021 11:28:22 -0800 Subject: [PATCH] Address review comments, fmt, and fix failing test. --- src/clang.rs | 9 ++++++ src/ir/comp.rs | 16 +++------- tests/expectations/tests/class_1_0.rs | 46 +++++++++++++-------------- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/clang.rs b/src/clang.rs index 488660c434..661250894e 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -632,6 +632,15 @@ impl Cursor { unsafe { clang_getCXXAccessSpecifier(self.x) } } + /// Is the cursor's referrent publically accessible in C++? + /// + /// Returns true if self.access_specifier() is `CX_CXXPublic` or + /// `CX_CXXInvalidAccessSpecifier`. + pub fn public_accessible(&self) -> bool { + let access = self.access_specifier(); + access == CX_CXXPublic || access == CX_CXXInvalidAccessSpecifier + } + /// Is this cursor's referent a field declaration that is marked as /// `mutable`? pub fn is_mutable_field(&self) -> bool { diff --git a/src/ir/comp.rs b/src/ir/comp.rs index 569a19f2c5..cb488cbd96 100644 --- a/src/ir/comp.rs +++ b/src/ir/comp.rs @@ -1291,8 +1291,7 @@ impl CompInfo { if !used { let field = RawField::new( - None, ty, None, None, None, public, - offset, + None, ty, None, None, None, public, offset, ); ci.fields.append_raw_field(field); } @@ -1309,8 +1308,7 @@ impl CompInfo { let comment = cur.raw_comment(); let annotations = Annotations::new(&cur); let name = cur.spelling(); - let is_public = - cur.access_specifier() != clang_sys::CX_CXXPrivate; + let is_public = cur.public_accessible(); let offset = cur.offset_of_field().ok(); // Name can be empty if there are bitfields, for example, @@ -1385,10 +1383,7 @@ impl CompInfo { cur.kind() != CXCursor_EnumDecl { let ty = cur.cur_type(); - let public = cur.access_specifier() == - clang_sys::CX_CXXPublic || - cur.access_specifier() == - clang_sys::CX_CXXInvalidAccessSpecifier; + let public = cur.public_accessible(); let offset = cur.offset_of_field().ok(); maybe_anonymous_struct_field = @@ -1543,9 +1538,8 @@ impl CompInfo { }); if let Some((ty, _, public, offset)) = maybe_anonymous_struct_field { - let field = RawField::new( - None, ty, None, None, None, public, offset, - ); + let field = + RawField::new(None, ty, None, None, None, public, offset); ci.fields.append_raw_field(field); } diff --git a/tests/expectations/tests/class_1_0.rs b/tests/expectations/tests/class_1_0.rs index b341bdbe87..40e5db3332 100644 --- a/tests/expectations/tests/class_1_0.rs +++ b/tests/expectations/tests/class_1_0.rs @@ -81,8 +81,8 @@ impl ::std::cmp::Eq for __BindgenUnionField {} #[repr(C)] #[derive(Copy)] pub struct C { - pub a: ::std::os::raw::c_int, - pub big_array: [::std::os::raw::c_char; 33usize], + a: ::std::os::raw::c_int, + big_array: [::std::os::raw::c_char; 33usize], } #[test] fn bindgen_test_layout_C() { @@ -129,9 +129,9 @@ impl ::std::cmp::PartialEq for C { } #[repr(C)] pub struct C_with_zero_length_array { - pub a: ::std::os::raw::c_int, - pub big_array: [::std::os::raw::c_char; 33usize], - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, + a: ::std::os::raw::c_int, + big_array: [::std::os::raw::c_char; 33usize], + zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, } #[test] fn bindgen_test_layout_C_with_zero_length_array() { @@ -193,8 +193,8 @@ impl Default for C_with_zero_length_array { #[repr(C)] #[derive(Debug, Default)] pub struct C_with_zero_length_array_2 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, + a: ::std::os::raw::c_int, + zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, } #[test] fn bindgen_test_layout_C_with_zero_length_array_2() { @@ -237,9 +237,9 @@ fn bindgen_test_layout_C_with_zero_length_array_2() { } #[repr(C)] pub struct C_with_incomplete_array { - pub a: ::std::os::raw::c_int, - pub big_array: [::std::os::raw::c_char; 33usize], - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, + a: ::std::os::raw::c_int, + big_array: [::std::os::raw::c_char; 33usize], + incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, } #[test] fn bindgen_test_layout_C_with_incomplete_array() { @@ -262,8 +262,8 @@ impl Default for C_with_incomplete_array { #[repr(C)] #[derive(Debug, Default)] pub struct C_with_incomplete_array_2 { - pub a: ::std::os::raw::c_int, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, + a: ::std::os::raw::c_int, + incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, } #[test] fn bindgen_test_layout_C_with_incomplete_array_2() { @@ -280,10 +280,10 @@ fn bindgen_test_layout_C_with_incomplete_array_2() { } #[repr(C)] pub struct C_with_zero_length_array_and_incomplete_array { - pub a: ::std::os::raw::c_int, - pub big_array: [::std::os::raw::c_char; 33usize], - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, + a: ::std::os::raw::c_int, + big_array: [::std::os::raw::c_char; 33usize], + zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, + incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, } #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array() { @@ -312,9 +312,9 @@ impl Default for C_with_zero_length_array_and_incomplete_array { #[repr(C)] #[derive(Debug, Default)] pub struct C_with_zero_length_array_and_incomplete_array_2 { - pub a: ::std::os::raw::c_int, - pub zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, - pub incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, + a: ::std::os::raw::c_int, + zero_length_array: __IncompleteArrayField<::std::os::raw::c_char>, + incomplete_array: __IncompleteArrayField<::std::os::raw::c_char>, } #[test] fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { @@ -340,7 +340,7 @@ fn bindgen_test_layout_C_with_zero_length_array_and_incomplete_array_2() { #[repr(C)] #[derive(Debug, Default, Hash, PartialEq, Eq)] pub struct WithDtor { - pub b: ::std::os::raw::c_int, + b: ::std::os::raw::c_int, } #[test] fn bindgen_test_layout_WithDtor() { @@ -367,8 +367,8 @@ fn bindgen_test_layout_WithDtor() { } #[repr(C)] pub struct IncompleteArrayNonCopiable { - pub whatever: *mut ::std::os::raw::c_void, - pub incomplete_array: __IncompleteArrayField, + whatever: *mut ::std::os::raw::c_void, + incomplete_array: __IncompleteArrayField, } #[test] fn bindgen_test_layout_IncompleteArrayNonCopiable() { @@ -426,7 +426,7 @@ impl Clone for Union { #[repr(C)] #[derive(Debug, Default, Copy, Hash, PartialEq)] pub struct WithUnion { - pub data: Union, + data: Union, } #[test] fn bindgen_test_layout_WithUnion() {