dotnet / ClangSharp

Clang bindings for .NET written in C#
MIT License
910 stars 146 forks source link

Option to generate an attribute with alternative names for a `typedef struct` #499

Open dpaoliello opened 10 months ago

dpaoliello commented 10 months ago

It would be useful for downstream projects (like Win32Metadata) for ClangSharp to mark types generated from typedef struct with an attribute to indicate what the alternative names for that struct were. This would allow downstream code generators for languages which support aliasing types to generate aliases with those names.

For example, given the C++ code:

typedef struct _MYSTRUCT {
  ...
} MYSTRUCT;

To generate C#:

[AlternativeName("MYSTRUCT")]
public partial struct _MYSTRUCT {
   ...
}
tannergooding commented 10 months ago

I don't think this is a scalable or a workable solution.

Structs are typically defined in one header. Typedefs can be defined in any number of headers, including arbitrary other headers (and frequently are).

So I don't think its feasible to attach such attributes to the struct definition itself. The metadata could be exposed in a different way, and I've considered providing a switch to allow global using aliases, but those aren't embedded themselves either; they are purely a source code concept.