rangeUntil member operator in builtins #KT-52933

This commit is contained in:
Ilya Gorbunov
2022-08-11 00:41:04 +02:00
committed by Space
parent ec9c862034
commit 203a00151d
23 changed files with 1109 additions and 97 deletions
+11 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -63,6 +63,16 @@ public class Char private constructor(public val value: Char) : Comparable<Char>
public operator fun rangeTo(other: Char): CharRange =
CharRange(this, other)
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Char): CharRange =
this until other
/** Returns the value of this character as a `Byte`. */
public inline fun toByte(): Byte =
this.toInt().toByte()
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* 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(
@@ -233,6 +233,62 @@ public class Byte private constructor(public val value: Byte) : Number(), Compar
public inline operator fun unaryMinus(): Int =
-this.toInt()
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Byte): IntRange {
return IntRange(this.toInt(), other.toInt())
}
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Short): IntRange {
return IntRange(this.toInt(), other.toInt())
}
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Int): IntRange {
return IntRange(this.toInt(), other.toInt())
}
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Long): LongRange {
return LongRange(this.toLong(), other.toLong())
}
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Byte): IntRange = this until other
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Short): IntRange = this until other
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Int): IntRange = this until other
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Long): LongRange = this until other
/** Returns this value. */
public override inline fun toByte(): Byte =
this
@@ -291,26 +347,6 @@ public class Byte private constructor(public val value: Byte) : Number(), Compar
*/
public override fun toDouble(): Double = wasm_f64_convert_i32_s(this.toInt())
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Byte): IntRange {
return IntRange(this.toInt(), other.toInt())
}
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Short): IntRange {
return IntRange(this.toInt(), other.toInt())
}
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Int): IntRange {
return IntRange(this.toInt(), other.toInt())
}
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Long): LongRange {
return LongRange(this.toLong(), other.toLong())
}
/** Performs a bitwise AND operation between the two values. */
@SinceKotlin("1.1")
@WasmOp(WasmOp.I32_AND)
@@ -593,6 +629,42 @@ public class Short private constructor(public val value: Short) : Number(), Comp
return LongRange(this.toLong(), other)
}
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Byte): IntRange = this until other
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Short): IntRange = this until other
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Int): IntRange = this until other
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Long): LongRange = this until other
/** Performs a bitwise AND operation between the two values. */
@SinceKotlin("1.1")
@WasmOp(WasmOp.I32_AND)
@@ -917,6 +989,62 @@ public class Int private constructor(val value: Int) : Number(), Comparable<Int>
/** Returns the negative of this value. */
public inline operator fun unaryMinus(): Int = 0 - this
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Byte): IntRange {
return IntRange(this, other.toInt())
}
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Short): IntRange {
return IntRange(this, other.toInt())
}
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Int): IntRange {
return IntRange(this, other.toInt())
}
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Long): LongRange {
return LongRange(this.toLong(), other.toLong())
}
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Byte): IntRange = this until other
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Short): IntRange = this until other
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Int): IntRange = this until other
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Long): LongRange = this until other
/**
* Shifts this value left by the [bitCount] number of bits.
*
@@ -966,26 +1094,6 @@ public class Int private constructor(val value: Int) : Number(), Comparable<Int>
public inline fun inv(): Int =
this.xor(-1)
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Byte): IntRange {
return IntRange(this, other.toInt())
}
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Short): IntRange {
return IntRange(this, other.toInt())
}
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Int): IntRange {
return IntRange(this, other.toInt())
}
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Long): LongRange {
return LongRange(this.toLong(), other.toLong())
}
/**
* Converts this [Int] value to [Byte].
*
@@ -1330,6 +1438,42 @@ public class Long private constructor(val value: Long) : Number(), Comparable<Lo
return LongRange(this, other.toLong())
}
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Byte): LongRange = this until other
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Short): LongRange = this until other
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Int): LongRange = this until other
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.7")
@ExperimentalStdlibApi
public operator fun rangeUntil(other: Long): LongRange = this until other
/**
* Shifts this value left by the [bitCount] number of bits.
*