Skip to content

Added [System.Flags] to enums that are flags.#354

Open
twindan wants to merge 5 commits into
Ruslan-B:mainfrom
twindan:add_flags_to_enums
Open

Added [System.Flags] to enums that are flags.#354
twindan wants to merge 5 commits into
Ruslan-B:mainfrom
twindan:add_flags_to_enums

Conversation

@twindan

@twindan twindan commented Jun 12, 2026

Copy link
Copy Markdown

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code generation update
  • Dependency update

Related Issues

#353

Testing

Ran the output

  • I have tested my changes locally
  • I have run dotnet build -c Release successfully
  • I have run dotnet test -c Release successfully
  • [N/A] I have tested with the example project if applicable

Checklist

  • My code follows the project's code style
  • [N/A] I have updated the documentation if needed
  • [N/A] I have added tests for new functionality if applicable
  • All existing tests pass
  • I have checked that my changes don't introduce new warnings

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 << n expressions 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.cs outputs to reflect [Flags] and 1 << n formatting 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.

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.

2 participants