Skip to content

Make clang::Cursor::specialized return an Option #191

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 3 commits into from
Nov 3, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be self.specialized().is_some() now, given we check if the cursor is valid in specialized.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking is_some() will only work after my requested changes to the is_valid() checking. This is a good insight, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I misread the implementation, but yeah :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

}

/// Is the referent a fully specialized template specialization without any
Expand Down Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than checking if self.is_valid(), we should make the FFI call to clang, and then check if the result of that FFI call .is_valid() and return None/Some based on that.

Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I misread the issue description. I thought the concern was that the existing Cursor was valid, not that the resulting one was valid. Thanks for the correction!

}

unsafe {
Cursor {
Some(Cursor {
x: clang_getSpecializedCursorTemplate(self.x),
}
})
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/ir/comp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down