Browse Source

Add pass to fix up pure C++ methods to C++ generator.

pull/1514/head
Joao Matos 5 years ago committed by João Matos
parent
commit
cbb1e19ef4
  1. 24
      src/Generator/Generators/C/CppGenerator.cs

24
src/Generator/Generators/C/CppGenerator.cs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System.Collections.Generic;
using CppSharp.AST;
using CppSharp.Generators.C;
using CppSharp.Passes;
namespace CppSharp.Generators.Cpp
{
@ -30,7 +31,11 @@ namespace CppSharp.Generators.Cpp @@ -30,7 +31,11 @@ namespace CppSharp.Generators.Cpp
return outputs;
}
public override bool SetupPasses() => true;
public override bool SetupPasses()
{
new FixupPureMethodsPass().VisitASTContext(Context.ASTContext);
return true;
}
public static bool ShouldGenerateClassNativeField(Class @class)
{
@ -45,4 +50,21 @@ namespace CppSharp.Generators.Cpp @@ -45,4 +50,21 @@ namespace CppSharp.Generators.Cpp
return type.Visit(typePrinter).ToString();
}
}
/// <summary>
/// Removes the pureness of virtual abstract methods in C++ classes since
/// the generated classes cannot have virtual pure methods, as they call
/// the original pure method.
/// This lets user code mark some methods as pure if needed, in that case
/// the generator can generate the necessary pure C++ code annotations safely
/// knowing the only pure functions were user-specified.
/// </summary>
public class FixupPureMethodsPass : TranslationUnitPass
{
public override bool VisitMethodDecl(Method method)
{
method.IsPure = false;
return base.VisitMethodDecl(method);
}
}
}

Loading…
Cancel
Save