Skip to content
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

Add option to not add enum name to bitfield or constant variants #543

Merged
merged 3 commits into from
Feb 27, 2017

Conversation

th0rex
Copy link
Contributor

@th0rex th0rex commented Feb 27, 2017

Many C libraries prefix the variants of their enums already, because C enums are not scoped. That means if bindgen prefixes them again that can lead to ugly names like cs_arch_CS_ARCH_ARM. The cs_arch_ part comes from the name of the enum itself and CS_ARCH_ARM is the name of the actual variant.

This pull request introduces a variable for changing this behaviour, alongside command line flags and a test case. If prepend_enum_names is set to false the resulting variant name will be CS_ARCH_ARM instead of cs_arch_CS_ARCH_ARM as it is now.

If there is anything that could be improved, or this toggle already exists (I have not found anything like that), please let me know.

Currently the name of a enum is always prepended to the beginning of a const or bitfield like variant. This can result in some quite unintuivite naming, if the library already prefixes its variants. For example hundreds of variants are named like this `cs_arch_CS_ARCH_ARM` when binding to the capstone library.

This commit introduces a toggle for prepending the `cs_arch_` part. By default it is enabled to preserve current behaviour. It can be toggled with the `prepend_enum_name` function on the Builder.
@emilio
Copy link
Contributor

emilio commented Feb 27, 2017

This looks reasonable, thanks for the patch!

@bors-servo r+

@bors-servo
Copy link

📌 Commit 49fa299 has been approved by emilio

@bors-servo
Copy link

⌛ Testing commit 49fa299 with merge 4e4f092...

bors-servo pushed a commit that referenced this pull request Feb 27, 2017
Add option to not add enum name to bitfield or constant variants

Many C libraries prefix the variants of their enums already, because C enums are not scoped. That means if bindgen prefixes them again that can lead to ugly names like `cs_arch_CS_ARCH_ARM`. The `cs_arch_` part comes from the name of the enum itself and `CS_ARCH_ARM` is the name of the actual variant.

This pull request introduces a variable for changing this behaviour, alongside command line flags and a test case. If `prepend_enum_names` is set to false the resulting variant name will be `CS_ARCH_ARM` instead of `cs_arch_CS_ARCH_ARM` as it is now.

If there is anything that could be improved, or this toggle already exists (I have not found anything like that), please let me know.
@emilio
Copy link
Contributor

emilio commented Feb 27, 2017

And also thanks for including tests!

@bors-servo
Copy link

☀️ Test successful - status-travis
Approved by: emilio
Pushing 4e4f092 to master...

@bors-servo bors-servo merged commit 49fa299 into rust-lang:master Feb 27, 2017
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.

4 participants