rust-lang / rust-lang/rust-bindgen
Add flag to parse matching `#define *` into `enum`s instead of constants
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Hi! I have a header file I'd rather not touch, and I want to convert some #define directives that are integers into enums, such that --constified-enum-module, --bitfield-enum etc would work as expected
#define FOO_BAR_A_BAZ 0
#define FOO_BAR_BOB 1
#define FOO_BAR_C 2
#define FOO_BAR_D 3
Given above header, generate the equivalent code as for when parsing
enum FOO_BAR {
A_BAZ=0,
BOB=1,
C=2,
D=3,
};
This should also keep comments intact.
Is this possible to implement?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how bindgen parses C #define directives and applies --constified-enum-module and --bitfield-enum. Compare that behavior with the generated output for the enum example, preserving comments. Done means matching prefixed defines can become enums and the existing flag behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100