-
Notifications
You must be signed in to change notification settings - Fork 748
Add support for constructors, and integration tests. #332
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
Conversation
…tmp, to avoid potential conflicts.
Works great with Skia, fwiw. Thanks! I'll file a feature request -- would be nice to be able to rename the rust-side constructors based on their signature by passing in some kind of mapping file to bindgen, otherwise there's no guarantee that the function names will be stable (e.g. if upstream adds another constructor/overload). |
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.
LGTM! Just a couple comments that I am not sure require any code changes, just clarification for my benefit.
r=me when you're ready to land :)
Thanks!
@@ -0,0 +1,13 @@ | |||
|
|||
class TestOverload { | |||
// This one shouldnt' be generated. |
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.
Because it is private, right?
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.
Right.
TestOverload(); | ||
public: | ||
TestOverload(int); | ||
TestOverload(double); |
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.
Do we handle when the class already has a new
method properly? Do we just treat the constructors or the new
methods as overloads? Care to add a small test case?
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.
Oh wait -- new
is a keyword ofc -- nvm
@@ -147,6 +147,7 @@ impl FunctionSig { | |||
}; | |||
let mut args: Vec<_> = match cursor.kind() { | |||
CXCursor_FunctionDecl | | |||
CXCursor_Constructor | | |||
CXCursor_CXXMethod => { |
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 there a reason this doesn't also match CXCursor_Destructor
like the ClangSubItemParser
impl further down does?
Is it handled elsewhere?
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.
Ah -- are we not binding destructors yet? That's surprising I really thought we were.
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.
Yeah, we're not doing it. We can without too much trouble though.
When we do, there's no point in doing that, though (we could, I guess?). But destructors have no arguments.
let is_static = cursor.method_is_static(); | ||
let is_method = cursor.kind() == CXCursor_CXXMethod; | ||
|
||
if is_method || cursor.kind() == CXCursor_Constructor { |
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.
Ditto about dtors for this check.
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.
Yeah, when we support them that check should be there. But we should also check for virtual destructors, etc.
@@ -1359,13 +1359,14 @@ impl MethodCodegen for Method { | |||
let mut stmts = vec![]; | |||
|
|||
// If it's a constructor, we need to insert an extra parameter with a | |||
// variable called `tmp` we're going to create. | |||
// variable called `__bindgen_tmp` we're going to create. |
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.
Great :)
@@ -1,6 +1,6 @@ | |||
#pragma once | |||
|
|||
class Test final { |
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.
Why no more final? We can't get at it with llvm_stable
?
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.
The travis gcc was complaining, and I didn't want to fight that battle :)
@@ -38,7 +38,8 @@ script: | |||
- cargo test --features "$BINDGEN_FEATURES" | |||
- cargo test --release --features "$BINDGEN_FEATURES" | |||
- cd ../bindgen-integration | |||
- cargo test | |||
- cargo test --features "$BINDGEN_FEATURES" | |||
- cargo test --release --features "$BINDGEN_FEATURES" |
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.
I think this is getting big enough that we should pull it out into a ./ci/test
script. In a follow up, of course.
@@ -466,6 +466,7 @@ impl CompInfo { | |||
&self.methods | |||
} | |||
|
|||
/// Get this type's set of constructors. |
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.
Gotcha ;)
@bors-servo r=fitzgen |
📌 Commit 1daf989 has been approved by |
⚡ Test exempted - status |
r? @fitzgen
cc @vvuk