Support unsigned integers in kotlinx-metadata-jvm
#KT-25371 Fixed
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
# kotlinx-metadata-jvm
|
# kotlinx-metadata-jvm
|
||||||
|
|
||||||
|
## 0.0.5
|
||||||
|
|
||||||
|
- [`KT-25371`](https://youtrack.jetbrains.com/issue/KT-25371) Support unsigned integers in kotlinx-metadata-jvm
|
||||||
|
|
||||||
## 0.0.4
|
## 0.0.4
|
||||||
|
|
||||||
- [`KT-25920`](https://youtrack.jetbrains.com/issue/KT-25920) Compile kotlinx-metadata-jvm with JVM target bytecode version 1.6 instead of 1.8
|
- [`KT-25920`](https://youtrack.jetbrains.com/issue/KT-25920) Compile kotlinx-metadata-jvm with JVM target bytecode version 1.6 instead of 1.8
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ sealed class KmAnnotationArgument<out T : Any> {
|
|||||||
data class DoubleValue(override val value: Double) : KmAnnotationArgument<Double>()
|
data class DoubleValue(override val value: Double) : KmAnnotationArgument<Double>()
|
||||||
data class BooleanValue(override val value: Boolean) : KmAnnotationArgument<Boolean>()
|
data class BooleanValue(override val value: Boolean) : KmAnnotationArgument<Boolean>()
|
||||||
|
|
||||||
|
data class UByteValue(override val value: Byte) : KmAnnotationArgument<Byte>()
|
||||||
|
data class UShortValue(override val value: Short) : KmAnnotationArgument<Short>()
|
||||||
|
data class UIntValue(override val value: Int) : KmAnnotationArgument<Int>()
|
||||||
|
data class ULongValue(override val value: Long) : KmAnnotationArgument<Long>()
|
||||||
|
|
||||||
data class StringValue(override val value: String) : KmAnnotationArgument<String>()
|
data class StringValue(override val value: String) : KmAnnotationArgument<String>()
|
||||||
data class KClassValue(override val value: ClassName) : KmAnnotationArgument<ClassName>()
|
data class KClassValue(override val value: ClassName) : KmAnnotationArgument<ClassName>()
|
||||||
data class EnumValue(val enumClassName: ClassName, val enumEntryName: String) : KmAnnotationArgument<String>() {
|
data class EnumValue(val enumClassName: ClassName, val enumEntryName: String) : KmAnnotationArgument<String>() {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import kotlinx.metadata.KmAnnotation
|
|||||||
import kotlinx.metadata.KmAnnotationArgument
|
import kotlinx.metadata.KmAnnotationArgument
|
||||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||||
import org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.Argument.Value.Type.*
|
import org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.Argument.Value.Type.*
|
||||||
|
import org.jetbrains.kotlin.metadata.deserialization.Flags
|
||||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||||
|
|
||||||
fun ProtoBuf.Annotation.readAnnotation(strings: NameResolver): KmAnnotation =
|
fun ProtoBuf.Annotation.readAnnotation(strings: NameResolver): KmAnnotation =
|
||||||
@@ -22,8 +23,18 @@ fun ProtoBuf.Annotation.readAnnotation(strings: NameResolver): KmAnnotation =
|
|||||||
}.toMap()
|
}.toMap()
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun ProtoBuf.Annotation.Argument.Value.readAnnotationArgument(strings: NameResolver): KmAnnotationArgument<*>? =
|
private fun ProtoBuf.Annotation.Argument.Value.readAnnotationArgument(strings: NameResolver): KmAnnotationArgument<*>? {
|
||||||
when (type) {
|
if (Flags.IS_UNSIGNED[flags]) {
|
||||||
|
return when (type) {
|
||||||
|
BYTE -> KmAnnotationArgument.UByteValue(intValue.toByte())
|
||||||
|
SHORT -> KmAnnotationArgument.UShortValue(intValue.toShort())
|
||||||
|
INT -> KmAnnotationArgument.UIntValue(intValue.toInt())
|
||||||
|
LONG -> KmAnnotationArgument.ULongValue(intValue)
|
||||||
|
else -> error("Cannot read value of unsigned type: $type")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return when (type) {
|
||||||
BYTE -> KmAnnotationArgument.ByteValue(intValue.toByte())
|
BYTE -> KmAnnotationArgument.ByteValue(intValue.toByte())
|
||||||
CHAR -> KmAnnotationArgument.CharValue(intValue.toChar())
|
CHAR -> KmAnnotationArgument.CharValue(intValue.toChar())
|
||||||
SHORT -> KmAnnotationArgument.ShortValue(intValue.toShort())
|
SHORT -> KmAnnotationArgument.ShortValue(intValue.toShort())
|
||||||
@@ -39,6 +50,7 @@ private fun ProtoBuf.Annotation.Argument.Value.readAnnotationArgument(strings: N
|
|||||||
ARRAY -> KmAnnotationArgument.ArrayValue(arrayElementList.mapNotNull { it.readAnnotationArgument(strings) })
|
ARRAY -> KmAnnotationArgument.ArrayValue(arrayElementList.mapNotNull { it.readAnnotationArgument(strings) })
|
||||||
null -> null
|
null -> null
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal fun NameResolver.getClassName(index: Int): ClassName {
|
internal fun NameResolver.getClassName(index: Int): ClassName {
|
||||||
val name = getQualifiedClassName(index)
|
val name = getQualifiedClassName(index)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import kotlinx.metadata.KmAnnotation
|
|||||||
import kotlinx.metadata.KmAnnotationArgument
|
import kotlinx.metadata.KmAnnotationArgument
|
||||||
import kotlinx.metadata.isLocal
|
import kotlinx.metadata.isLocal
|
||||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||||
|
import org.jetbrains.kotlin.metadata.deserialization.Flags
|
||||||
import org.jetbrains.kotlin.metadata.serialization.StringTable
|
import org.jetbrains.kotlin.metadata.serialization.StringTable
|
||||||
|
|
||||||
fun KmAnnotation.writeAnnotation(strings: StringTable): ProtoBuf.Annotation.Builder =
|
fun KmAnnotation.writeAnnotation(strings: StringTable): ProtoBuf.Annotation.Builder =
|
||||||
@@ -58,6 +59,26 @@ private fun KmAnnotationArgument<*>.writeAnnotationArgument(strings: StringTable
|
|||||||
this.type = ProtoBuf.Annotation.Argument.Value.Type.BOOLEAN
|
this.type = ProtoBuf.Annotation.Argument.Value.Type.BOOLEAN
|
||||||
this.intValue = if (value) 1 else 0
|
this.intValue = if (value) 1 else 0
|
||||||
}
|
}
|
||||||
|
is KmAnnotationArgument.UByteValue -> {
|
||||||
|
this.type = ProtoBuf.Annotation.Argument.Value.Type.BYTE
|
||||||
|
this.intValue = value.toLong()
|
||||||
|
this.flags = Flags.IS_UNSIGNED.toFlags(true)
|
||||||
|
}
|
||||||
|
is KmAnnotationArgument.UShortValue -> {
|
||||||
|
this.type = ProtoBuf.Annotation.Argument.Value.Type.SHORT
|
||||||
|
this.intValue = value.toLong()
|
||||||
|
this.flags = Flags.IS_UNSIGNED.toFlags(true)
|
||||||
|
}
|
||||||
|
is KmAnnotationArgument.UIntValue -> {
|
||||||
|
this.type = ProtoBuf.Annotation.Argument.Value.Type.INT
|
||||||
|
this.intValue = value.toLong()
|
||||||
|
this.flags = Flags.IS_UNSIGNED.toFlags(true)
|
||||||
|
}
|
||||||
|
is KmAnnotationArgument.ULongValue -> {
|
||||||
|
this.type = ProtoBuf.Annotation.Argument.Value.Type.LONG
|
||||||
|
this.intValue = value.toLong()
|
||||||
|
this.flags = Flags.IS_UNSIGNED.toFlags(true)
|
||||||
|
}
|
||||||
is KmAnnotationArgument.StringValue -> {
|
is KmAnnotationArgument.StringValue -> {
|
||||||
this.type = ProtoBuf.Annotation.Argument.Value.Type.STRING
|
this.type = ProtoBuf.Annotation.Argument.Value.Type.STRING
|
||||||
this.stringValue = strings.getStringIndex(value)
|
this.stringValue = strings.getStringIndex(value)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
|
||||||
description = "kotlinp"
|
description = "kotlinp"
|
||||||
|
|
||||||
@@ -55,3 +56,9 @@ tasks {
|
|||||||
dependsOn(":kotlin-script-runtime:dist")
|
dependsOn(":kotlin-script-runtime:dist")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.withType<KotlinCompile> {
|
||||||
|
kotlinOptions {
|
||||||
|
freeCompilerArgs += listOf("-Xuse-experimental=kotlin.Experimental")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -427,6 +427,7 @@ private fun renderAnnotation(annotation: KmAnnotation): String =
|
|||||||
"$name = ${renderAnnotationArgument(argument)}"
|
"$name = ${renderAnnotationArgument(argument)}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseExperimental(ExperimentalUnsignedTypes::class)
|
||||||
private fun renderAnnotationArgument(arg: KmAnnotationArgument<*>): String =
|
private fun renderAnnotationArgument(arg: KmAnnotationArgument<*>): String =
|
||||||
when (arg) {
|
when (arg) {
|
||||||
is KmAnnotationArgument.ByteValue -> arg.value.toString() + ".toByte()"
|
is KmAnnotationArgument.ByteValue -> arg.value.toString() + ".toByte()"
|
||||||
@@ -436,6 +437,10 @@ private fun renderAnnotationArgument(arg: KmAnnotationArgument<*>): String =
|
|||||||
is KmAnnotationArgument.LongValue -> arg.value.toString() + "L"
|
is KmAnnotationArgument.LongValue -> arg.value.toString() + "L"
|
||||||
is KmAnnotationArgument.FloatValue -> arg.value.toString() + "f"
|
is KmAnnotationArgument.FloatValue -> arg.value.toString() + "f"
|
||||||
is KmAnnotationArgument.DoubleValue -> arg.value.toString()
|
is KmAnnotationArgument.DoubleValue -> arg.value.toString()
|
||||||
|
is KmAnnotationArgument.UByteValue -> arg.value.toUByte().toString() + ".toUByte()"
|
||||||
|
is KmAnnotationArgument.UShortValue -> arg.value.toUShort().toString() + ".toUShort()"
|
||||||
|
is KmAnnotationArgument.UIntValue -> arg.value.toUInt().toString() + "u"
|
||||||
|
is KmAnnotationArgument.ULongValue -> arg.value.toULong().toString() + "uL"
|
||||||
is KmAnnotationArgument.BooleanValue -> arg.value.toString()
|
is KmAnnotationArgument.BooleanValue -> arg.value.toString()
|
||||||
is KmAnnotationArgument.StringValue -> "\"${arg.value.sanitize(quote = '"')}\""
|
is KmAnnotationArgument.StringValue -> "\"${arg.value.sanitize(quote = '"')}\""
|
||||||
is KmAnnotationArgument.KClassValue -> "${arg.value}::class"
|
is KmAnnotationArgument.KClassValue -> "${arg.value}::class"
|
||||||
|
|||||||
+16
@@ -10,6 +10,14 @@ annotation class A(
|
|||||||
val f: Float,
|
val f: Float,
|
||||||
val j: Long,
|
val j: Long,
|
||||||
val d: Double,
|
val d: Double,
|
||||||
|
val ui: UInt,
|
||||||
|
val ub: UByte,
|
||||||
|
val us: UShort,
|
||||||
|
val ul: ULong,
|
||||||
|
val ui_max: UInt,
|
||||||
|
val ub_max: UByte,
|
||||||
|
val us_max: UShort,
|
||||||
|
val ul_max: ULong,
|
||||||
val za: BooleanArray,
|
val za: BooleanArray,
|
||||||
val ca: CharArray,
|
val ca: CharArray,
|
||||||
val ba: ByteArray,
|
val ba: ByteArray,
|
||||||
@@ -39,6 +47,14 @@ class C {
|
|||||||
-2.72f,
|
-2.72f,
|
||||||
239239239239239L,
|
239239239239239L,
|
||||||
3.14,
|
3.14,
|
||||||
|
1u,
|
||||||
|
0xFFu,
|
||||||
|
3u,
|
||||||
|
4uL,
|
||||||
|
0xFFFF_FFFFu,
|
||||||
|
UByte.MAX_VALUE,
|
||||||
|
0xFF_FFu,
|
||||||
|
18446744073709551615u,
|
||||||
[true],
|
[true],
|
||||||
['\''],
|
['\''],
|
||||||
[1.toByte()],
|
[1.toByte()],
|
||||||
|
|||||||
+44
-3
@@ -2,8 +2,9 @@
|
|||||||
// ------------------------------------------
|
// ------------------------------------------
|
||||||
public final annotation class A : kotlin/Annotation {
|
public final annotation class A : kotlin/Annotation {
|
||||||
|
|
||||||
// signature: <init>(ZCBSIFJD[Z[C[B[S[I[F[J[DLjava/lang/String;Lkotlin/annotation/AnnotationTarget;Lkotlin/reflect/KClass;LB;)V
|
// requires language version 1.3.0 (level=ERROR)
|
||||||
public /* primary */ constructor(z: kotlin/Boolean, c: kotlin/Char, b: kotlin/Byte, s: kotlin/Short, i: kotlin/Int, f: kotlin/Float, j: kotlin/Long, d: kotlin/Double, za: kotlin/BooleanArray, ca: kotlin/CharArray, ba: kotlin/ByteArray, sa: kotlin/ShortArray, ia: kotlin/IntArray, fa: kotlin/FloatArray, ja: kotlin/LongArray, da: kotlin/DoubleArray, str: kotlin/String, enum: kotlin/annotation/AnnotationTarget, klass: kotlin/reflect/KClass<*>, anno: B)
|
// signature: <init>(ZCBSIFJDLkotlin/UInt;Lkotlin/UByte;Lkotlin/UShort;Lkotlin/ULong;Lkotlin/UInt;Lkotlin/UByte;Lkotlin/UShort;Lkotlin/ULong;[Z[C[B[S[I[F[J[DLjava/lang/String;Lkotlin/annotation/AnnotationTarget;Lkotlin/reflect/KClass;LB;)V
|
||||||
|
public /* primary */ constructor(z: kotlin/Boolean, c: kotlin/Char, b: kotlin/Byte, s: kotlin/Short, i: kotlin/Int, f: kotlin/Float, j: kotlin/Long, d: kotlin/Double, ui: kotlin/UInt, ub: kotlin/UByte, us: kotlin/UShort, ul: kotlin/ULong, ui_max: kotlin/UInt, ub_max: kotlin/UByte, us_max: kotlin/UShort, ul_max: kotlin/ULong, za: kotlin/BooleanArray, ca: kotlin/CharArray, ba: kotlin/ByteArray, sa: kotlin/ShortArray, ia: kotlin/IntArray, fa: kotlin/FloatArray, ja: kotlin/LongArray, da: kotlin/DoubleArray, str: kotlin/String, enum: kotlin/annotation/AnnotationTarget, klass: kotlin/reflect/KClass<*>, anno: B)
|
||||||
|
|
||||||
// getter: anno()LB;
|
// getter: anno()LB;
|
||||||
public final val anno: B
|
public final val anno: B
|
||||||
@@ -77,6 +78,46 @@ public final annotation class A : kotlin/Annotation {
|
|||||||
public final val str: kotlin/String
|
public final val str: kotlin/String
|
||||||
public final get
|
public final get
|
||||||
|
|
||||||
|
// requires language version 1.3.0 (level=ERROR)
|
||||||
|
// getter: ub()B
|
||||||
|
public final val ub: kotlin/UByte
|
||||||
|
public final get
|
||||||
|
|
||||||
|
// requires language version 1.3.0 (level=ERROR)
|
||||||
|
// getter: ub_max()B
|
||||||
|
public final val ub_max: kotlin/UByte
|
||||||
|
public final get
|
||||||
|
|
||||||
|
// requires language version 1.3.0 (level=ERROR)
|
||||||
|
// getter: ui()I
|
||||||
|
public final val ui: kotlin/UInt
|
||||||
|
public final get
|
||||||
|
|
||||||
|
// requires language version 1.3.0 (level=ERROR)
|
||||||
|
// getter: ui_max()I
|
||||||
|
public final val ui_max: kotlin/UInt
|
||||||
|
public final get
|
||||||
|
|
||||||
|
// requires language version 1.3.0 (level=ERROR)
|
||||||
|
// getter: ul()J
|
||||||
|
public final val ul: kotlin/ULong
|
||||||
|
public final get
|
||||||
|
|
||||||
|
// requires language version 1.3.0 (level=ERROR)
|
||||||
|
// getter: ul_max()J
|
||||||
|
public final val ul_max: kotlin/ULong
|
||||||
|
public final get
|
||||||
|
|
||||||
|
// requires language version 1.3.0 (level=ERROR)
|
||||||
|
// getter: us()S
|
||||||
|
public final val us: kotlin/UShort
|
||||||
|
public final get
|
||||||
|
|
||||||
|
// requires language version 1.3.0 (level=ERROR)
|
||||||
|
// getter: us_max()S
|
||||||
|
public final val us_max: kotlin/UShort
|
||||||
|
public final get
|
||||||
|
|
||||||
// getter: z()Z
|
// getter: z()Z
|
||||||
public final val z: kotlin/Boolean
|
public final val z: kotlin/Boolean
|
||||||
public final get
|
public final get
|
||||||
@@ -107,7 +148,7 @@ public final class C : kotlin/Any {
|
|||||||
public final fun parameterTypeAnnotation(p: @JvmNamed(value = "Q_Q") kotlin/Any): kotlin/Any
|
public final fun parameterTypeAnnotation(p: @JvmNamed(value = "Q_Q") kotlin/Any): kotlin/Any
|
||||||
|
|
||||||
// signature: returnTypeAnnotation()V
|
// signature: returnTypeAnnotation()V
|
||||||
public final fun returnTypeAnnotation(): @A(z = true, c = 'x', b = 1.toByte(), s = 42.toShort(), i = 42424242, f = -2.72f, j = 239239239239239L, d = 3.14, za = [true], ca = ['\''], ba = [1.toByte()], sa = [42.toShort()], ia = [42424242], fa = [-2.72f], ja = [239239239239239L], da = [3.14], str = "aba\ncaba'\"\t\u0001\u0002ꙮ", enum = kotlin/annotation/AnnotationTarget.CLASS, klass = C::class, anno = B(value = "aba\ncaba'\"\t\u0001\u0002ꙮ")) kotlin/Unit
|
public final fun returnTypeAnnotation(): @A(z = true, c = 'x', b = 1.toByte(), s = 42.toShort(), i = 42424242, f = -2.72f, j = 239239239239239L, d = 3.14, ui = 1u, ub = 255.toUByte(), us = 3.toUShort(), ul = 4uL, ui_max = 4294967295u, ub_max = 255.toUByte(), us_max = 65535.toUShort(), ul_max = 18446744073709551615uL, za = [true], ca = ['\''], ba = [1.toByte()], sa = [42.toShort()], ia = [42424242], fa = [-2.72f], ja = [239239239239239L], da = [3.14], str = "aba\ncaba'\"\t\u0001\u0002ꙮ", enum = kotlin/annotation/AnnotationTarget.CLASS, klass = C::class, anno = B(value = "aba\ncaba'\"\t\u0001\u0002ꙮ")) kotlin/Unit
|
||||||
}
|
}
|
||||||
// JvmNamed.class
|
// JvmNamed.class
|
||||||
// ------------------------------------------
|
// ------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user