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("@SinceKotlin(\"1.3\")")
|
||||
out.println("@ExperimentalUnsignedTypes")
|
||||
out.println("public inline class $className internal constructor(private val data: $storageType) : Comparable<$className> {")
|
||||
out.println()
|
||||
out.println(""" companion object {
|
||||
@@ -198,6 +199,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
|
||||
val otherSigned = otherType.asSigned.capitalized
|
||||
val thisSigned = type.asSigned.capitalized
|
||||
out.println("@SinceKotlin(\"1.3\")")
|
||||
out.println("@ExperimentalUnsignedTypes")
|
||||
out.print("public fun $otherSigned.to$className(): $className = ")
|
||||
out.println(when {
|
||||
otherType < type -> "$className(this.to$thisSigned() and ${otherType.mask})"
|
||||
@@ -241,6 +243,7 @@ class UnsignedIteratorsGenerator(out: PrintWriter) : BuiltInsSourceGenerator(out
|
||||
val s = type.capitalized
|
||||
out.println("/** An iterator over a sequence of values of type `$s`. */")
|
||||
out.println("@SinceKotlin(\"1.3\")")
|
||||
out.println("@ExperimentalUnsignedTypes")
|
||||
out.println("public abstract class ${s}Iterator : Iterator<$s> {")
|
||||
// TODO: Sort modifiers
|
||||
out.println(" override final fun next() = next$s()")
|
||||
@@ -261,6 +264,7 @@ class UnsignedArrayGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIn
|
||||
val storageArrayType = storageElementType + "Array"
|
||||
override fun generateBody() {
|
||||
out.println("@SinceKotlin(\"1.3\")")
|
||||
out.println("@ExperimentalUnsignedTypes")
|
||||
out.println("public inline class $arrayType")
|
||||
out.println("@Suppress(\"NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS\")")
|
||||
out.println("@PublishedApi")
|
||||
@@ -299,11 +303,13 @@ class UnsignedArrayGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIn
|
||||
// TODO: Make inline constructor, like in ByteArray
|
||||
out.println()
|
||||
out.println("@SinceKotlin(\"1.3\")")
|
||||
out.println("@ExperimentalUnsignedTypes")
|
||||
out.println("""public inline fun $arrayType(size: Int, init: (Int) -> $elementType): $arrayType {
|
||||
return $arrayType($storageArrayType(size) { index -> init(index).to$storageElementType() })
|
||||
}
|
||||
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
// TODO: @kotlin.internal.InlineOnly
|
||||
public inline fun $arrayTypeOf(vararg elements: $elementType): $arrayType = elements"""
|
||||
)
|
||||
@@ -330,6 +336,7 @@ import kotlin.internal.*
|
||||
* A range of values of type `$elementType`.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
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
|
||||
@@ -357,6 +364,7 @@ public class ${elementType}Range(start: $elementType, endInclusive: $elementType
|
||||
* A progression of values of type `$elementType`.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
public open class ${elementType}Progression
|
||||
internal constructor(
|
||||
start: $elementType,
|
||||
@@ -413,6 +421,7 @@ internal constructor(
|
||||
* @property step the number by which the value is incremented on each step.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalUnsignedTypes
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user