summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakanori Ishibashi <takanori.1112@gmail.com>2016-11-14 08:26:48 +0900
committerTakanori Ishibashi <takanori.1112@gmail.com>2016-11-14 08:26:48 +0900
commit76b5372efa95047bc0200067a3f7493b39060a5f (patch)
treee583959eef4a61f742468423d7e8110c1efdeb04
parentc9eccea095a77989950410bf2715d59a8af7a1fd (diff)
Return Option<Cursor> instead of Cursor
-rwxr-xr-xsrc/clang.rs8
-rw-r--r--src/ir/ty.rs4
2 files changed, 7 insertions, 5 deletions
diff --git a/src/clang.rs b/src/clang.rs
index 12397534..315d87a0 100755
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -263,11 +263,13 @@ impl Cursor {
/// Given that this cursor's referent is reference type, get the cursor
/// pointing to the referenced type.
- pub fn referenced(&self) -> Cursor {
+ pub fn referenced(&self) -> Option<Cursor> {
unsafe {
- Cursor {
+ let ret = Cursor {
x: clang_getCursorReferenced(self.x),
- }
+ };
+
+ if ret.is_valid() { Some(ret) } else { None }
}
}
diff --git a/src/ir/ty.rs b/src/ir/ty.rs
index 77dc61be..09961637 100644
--- a/src/ir/ty.rs
+++ b/src/ir/ty.rs
@@ -612,7 +612,7 @@ impl Type {
TypeKind::TemplateAlias(inner.unwrap(), args)
}
CXCursor_TemplateRef => {
- let referenced = location.referenced();
+ let referenced = location.referenced().expect("expected value, got none");
let referenced_ty = referenced.cur_type();
let referenced_declaration =
Some(referenced_ty.declaration());
@@ -624,7 +624,7 @@ impl Type {
ctx);
}
CXCursor_TypeRef => {
- let referenced = location.referenced();
+ let referenced = location.referenced().expect("expected value, got none");
let referenced_ty = referenced.cur_type();
let referenced_declaration =
Some(referenced_ty.declaration());