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

7
src/Generator/Options.cs

@ -5,6 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.Generators; using CppSharp.Generators;
using CppSharp.Passes;
namespace CppSharp namespace CppSharp
{ {
@ -254,6 +255,12 @@ namespace CppSharp
/// </summary> /// </summary>
public bool GenerateExternalDataFields { get; set; } = false; 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 #endregion
} }

Loading…
Cancel
Save