Skip to content

clang::Cursor::args should return an Option<Vec<Cursor>> #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions libbindgen/src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,26 @@ impl Cursor {

/// Given that this cursor's referent is a function, return cursors to its
/// parameters.
pub fn args(&self) -> Vec<Cursor> {
pub fn args(&self) -> Option<Vec<Cursor>> {
// XXX: We might want to use and keep num_args
// match self.kind() {
// CXCursor_FunctionDecl |
// CXCursor_CXXMethod => {
unsafe {
let num = self.num_args().expect("expected value, got none") as u32;
let mut args = vec![];
for i in 0..num {
args.push(Cursor {
x: clang_Cursor_getArgument(self.x, i as c_uint),
});
let w = clang_Cursor_getNumArguments(self.x);
if w == -1 {
None
} else {
let num = w as u32;

let mut args = vec![];
for i in 0..num {
args.push(Cursor {
x: clang_Cursor_getArgument(self.x, i as c_uint),
});
}
Some(args)
}
args
}
}

Expand Down
2 changes: 1 addition & 1 deletion libbindgen/src/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl FunctionSig {
CXCursor_CXXMethod => {
// For CXCursor_FunctionDecl, cursor.args() is the reliable way
// to get parameter names and types.
cursor.args()
cursor.args().expect("It cannot be None because we are in a method/function")
.iter()
.map(|arg| {
let arg_ty = arg.cur_type();
Expand Down
12 changes: 12 additions & 0 deletions libbindgen/tests/expectations/tests/variadic_template_function.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* automatically generated by rust-bindgen */


#![allow(non_snake_case)]


#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct VariadicFunctionObject<T> {
pub _address: u8,
pub _phantom_0: ::std::marker::PhantomData<T>,
}
6 changes: 6 additions & 0 deletions libbindgen/tests/headers/variadic_template_function.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

template <typename T>
class VariadicFunctionObject {
public:
int add_em_up(T count,...);
};