Compile unsigned types sourceset with 1.3 and annotate them with SinceKotlin("1.3")

This commit is contained in:
Ilya Gorbunov
2018-06-29 16:08:50 +03:00
parent a72ad8b267
commit 615f57f2fc
15 changed files with 59 additions and 2 deletions
@@ -10,6 +10,7 @@ package kotlin
import kotlin.experimental.*
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
@SinceKotlin("1.3")
public inline class UByte internal constructor(private val data: Byte) : Comparable<UByte> {
companion object {
@@ -128,7 +129,11 @@ public inline class UByte internal constructor(private val data: Byte) : Compara
}
@SinceKotlin("1.3")
public fun Byte.toUByte(): UByte = UByte(this)
@SinceKotlin("1.3")
public fun Short.toUByte(): UByte = UByte(this.toByte())
@SinceKotlin("1.3")
public fun Int.toUByte(): UByte = UByte(this.toByte())
@SinceKotlin("1.3")
public fun Long.toUByte(): UByte = UByte(this.toByte())
@@ -8,6 +8,7 @@
package kotlin
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
@SinceKotlin("1.3")
public inline class UByteArray internal constructor(private val storage: ByteArray) : Collection<UByte> {
/** Returns the array element at the given [index]. This method can be called using the index operator. */
@@ -37,11 +38,13 @@ public inline class UByteArray internal constructor(private val storage: ByteArr
override fun isEmpty(): Boolean = this.storage.size == 0
}
@SinceKotlin("1.3")
public /*inline*/ fun UByteArray(size: Int, init: (Int) -> UByte): UByteArray {
return UByteArray(ByteArray(size) { index -> init(index).toByte() })
}
@Suppress("FORBIDDEN_VARARG_PARAMETER_TYPE")
@SinceKotlin("1.3")
public fun ubyteArrayOf(vararg elements: UByte): UByteArray {
return UByteArray(elements.size) { index -> elements[index] }
}
@@ -10,6 +10,7 @@ package kotlin
import kotlin.experimental.*
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
@SinceKotlin("1.3")
public inline class UInt internal constructor(private val data: Int) : Comparable<UInt> {
companion object {
@@ -132,7 +133,11 @@ public inline class UInt internal constructor(private val data: Int) : Comparabl
}
@SinceKotlin("1.3")
public fun Byte.toUInt(): UInt = UInt(this.toInt() and 0xFF)
@SinceKotlin("1.3")
public fun Short.toUInt(): UInt = UInt(this.toInt() and 0xFFFF)
@SinceKotlin("1.3")
public fun Int.toUInt(): UInt = UInt(this)
@SinceKotlin("1.3")
public fun Long.toUInt(): UInt = UInt(this.toInt())
@@ -8,6 +8,7 @@
package kotlin
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
@SinceKotlin("1.3")
public inline class UIntArray internal constructor(private val storage: IntArray) : Collection<UInt> {
/** Returns the array element at the given [index]. This method can be called using the index operator. */
@@ -37,11 +38,13 @@ public inline class UIntArray internal constructor(private val storage: IntArray
override fun isEmpty(): Boolean = this.storage.size == 0
}
@SinceKotlin("1.3")
public /*inline*/ fun UIntArray(size: Int, init: (Int) -> UInt): UIntArray {
return UIntArray(IntArray(size) { index -> init(index).toInt() })
}
@Suppress("FORBIDDEN_VARARG_PARAMETER_TYPE")
@SinceKotlin("1.3")
public fun uintArrayOf(vararg elements: UInt): UIntArray {
return UIntArray(elements.size) { index -> elements[index] }
}
@@ -14,6 +14,7 @@ import kotlin.internal.*
/**
* A range of values of type `UInt`.
*/
@SinceKotlin("1.3")
public class UIntRange(start: UInt, endInclusive: UInt) : UIntProgression(start, endInclusive, 1), ClosedRange<UInt> {
override val start: UInt get() = first
override val endInclusive: UInt get() = last
@@ -40,6 +41,7 @@ public class UIntRange(start: UInt, endInclusive: UInt) : UIntProgression(start,
/**
* A progression of values of type `UInt`.
*/
@SinceKotlin("1.3")
public open class UIntProgression
internal constructor(
start: UInt,
@@ -95,6 +97,7 @@ internal constructor(
* An iterator over a progression of values of type `UInt`.
* @property step the number by which the value is incremented on each step.
*/
@SinceKotlin("1.3")
private class UIntProgressionIterator(first: UInt, last: UInt, step: Int) : UIntIterator() {
private val finalElement = last
private var hasNext: Boolean = if (step > 0) first <= last else first >= last
@@ -8,6 +8,7 @@
package kotlin.collections
/** An iterator over a sequence of values of type `UByte`. */
@SinceKotlin("1.3")
public abstract class UByteIterator : Iterator<UByte> {
override final fun next() = nextUByte()
@@ -16,6 +17,7 @@ public abstract class UByteIterator : Iterator<UByte> {
}
/** An iterator over a sequence of values of type `UShort`. */
@SinceKotlin("1.3")
public abstract class UShortIterator : Iterator<UShort> {
override final fun next() = nextUShort()
@@ -24,6 +26,7 @@ public abstract class UShortIterator : Iterator<UShort> {
}
/** An iterator over a sequence of values of type `UInt`. */
@SinceKotlin("1.3")
public abstract class UIntIterator : Iterator<UInt> {
override final fun next() = nextUInt()
@@ -32,6 +35,7 @@ public abstract class UIntIterator : Iterator<UInt> {
}
/** An iterator over a sequence of values of type `ULong`. */
@SinceKotlin("1.3")
public abstract class ULongIterator : Iterator<ULong> {
override final fun next() = nextULong()
@@ -10,6 +10,7 @@ package kotlin
import kotlin.experimental.*
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
@SinceKotlin("1.3")
public inline class ULong internal constructor(private val data: Long) : Comparable<ULong> {
companion object {
@@ -132,7 +133,11 @@ public inline class ULong internal constructor(private val data: Long) : Compara
}
@SinceKotlin("1.3")
public fun Byte.toULong(): ULong = ULong(this.toLong() and 0xFF)
@SinceKotlin("1.3")
public fun Short.toULong(): ULong = ULong(this.toLong() and 0xFFFF)
@SinceKotlin("1.3")
public fun Int.toULong(): ULong = ULong(this.toLong() and 0xFFFF_FFFF)
@SinceKotlin("1.3")
public fun Long.toULong(): ULong = ULong(this)
@@ -8,6 +8,7 @@
package kotlin
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
@SinceKotlin("1.3")
public inline class ULongArray internal constructor(private val storage: LongArray) : Collection<ULong> {
/** Returns the array element at the given [index]. This method can be called using the index operator. */
@@ -37,11 +38,13 @@ public inline class ULongArray internal constructor(private val storage: LongArr
override fun isEmpty(): Boolean = this.storage.size == 0
}
@SinceKotlin("1.3")
public /*inline*/ fun ULongArray(size: Int, init: (Int) -> ULong): ULongArray {
return ULongArray(LongArray(size) { index -> init(index).toLong() })
}
@Suppress("FORBIDDEN_VARARG_PARAMETER_TYPE")
@SinceKotlin("1.3")
public fun ulongArrayOf(vararg elements: ULong): ULongArray {
return ULongArray(elements.size) { index -> elements[index] }
}
@@ -14,6 +14,7 @@ import kotlin.internal.*
/**
* A range of values of type `ULong`.
*/
@SinceKotlin("1.3")
public class ULongRange(start: ULong, endInclusive: ULong) : ULongProgression(start, endInclusive, 1), ClosedRange<ULong> {
override val start: ULong get() = first
override val endInclusive: ULong get() = last
@@ -40,6 +41,7 @@ public class ULongRange(start: ULong, endInclusive: ULong) : ULongProgression(st
/**
* A progression of values of type `ULong`.
*/
@SinceKotlin("1.3")
public open class ULongProgression
internal constructor(
start: ULong,
@@ -95,6 +97,7 @@ internal constructor(
* An iterator over a progression of values of type `ULong`.
* @property step the number by which the value is incremented on each step.
*/
@SinceKotlin("1.3")
private class ULongProgressionIterator(first: ULong, last: ULong, step: Long) : ULongIterator() {
private val finalElement = last
private var hasNext: Boolean = if (step > 0) first <= last else first >= last
@@ -35,6 +35,7 @@ private fun differenceModulo(a: ULong, b: ULong, c: ULong): ULong {
* @suppress
*/
@PublishedApi
@SinceKotlin("1.3")
internal fun getProgressionLastElement(start: UInt, end: UInt, step: Int): UInt = when {
step > 0 -> if (start >= end) end else end - differenceModulo(end, start, step.toUInt())
step < 0 -> if (start <= end) end else end + differenceModulo(start, end, (-step).toUInt())
@@ -58,6 +59,7 @@ internal fun getProgressionLastElement(start: UInt, end: UInt, step: Int): UInt
* @suppress
*/
@PublishedApi
@SinceKotlin("1.3")
internal fun getProgressionLastElement(start: ULong, end: ULong, step: Long): ULong = when {
step > 0 -> if (start >= end) end else end - differenceModulo(end, start, step.toULong())
step < 0 -> if (start <= end) end else end + differenceModulo(start, end, (-step).toULong())
@@ -10,6 +10,7 @@ package kotlin
import kotlin.experimental.*
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
@SinceKotlin("1.3")
public inline class UShort internal constructor(private val data: Short) : Comparable<UShort> {
companion object {
@@ -128,7 +129,11 @@ public inline class UShort internal constructor(private val data: Short) : Compa
}
@SinceKotlin("1.3")
public fun Byte.toUShort(): UShort = UShort(this.toShort() and 0xFF)
@SinceKotlin("1.3")
public fun Short.toUShort(): UShort = UShort(this)
@SinceKotlin("1.3")
public fun Int.toUShort(): UShort = UShort(this.toShort())
@SinceKotlin("1.3")
public fun Long.toUShort(): UShort = UShort(this.toShort())
@@ -8,6 +8,7 @@
package kotlin
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
@SinceKotlin("1.3")
public inline class UShortArray internal constructor(private val storage: ShortArray) : Collection<UShort> {
/** Returns the array element at the given [index]. This method can be called using the index operator. */
@@ -37,11 +38,13 @@ public inline class UShortArray internal constructor(private val storage: ShortA
override fun isEmpty(): Boolean = this.storage.size == 0
}
@SinceKotlin("1.3")
public /*inline*/ fun UShortArray(size: Int, init: (Int) -> UShort): UShortArray {
return UShortArray(ShortArray(size) { index -> init(index).toShort() })
}
@Suppress("FORBIDDEN_VARARG_PARAMETER_TYPE")
@SinceKotlin("1.3")
public fun ushortArrayOf(vararg elements: UShort): UShortArray {
return UShortArray(elements.size) { index -> elements[index] }
}