forked from michaelwu/rust-bindgen
-
Notifications
You must be signed in to change notification settings - Fork 1
C++ namespaces \o/ #3
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This way we can share the global map, while having each module custom globals.
This actually keeps working as before.
We generate almost valid code, we just have to add some use statements. Or maybe is a better idea to add an unintelligible name to the root mod, and actually output a root mod plus a use root::* before.
There's just an edge case I've detected, and it's when we remove the instantiation of C<int>, and another module uses it, because that means we only know of its existance in that other module. Probably we might want to use cursor_getSemanticParent to get the real class instead of the instantiated, but I'm not too confident about that.
This can be annoying if filtering files out.
Author
|
For the record, the output generated with that test file is: /* automatically generated by rust-bindgen */
pub use root::*;
pub mod root {
#[repr(C)]
#[derive(Copy, Clone)]
pub struct C<T> {
pub _base: __anonymous1::A,
pub m_c: T,
}
extern "C" {
#[link_name = "_Z9top_levelv"]
pub fn top_level();
}
pub mod whatever {
pub use root;
pub type whatever_int_t = i32;
extern "C" {
#[link_name = "_ZN8whatever11in_whateverEv"]
pub fn in_whatever();
}
}
pub mod __anonymous1 {
pub use root;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct A {
pub b: root::whatever::whatever_int_t,
}
extern "C" {
#[link_name = "_ZN12_GLOBAL__N_13fooEv"]
pub fn foo();
}
pub mod empty {
pub use root;
}
}
pub mod w {
pub use root;
pub type whatever_int_t = u32;
#[repr(C)]
#[derive(Copy, Clone)]
pub struct D<T> {
pub m_c: root::C<T>,
}
extern "C" {
#[link_name = "_ZN1w3hehEv"]
pub fn heh() -> root::w::whatever_int_t;
#[link_name = "_ZN1w3fooEv"]
pub fn foo() -> root::C<i32>;
#[link_name = "_ZN1w4barrEv"]
pub fn barr() -> root::C<f32>;
}
}
}Which is completely correct if I'm not wrong. |
Owner
Owner
|
Alright, merge it is. :-) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I couldn't sleep so... I went with it.
Wasn't easy, there were a few corner cases, but it worked out pretty well.
To see why we're doing the things like we're, please read e90066a (I later changed my mind and removed it).
This keeps the namespace work behind a flag, just in case there's some corner case it still can't handle. It seems pretty stable though.
r? @bholley