diff options
author | th0rex <omit2912@web.de> | 2017-02-27 18:17:28 +0100 |
---|---|---|
committer | th0rex <omit2912@web.de> | 2017-02-27 18:17:28 +0100 |
commit | 1bf453cdc5fb278a0c840986a6723ad9c01f5ef3 (patch) | |
tree | fe4955cb50c6d7bdc75f1c8f0cfe821608aaf736 /src/codegen/mod.rs | |
parent | b666c733057e77ccb670734b56bcdc8bb1be4ce4 (diff) |
Add toggle for prepending enum name to variant
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.
Diffstat (limited to 'src/codegen/mod.rs')
-rw-r--r-- | src/codegen/mod.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 46b0a3e7..120acefa 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1993,10 +1993,14 @@ impl CodeGenerator for Enum { Some(item.parent_id().canonical_name(ctx)) }; - let constant_mangling_prefix = if enum_ty.name().is_none() { - parent_canonical_name.as_ref().map(|n| &*n) + let constant_mangling_prefix = if ctx.options().prepend_enum_name { + if enum_ty.name().is_none() { + parent_canonical_name.as_ref().map(|n| &*n) + } else { + Some(&name) + } } else { - Some(&name) + None }; // NB: We defer the creation of constified variants, in case we find |