Make unsigned types experimental (with warning if not opted-in)
This commit is contained in:
@@ -43,6 +43,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
|
|||||||
|
|
||||||
out.println("@Suppress(\"NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS\")")
|
out.println("@Suppress(\"NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS\")")
|
||||||
out.println("@SinceKotlin(\"1.3\")")
|
out.println("@SinceKotlin(\"1.3\")")
|
||||||
|
out.println("@ExperimentalUnsignedTypes")
|
||||||
out.println("public inline class $className internal constructor(private val data: $storageType) : Comparable<$className> {")
|
out.println("public inline class $className internal constructor(private val data: $storageType) : Comparable<$className> {")
|
||||||
out.println()
|
out.println()
|
||||||
out.println(""" companion object {
|
out.println(""" companion object {
|
||||||
@@ -198,6 +199,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
|
|||||||
val otherSigned = otherType.asSigned.capitalized
|
val otherSigned = otherType.asSigned.capitalized
|
||||||
val thisSigned = type.asSigned.capitalized
|
val thisSigned = type.asSigned.capitalized
|
||||||
out.println("@SinceKotlin(\"1.3\")")
|
out.println("@SinceKotlin(\"1.3\")")
|
||||||
|
out.println("@ExperimentalUnsignedTypes")
|
||||||
out.print("public fun $otherSigned.to$className(): $className = ")
|
out.print("public fun $otherSigned.to$className(): $className = ")
|
||||||
out.println(when {
|
out.println(when {
|
||||||
otherType < type -> "$className(this.to$thisSigned() and ${otherType.mask})"
|
otherType < type -> "$className(this.to$thisSigned() and ${otherType.mask})"
|
||||||
@@ -241,6 +243,7 @@ class UnsignedIteratorsGenerator(out: PrintWriter) : BuiltInsSourceGenerator(out
|
|||||||
val s = type.capitalized
|
val s = type.capitalized
|
||||||
out.println("/** An iterator over a sequence of values of type `$s`. */")
|
out.println("/** An iterator over a sequence of values of type `$s`. */")
|
||||||
out.println("@SinceKotlin(\"1.3\")")
|
out.println("@SinceKotlin(\"1.3\")")
|
||||||
|
out.println("@ExperimentalUnsignedTypes")
|
||||||
out.println("public abstract class ${s}Iterator : Iterator<$s> {")
|
out.println("public abstract class ${s}Iterator : Iterator<$s> {")
|
||||||
// TODO: Sort modifiers
|
// TODO: Sort modifiers
|
||||||
out.println(" override final fun next() = next$s()")
|
out.println(" override final fun next() = next$s()")
|
||||||
@@ -261,6 +264,7 @@ class UnsignedArrayGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIn
|
|||||||
val storageArrayType = storageElementType + "Array"
|
val storageArrayType = storageElementType + "Array"
|
||||||
override fun generateBody() {
|
override fun generateBody() {
|
||||||
out.println("@SinceKotlin(\"1.3\")")
|
out.println("@SinceKotlin(\"1.3\")")
|
||||||
|
out.println("@ExperimentalUnsignedTypes")
|
||||||
out.println("public inline class $arrayType")
|
out.println("public inline class $arrayType")
|
||||||
out.println("@Suppress(\"NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS\")")
|
out.println("@Suppress(\"NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS\")")
|
||||||
out.println("@PublishedApi")
|
out.println("@PublishedApi")
|
||||||
@@ -299,11 +303,13 @@ class UnsignedArrayGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIn
|
|||||||
// TODO: Make inline constructor, like in ByteArray
|
// TODO: Make inline constructor, like in ByteArray
|
||||||
out.println()
|
out.println()
|
||||||
out.println("@SinceKotlin(\"1.3\")")
|
out.println("@SinceKotlin(\"1.3\")")
|
||||||
|
out.println("@ExperimentalUnsignedTypes")
|
||||||
out.println("""public inline fun $arrayType(size: Int, init: (Int) -> $elementType): $arrayType {
|
out.println("""public inline fun $arrayType(size: Int, init: (Int) -> $elementType): $arrayType {
|
||||||
return $arrayType($storageArrayType(size) { index -> init(index).to$storageElementType() })
|
return $arrayType($storageArrayType(size) { index -> init(index).to$storageElementType() })
|
||||||
}
|
}
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
// TODO: @kotlin.internal.InlineOnly
|
// TODO: @kotlin.internal.InlineOnly
|
||||||
public inline fun $arrayTypeOf(vararg elements: $elementType): $arrayType = elements"""
|
public inline fun $arrayTypeOf(vararg elements: $elementType): $arrayType = elements"""
|
||||||
)
|
)
|
||||||
@@ -330,6 +336,7 @@ import kotlin.internal.*
|
|||||||
* A range of values of type `$elementType`.
|
* A range of values of type `$elementType`.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public class ${elementType}Range(start: $elementType, endInclusive: $elementType) : ${elementType}Progression(start, endInclusive, 1), ClosedRange<${elementType}> {
|
public class ${elementType}Range(start: $elementType, endInclusive: $elementType) : ${elementType}Progression(start, endInclusive, 1), ClosedRange<${elementType}> {
|
||||||
override val start: $elementType get() = first
|
override val start: $elementType get() = first
|
||||||
override val endInclusive: $elementType get() = last
|
override val endInclusive: $elementType get() = last
|
||||||
@@ -357,6 +364,7 @@ public class ${elementType}Range(start: $elementType, endInclusive: $elementType
|
|||||||
* A progression of values of type `$elementType`.
|
* A progression of values of type `$elementType`.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public open class ${elementType}Progression
|
public open class ${elementType}Progression
|
||||||
internal constructor(
|
internal constructor(
|
||||||
start: $elementType,
|
start: $elementType,
|
||||||
@@ -413,6 +421,7 @@ internal constructor(
|
|||||||
* @property step the number by which the value is incremented on each step.
|
* @property step the number by which the value is incremented on each step.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
private class ${elementType}ProgressionIterator(first: $elementType, last: $elementType, step: $stepType) : ${elementType}Iterator() {
|
private class ${elementType}ProgressionIterator(first: $elementType, last: $elementType, step: $stepType) : ${elementType}Iterator() {
|
||||||
private val finalElement = last
|
private val finalElement = last
|
||||||
private var hasNext: Boolean = if (step > 0) first <= last else first >= last
|
private var hasNext: Boolean = if (step > 0) first <= last else first >= last
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ compileUnsignedKotlinCommon {
|
|||||||
languageVersion = "1.3"
|
languageVersion = "1.3"
|
||||||
apiVersion = "1.3"
|
apiVersion = "1.3"
|
||||||
freeCompilerArgs += [
|
freeCompilerArgs += [
|
||||||
|
"-Xuse-experimental=kotlin.Experimental",
|
||||||
|
"-Xuse-experimental=kotlin.ExperimentalUnsignedTypes",
|
||||||
"-XXLanguage:+InlineClasses"
|
"-XXLanguage:+InlineClasses"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,6 +212,8 @@ compileUnsignedKotlin {
|
|||||||
languageVersion = "1.3"
|
languageVersion = "1.3"
|
||||||
apiVersion = "1.3"
|
apiVersion = "1.3"
|
||||||
freeCompilerArgs += [
|
freeCompilerArgs += [
|
||||||
|
"-Xuse-experimental=kotlin.Experimental",
|
||||||
|
"-Xuse-experimental=kotlin.ExperimentalUnsignedTypes",
|
||||||
"-XXLanguage:+InlineClasses"
|
"-XXLanguage:+InlineClasses"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import kotlin.experimental.*
|
|||||||
|
|
||||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public inline class UByte internal constructor(private val data: Byte) : Comparable<UByte> {
|
public inline class UByte internal constructor(private val data: Byte) : Comparable<UByte> {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -130,10 +131,14 @@ public inline class UByte internal constructor(private val data: Byte) : Compara
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Byte.toUByte(): UByte = UByte(this)
|
public fun Byte.toUByte(): UByte = UByte(this)
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Short.toUByte(): UByte = UByte(this.toByte())
|
public fun Short.toUByte(): UByte = UByte(this.toByte())
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Int.toUByte(): UByte = UByte(this.toByte())
|
public fun Int.toUByte(): UByte = UByte(this.toByte())
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Long.toUByte(): UByte = UByte(this.toByte())
|
public fun Long.toUByte(): UByte = UByte(this.toByte())
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public inline class UByteArray
|
public inline class UByteArray
|
||||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
@@ -41,10 +42,12 @@ internal constructor(private val storage: ByteArray) : Collection<UByte> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public inline fun UByteArray(size: Int, init: (Int) -> UByte): UByteArray {
|
public inline fun UByteArray(size: Int, init: (Int) -> UByte): UByteArray {
|
||||||
return UByteArray(ByteArray(size) { index -> init(index).toByte() })
|
return UByteArray(ByteArray(size) { index -> init(index).toByte() })
|
||||||
}
|
}
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
// TODO: @kotlin.internal.InlineOnly
|
// TODO: @kotlin.internal.InlineOnly
|
||||||
public inline fun ubyteArrayOf(vararg elements: UByte): UByteArray = elements
|
public inline fun ubyteArrayOf(vararg elements: UByte): UByteArray = elements
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import kotlin.experimental.*
|
|||||||
|
|
||||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public inline class UInt internal constructor(private val data: Int) : Comparable<UInt> {
|
public inline class UInt internal constructor(private val data: Int) : Comparable<UInt> {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -134,10 +135,14 @@ public inline class UInt internal constructor(private val data: Int) : Comparabl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Byte.toUInt(): UInt = UInt(this.toInt() and 0xFF)
|
public fun Byte.toUInt(): UInt = UInt(this.toInt() and 0xFF)
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Short.toUInt(): UInt = UInt(this.toInt() and 0xFFFF)
|
public fun Short.toUInt(): UInt = UInt(this.toInt() and 0xFFFF)
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Int.toUInt(): UInt = UInt(this)
|
public fun Int.toUInt(): UInt = UInt(this)
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Long.toUInt(): UInt = UInt(this.toInt())
|
public fun Long.toUInt(): UInt = UInt(this.toInt())
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public inline class UIntArray
|
public inline class UIntArray
|
||||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
@@ -41,10 +42,12 @@ internal constructor(private val storage: IntArray) : Collection<UInt> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public inline fun UIntArray(size: Int, init: (Int) -> UInt): UIntArray {
|
public inline fun UIntArray(size: Int, init: (Int) -> UInt): UIntArray {
|
||||||
return UIntArray(IntArray(size) { index -> init(index).toInt() })
|
return UIntArray(IntArray(size) { index -> init(index).toInt() })
|
||||||
}
|
}
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
// TODO: @kotlin.internal.InlineOnly
|
// TODO: @kotlin.internal.InlineOnly
|
||||||
public inline fun uintArrayOf(vararg elements: UInt): UIntArray = elements
|
public inline fun uintArrayOf(vararg elements: UInt): UIntArray = elements
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import kotlin.internal.*
|
|||||||
* A range of values of type `UInt`.
|
* A range of values of type `UInt`.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public class UIntRange(start: UInt, endInclusive: UInt) : UIntProgression(start, endInclusive, 1), ClosedRange<UInt> {
|
public class UIntRange(start: UInt, endInclusive: UInt) : UIntProgression(start, endInclusive, 1), ClosedRange<UInt> {
|
||||||
override val start: UInt get() = first
|
override val start: UInt get() = first
|
||||||
override val endInclusive: UInt get() = last
|
override val endInclusive: UInt get() = last
|
||||||
@@ -42,6 +43,7 @@ public class UIntRange(start: UInt, endInclusive: UInt) : UIntProgression(start,
|
|||||||
* A progression of values of type `UInt`.
|
* A progression of values of type `UInt`.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public open class UIntProgression
|
public open class UIntProgression
|
||||||
internal constructor(
|
internal constructor(
|
||||||
start: UInt,
|
start: UInt,
|
||||||
@@ -98,6 +100,7 @@ internal constructor(
|
|||||||
* @property step the number by which the value is incremented on each step.
|
* @property step the number by which the value is incremented on each step.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
private class UIntProgressionIterator(first: UInt, last: UInt, step: Int) : UIntIterator() {
|
private class UIntProgressionIterator(first: UInt, last: UInt, step: Int) : UIntIterator() {
|
||||||
private val finalElement = last
|
private val finalElement = last
|
||||||
private var hasNext: Boolean = if (step > 0) first <= last else first >= last
|
private var hasNext: Boolean = if (step > 0) first <= last else first >= last
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ package kotlin.collections
|
|||||||
|
|
||||||
/** An iterator over a sequence of values of type `UByte`. */
|
/** An iterator over a sequence of values of type `UByte`. */
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public abstract class UByteIterator : Iterator<UByte> {
|
public abstract class UByteIterator : Iterator<UByte> {
|
||||||
override final fun next() = nextUByte()
|
override final fun next() = nextUByte()
|
||||||
|
|
||||||
@@ -18,6 +19,7 @@ public abstract class UByteIterator : Iterator<UByte> {
|
|||||||
|
|
||||||
/** An iterator over a sequence of values of type `UShort`. */
|
/** An iterator over a sequence of values of type `UShort`. */
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public abstract class UShortIterator : Iterator<UShort> {
|
public abstract class UShortIterator : Iterator<UShort> {
|
||||||
override final fun next() = nextUShort()
|
override final fun next() = nextUShort()
|
||||||
|
|
||||||
@@ -27,6 +29,7 @@ public abstract class UShortIterator : Iterator<UShort> {
|
|||||||
|
|
||||||
/** An iterator over a sequence of values of type `UInt`. */
|
/** An iterator over a sequence of values of type `UInt`. */
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public abstract class UIntIterator : Iterator<UInt> {
|
public abstract class UIntIterator : Iterator<UInt> {
|
||||||
override final fun next() = nextUInt()
|
override final fun next() = nextUInt()
|
||||||
|
|
||||||
@@ -36,6 +39,7 @@ public abstract class UIntIterator : Iterator<UInt> {
|
|||||||
|
|
||||||
/** An iterator over a sequence of values of type `ULong`. */
|
/** An iterator over a sequence of values of type `ULong`. */
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public abstract class ULongIterator : Iterator<ULong> {
|
public abstract class ULongIterator : Iterator<ULong> {
|
||||||
override final fun next() = nextULong()
|
override final fun next() = nextULong()
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import kotlin.experimental.*
|
|||||||
|
|
||||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public inline class ULong internal constructor(private val data: Long) : Comparable<ULong> {
|
public inline class ULong internal constructor(private val data: Long) : Comparable<ULong> {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -134,10 +135,14 @@ public inline class ULong internal constructor(private val data: Long) : Compara
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Byte.toULong(): ULong = ULong(this.toLong() and 0xFF)
|
public fun Byte.toULong(): ULong = ULong(this.toLong() and 0xFF)
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Short.toULong(): ULong = ULong(this.toLong() and 0xFFFF)
|
public fun Short.toULong(): ULong = ULong(this.toLong() and 0xFFFF)
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Int.toULong(): ULong = ULong(this.toLong() and 0xFFFF_FFFF)
|
public fun Int.toULong(): ULong = ULong(this.toLong() and 0xFFFF_FFFF)
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Long.toULong(): ULong = ULong(this)
|
public fun Long.toULong(): ULong = ULong(this)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public inline class ULongArray
|
public inline class ULongArray
|
||||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
@@ -41,10 +42,12 @@ internal constructor(private val storage: LongArray) : Collection<ULong> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public inline fun ULongArray(size: Int, init: (Int) -> ULong): ULongArray {
|
public inline fun ULongArray(size: Int, init: (Int) -> ULong): ULongArray {
|
||||||
return ULongArray(LongArray(size) { index -> init(index).toLong() })
|
return ULongArray(LongArray(size) { index -> init(index).toLong() })
|
||||||
}
|
}
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
// TODO: @kotlin.internal.InlineOnly
|
// TODO: @kotlin.internal.InlineOnly
|
||||||
public inline fun ulongArrayOf(vararg elements: ULong): ULongArray = elements
|
public inline fun ulongArrayOf(vararg elements: ULong): ULongArray = elements
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import kotlin.internal.*
|
|||||||
* A range of values of type `ULong`.
|
* A range of values of type `ULong`.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public class ULongRange(start: ULong, endInclusive: ULong) : ULongProgression(start, endInclusive, 1), ClosedRange<ULong> {
|
public class ULongRange(start: ULong, endInclusive: ULong) : ULongProgression(start, endInclusive, 1), ClosedRange<ULong> {
|
||||||
override val start: ULong get() = first
|
override val start: ULong get() = first
|
||||||
override val endInclusive: ULong get() = last
|
override val endInclusive: ULong get() = last
|
||||||
@@ -42,6 +43,7 @@ public class ULongRange(start: ULong, endInclusive: ULong) : ULongProgression(st
|
|||||||
* A progression of values of type `ULong`.
|
* A progression of values of type `ULong`.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public open class ULongProgression
|
public open class ULongProgression
|
||||||
internal constructor(
|
internal constructor(
|
||||||
start: ULong,
|
start: ULong,
|
||||||
@@ -98,6 +100,7 @@ internal constructor(
|
|||||||
* @property step the number by which the value is incremented on each step.
|
* @property step the number by which the value is incremented on each step.
|
||||||
*/
|
*/
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
private class ULongProgressionIterator(first: ULong, last: ULong, step: Long) : ULongIterator() {
|
private class ULongProgressionIterator(first: ULong, last: ULong, step: Long) : ULongIterator() {
|
||||||
private val finalElement = last
|
private val finalElement = last
|
||||||
private var hasNext: Boolean = if (step > 0) first <= last else first >= last
|
private var hasNext: Boolean = if (step > 0) first <= last else first >= last
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import kotlin.experimental.*
|
|||||||
|
|
||||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public inline class UShort internal constructor(private val data: Short) : Comparable<UShort> {
|
public inline class UShort internal constructor(private val data: Short) : Comparable<UShort> {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -130,10 +131,14 @@ public inline class UShort internal constructor(private val data: Short) : Compa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Byte.toUShort(): UShort = UShort(this.toShort() and 0xFF)
|
public fun Byte.toUShort(): UShort = UShort(this.toShort() and 0xFF)
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Short.toUShort(): UShort = UShort(this)
|
public fun Short.toUShort(): UShort = UShort(this)
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Int.toUShort(): UShort = UShort(this.toShort())
|
public fun Int.toUShort(): UShort = UShort(this.toShort())
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public fun Long.toUShort(): UShort = UShort(this.toShort())
|
public fun Long.toUShort(): UShort = UShort(this.toShort())
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public inline class UShortArray
|
public inline class UShortArray
|
||||||
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
@@ -41,10 +42,12 @@ internal constructor(private val storage: ShortArray) : Collection<UShort> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
public inline fun UShortArray(size: Int, init: (Int) -> UShort): UShortArray {
|
public inline fun UShortArray(size: Int, init: (Int) -> UShort): UShortArray {
|
||||||
return UShortArray(ShortArray(size) { index -> init(index).toShort() })
|
return UShortArray(ShortArray(size) { index -> init(index).toShort() })
|
||||||
}
|
}
|
||||||
|
|
||||||
@SinceKotlin("1.3")
|
@SinceKotlin("1.3")
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
// TODO: @kotlin.internal.InlineOnly
|
// TODO: @kotlin.internal.InlineOnly
|
||||||
public inline fun ushortArrayOf(vararg elements: UShort): UShortArray = elements
|
public inline fun ushortArrayOf(vararg elements: UShort): UShortArray = elements
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
||||||
|
package kotlin
|
||||||
|
|
||||||
|
import kotlin.annotation.AnnotationTarget.*
|
||||||
|
import kotlin.internal.RequireKotlin
|
||||||
|
import kotlin.internal.RequireKotlinVersionKind
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks the API that is dependent on the experimental unsigned types, including those types themselves.
|
||||||
|
*
|
||||||
|
* Usages of such API will be reported as warnings unless an explicit opt-in with the [UseExperimental] annotation
|
||||||
|
* or the `-Xuse-experimental=kotlin.ExperimentalUnsignedTypes` compiler option is done.
|
||||||
|
*/
|
||||||
|
@Experimental(level = Experimental.Level.WARNING)
|
||||||
|
@Target(CLASS, ANNOTATION_CLASS, PROPERTY, FIELD, LOCAL_VARIABLE, VALUE_PARAMETER, CONSTRUCTOR, FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER, TYPEALIAS)
|
||||||
|
@Retention(AnnotationRetention.BINARY)
|
||||||
|
@RequireKotlin("1.2.50", versionKind = RequireKotlinVersionKind.COMPILER_VERSION)
|
||||||
|
public annotation class ExperimentalUnsignedTypes
|
||||||
Reference in New Issue
Block a user