Skip to content

Conversation

@emilio
Copy link

@emilio emilio commented Mar 10, 2016

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

emilio added 13 commits March 9, 2016 22:14
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.
@emilio
Copy link
Author

emilio commented Mar 10, 2016

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.

@bholley
Copy link
Owner

bholley commented Mar 10, 2016

Awesome!!

I'm happy to delegate the reviewing for bindgen stuff to @nox, since it looks like he's taking over a lot of the work there. @nox, let me know if you want to comment on this PR at this stage, otherwise I'll just merge it in the morning and you can look at it later.

@bholley
Copy link
Owner

bholley commented Mar 10, 2016

Alright, merge it is. :-)

bholley added a commit that referenced this pull request Mar 10, 2016
@bholley bholley merged commit 6a85e6b into bholley:sm-hacks Mar 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants