ClangSharp
ClangSharp copied to clipboard
Fix imported constructors and instance methods
Constructors were supported when they had bodies and were generated as actual C# constructors, but trying to import them produced invalid C#, e.g:
public partial struct MyStruct
{
[DllImport("", CallingConvention = CallingConvention.ThisCall, EntryPoint = "...", ExactSpelling = true)]
public static extern MyStruct();
}
So three things had to be fixed:
- The name has to be remapped to not conflict with C# constructors (static or not)
Also copy/move constructors will conflict with each other thus they get different names - A return type has to be added (Clang said
voidalthough it might also be a pointer to the struct?) - A
pThisparameter has to be added.
This point applied to all imported instance methods.
Here is an example of the result of this PR:
public partial struct MyStruct
{
[DllImport("", CallingConvention = CallingConvention.ThisCall, EntryPoint = "...", ExactSpelling = true)]
public static extern unsafe void Constructor(MyStruct* pThis);
[DllImport("", CallingConvention = CallingConvention.ThisCall, EntryPoint = "...", ExactSpelling = true)]
public static extern unsafe void CopyConstructor(MyStruct* pThis, [NativeTypeName("const MyStruct &")] MyStruct* other);
[DllImport("", CallingConvention = CallingConvention.ThisCall, EntryPoint = "...", ExactSpelling=true)]
public static extern unsafe void MoveConstructor(MyStruct* pThis, [NativeTypeName("MyStruct &&")] MyStruct* other);
[DllImport("", CallingConvention = CallingConvention.ThisCall, EntryPoint = "...", ExactSpelling = true)]
public static extern unsafe void MyMethod(MyStruct* pThis);
}