-
Notifications
You must be signed in to change notification settings - Fork 742
clang::Cursor::args should return an Option<Vec<Cursor>> #207
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
clang::Cursor::args should return an Option<Vec<Cursor>> #207
Conversation
@@ -387,16 +387,26 @@ impl Cursor { | |||
|
|||
/// Given that this cursor's referent is a function, return cursors to its | |||
/// parameters. | |||
pub fn args(&self) -> Vec<Cursor> { | |||
pub fn args(&self) -> Option<Vec<Cursor>> { | |||
// XXX: We might want to use and keep num_args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an option, do you think it would be better than not using num_args
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use an iterator pattern somewhere else (for comment children and attributes), so something like that can also work, and it'd be better IMO.
If you want to give a crack at it, that'd be awesome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate on this, please? Does this mean we should be returning an iterator instead of a Vec? Or that there's some sort of iterator that we can "build on" to write this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning an iterator is definitely preferable, since it's more efficient. You can implement something like TypeTemplateArgIterator
(in that same file). That being said, only a Vec
is also fine if you prefer :)
@@ -150,7 +150,7 @@ impl FunctionSig { | |||
CXCursor_CXXMethod => { | |||
// For CXCursor_FunctionDecl, cursor.args() is the reliable way | |||
// to get parameter names and types. | |||
cursor.args() | |||
cursor.args().expect("It cannot be None because we are in a method/function") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is expect the right way to handle this there?
Can we rely on the fact that cursor.args()
is now None in case it is not a function or method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I'd expect we might want to test this with stuff like variadic functions, but if all tests are passing seems like we can keep it, and then if it fails in some weird situation returning an empty vector in the case it's none to preser behavior is a really easy change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, could you write a test with a template and a variadic function here? Otherwise I think yeah, we should be pretty confident.
@Natim, everything going OK? Have any questions we can help answer or clarifications we can make? |
I think I understood we should write a test for that. I hope to find some bandwith do to it with @glasserc later this week. |
☔ The latest upstream changes (presumably #204) made this pull request unmergeable. Please resolve the merge conflicts. |
…ption<Vec<Cursor>>
c940bd8
to
e65cd9b
Compare
We tried to work on a test, writing this hpp file:
And hoping to get this RS file:
But instead we get:
Even without our patch we get the last one so I guess rust-bindgen is not handling variadic function yet. Can you provide some guidance there? |
Yeah, I don't think it would be possible to autogenerate those in rust, mainly because those functions don't always have symbols until they're instantiated. In general any method for a template class can't be automatically generated. We could generate those for specializations though, but specializations should be in rust too. |
Hmm, so then is this what you meant by "could you write a test with a template and a variadic function here?" Or should the test have the a template and a variadic function but not one inside the other? |
Yeah, you should be able to add a test with that, and ensure we're not crashing, the output doesn't need to change :) |
So we can just add the two file in the comment I made? |
Yup! That'd be fine :) |
Sorry for being confusing, totally my fault :( |
No worries, let us know what you think is the next step then 👍 |
d41c2eb
to
3f0f868
Compare
Looks good! @bors-servo r+ |
📌 Commit 3f0f868 has been approved by |
clang::Cursor::args should return an Option<Vec<Cursor>> Attempt to fix #130
☀️ Test successful - status-travis |
Attempt to fix #130