Biohazrd
Biohazrd copied to clipboard
Handle forward-declared out-of-scope/never-defined structs more elegantly
In C++ it is possible and sometimes common to forward-declare structs to avoid including large header files when you only need a few types from them.
For example, in imgui_impl_dx12.h
:
https://github.com/ocornut/imgui/blob/682249396f02b8c21e5ff333ab4a1969c89387ad/examples/imgui_impl_dx12.h#L20-L25
https://github.com/ocornut/imgui/blob/682249396f02b8c21e5ff333ab4a1969c89387ad/examples/imgui_impl_dx12.h#L31-L32
This is allowed in C++, although the end result is that you can't actually call ImGui_ImplDX12_Init
without including d3d12.h
.
Right now if you try to translate this file with Biohazrd it will violently combust in ClangSharpExtensions.RecordMustBePassedByReference
:
https://github.com/InfectedLibraries/Biohazrd/blob/main/Biohazrd/ClangSharpExtensions.cs#L74-L75
This is because Biohazrd is trying to "use" the type, which it can't since it was never actually defined. Biohazrd should handle this situation more elegantly and instead the result should be an uncallable ImGui_ImplDX12_Init
with a warning that those structs were never defined.
For this situation in particular, I think it'd also be valuable for the developer to be able to either:
- Provide tiny snippets of code that get added to the Biohazrd index file without being translated. (In this case, the developer might just manually provide those struct definitions.)
- Provide included but out-of-scope includes to Biohazrd. (In this case, the developer might tell Biohazrd to include
d3d12.h
but we obviously don't want it to be in-scope.)