Browse Source

Merge branch 'mono:main' into GeneratorKind-registration

pull/1794/head
deadlocklogic 2 years ago committed by GitHub
parent
commit
8d32ad8eaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/Generator/BindingContext.cs
  2. 7
      src/Generator/Options.cs
  3. 10
      src/Generator/Passes/Pass.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
}

10
src/Generator/Passes/Pass.cs

@ -51,6 +51,16 @@ namespace CppSharp.Passes @@ -51,6 +51,16 @@ namespace CppSharp.Passes
}
}
public class TranslationUnitPassGeneratorDependent : TranslationUnitPass
{
public Generator Generator { get; }
public TranslationUnitPassGeneratorDependent(Generator generator)
{
Generator = generator;
}
}
/// <summary>
/// Used to modify generated output.
/// </summary>

Loading…
Cancel
Save