Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit eb07661

Browse files
add sequential naming tools
1 parent fa2051d commit eb07661

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using SwiftReflector.Demangling;
3+
4+
#nullable enable
5+
6+
namespace SwiftReflector.Naming {
7+
public class SequentialNamer {
8+
int current;
9+
string prefix;
10+
object nameLock = new object ();
11+
12+
public SequentialNamer (string prefix, int start = 0)
13+
{
14+
this.prefix = prefix;
15+
current = start;
16+
}
17+
18+
public string SafeName (string name)
19+
{
20+
lock (nameLock) {
21+
return CSSafeNaming.SafeIdentifier ($"{prefix}{name}{current++}");
22+
}
23+
}
24+
}
25+
26+
public class PInvokeNamer : SequentialNamer {
27+
public PInvokeNamer (int start = 0) : base ("PI", start)
28+
{
29+
}
30+
31+
public string SafeName (TLFunction tlf)
32+
{
33+
var module = tlf.Module.Name ?? "NoModule";
34+
var name = tlf.Name.Name ?? "Anonymous";
35+
return Name ($"_{module}_{name}");
36+
}
37+
}
38+
}
39+

0 commit comments

Comments
 (0)