summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEthan Glasser-Camp <ethan@betacantrips.com>2016-11-02 12:41:35 -0400
committerEthan Glasser-Camp <ethan@betacantrips.com>2016-11-02 12:52:18 -0400
commit5f92d86a3c88c47817e061bb2870e917757a738c (patch)
tree940f5589d02d4dc8752fceb264f1c8cb9ac4dd3b
parentff53d7a02aced68d3bf64e1ca679061768183f69 (diff)
Make clang::Cursor::specialized return an Option
Fixes #122.
-rwxr-xr-xsrc/clang.rs12
-rw-r--r--src/ir/comp.rs3
2 files changed, 10 insertions, 5 deletions
diff --git a/src/clang.rs b/src/clang.rs
index d69c8b14..bbe0648d 100755
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -187,7 +187,7 @@ impl Cursor {
/// Is the referent a template specialization?
pub fn is_template(&self) -> bool {
- self.specialized().is_valid()
+ self.specialized().map_or(false, |c| c.is_valid())
}
/// Is the referent a fully specialized template specialization without any
@@ -287,11 +287,15 @@ impl Cursor {
/// Given that this cursor points to a template specialization, get a cursor
/// pointing to the template definition that is being specialized.
- pub fn specialized(&self) -> Cursor {
+ pub fn specialized(&self) -> Option<Cursor> {
+ if !self.is_valid() {
+ return None;
+ }
+
unsafe {
- Cursor {
+ Some(Cursor {
x: clang_getSpecializedCursorTemplate(self.x),
- }
+ })
}
}
diff --git a/src/ir/comp.rs b/src/ir/comp.rs
index d55c24ca..91be2eca 100644
--- a/src/ir/comp.rs
+++ b/src/ir/comp.rs
@@ -512,7 +512,8 @@ impl CompInfo {
}
};
- ci.ref_template = Item::parse(cursor.specialized(), None, ctx).ok();
+ ci.ref_template = cursor.specialized()
+ .and_then(|c| Item::parse(c, None, ctx).ok());
let mut maybe_anonymous_struct_field = None;
cursor.visit(|cur, _other| {