Skip to content

[3.0] Apply MaybeBool transformation to fields/properties#2574

Open
Exanite wants to merge 9 commits into
develop/3.0from
feature/bool-field-property-transformation
Open

[3.0] Apply MaybeBool transformation to fields/properties#2574
Exanite wants to merge 9 commits into
develop/3.0from
feature/bool-field-property-transformation

Conversation

@Exanite
Copy link
Copy Markdown
Member

@Exanite Exanite commented May 1, 2026

Summary of the PR

This adds MaybeBool transformation to fields and properties in TransformProperties, similar to how BoolTransformer for TransformFunctions currently works.

Related issues, Discord discussions, or proposals

Discord thread: https://discord.com/channels/521092042781229087/1499733234714546286

Further Comments

Tasks:

  • Implement BoolType to MaybeBool transformation
  • Update generator.json to use the new config option
  • Wait for SDL update PR to be merged ([3.0] Update SDL and ClangSharp #2570)
  • Regenerate binding using Windows

@Exanite Exanite changed the base branch from main to develop/3.0 May 1, 2026 13:42
Not actually sure if this is ever going to be used, but I guess it will at least be consistent in behavior with BoolTransformer
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

File Coverage
All files 15%

Minimum allowed coverage is 0%

Generated by 🐒 cobertura-action against c47136e

Copy link
Copy Markdown
Member Author

@Exanite Exanite left a comment

Choose a reason for hiding this comment

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

Self review completed. Note that OpenAL/GL don't really have structs so no bindings changes there.

/// Types to treat as boolean and their boolean schemes if different to default.
/// Types to treat as boolean and their boolean schemes if different from the default.
/// </summary>
public Dictionary<string, string?>? BoolTypes { get; init; }
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.

Saving an allocation is not worth the complexity of null checking. Also, performance difference is negligible either way.

node.AttributeLists.GetNativeTypeName() ?? node.Declaration.Type.ToString();
if (
config.BoolTypes.TryGetValue(nativeType, out var scheme)
|| (nativeType == "bool" && node.Declaration.Type.ToString().Trim() != "bool") // stdbool.h, hopefully...
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.

I'm not familiar enough with C library headers (specifically, where bool might be used) to say whether the bool handling here is important or not. This just copies the behavior from BoolTransformer.

@Exanite Exanite marked this pull request as ready for review May 18, 2026 16:30
@Exanite Exanite requested a review from a team as a code owner May 18, 2026 16:30
public override SyntaxNode? VisitPropertyDeclaration(PropertyDeclarationSyntax node)
{
// Transform bool-like properties to use MaybeBool
var nativeType = node.AttributeLists.GetNativeTypeName() ?? node.Type.ToString();
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.

On second thought, I should analyze whether this transformation is correct or not. There's some possible edge cases here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant