Change illegal local variable mangling rules

This commit is contained in:
Yan Zhulanow
2019-01-09 20:15:08 +03:00
committed by Yan Zhulanow
parent 47f0b68a8c
commit aca3be12e9
2 changed files with 14 additions and 6 deletions
@@ -25,7 +25,6 @@ fun getNameForDestructuredParameterOrNull(valueParameterDescriptor: ValueParamet
}
}
fun mangleNameIfNeeded(name: String): String {
if (name.all { it.isValidCharacter() }) {
return name
@@ -35,14 +34,23 @@ fun mangleNameIfNeeded(name: String): String {
for (c in name) {
if (c.isValidCharacter()) {
append(c)
continue
} else {
append('-').append(c.toHex())
}
append("_u").append(Integer.toHexString(c.toInt()))
}
}
}
private fun Char.toHex(): String {
val hexString = Integer.toHexString(this.toInt())
assert(hexString.length <= 4)
return if (hexString.length == 4) {
hexString
} else {
"0".repeat(4 - hexString.length) + hexString
}
}
private fun Char.isValidCharacter(): Boolean {
return this != '$' && this != '-' && isValidDalvikCharacter(this)
}