C: fix naming when bytecode contains method names with special characters

This commit is contained in:
Alexey Andreev 2020-05-14 14:31:48 +03:00
parent 7313b2bb62
commit 4284bb2a6c

View File

@ -160,22 +160,23 @@ public abstract class LowLevelNameProvider implements NameProvider {
private String sanitize(String name) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < name.length(); ++i) {
char c = name.charAt(i);
switch (c) {
case '>':
case '<':
case '$':
sb.append('_');
break;
default:
sb.append(c);
break;
}
char c = name.charAt(0);
sb.append(isIdentifierStart(c) ? c : '_');
for (int i = 1; i < name.length(); ++i) {
c = name.charAt(i);
sb.append(isIdentifierPart(c) ? c : '_');
}
return sb.toString();
}
private static boolean isIdentifierStart(char c) {
return c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c == '_';
}
private static boolean isIdentifierPart(char c) {
return isIdentifierStart(c) || c >= '0' && c <= '9';
}
private String pickUnoccupied(String name) {
return pickUnoccupied(name, occupiedTopLevelNames);
}