Browse Source

CppSharp.Generators.Options: added pre/post TranslationUnitPass callback

pull/1792/head
Deadlocklogic 2 years ago
parent
commit
36b33bee8d
  1. 8
      src/Generator/BindingContext.cs
  2. 7
      src/Generator/Options.cs

8
src/Generator/BindingContext.cs

@ -2,6 +2,7 @@ using CppSharp.AST; @@ -2,6 +2,7 @@ using CppSharp.AST;
using CppSharp.Passes;
using CppSharp.Types;
using CppSharp.Parser;
using System.Collections.Generic;
namespace CppSharp.Generators
{
@ -36,14 +37,21 @@ namespace CppSharp.Generators @@ -36,14 +37,21 @@ namespace CppSharp.Generators
public void RunPasses()
{
Dictionary<System.Type, int> passesByType = new Dictionary<System.Type, int>();
int index = 0;
TranslationUnitPasses.RunPasses(pass =>
{
int count = passesByType.GetValueOrDefault(pass.GetType(), 0);
Diagnostics.Debug("Pass '{0}'", pass);
Diagnostics.PushIndent();
Options.TranslationUnitPassPreCallBack?.Invoke(pass, index, count);
pass.Context = this;
pass.VisitASTContext(ASTContext);
Options.TranslationUnitPassPostCallBack?.Invoke(pass, index, count);
Diagnostics.PopIndent();
passesByType[pass.GetType()] = count + 1;
index += 1;
});
}
}

7
src/Generator/Options.cs

@ -5,6 +5,7 @@ using System.Linq; @@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Passes;
namespace CppSharp
{
@ -254,6 +255,12 @@ namespace CppSharp @@ -254,6 +255,12 @@ namespace CppSharp
/// </summary>
public bool GenerateExternalDataFields { get; set; } = false;
public delegate void TranslationUnitPassCallBack(TranslationUnitPass pass, int index, int count);
public TranslationUnitPassCallBack TranslationUnitPassPreCallBack { get; set; }
public TranslationUnitPassCallBack TranslationUnitPassPostCallBack { get; set; }
#endregion
}

Loading…
Cancel
Save