When name of method parameter is not an identifier, mangle it to contain only Java identifier character

This commit is contained in:
Alexey Andreev 2016-05-11 21:15:36 +03:00
parent eb3558cb1a
commit 3f58e3b24f

View File

@ -1245,12 +1245,21 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
List<String> nameList = new ArrayList<>(names);
Collections.sort(nameList);
for (String name : nameList) {
sb.append('_').append(name);
sb.append('_').append(escapeName(name));
}
}
return sb.toString();
}
private static String escapeName(String name) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < name.length(); ++i) {
char c = name.charAt(i);
sb.append(Character.isJavaIdentifierPart(c) ? c : '_');
}
return sb.toString();
}
private String pointerName() {
return minifying ? "$p" : "$ptr";
}