Skip to content

Missing #define when bit shifting? #1642

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

Closed
Geobert opened this issue Oct 8, 2019 · 1 comment
Closed

Missing #define when bit shifting? #1642

Geobert opened this issue Oct 8, 2019 · 1 comment

Comments

@Geobert
Copy link

Geobert commented Oct 8, 2019

enum MY_Status_t
{
    SHIFT0 = 0,
    SHIFT1,
};

#define MY_VAL1 (1 << SHIFT1)

Bindgen Invocation

bindgen::Builder::default()
        .clang_args(&["-target", "thumbv7em-none-eabihf"])
        .layout_tests(false)
        .generate_comments(false)
        .use_core()
        .whitelist_function("MY_.*")
        .whitelist_var("MY_.*")
        .whitelist_type("MY_.*")
        .header("wrapper.h")
        .generate()
        .expect("Unable to generate bindings");

Actual Results

/* automatically generated by rust-bindgen */

pub const MY_Status_t_SHIFT0: MY_Status_t = 0;
pub const MY_Status_t_SHIFT1: MY_Status_t = 1;
pub type MY_Status_t = u32;

Expected Results

MY_VAL1 should be converted to something similar to:

pub const MY_VAL1: u32 = 1 << MY_Status_t_SHIFT1;

Shouldn't it? (I'm not sure)

@emilio
Copy link
Contributor

emilio commented Oct 8, 2019

Dupe of #258, but this is really not quite fixable without some sort of heuristic (see similar requests for struct names #1546, struct definitnions (#1044), etc...

This works as expected if you had something like:

const unsigned MY_VAL1 = (1 << SHIFT1); in the C / C++ code.

@emilio emilio closed this as completed Oct 8, 2019
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

No branches or pull requests

2 participants