mirror of
https://github.com/AssetRipper/NativeFileDialogs.NET.git
synced 2026-11-13 18:07:38 -10:00
Rename during CppSharp generation
This commit is contained in:
1 parent
3c1b069db6
commit
63afade403
10 files changed
+259
-212
No files matched your search
@@ -7,9 +7,11 @@ using CppSharp.AST;
|
||||
using CppSharp.Generators;
|
||||
using CppSharp.Passes;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Versioning;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace NativeFileDialogs.CppSharpGenerator;
|
||||
|
||||
@@ -41,7 +43,18 @@ public class NativeFileDialogsLibrary : ILibrary
|
||||
|
||||
public void SetupPasses(Driver driver)
|
||||
{
|
||||
driver.Context.TranslationUnitPasses.RemovePrefix("NFD_");
|
||||
driver.Context.TranslationUnitPasses.RemovePrefix("nfd");
|
||||
|
||||
driver.Context.TranslationUnitPasses.RenameDeclsUpperCase(RenameTargets.Any);
|
||||
|
||||
driver.Context.TranslationUnitPasses.AddPass(new RegexRenamePass("^([A-Z]+)$", m => m.Value.ToLowerInvariant(), RenameTargets.EnumItem));
|
||||
|
||||
driver.Context.TranslationUnitPasses.RenameWithPattern("T$", "", RenameTargets.Enum | RenameTargets.Class);
|
||||
|
||||
driver.Context.TranslationUnitPasses.RenameWithPattern("^(.+)filteritem$", "FilterItem$1", RenameTargets.Enum | RenameTargets.Class);
|
||||
|
||||
driver.Context.TranslationUnitPasses.RenameWithPattern("(Pathsetenum)|(PathSetEnum)", "PathSetEnumerator", RenameTargets.Any);
|
||||
}
|
||||
|
||||
public void Preprocess(Driver driver, ASTContext ctx)
|
||||
@@ -54,7 +67,7 @@ public class NativeFileDialogsLibrary : ILibrary
|
||||
{
|
||||
AddWindowsOnlyAttribute(function);
|
||||
}
|
||||
AddWindowsOnlyAttribute(ctx.FindClass("NfdnfilteritemT").First());
|
||||
AddWindowsOnlyAttribute(ctx.FindClass("FilterItemN").First());
|
||||
}
|
||||
|
||||
public void GenerateCode(Driver driver, List<GeneratorOutput> outputs)
|
||||
@@ -65,4 +78,38 @@ public class NativeFileDialogsLibrary : ILibrary
|
||||
{
|
||||
declaration.Attributes.Add(new Attribute() { Type = typeof(SupportedOSPlatformAttribute), Value = "\"windows\"" });
|
||||
}
|
||||
|
||||
private class RegexRenamePass : RenamePass
|
||||
{
|
||||
public string Pattern { get; }
|
||||
|
||||
public MatchEvaluator MatchEvaluator { get; }
|
||||
|
||||
public RegexRenamePass([StringSyntax("regex")] string pattern, MatchEvaluator matchEvaluator, RenameTargets targets = RenameTargets.Any)
|
||||
{
|
||||
Pattern = pattern;
|
||||
MatchEvaluator = matchEvaluator;
|
||||
Targets = targets;
|
||||
}
|
||||
|
||||
public override bool Rename(Declaration decl, [NotNullWhen(true)] out string? newName)
|
||||
{
|
||||
if (base.Rename(decl, out newName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
string text = Regex.Replace(decl.Name, Pattern, MatchEvaluator);
|
||||
if (!decl.Name.Equals(text, System.StringComparison.Ordinal))
|
||||
{
|
||||
newName = text;
|
||||
return true;
|
||||
}
|
||||
|
||||
newName = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString() => "RegexRenamePass: " + Pattern;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user