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
+11 -2
View File
@@ -42,6 +42,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
out.println()
out.println("@Suppress(\"NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS\")")
out.println("@SinceKotlin(\"1.3\")")
out.println("public inline class $className internal constructor(private val data: $storageType) : Comparable<$className> {")
out.println()
out.println(""" companion object {
@@ -196,6 +197,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
for (otherType in UnsignedType.values()) {
val otherSigned = otherType.asSigned.capitalized
val thisSigned = type.asSigned.capitalized
out.println("@SinceKotlin(\"1.3\")")
out.print("public fun $otherSigned.to$className(): $className = ")
out.println(when {
otherType < type -> "$className(this.to$thisSigned() and ${otherType.mask})"
@@ -238,6 +240,7 @@ class UnsignedIteratorsGenerator(out: PrintWriter) : BuiltInsSourceGenerator(out
for (type in UnsignedType.values()) {
val s = type.capitalized
out.println("/** An iterator over a sequence of values of type `$s`. */")
out.println("@SinceKotlin(\"1.3\")")
out.println("public abstract class ${s}Iterator : Iterator<$s> {")
// TODO: Sort modifiers
out.println(" override final fun next() = next$s()")
@@ -258,6 +261,7 @@ class UnsignedArrayGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIn
val storageArrayType = storageElementType + "Array"
override fun generateBody() {
out.println("@Suppress(\"NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS\")")
out.println("@SinceKotlin(\"1.3\")")
out.println("public inline class $arrayType internal constructor(private val storage: $storageArrayType) : Collection<$elementType> {")
out.println(
"""
@@ -290,12 +294,14 @@ class UnsignedArrayGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIn
out.println("}")
out.println("""
public /*inline*/ fun $arrayType(size: Int, init: (Int) -> $elementType): $arrayType {
out.println()
out.println("@SinceKotlin(\"1.3\")")
out.println("""public /*inline*/ fun $arrayType(size: Int, init: (Int) -> $elementType): $arrayType {
return $arrayType($storageArrayType(size) { index -> init(index).to$storageElementType() })
}
@Suppress("FORBIDDEN_VARARG_PARAMETER_TYPE")
@SinceKotlin("1.3")
public fun $arrayTypeOf(vararg elements: $elementType): $arrayType {
return $arrayType(elements.size) { index -> elements[index] }
}"""
@@ -322,6 +328,7 @@ import kotlin.internal.*
/**
* A range of values of type `$elementType`.
*/
@SinceKotlin("1.3")
public class ${elementType}Range(start: $elementType, endInclusive: $elementType) : ${elementType}Progression(start, endInclusive, 1), ClosedRange<${elementType}> {
override val start: $elementType get() = first
override val endInclusive: $elementType get() = last
@@ -348,6 +355,7 @@ public class ${elementType}Range(start: $elementType, endInclusive: $elementType
/**
* A progression of values of type `$elementType`.
*/
@SinceKotlin("1.3")
public open class ${elementType}Progression
internal constructor(
start: $elementType,
@@ -403,6 +411,7 @@ internal constructor(
* An iterator over a progression of values of type `$elementType`.
* @property step the number by which the value is incremented on each step.
*/
@SinceKotlin("1.3")
private class ${elementType}ProgressionIterator(first: $elementType, last: $elementType, step: $stepType) : ${elementType}Iterator() {
private val finalElement = last
private var hasNext: Boolean = if (step > 0) first <= last else first >= last
+2
View File
@@ -64,6 +64,8 @@ compileKotlinCommon {
compileUnsignedKotlinCommon {
kotlinOptions {
languageVersion = "1.3"
apiVersion = "1.3"
freeCompilerArgs += [
"-XXLanguage:+InlineClasses"
]
+2
View File
@@ -209,6 +209,8 @@ compileCoroutinesKotlin {
compileUnsignedKotlin {
kotlinOptions {
languageVersion = "1.3"
apiVersion = "1.3"
freeCompilerArgs += [
"-XXLanguage:+InlineClasses"
]
@@ -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] }
}