diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-01-16 20:03:30 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-01-16 20:04:18 +0100 |
commit | d021caab5ea0180395cb790eb8ecafa8f66dc7b6 (patch) | |
tree | ffe5b5e678a8bfb632dc31b04abd237c8e5f0e6e | |
parent | b570ce853e33bfcfa05dd339bf432377c4a2fab8 (diff) |
ir: Unify function checks so they apply to non-methods.
-rw-r--r-- | libbindgen/src/ir/comp.rs | 29 | ||||
-rw-r--r-- | libbindgen/src/ir/function.rs | 19 | ||||
-rw-r--r-- | libbindgen/tests/expectations/tests/inline-function.rs | 7 | ||||
-rw-r--r-- | libbindgen/tests/expectations/tests/namespace.rs | 13 | ||||
-rw-r--r-- | libbindgen/tests/headers/inline-function.h | 6 |
5 files changed, 49 insertions, 25 deletions
diff --git a/libbindgen/src/ir/comp.rs b/libbindgen/src/ir/comp.rs index 70dfd4a6..30654901 100644 --- a/libbindgen/src/ir/comp.rs +++ b/libbindgen/src/ir/comp.rs @@ -652,29 +652,6 @@ impl CompInfo { ci.has_destructor |= cur.kind() == CXCursor_Destructor; ci.has_vtable |= is_virtual; - let linkage = cur.linkage(); - if linkage != CXLinkage_External { - return CXChildVisit_Continue; - } - - if cur.access_specifier() == CX_CXXPrivate { - return CXChildVisit_Continue; - } - - let visibility = cur.visibility(); - if visibility != CXVisibility_Default { - return CXChildVisit_Continue; - } - - if cur.is_inlined_function() { - return CXChildVisit_Continue; - } - - let spelling = cur.spelling(); - if spelling.starts_with("operator") { - return CXChildVisit_Continue; - } - // This used to not be here, but then I tried generating // stylo bindings with this (without path filters), and // cried a lot with a method in gfx/Point.h @@ -691,8 +668,10 @@ impl CompInfo { // NB: This gets us an owned `Function`, not a // `FunctionSig`. - let signature = Item::parse(cur, Some(potential_id), ctx) - .expect("CXXMethod"); + let signature = match Item::parse(cur, Some(potential_id), ctx) { + Ok(item) if ctx.resolve_item(item).kind().is_function() => item, + _ => return CXChildVisit_Continue, + }; match cur.kind() { CXCursor_Constructor => { diff --git a/libbindgen/src/ir/function.rs b/libbindgen/src/ir/function.rs index 88ab861d..50c442db 100644 --- a/libbindgen/src/ir/function.rs +++ b/libbindgen/src/ir/function.rs @@ -150,6 +150,7 @@ impl FunctionSig { } else { ty.declaration() }; + let mut args: Vec<_> = match cursor.kind() { CXCursor_FunctionDecl | CXCursor_Constructor | @@ -262,6 +263,24 @@ impl ClangSubItemParser for Function { debug!("Function::parse({:?}, {:?})", cursor, cursor.cur_type()); + let visibility = cursor.visibility(); + if visibility != CXVisibility_Default { + return Err(ParseError::Continue); + } + + if cursor.access_specifier() == CX_CXXPrivate { + return Err(ParseError::Continue); + } + + if cursor.is_inlined_function() { + return Err(ParseError::Continue); + } + + let linkage = cursor.linkage(); + if linkage != CXLinkage_External && linkage != CXLinkage_UniqueExternal { + return Err(ParseError::Continue); + } + // Grab the signature using Item::from_ty. let sig = try!(Item::from_ty(&cursor.cur_type(), Some(cursor), diff --git a/libbindgen/tests/expectations/tests/inline-function.rs b/libbindgen/tests/expectations/tests/inline-function.rs new file mode 100644 index 00000000..b4b7b2bc --- /dev/null +++ b/libbindgen/tests/expectations/tests/inline-function.rs @@ -0,0 +1,7 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + + diff --git a/libbindgen/tests/expectations/tests/namespace.rs b/libbindgen/tests/expectations/tests/namespace.rs index 3d6e5974..ece4e341 100644 --- a/libbindgen/tests/expectations/tests/namespace.rs +++ b/libbindgen/tests/expectations/tests/namespace.rs @@ -37,9 +37,22 @@ pub mod root { assert_eq!(::std::mem::size_of::<A>() , 4usize); assert_eq!(::std::mem::align_of::<A>() , 4usize); } + extern "C" { + #[link_name = "_ZN12_GLOBAL__N_11A20lets_hope_this_worksEv"] + pub fn A_lets_hope_this_works(this: + *mut root::_bindgen_mod_id_13::A) + -> ::std::os::raw::c_int; + } impl Clone for A { fn clone(&self) -> Self { *self } } + impl A { + #[inline] + pub unsafe fn lets_hope_this_works(&mut self) + -> ::std::os::raw::c_int { + A_lets_hope_this_works(&mut *self) + } + } } #[repr(C)] #[derive(Debug)] diff --git a/libbindgen/tests/headers/inline-function.h b/libbindgen/tests/headers/inline-function.h new file mode 100644 index 00000000..02cb7c08 --- /dev/null +++ b/libbindgen/tests/headers/inline-function.h @@ -0,0 +1,6 @@ +// bindgen-unstable + +/** The point of this test is to _not_ generate these functions. */ + +inline static int myadd(const int x, const int y) { return x + y; } +static int mysub(const int x, const int y) { return x - y; } |