ClangSharp icon indicating copy to clipboard operation
ClangSharp copied to clipboard

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

Open dpaoliello opened this issue 2 years ago • 1 comments

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 {
   ...
}

dpaoliello avatar Nov 22 '23 00:11 dpaoliello

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.

tannergooding avatar Nov 22 '23 17:11 tannergooding