Skip to content

cbindgen doesnt understand simple shifts and bitwise OR #412

@jaseemabid

Description

@jaseemabid

Constants defined with << and | doesn't seem to be supported.

For example, this block fails

pub const FALSE: i64 = (0 << SHIFT) | BOOL;
pub const TRUE: i64 = (1 << SHIFT) | BOOL;

with the error

WARN: Skip inc::FALSE - (Unsupported literal expression. Paren(ExprParen { attrs: [], paren_token: Paren, expr: Binary(ExprBinary { attrs: [], left: Lit(ExprLit { attrs: [], lit: Int(LitInt { token: 0 }) }), op: Shl(Shl), right: Path(ExprPath { attrs: [], qself: None, path: Path { leading_colon: None, segments: [PathSegment { ident: Ident(SHIFT), arguments: None }] } }) }) }))
WARN: Skip inc::TRUE - (Unsupported literal expression. Paren(ExprParen { attrs: [], paren_token: Paren, expr: Binary(ExprBinary { attrs: [], left: Lit(ExprLit { attrs: [], lit: Int(LitInt { token: 1 }) }), op: Shl(Shl), right: Path(ExprPath { attrs: [], qself: None, path: Path { leading_colon: None, segments: [PathSegment { ident: Ident(SHIFT), 

I've no idea how hard it is to support something like this, but it looks like something that can be translated to into C. I'm happy to give this a try if this is good to have feature.

PS: I just used cbindgen to rewrite a lot of C in Rust (jaseemabid/inc@314e5fe) and it was a pretty good experience except some minor hiccups. I've also filed #411 and is happy to work on both issues. Thanks a lot for this project! :D

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions