Migrate deprecations in Native compiler

Replacing deprecated Char.toInt() with Char.code and
Number.toChar() with Number.toInt().toChar(), where Number is not Int.

KT-23451
This commit is contained in:
Ilya Gorbunov
2021-04-06 20:44:24 +03:00
parent e450a6494a
commit 833955e56d
5 changed files with 7 additions and 7 deletions
@@ -479,12 +479,12 @@ private class U32CString(val chars: CharArray): CValues<IntVar>() {
var indexIn = 0
var indexOut = 0
while (indexIn < chars.size) {
var value = chars[indexIn++].toInt()
var value = chars[indexIn++].code
if (value >= 0xd800 && value < 0xdc00) {
// Surrogate pair.
if (indexIn >= chars.size - 1) throw IllegalArgumentException()
indexIn++
val next = chars[indexIn].toInt()
val next = chars[indexIn].code
if (next < 0xdc00 || next >= 0xe000) throw IllegalArgumentException()
value = 0x10000 + ((value and 0x3ff) shl 10) + (next and 0x3ff)
}
@@ -527,7 +527,7 @@ public fun CPointer<ShortVar>.toKStringFromUtf16(): String {
val chars = CharArray(length)
var index = 0
while (index < length) {
chars[index] = nativeBytes[index].toChar()
chars[index] = nativeBytes[index].toInt().toChar()
++index
}
return chars.concatToString()
@@ -71,7 +71,7 @@ fun String.quoteAsKotlinLiteral(): KotlinExpression = buildString {
when (c) {
in charactersAllowedInKotlinStringLiterals -> append(c)
'$' -> append("\\$")
else -> append("\\u" + "%04X".format(c.toInt()))
else -> append("\\u" + "%04X".format(c.code))
}
}
@@ -128,7 +128,7 @@ internal class Int16(val value: Short) : ConstValue {
}
internal class Char16(val value: Char) : ConstValue {
override val llvm = LLVMConstInt(int16Type, value.toLong(), 1)!!
override val llvm = LLVMConstInt(int16Type, value.code.toLong(), 1)!!
}
internal class Int32(val value: Int) : ConstValue {
@@ -173,6 +173,6 @@ internal class StaticData(override val context: Context): ContextUtils {
* @param args data for constant creation.
*/
internal fun StaticData.createImmutableBlob(value: IrConst<String>): LLVMValueRef {
val args = value.value.map { Int8(it.toByte()).llvm }
val args = value.value.map { Int8(it.code.toByte()).llvm }
return createConstKotlinArray(context.ir.symbols.immutableBlob.owner, args)
}
@@ -87,7 +87,7 @@ internal class PostInlineLowering(val context: Context) : BodyLoweringPass {
// Luckily, all values in range 0x00 .. 0xff represent valid UTF-16 symbols,
// block 0 (Basic Latin) and block 1 (Latin-1 Supplement) in
// Basic Multilingual Plane, so we could just append data "as is".
builder.append(value.toChar())
builder.append(value.toInt().toChar())
}
expression.putValueArgument(0, IrConstImpl(
expression.startOffset, expression.endOffset,