Add --with-enum-member-strip for per-enum member name stripping - #770
Merged
tannergooding merged 2 commits intoJul 14, 2026
Merged
Conversation
Adds a per-enum option keyed by the remapped enum name (with a * global default) selecting how member names are stripped: none, common-prefix, common-suffix, type-name, prefix:<str>, or suffix:<str>. Auto-detected prefixes/suffixes are trimmed to a _ token boundary and applied all-or-nothing per enum, abandoning the strip with an Info diagnostic when it would empty or collide members. Legacy strip-enum-member-type-name and --typePrefixStrip remain the fallback when no mode resolves. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Covers common-prefix/-suffix, explicit prefix:/suffix:, the leading-digit guard, single-member no-op, collision abandonment with an Info diagnostic, type-name matching the legacy behavior, the '*' default with a per-enum override, and decl/ref consistency for sibling references. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This PR body was drafted by Copilot.
Resolves #461 -- adds a single, mode-based option for stripping a common prefix or suffix from an enum's member names, so
enum abc_some_enum { abc_some_enum_key1, ... }can generatefirst/second/... instead of the fully-qualified member names.--with-enum-member-strip <enum-name>=<mode>(alias-wems) is a per-enum knob keyed by the remapped enum name, reusing the existingwith-*dictionary plumbing:*sets a global default and per-enum entries override it. Modes:none-- leave the members alone.common-prefix-- auto-detect the longest common prefix of the members.common-suffix-- same, for the "common POSTfix instead of prefix" case.type-name-- strip the enum type name (identical tostrip-enum-member-type-name).prefix:<str>/suffix:<str>-- strip an explicit string.Honored edge cases for the auto-detect modes:
_token boundary so a non-obvious prefix never cuts mid-token (abc_some_enum_key1/key2->key1/key2, not1/2)._since it isn't a valid C# identifier start (abc_version_1_0->_1_0).Infodiagnostic is emitted naming the enum and the reason, so the member set stays internally consistent.primary = vulkan | metal), so the generated bindings still compile.This composes with, and falls back to, the existing behavior: when no mode resolves for an enum, the legacy
strip-enum-member-type-name/--typePrefixStriphandling runs unchanged.using static <EnumType>;also remains available as a zero-config workaround.Added golden tests covering common-prefix/-suffix, explicit
prefix:/suffix:, the digit guard, single-member no-op, collision abandonment with the diagnostic,type-namematching the legacy behavior, the*default with a per-enum override, and decl/ref consistency for sibling references.