Skip to content

Commit 1d7dc38

Browse files
committed
Optimize the cleaning of invalid names
Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent 82e41d3 commit 1d7dc38

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Generator/Passes/CleanInvalidDeclNamesPass.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ namespace CppSharp.Passes
1010
{
1111
public class CleanInvalidDeclNamesPass : TranslationUnitPass
1212
{
13+
public override bool VisitASTContext(ASTContext context)
14+
{
15+
// TODO: Fix this to not need per-generator code.
16+
generator = Options.IsCLIGenerator ?
17+
new CLIHeaders(Context, new List<TranslationUnit>()) :
18+
(CodeGenerator) new CSharpSources(Context);
19+
return base.VisitASTContext(context);
20+
}
21+
1322
public override bool VisitClassDecl(Class @class)
1423
{
1524
if (!base.VisitClassDecl(@class))
@@ -129,13 +138,10 @@ private string CheckName(string name, ref int order)
129138
if (char.IsNumber(name[0]))
130139
return '_' + name;
131140

132-
// TODO: Fix this to not need per-generator code.
133-
var units = new List<TranslationUnit> { new TranslationUnit() };
134-
if (Options.IsCLIGenerator)
135-
return new CLIHeaders(Context, units).SafeIdentifier(name);
136-
137-
return new CSharpSources(Context, units).SafeIdentifier(name);
141+
return generator.SafeIdentifier(name);
138142
}
143+
144+
private CodeGenerator generator;
139145
}
140146
}
141147

0 commit comments

Comments
 (0)