MochiLibraries / Biohazrd

A framework for automatically generating binding wrappers for C/C++ libraries
MIT License
60 stars 8 forks source link

Create infrastructure for emitting private helper types in CSharpLibraryGenerator #63

Open PathogenDavid opened 3 years ago

PathogenDavid commented 3 years ago

Right now there's no easy way to emit implementation detail-type types inside CShapLibraryGenerator. For constant arrays, we need some helper types for allowing them to be enumerated. Right now we just emit them before the first constant array is emitted, but this would not work if the constant array types were spread throughout multiple files.

We should consider providing some canonical mechanism for adding these sorts of types.

PathogenDavid commented 3 years ago

I gave this some more thought while implementing the fix for https://github.com/InfectedLibraries/Biohazrd/issues/146

I think it might be valuable for declarations to be marked for lazy emit. Essentially the declarations won't be written out unless something references them. This would be good for these sorts of infrastructure types as well as things like NativeBool.

We likely want to add some infrastructure for detecting which lazy declarations were emitted so that we can only emit diagnostics relating to these declarations if they were actually emitted. This would be useful in the InfectedWin32 use-case where we only emit declarations filtered by an allowlist and their dependencies.

Although it might be just as easy to have this be a transformation that runs just before output generation.

PathogenDavid commented 3 years ago

TranslatedUndefinedRecord is another good candidate for this. It's usually referenced to start with, but sometimes all references to them are removed by transformations.