diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-03-31 00:04:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-31 00:04:43 +0200 |
commit | d2af109f70583144a393132cd5ea4159752176eb (patch) | |
tree | 97030e1bea46c205a6952f197c4ef7419c01f539 | |
parent | 7ed7c2492fbda2e25fe84be0696341288998bd8b (diff) | |
parent | 90218545c38c79b91e211b5f0a6a9377a96ef146 (diff) |
Merge pull request #602 from emilio/clang-5
clang: Fix most of the clang 5.0 regressions in our tests.
-rw-r--r-- | src/clang.rs | 22 | ||||
-rw-r--r-- | src/ir/ty.rs | 7 | ||||
-rw-r--r-- | tests/expectations/tests/struct_typedef_ns.rs | 27 |
3 files changed, 33 insertions, 23 deletions
diff --git a/src/clang.rs b/src/clang.rs index ee422745..2dbe5e51 100644 --- a/src/clang.rs +++ b/src/clang.rs @@ -600,6 +600,17 @@ impl Cursor { } } +/// Checks whether the name looks like an identifier, i.e. is alphanumeric +/// (including '_') and does not start with a digit. +pub fn is_valid_identifier(name: &str) -> bool { + let mut chars = name.chars(); + let first_valid = chars.next() + .map(|c| c.is_alphabetic() || c == '_') + .unwrap_or(false); + + first_valid && chars.all(|c| c.is_alphanumeric() || c == '_') +} + extern "C" fn visit_children<Visitor>(cur: CXCursor, _parent: CXCursor, data: CXClientData) @@ -729,7 +740,16 @@ impl Type { /// Get a raw display name for this type. pub fn spelling(&self) -> String { - unsafe { cxstring_into_string(clang_getTypeSpelling(self.x)) } + let s = unsafe { cxstring_into_string(clang_getTypeSpelling(self.x)) }; + // Clang 5.0 introduced changes in the spelling API so it returned the + // full qualified name. Let's undo that here. + if s.split("::").all(|s| is_valid_identifier(s)) { + if let Some(s) = s.split("::").last() { + return s.to_owned(); + } + } + + s } /// Is this type const qualified? diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 54925696..60d750ed 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -429,12 +429,7 @@ impl Type { /// Checks whether the name looks like an identifier, /// i.e. is alphanumeric (including '_') and does not start with a digit. pub fn is_valid_identifier(name: &str) -> bool { - let mut chars = name.chars(); - let first_valid = chars.next() - .map(|c| c.is_alphabetic() || c == '_') - .unwrap_or(false); - - first_valid && chars.all(|c| c.is_alphanumeric() || c == '_') + clang::is_valid_identifier(name) } /// See safe_canonical_type. diff --git a/tests/expectations/tests/struct_typedef_ns.rs b/tests/expectations/tests/struct_typedef_ns.rs index 0f078e6f..9f2c3b34 100644 --- a/tests/expectations/tests/struct_typedef_ns.rs +++ b/tests/expectations/tests/struct_typedef_ns.rs @@ -13,34 +13,29 @@ pub mod root { use self::super::super::root; #[repr(C)] #[derive(Debug, Default, Copy)] - pub struct _bindgen_ty_1 { + pub struct typedef_struct { pub foo: ::std::os::raw::c_int, } #[test] - fn bindgen_test_layout__bindgen_ty_1() { - assert_eq!(::std::mem::size_of::<_bindgen_ty_1>() , 4usize , - concat ! ( "Size of: " , stringify ! ( _bindgen_ty_1 ) + fn bindgen_test_layout_typedef_struct() { + assert_eq!(::std::mem::size_of::<typedef_struct>() , 4usize , + concat ! ( "Size of: " , stringify ! ( typedef_struct ) )); - assert_eq! (::std::mem::align_of::<_bindgen_ty_1>() , 4usize , + assert_eq! (::std::mem::align_of::<typedef_struct>() , 4usize , concat ! ( - "Alignment of " , stringify ! ( _bindgen_ty_1 ) )); + "Alignment of " , stringify ! ( typedef_struct ) )); assert_eq! (unsafe { - & ( * ( 0 as * const _bindgen_ty_1 ) ) . foo as * + & ( * ( 0 as * const typedef_struct ) ) . foo as * const _ as usize } , 0usize , concat ! ( - "Alignment of field: " , stringify ! ( _bindgen_ty_1 ) - , "::" , stringify ! ( foo ) )); + "Alignment of field: " , stringify ! ( typedef_struct + ) , "::" , stringify ! ( foo ) )); } - impl Clone for _bindgen_ty_1 { + impl Clone for typedef_struct { fn clone(&self) -> Self { *self } } - pub type typedef_struct = root::whatever::_bindgen_ty_1; - pub const whatever_BAR: root::whatever::_bindgen_ty_2 = - _bindgen_ty_2::BAR; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] - pub enum _bindgen_ty_2 { BAR = 1, } - pub use self::super::super::root::whatever::_bindgen_ty_2 as - typedef_enum; + pub enum typedef_enum { BAR = 1, } } pub mod _bindgen_mod_id_12 { #[allow(unused_imports)] |