Skip to content

Commit d021caa

Browse files
committed
ir: Unify function checks so they apply to non-methods.
1 parent b570ce8 commit d021caa

File tree

5 files changed

+49
-25
lines changed

5 files changed

+49
-25
lines changed

libbindgen/src/ir/comp.rs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -652,29 +652,6 @@ impl CompInfo {
652652
ci.has_destructor |= cur.kind() == CXCursor_Destructor;
653653
ci.has_vtable |= is_virtual;
654654

655-
let linkage = cur.linkage();
656-
if linkage != CXLinkage_External {
657-
return CXChildVisit_Continue;
658-
}
659-
660-
if cur.access_specifier() == CX_CXXPrivate {
661-
return CXChildVisit_Continue;
662-
}
663-
664-
let visibility = cur.visibility();
665-
if visibility != CXVisibility_Default {
666-
return CXChildVisit_Continue;
667-
}
668-
669-
if cur.is_inlined_function() {
670-
return CXChildVisit_Continue;
671-
}
672-
673-
let spelling = cur.spelling();
674-
if spelling.starts_with("operator") {
675-
return CXChildVisit_Continue;
676-
}
677-
678655
// This used to not be here, but then I tried generating
679656
// stylo bindings with this (without path filters), and
680657
// cried a lot with a method in gfx/Point.h
@@ -691,8 +668,10 @@ impl CompInfo {
691668

692669
// NB: This gets us an owned `Function`, not a
693670
// `FunctionSig`.
694-
let signature = Item::parse(cur, Some(potential_id), ctx)
695-
.expect("CXXMethod");
671+
let signature = match Item::parse(cur, Some(potential_id), ctx) {
672+
Ok(item) if ctx.resolve_item(item).kind().is_function() => item,
673+
_ => return CXChildVisit_Continue,
674+
};
696675

697676
match cur.kind() {
698677
CXCursor_Constructor => {

libbindgen/src/ir/function.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ impl FunctionSig {
150150
} else {
151151
ty.declaration()
152152
};
153+
153154
let mut args: Vec<_> = match cursor.kind() {
154155
CXCursor_FunctionDecl |
155156
CXCursor_Constructor |
@@ -262,6 +263,24 @@ impl ClangSubItemParser for Function {
262263

263264
debug!("Function::parse({:?}, {:?})", cursor, cursor.cur_type());
264265

266+
let visibility = cursor.visibility();
267+
if visibility != CXVisibility_Default {
268+
return Err(ParseError::Continue);
269+
}
270+
271+
if cursor.access_specifier() == CX_CXXPrivate {
272+
return Err(ParseError::Continue);
273+
}
274+
275+
if cursor.is_inlined_function() {
276+
return Err(ParseError::Continue);
277+
}
278+
279+
let linkage = cursor.linkage();
280+
if linkage != CXLinkage_External && linkage != CXLinkage_UniqueExternal {
281+
return Err(ParseError::Continue);
282+
}
283+
265284
// Grab the signature using Item::from_ty.
266285
let sig = try!(Item::from_ty(&cursor.cur_type(),
267286
Some(cursor),
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+

libbindgen/tests/expectations/tests/namespace.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,22 @@ pub mod root {
3737
assert_eq!(::std::mem::size_of::<A>() , 4usize);
3838
assert_eq!(::std::mem::align_of::<A>() , 4usize);
3939
}
40+
extern "C" {
41+
#[link_name = "_ZN12_GLOBAL__N_11A20lets_hope_this_worksEv"]
42+
pub fn A_lets_hope_this_works(this:
43+
*mut root::_bindgen_mod_id_13::A)
44+
-> ::std::os::raw::c_int;
45+
}
4046
impl Clone for A {
4147
fn clone(&self) -> Self { *self }
4248
}
49+
impl A {
50+
#[inline]
51+
pub unsafe fn lets_hope_this_works(&mut self)
52+
-> ::std::os::raw::c_int {
53+
A_lets_hope_this_works(&mut *self)
54+
}
55+
}
4356
}
4457
#[repr(C)]
4558
#[derive(Debug)]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// bindgen-unstable
2+
3+
/** The point of this test is to _not_ generate these functions. */
4+
5+
inline static int myadd(const int x, const int y) { return x + y; }
6+
static int mysub(const int x, const int y) { return x - y; }

0 commit comments

Comments
 (0)