Skip to content

Commit

Permalink
Address review comments, fmt, and fix failing test.
Browse files Browse the repository at this point in the history
  • Loading branch information
SilensAngelusNex committed Jan 12, 2021
1 parent a7093b0 commit a91f185
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
9 changes: 9 additions & 0 deletions src/clang.rs
Expand Up @@ -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 {
Expand Down
16 changes: 5 additions & 11 deletions src/ir/comp.rs
Expand Up @@ -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);
}
Expand All @@ -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,
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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);
}

Expand Down
46 changes: 23 additions & 23 deletions tests/expectations/tests/class_1_0.rs
Expand Up @@ -81,8 +81,8 @@ impl<T> ::std::cmp::Eq for __BindgenUnionField<T> {}
#[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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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<C>,
whatever: *mut ::std::os::raw::c_void,
incomplete_array: __IncompleteArrayField<C>,
}
#[test]
fn bindgen_test_layout_IncompleteArrayNonCopiable() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit a91f185

Please sign in to comment.