From 833955e56df97f89b373c17d0443b6b244269a25 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 6 Apr 2021 20:44:24 +0300 Subject: [PATCH] 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 --- .../Runtime/src/main/kotlin/kotlinx/cinterop/Utils.kt | 6 +++--- .../org/jetbrains/kotlin/native/interop/gen/CodeUtils.kt | 2 +- .../org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt | 2 +- .../org/jetbrains/kotlin/backend/konan/llvm/StaticData.kt | 2 +- .../kotlin/backend/konan/lower/PostInlineLowering.kt | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/kotlin-native/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Utils.kt b/kotlin-native/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Utils.kt index 0f74241fe7e..299af2ac987 100644 --- a/kotlin-native/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Utils.kt +++ b/kotlin-native/Interop/Runtime/src/main/kotlin/kotlinx/cinterop/Utils.kt @@ -479,12 +479,12 @@ private class U32CString(val chars: CharArray): CValues() { 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.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() diff --git a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/CodeUtils.kt b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/CodeUtils.kt index 6ad1baf79d9..95e313e3013 100644 --- a/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/CodeUtils.kt +++ b/kotlin-native/Interop/StubGenerator/src/main/kotlin/org/jetbrains/kotlin/native/interop/gen/CodeUtils.kt @@ -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)) } } diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt index 480dff89f48..29d536b4e8a 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/LlvmUtils.kt @@ -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 { diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/StaticData.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/StaticData.kt index 8b27ff9bebc..b0efffa7147 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/StaticData.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/StaticData.kt @@ -173,6 +173,6 @@ internal class StaticData(override val context: Context): ContextUtils { * @param args data for constant creation. */ internal fun StaticData.createImmutableBlob(value: IrConst): 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) } \ No newline at end of file diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt index bd4ad0a2dc3..c60d5069870 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt @@ -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,