Skip to content

Proposal: Replace enums.json with conditional C++ enum declarations#2247

Merged
jevansaks merged 2 commits into
mainfrom
user/jevansa/enum-annotations
Apr 28, 2026
Merged

Proposal: Replace enums.json with conditional C++ enum declarations#2247
jevansaks merged 2 commits into
mainfrom
user/jevansa/enum-annotations

Conversation

@jevansaks
Copy link
Copy Markdown
Member

@jevansaks jevansaks commented Apr 22, 2026

Proposal for review

This PR adds documentation proposing how to replace enums.json (~37K lines, ~1,072 enum definitions) with conditional C++ enum declarations in SDK headers.

No code changes — this PR contains only .md files for review and discussion.

Documents

  • docs/copilot/plans/enum-remapping-proposal.md — The full proposal, including:

    • The core pattern (#ifdef _WIN32METADATA_ / #else #define NAME DWORD)
    • Three member patterns (renamed, same-name, signed overflow)
    • Flags via [[clang::flag_enum]] + DEFINE_ENUM_FLAG_OPERATORS
    • Constant suppression strategy
    • Migration steps from enums.json
    • Alternatives considered and why they were rejected
  • docs/spec.md — High-level spec of how win32metadata derives each metadata construct from SDK headers (types, functions, constants, enums, COM interfaces, annotations)

Validated

The proposed approach was validated end-to-end (in a separate local branch):

  • Replaced SET_THEME_APP_PROPERTIES_FLAGS in enums.json with a conditional enum in Uxtheme.h
  • ClangSharp generated the enum natively with correct members, values, [Flags], and typed function signatures
  • All 13 Windows.Win32.Tests passed
  • Zero winmd differences for affected APIs
  • No tooling code changes required

Comment thread docs/copilot/plans/enum-remapping-proposal.md
Comment thread docs/copilot/plans/enum-remapping-proposal.md
```cpp
#ifdef _WIN32METADATA_

enum __attribute__((flag_enum)) SET_THEME_APP_PROPERTIES_FLAGS : unsigned int {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this just say DWORD for the type?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, good idea.

Comment thread docs/copilot/plans/enum-remapping-proposal.md
} DISPLAY_DEVICE;

// Return value
_Enum_return_(SET_THEME_APP_PROPERTIES_FLAGS)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need these macros, since the symbol is already a DWORD for non-metadata runs, and a ProperTypeWithMembers otherwise?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was an alternate option in the proposal. The winning proposal doesn't need it. I'll make sure it's clearer.

Add enum remapping proposal and metadata derivation spec:

- docs/copilot/plans/enum-remapping-proposal.md: Proposal for replacing
  enums.json with conditional C++ enum declarations in headers using
  [[clang::flag_enum]], DEFINE_ENUM_FLAG_OPERATORS, and the
  #else #define NAME DWORD pattern. Validated end-to-end.
- docs/spec.md: High-level spec of how win32metadata derives each
  construct from SDK headers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jevansaks jevansaks force-pushed the user/jevansa/enum-annotations branch from e7a306b to 933d34c Compare April 23, 2026 16:25
@jevansaks jevansaks changed the title POC: Replace enums.json with conditional C++ enum declarations in headers Proposal: Replace enums.json with conditional C++ enum declarations Apr 23, 2026
Per jonwis feedback: unscoped enum leaks member names into the
enclosing namespace. Use enum class (scoped enum) throughout to
keep member names scoped to the enum type.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jevansaks jevansaks marked this pull request as ready for review April 28, 2026 17:24
@jevansaks jevansaks requested review from a team and vineeththomasalex as code owners April 28, 2026 17:24
@jevansaks jevansaks merged commit 9a59e4f into main Apr 28, 2026
2 checks passed
@jevansaks jevansaks deleted the user/jevansa/enum-annotations branch April 28, 2026 17:39
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