Biohazrd icon indicating copy to clipboard operation
Biohazrd copied to clipboard

Biohazrd should have a dedicated fallback type instead of using int

Open PathogenDavid opened this issue 3 years ago • 5 comments

Right now if Biohazrd fails to emit a type, it will emit it as int in order to make sure the C# code still compiles:

[FieldOffset(0)] public /* Failed to emit TranslatedNormalField ShortPair: ClangTypeReference is not supported by the C# output generator. */
int ShortPair;

This is great during generator development because it means you can test unaffected portions of the library without having to resolve these issues.

Unfortunately it also becomes non-obvious that affected members are broken.

In this scenario, we should emit a special type to signify that this member is broken. (We cannot realistically go back and mark the member as obsolete because this is last-chance error handling that occurs while the file is being written. Ideally we might do that for certain cases, but it'd be part of the verification stage.)

PathogenDavid avatar Nov 29 '20 03:11 PathogenDavid

Note: Make sure to update the documentation for KludgeUnknownClangTypesIntoBuiltinTypesTransformation when this is completed.

PathogenDavid avatar Nov 29 '20 03:11 PathogenDavid

Another quirk revealed by this issue: If more than one function fails to emit a type it can break disambiguation by operator overloading. IE:

class MyClass {}; // <-- Remove this declaration with a transform

void Write(int* x);
void Write(MyClass* x);

will become:

void Write(int* x);
void Write(/* Failed to emit TranslatedParameter x: Failed to resolve `Ref resolved by MyClass` during emit time. `*/ int* x);

Which cannot build.

PathogenDavid avatar Jan 31 '21 01:01 PathogenDavid

Honestly we should instead just fail these sorts of methods during the verification stage.

Edit: We actually need to do this after the broken declaration extractor runs because it can break references. (It'd actually probably have to be a persistent transformation.)

PathogenDavid avatar Jan 31 '21 01:01 PathogenDavid

Honestly we should instead just fail these sorts of methods during the verification stage.

https://github.com/InfectedLibraries/Biohazrd/issues/47

PathogenDavid avatar Jul 04 '21 13:07 PathogenDavid

While we should definitely fail these methods during verification, I think it could be valuable to have the ability to last-minute remove a failed declaration.

We already buffer the contents of the file with a StringBuilder inside CodeWriter, we could pretty easily use StringBuilder.Insert or StringBuilder.Remove to either #if-disable/remove broken code instead of straining ourselves to make it valid.

PathogenDavid avatar Dec 07 '21 16:12 PathogenDavid