File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
src/Generator/Generators/C Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
1
using System . Collections . Generic ;
2
2
using CppSharp . AST ;
3
3
using CppSharp . Generators . C ;
4
+ using CppSharp . Passes ;
4
5
5
6
namespace CppSharp . Generators . Cpp
6
7
{
@@ -30,7 +31,11 @@ public override List<CodeGenerator> Generate(IEnumerable<TranslationUnit> units)
30
31
return outputs ;
31
32
}
32
33
33
- public override bool SetupPasses ( ) => true ;
34
+ public override bool SetupPasses ( )
35
+ {
36
+ new FixupPureMethodsPass ( ) . VisitASTContext ( Context . ASTContext ) ;
37
+ return true ;
38
+ }
34
39
35
40
public static bool ShouldGenerateClassNativeField ( Class @class )
36
41
{
@@ -45,4 +50,21 @@ protected override string TypePrinterDelegate(Type type)
45
50
return type . Visit ( typePrinter ) . ToString ( ) ;
46
51
}
47
52
}
53
+
54
+ /// <summary>
55
+ /// Removes the pureness of virtual abstract methods in C++ classes since
56
+ /// the generated classes cannot have virtual pure methods, as they call
57
+ /// the original pure method.
58
+ /// This lets user code mark some methods as pure if needed, in that case
59
+ /// the generator can generate the necessary pure C++ code annotations safely
60
+ /// knowing the only pure functions were user-specified.
61
+ /// </summary>
62
+ public class FixupPureMethodsPass : TranslationUnitPass
63
+ {
64
+ public override bool VisitMethodDecl ( Method method )
65
+ {
66
+ method . IsPure = false ;
67
+ return base . VisitMethodDecl ( method ) ;
68
+ }
69
+ }
48
70
}
You can’t perform that action at this time.
0 commit comments