CppSharp
CppSharp copied to clipboard
RenamePass: add option to include/exclude namespaces from renaming
I am really not sure why this wasn't an option before, if it's simply and oversight or if this change might have more implications.
A first CI run will probably give some answers.
Also the Mac CI action is failing due to Actions deprecating macOS 10.5 which we were using.
I've since updated main branch to update it to macOS 11 but the PR won't get the fix until you rebase.
Not really necessary tho, as the other OSes should provide plenty testing anyway.
@tritao I realized what I did wrong. I removed the existing RenamePass, and then just appended my own RenamePass at the end of the Passes list. Which then obviously runs after the CheckKeywordNamesPass.
Is there a "good" way to replace the existing RenamePass with a custom one? This is our current approach, which requires this pull request:
public void Preprocess(Driver driver, ASTContext ctx)
{
int index = driver.Context.TranslationUnitPasses.Passes.FindIndex(pass => pass.GetType() == typeof(CaseRenamePass));
int numRemoved = driver.Context.TranslationUnitPasses.Passes.RemoveAll(pass => pass.GetType() == typeof(CaseRenamePass));
if (numRemoved != 1)
{
throw new Exception("Something went wrong with removing the existing rename pass. " +
$"Excepted to remove one CaseRenamePass, actual number of removed passes: {numRemoved}");
}
driver.Context.TranslationUnitPasses.Passes.InsertRange(index,
new TranslationUnitPass[]{
new CaseRenamePass(RenameTargets.Any & ~RenameTargets.Parameter & ~RenameTargets.Property, RenameCasePattern.UpperCamelCase),
new CaseRenamePass(RenameTargets.Property, RenameCasePattern.LowerCamelCase)
}
);
}
Also, this code has to be in Preprocess, but in SetupPasses() the Rename Pass hasn't been added yet.
@tritao I realized what I did wrong. I removed the existing RenamePass, and then just appended my own RenamePass at the end of the Passes list. Which then obviously runs after the CheckKeywordNamesPass.
Is there a "good" way to replace the existing RenamePass with a custom one? This is our current approach, which requires this pull request:
public void Preprocess(Driver driver, ASTContext ctx) { int index = driver.Context.TranslationUnitPasses.Passes.FindIndex(pass => pass.GetType() == typeof(CaseRenamePass)); int numRemoved = driver.Context.TranslationUnitPasses.Passes.RemoveAll(pass => pass.GetType() == typeof(CaseRenamePass)); if (numRemoved != 1) { throw new Exception("Something went wrong with removing the existing rename pass. " + $"Excepted to remove one CaseRenamePass, actual number of removed passes: {numRemoved}"); } driver.Context.TranslationUnitPasses.Passes.InsertRange(index, new TranslationUnitPass[]{ new CaseRenamePass(RenameTargets.Any & ~RenameTargets.Parameter & ~RenameTargets.Property, RenameCasePattern.UpperCamelCase), new CaseRenamePass(RenameTargets.Property, RenameCasePattern.LowerCamelCase) } ); }Also, this code has to be in Preprocess, but in SetupPasses() the Rename Pass hasn't been added yet.
Yeah that doesn't look ideal, but I don't think we have a good way to do that atm. Perhaps we could have a ReplacePass API that abstracts that logic?