diff options
author | Rémy HUBSCHER <rhubscher@mozilla.com> | 2016-11-04 17:24:53 +0100 |
---|---|---|
committer | Rémy HUBSCHER <rhubscher@mozilla.com> | 2016-11-04 17:25:09 +0100 |
commit | 42f1078e1ca06c9cfb264307ce8eeca59b05f5fe (patch) | |
tree | 03ed6199b4f1c0e5ef614f01739d6511c904c7e2 /src | |
parent | b4d5338b557b9ec8edb777deb6866bdfd434b458 (diff) |
clang::Cursor::definition should return Option<clang::Cursor> — Fixes #123
Paired with @glasserc
Diffstat (limited to 'src')
-rwxr-xr-x | src/clang.rs | 8 | ||||
-rw-r--r-- | src/ir/item.rs | 14 |
2 files changed, 7 insertions, 15 deletions
diff --git a/src/clang.rs b/src/clang.rs index 045c4987..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 } } } diff --git a/src/ir/item.rs b/src/ir/item.rs index a9b625f2..6eff60c9 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -801,12 +801,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, @@ -937,12 +932,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() |