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

Commit 404106d

Browse files
Merge pull request #838 from xamarin/more-naming
add sequential naming tools
2 parents fa2051d + 20c0fe9 commit 404106d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Threading;
3+
using SwiftReflector.Demangling;
4+
5+
#nullable enable
6+
7+
namespace SwiftReflector.Naming {
8+
public class SequentialNamer {
9+
int current;
10+
string prefix;
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+
return CSSafeNaming.SafeIdentifier ($"{prefix}{name}{Interlocked.Increment (ref current)}");
21+
}
22+
}
23+
24+
public class PInvokeNamer : SequentialNamer {
25+
public PInvokeNamer (int start = 0) : base ("PI", start)
26+
{
27+
}
28+
29+
public string SafeName (TLFunction tlf)
30+
{
31+
var module = tlf.Module.Name ?? "NoModule";
32+
var name = tlf.Name.Name ?? "Anonymous";
33+
return SafeName ($"_{module}_{name}");
34+
}
35+
}
36+
}
37+

0 commit comments

Comments
 (0)