Browse Source

Generate valid C++ for protected destructors

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1557/head
Dimitar Dobrev 4 years ago
parent
commit
d741ced55a
  1. 15
      src/Generator/Passes/SymbolsCodeGenerator.cs
  2. 6
      tests/CSharp/CSharp.h

15
src/Generator/Passes/SymbolsCodeGenerator.cs

@ -201,21 +201,24 @@ namespace CppSharp.Passes
bool needSubclass = method.Access == AccessSpecifier.Protected || bool needSubclass = method.Access == AccessSpecifier.Protected ||
((Class) method.Namespace).IsAbstract; ((Class) method.Namespace).IsAbstract;
string @namespace = method.Namespace.Visit(cppTypePrinter); string @namespace = method.Namespace.Visit(cppTypePrinter);
if (!needSubclass)
Write("extern \"C\" "); Write("extern \"C\" ");
Write($"{GetExporting()}void {wrapper}"); Write($"{GetExporting()}void {wrapper}");
if (needSubclass) if (needSubclass)
Write("Protected"); Write("Protected");
string instance = Helpers.InstanceField; string instance = Helpers.InstanceField;
string @class = needSubclass ? wrapper : @namespace;
Write($"({@class}* {instance}) {{ {instance}->~{method.Namespace.Name}(); }};");
if (needSubclass) if (needSubclass)
{ {
NewLine(); string @class = wrapper + method.Namespace.Name;
Write($@"extern ""C"" {GetExporting()}void {wrapper}({wrapper}* {instance}) {{ { WriteLine($"() {{ this->~{@class}(); }} }};");
instance}->{wrapper}Protected({instance}); }}"); Write($@"extern ""C"" {GetExporting()}void {wrapper}({
@class}* {instance}) {{ {instance}->{wrapper}Protected");
} }
NewLine(); else
Write($@"({$"{@namespace}*{instance}"}) {{ {
instance}->~{method.Namespace.Name}");
WriteLine("(); }");
} }
private void TakeFunctionAddress(Function function, string wrapper) private void TakeFunctionAddress(Function function, string wrapper)

6
tests/CSharp/CSharp.h

@ -1502,6 +1502,12 @@ struct DLL_API ClassMicrosoftObjectAlignment : ClassMicrosoftObjectAlignmentBase
bool boolean; bool boolean;
}; };
class DLL_API ProtectedDestructor
{
protected:
~ProtectedDestructor() {}
};
DLL_API extern const unsigned ClassCustomTypeAlignmentOffsets[5]; DLL_API extern const unsigned ClassCustomTypeAlignmentOffsets[5];
DLL_API extern const unsigned ClassCustomObjectAlignmentOffsets[2]; DLL_API extern const unsigned ClassCustomObjectAlignmentOffsets[2];
DLL_API extern const unsigned ClassMicrosoftObjectAlignmentOffsets[4]; DLL_API extern const unsigned ClassMicrosoftObjectAlignmentOffsets[4];

Loading…
Cancel
Save