Added [System.Flags] to enums that are flags.#354
Open
twindan wants to merge 5 commits into
Open
Conversation
…just in case they come up in the future.
There was a problem hiding this comment.
Pull request overview
This PR updates the unsafe generator and regenerated enum outputs so that enums whose members are all expressed as single-bit shifts (1 << n) are emitted as C# flags enums ([Flags]) and preserve the shift-form instead of collapsing to numeric literals.
Changes:
- Updated enum processing to preserve
= 1 << nexpressions in generated enum member values (with appropriate numeric literal suffixes). - Updated enum generation to emit
using System;and add[Flags]to enums where every member value contains a left-shift. - Regenerated
Enums.g.csoutputs to reflect[Flags]and1 << nformatting for the affected enums (e.g.,SwsFlags,AVTimecodeFlag).
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| FFmpeg.AutoGen/generated/Enums.g.cs | Regenerated enums now include using System;, [Flags] on identified flags enums, and 1 << n member values. |
| FFmpeg.AutoGen.CppSharpUnsafeGenerator/Processing/EnumerationProcessor.cs | Preserves = 1 << n expressions during enum item value conversion via a generated regex. |
| FFmpeg.AutoGen.CppSharpUnsafeGenerator/Generation/EnumsGenerator.cs | Emits using System; and adds [Flags] when all enum items contain <<. |
| FFmpeg.AutoGen.Abstractions/generated/Enums.g.cs | Same regeneration as main package enums: using System;, [Flags], and 1 << n values where applicable. |
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.
Description
Some enums that are conceptually flags (e.g., SwsFlags) do no have [System.Flags] on the enum definition. This code adds that definition for the relevant classes.
What I do is look at the enum definition in ffmpeg when parsing. If it is of the form "1 << n", then I preserve the definition instead of collapsing the value (so the generated file say "VALUE = 1 << 3" instead of "VALUE = 8"). If all items in an enum are of the form 1 << n, then I treat it as a [System.Flags]. This seems to be how ffmpeg uses enumerated values.
Type of Change
Related Issues
#353
Testing
Ran the output
dotnet build -c Releasesuccessfullydotnet test -c ReleasesuccessfullyChecklist
Additional Notes
Output is the same except for enums that now have [System.Flags] appended. I have included the new generated files in this PR. Ran against ffmpeg commit 9047fa1b.