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

6
tests/CSharp/CSharp.h

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

Loading…
Cancel
Save