diff --git a/src/Generator/BindingContext.cs b/src/Generator/BindingContext.cs index e7c094c69..cf0cbd3e4 100644 --- a/src/Generator/BindingContext.cs +++ b/src/Generator/BindingContext.cs @@ -2,6 +2,7 @@ using CppSharp.Passes; using CppSharp.Types; using CppSharp.Parser; +using System.Collections.Generic; namespace CppSharp.Generators { @@ -36,14 +37,21 @@ public BindingContext(DriverOptions options, ParserOptions parserOptions = null) public void RunPasses() { + Dictionary passesByType = new Dictionary(); + 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; }); } } diff --git a/src/Generator/Options.cs b/src/Generator/Options.cs index 567153c05..f42236cd6 100644 --- a/src/Generator/Options.cs +++ b/src/Generator/Options.cs @@ -5,6 +5,7 @@ using System.Text; using CppSharp.AST; using CppSharp.Generators; +using CppSharp.Passes; namespace CppSharp { @@ -254,6 +255,12 @@ public bool GenerateSingleCSharpFile /// 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 } diff --git a/src/Generator/Passes/Pass.cs b/src/Generator/Passes/Pass.cs index 877a1116e..3ea925528 100644 --- a/src/Generator/Passes/Pass.cs +++ b/src/Generator/Passes/Pass.cs @@ -51,6 +51,16 @@ bool IsDeclExcluded(Declaration decl) } } + public class TranslationUnitPassGeneratorDependent : TranslationUnitPass + { + public Generator Generator { get; } + + public TranslationUnitPassGeneratorDependent(Generator generator) + { + Generator = generator; + } + } + /// /// Used to modify generated output. ///