Biohazrd
Biohazrd copied to clipboard
Fix support for constant arrays of void*
Right now constant arrays of void*
tries to emit an array helper with the following enumerator:
public ConstantArrayOfPointersEnumerator<void> GetEnumerator()
=> new ConstantArrayOfPointersEnumerator<void>(Element0Pointer, 2000);
This isn't valid since void
cannot be a generic type argument. We need to special-case void*
arrays.
Workaround transformation to rewrite the constant arrays to byte*[]
arrays:
using Biohazrd;
using Biohazrd.CSharp;
using Biohazrd.Transformation;
namespace Mochi.MuJoCo.Generator
{
// This is a workaround for https://github.com/InfectedLibraries/Biohazrd/issues/221
internal sealed class __WorkaroundBiohazrd221Transformation : CSharpTransformationBase
{
protected override TransformationResult TransformConstantArrayType(TransformationContext context, ConstantArrayTypeDeclaration declaration)
{
if (declaration.Type == VoidTypeReference.PointerInstance)
{
return declaration with { Type = new PointerTypeReference(CSharpBuiltinType.Byte) };
}
else
{ return declaration; }
}
}
}
(Note: This doesn't properly handle void**
and other levels of indirection.)