diff options
-rwxr-xr-x | src/bin/bindgen.rs | 12 | ||||
-rwxr-xr-x | src/clang.rs | 20 | ||||
-rw-r--r-- | src/ir/item.rs | 18 | ||||
-rwxr-xr-x | src/lib.rs | 27 |
4 files changed, 36 insertions, 41 deletions
diff --git a/src/bin/bindgen.rs b/src/bin/bindgen.rs index 2127ea49..c906efee 100755 --- a/src/bin/bindgen.rs +++ b/src/bin/bindgen.rs @@ -8,7 +8,7 @@ extern crate log; extern crate clang_sys; extern crate rustc_serialize; -use bindgen::{BindgenOptions, Bindings, LinkType, ClangVersion, clang_version}; +use bindgen::{BindgenOptions, Bindings, ClangVersion, LinkType, clang_version}; use std::default::Default; use std::env; use std::fs; @@ -233,14 +233,20 @@ pub fn main() { let mut bind_args: Vec<_> = env::args().collect(); let version = clang_version(); - let expected_version = if cfg!(feature = "llvm_stable") { (3,8) } else { (3,9) }; + let expected_version = if cfg!(feature = "llvm_stable") { + (3, 8) + } else { + (3, 9) + }; info!("Clang Version: {}", version.full); match version.parsed { None => warn!("Couldn't parse libclang version"), Some(version) if version != expected_version => { - error!("Using clang {:?}, expected {:?}", version, expected_version); + error!("Using clang {:?}, expected {:?}", + version, + expected_version); } _ => {} } diff --git a/src/clang.rs b/src/clang.rs index b335a585..94e74d87 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -249,11 +249,13 @@ impl Cursor { /// Given that this cursor's referent is a reference to another type, or is /// a declaration, get the cursor pointing to the referenced type or type of /// the declared thing. - pub fn definition(&self) -> Cursor { + pub fn definition(&self) -> Option<Cursor> { unsafe { - Cursor { + let ret = Cursor { x: clang_getCursorDefinition(self.x), - } + }; + + if ret.is_valid() { Some(ret) } else { None } } } @@ -285,7 +287,7 @@ impl Cursor { pub fn specialized(&self) -> Option<Cursor> { unsafe { let ret = Cursor { - x: clang_getSpecializedCursorTemplate(self.x) + x: clang_getSpecializedCursorTemplate(self.x), }; if ret.is_valid() { Some(ret) } else { None } } @@ -401,16 +403,6 @@ impl Cursor { } /// Given that this cursor's referent is a function/method call or - /// declaration, return a cursor to its return type. - pub fn ret_type(&self) -> Type { - unsafe { - Type { - x: clang_getCursorResultType(self.x), - } - } - } - - /// Given that this cursor's referent is a function/method call or /// declaration, return the number of arguments it takes. /// /// Returns -1 if the cursor's referent is not a function/method call or diff --git a/src/ir/item.rs b/src/ir/item.rs index ecb86374..6d2d4b02 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -49,7 +49,9 @@ pub trait ItemCanonicalPath { /// up to (but not including) the implicit root module. pub trait ItemAncestors { /// Get an iterable over this item's ancestors. - fn ancestors<'a, 'b>(&self, ctx: &'a BindgenContext<'b>) -> ItemAncestorsIter<'a, 'b>; + fn ancestors<'a, 'b>(&self, + ctx: &'a BindgenContext<'b>) + -> ItemAncestorsIter<'a, 'b>; } /// An iterator over an item and its ancestors. @@ -800,12 +802,7 @@ impl ClangItemParser for Item { // Types are sort of special, so to avoid parsing template classes // twice, handle them separately. { - let definition = cursor.definition(); - let applicable_cursor = if definition.is_valid() { - definition - } else { - cursor - }; + let applicable_cursor = cursor.definition().unwrap_or(cursor); match Self::from_ty(&applicable_cursor.cur_type(), Some(applicable_cursor), parent_id, @@ -936,12 +933,7 @@ impl ClangItemParser for Item { let decl = { let decl = ty.declaration(); - let definition = decl.definition(); - if definition.is_valid() { - definition - } else { - decl - } + decl.definition().unwrap_or(decl) }; let comment = decl.raw_comment() @@ -496,7 +496,7 @@ fn parse(context: &mut BindgenContext) { #[derive(Debug)] pub struct ClangVersion { /// Major and minor semvar, if parsing was successful - pub parsed: Option<(u32,u32)>, + pub parsed: Option<(u32, u32)>, /// full version string pub full: String, } @@ -504,8 +504,7 @@ pub struct ClangVersion { /// Get the major and the minor semvar numbers of Clang's version pub fn clang_version() -> ClangVersion { let raw_v: String = clang::extract_clang_version(); - let split_v: Option<Vec<&str>> = raw_v - .split_whitespace() + let split_v: Option<Vec<&str>> = raw_v.split_whitespace() .nth(2) .map(|v| v.split('.').collect()); match split_v { @@ -513,15 +512,21 @@ pub fn clang_version() -> ClangVersion { if v.len() >= 2 { let maybe_major = v[0].parse::<u32>(); let maybe_minor = v[1].parse::<u32>(); - match (maybe_major,maybe_minor) { - (Ok(major),Ok(minor)) => return ClangVersion { parsed: Some((major,minor)), full: raw_v.clone() }, - _ => {}, + match (maybe_major, maybe_minor) { + (Ok(major), Ok(minor)) => { + return ClangVersion { + parsed: Some((major, minor)), + full: raw_v.clone(), + } + } + _ => {} } } - }, - None => {}, + } + None => {} }; - ClangVersion { parsed: None, full: raw_v.clone() } + ClangVersion { + parsed: None, + full: raw_v.clone(), + } } - - |