Browse Source

Generate valid C++ for protected constructors

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

26
src/Generator/Passes/SymbolsCodeGenerator.cs

@ -153,25 +153,21 @@ namespace CppSharp.Passes
Context.ParserOptions.IsItaniumLikeAbi).Select( Context.ParserOptions.IsItaniumLikeAbi).Select(
p => cppTypePrinter.VisitParameter(p))); p => cppTypePrinter.VisitParameter(p)));
string @namespace = method.Namespace.Visit(cppTypePrinter); if (method.Access != AccessSpecifier.Protected)
Class @class = (Class) method.Namespace; Write("extern \"C\" ");
bool needSubclass = method.Access == AccessSpecifier.Protected || @class.IsAbstract; Write($"{GetExporting()}void {wrapper}({signature}) ");
if (needSubclass)
if (method.Access == AccessSpecifier.Protected ||
((Class) method.Namespace).IsAbstract)
{ {
Write($"extern \"C\" {GetExporting()}void {wrapper}({signature}) "); Write($@"{{ ::new ({Helpers.InstanceField}) {
WriteLine($"{{ ::new ({Helpers.InstanceField}) {wrapper}{method.Namespace.Name}({@params}); }}"); wrapper}{method.Namespace.Name}({@params}); }}");
WriteLine(method.Access == AccessSpecifier.Protected ? " };" : string.Empty);
} }
else else
{ {
Write("extern \"C\" "); string @namespace = method.Namespace.Visit(cppTypePrinter);
if (needSubclass) WriteLine($"{{ ::new ({Helpers.InstanceField}) {@namespace}({@params}); }}");
Write($@"class {wrapper}{method.Namespace.Namespace.Name} : public {
method.Namespace.Namespace.Visit(cppTypePrinter)} {{ ");
Write($"{GetExporting()}void {wrapper}({signature}) ");
Write($"{{ ::new ({Helpers.InstanceField}) {@namespace}({@params}); }}");
if (needSubclass)
Write("; }");
NewLine();
} }
foreach (var param in method.Parameters.Where(p => foreach (var param in method.Parameters.Where(p =>

5
tests/CSharp/CSharp.h

@ -1502,10 +1502,11 @@ struct DLL_API ClassMicrosoftObjectAlignment : ClassMicrosoftObjectAlignmentBase
bool boolean; bool boolean;
}; };
class DLL_API ProtectedDestructor class DLL_API ProtectedConstructorDestructor
{ {
protected: protected:
~ProtectedDestructor() {} ProtectedConstructorDestructor() {}
~ProtectedConstructorDestructor() {}
}; };
DLL_API extern const unsigned ClassCustomTypeAlignmentOffsets[5]; DLL_API extern const unsigned ClassCustomTypeAlignmentOffsets[5];

Loading…
Cancel
Save