From d28ecc231656e63a021a054dbc1aff2e928f475c Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Tue, 29 Sep 2015 19:22:33 +0300 Subject: [PATCH] Mark builtins and stdlib functions with 'infix' --- core/builtins/native/kotlin/Boolean.kt | 6 +- core/builtins/native/kotlin/Primitives.kt | 24 ++-- .../kotlin/generators/builtins/primitives.kt | 4 +- libraries/stdlib/src/generated/_Ranges.kt | 136 +++++++++--------- libraries/stdlib/src/kotlin/util/Tuples.kt | 2 +- .../kotlin-stdlib-gen/src/templates/Engine.kt | 3 + .../kotlin-stdlib-gen/src/templates/Ranges.kt | 6 + 7 files changed, 95 insertions(+), 86 deletions(-) diff --git a/core/builtins/native/kotlin/Boolean.kt b/core/builtins/native/kotlin/Boolean.kt index 578f2770cad..0e6b2dd52ab 100644 --- a/core/builtins/native/kotlin/Boolean.kt +++ b/core/builtins/native/kotlin/Boolean.kt @@ -29,17 +29,17 @@ public class Boolean private () : Comparable { /** * Performs a logical `and` operation between this Boolean and the [other] one. */ - public fun and(other: Boolean): Boolean + public infix fun and(other: Boolean): Boolean /** * Performs a logical `or` operation between this Boolean and the [other] one. */ - public fun or(other: Boolean): Boolean + public infix fun or(other: Boolean): Boolean /** * Performs a logical `xor` operation between this Boolean and the [other] one. */ - public fun xor(other: Boolean): Boolean + public infix fun xor(other: Boolean): Boolean public override fun compareTo(other: Boolean): Int } diff --git a/core/builtins/native/kotlin/Primitives.kt b/core/builtins/native/kotlin/Primitives.kt index 5b1e542de7b..ececdf90ec8 100644 --- a/core/builtins/native/kotlin/Primitives.kt +++ b/core/builtins/native/kotlin/Primitives.kt @@ -430,17 +430,17 @@ public class Int private () : Number, Comparable { public operator fun rangeTo(other: Double): DoubleRange /** Shifts this value left by [bits]. */ - public fun shl(bits: Int): Int + public infix fun shl(bits: Int): Int /** Shifts this value right by [bits], filling the leftmost bits with copies of the sign bit. */ - public fun shr(bits: Int): Int + public infix fun shr(bits: Int): Int /** Shifts this value right by [bits], filling the leftmost bits with zeros. */ - public fun ushr(bits: Int): Int + public infix fun ushr(bits: Int): Int /** Performs a bitwise AND operation between the two values. */ - public fun and(other: Int): Int + public infix fun and(other: Int): Int /** Performs a bitwise OR operation between the two values. */ - public fun or(other: Int): Int + public infix fun or(other: Int): Int /** Performs a bitwise XOR operation between the two values. */ - public fun xor(other: Int): Int + public infix fun xor(other: Int): Int /** Inverts the bits in this value/ */ public fun inv(): Int @@ -585,17 +585,17 @@ public class Long private () : Number, Comparable { public operator fun rangeTo(other: Double): DoubleRange /** Shifts this value left by [bits]. */ - public fun shl(bits: Int): Long + public infix fun shl(bits: Int): Long /** Shifts this value right by [bits], filling the leftmost bits with copies of the sign bit. */ - public fun shr(bits: Int): Long + public infix fun shr(bits: Int): Long /** Shifts this value right by [bits], filling the leftmost bits with zeros. */ - public fun ushr(bits: Int): Long + public infix fun ushr(bits: Int): Long /** Performs a bitwise AND operation between the two values. */ - public fun and(other: Long): Long + public infix fun and(other: Long): Long /** Performs a bitwise OR operation between the two values. */ - public fun or(other: Long): Long + public infix fun or(other: Long): Long /** Performs a bitwise XOR operation between the two values. */ - public fun xor(other: Long): Long + public infix fun xor(other: Long): Long /** Inverts the bits in this value/ */ public fun inv(): Long diff --git a/generators/src/org/jetbrains/kotlin/generators/builtins/primitives.kt b/generators/src/org/jetbrains/kotlin/generators/builtins/primitives.kt index 879584eabb6..7e86902a42c 100644 --- a/generators/src/org/jetbrains/kotlin/generators/builtins/primitives.kt +++ b/generators/src/org/jetbrains/kotlin/generators/builtins/primitives.kt @@ -141,11 +141,11 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { private fun generateBitwiseOperators(className: String) { for ((name, doc) in shiftOperators) { out.println(" /** $doc */") - out.println(" public fun $name(bits: Int): $className") + out.println(" public infix fun $name(bits: Int): $className") } for ((name, doc) in bitwiseOperators) { out.println(" /** $doc */") - out.println(" public fun $name(other: $className): $className") + out.println(" public infix fun $name(other: $className): $className") } out.println(" /** Inverts the bits in this value/ */") out.println(" public fun inv(): $className") diff --git a/libraries/stdlib/src/generated/_Ranges.kt b/libraries/stdlib/src/generated/_Ranges.kt index a16323c22a7..a12f48200ee 100644 --- a/libraries/stdlib/src/generated/_Ranges.kt +++ b/libraries/stdlib/src/generated/_Ranges.kt @@ -316,7 +316,7 @@ public operator fun CharRange.contains(item: Short): Nothing { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Int.downTo(to: Byte): IntProgression { +public infix fun Int.downTo(to: Byte): IntProgression { return IntProgression(this, to.toInt(), -1) } @@ -324,7 +324,7 @@ public fun Int.downTo(to: Byte): IntProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Long.downTo(to: Byte): LongProgression { +public infix fun Long.downTo(to: Byte): LongProgression { return LongProgression(this, to.toLong(), -1L) } @@ -332,7 +332,7 @@ public fun Long.downTo(to: Byte): LongProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Byte.downTo(to: Byte): ByteProgression { +public infix fun Byte.downTo(to: Byte): ByteProgression { return ByteProgression(this, to, -1) } @@ -340,7 +340,7 @@ public fun Byte.downTo(to: Byte): ByteProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Short.downTo(to: Byte): ShortProgression { +public infix fun Short.downTo(to: Byte): ShortProgression { return ShortProgression(this, to.toShort(), -1) } @@ -348,7 +348,7 @@ public fun Short.downTo(to: Byte): ShortProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Double.downTo(to: Byte): DoubleProgression { +public infix fun Double.downTo(to: Byte): DoubleProgression { return DoubleProgression(this, to.toDouble(), -1.0) } @@ -356,7 +356,7 @@ public fun Double.downTo(to: Byte): DoubleProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Float.downTo(to: Byte): FloatProgression { +public infix fun Float.downTo(to: Byte): FloatProgression { return FloatProgression(this, to.toFloat(), -1.0F) } @@ -364,7 +364,7 @@ public fun Float.downTo(to: Byte): FloatProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Char.downTo(to: Char): CharProgression { +public infix fun Char.downTo(to: Char): CharProgression { return CharProgression(this, to, -1) } @@ -372,7 +372,7 @@ public fun Char.downTo(to: Char): CharProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Int.downTo(to: Double): DoubleProgression { +public infix fun Int.downTo(to: Double): DoubleProgression { return DoubleProgression(this.toDouble(), to, -1.0) } @@ -380,7 +380,7 @@ public fun Int.downTo(to: Double): DoubleProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Long.downTo(to: Double): DoubleProgression { +public infix fun Long.downTo(to: Double): DoubleProgression { return DoubleProgression(this.toDouble(), to, -1.0) } @@ -388,7 +388,7 @@ public fun Long.downTo(to: Double): DoubleProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Byte.downTo(to: Double): DoubleProgression { +public infix fun Byte.downTo(to: Double): DoubleProgression { return DoubleProgression(this.toDouble(), to, -1.0) } @@ -396,7 +396,7 @@ public fun Byte.downTo(to: Double): DoubleProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Short.downTo(to: Double): DoubleProgression { +public infix fun Short.downTo(to: Double): DoubleProgression { return DoubleProgression(this.toDouble(), to, -1.0) } @@ -404,7 +404,7 @@ public fun Short.downTo(to: Double): DoubleProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Double.downTo(to: Double): DoubleProgression { +public infix fun Double.downTo(to: Double): DoubleProgression { return DoubleProgression(this, to, -1.0) } @@ -412,7 +412,7 @@ public fun Double.downTo(to: Double): DoubleProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Float.downTo(to: Double): DoubleProgression { +public infix fun Float.downTo(to: Double): DoubleProgression { return DoubleProgression(this.toDouble(), to, -1.0) } @@ -420,7 +420,7 @@ public fun Float.downTo(to: Double): DoubleProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Int.downTo(to: Float): FloatProgression { +public infix fun Int.downTo(to: Float): FloatProgression { return FloatProgression(this.toFloat(), to, -1.0F) } @@ -428,7 +428,7 @@ public fun Int.downTo(to: Float): FloatProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Long.downTo(to: Float): FloatProgression { +public infix fun Long.downTo(to: Float): FloatProgression { return FloatProgression(this.toFloat(), to, -1.0F) } @@ -436,7 +436,7 @@ public fun Long.downTo(to: Float): FloatProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Byte.downTo(to: Float): FloatProgression { +public infix fun Byte.downTo(to: Float): FloatProgression { return FloatProgression(this.toFloat(), to, -1.0F) } @@ -444,7 +444,7 @@ public fun Byte.downTo(to: Float): FloatProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Short.downTo(to: Float): FloatProgression { +public infix fun Short.downTo(to: Float): FloatProgression { return FloatProgression(this.toFloat(), to, -1.0F) } @@ -452,7 +452,7 @@ public fun Short.downTo(to: Float): FloatProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Double.downTo(to: Float): DoubleProgression { +public infix fun Double.downTo(to: Float): DoubleProgression { return DoubleProgression(this, to.toDouble(), -1.0) } @@ -460,7 +460,7 @@ public fun Double.downTo(to: Float): DoubleProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Float.downTo(to: Float): FloatProgression { +public infix fun Float.downTo(to: Float): FloatProgression { return FloatProgression(this, to, -1.0F) } @@ -468,7 +468,7 @@ public fun Float.downTo(to: Float): FloatProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Int.downTo(to: Int): IntProgression { +public infix fun Int.downTo(to: Int): IntProgression { return IntProgression(this, to, -1) } @@ -476,7 +476,7 @@ public fun Int.downTo(to: Int): IntProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Long.downTo(to: Int): LongProgression { +public infix fun Long.downTo(to: Int): LongProgression { return LongProgression(this, to.toLong(), -1L) } @@ -484,7 +484,7 @@ public fun Long.downTo(to: Int): LongProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Byte.downTo(to: Int): IntProgression { +public infix fun Byte.downTo(to: Int): IntProgression { return IntProgression(this.toInt(), to, -1) } @@ -492,7 +492,7 @@ public fun Byte.downTo(to: Int): IntProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Short.downTo(to: Int): IntProgression { +public infix fun Short.downTo(to: Int): IntProgression { return IntProgression(this.toInt(), to, -1) } @@ -500,7 +500,7 @@ public fun Short.downTo(to: Int): IntProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Double.downTo(to: Int): DoubleProgression { +public infix fun Double.downTo(to: Int): DoubleProgression { return DoubleProgression(this, to.toDouble(), -1.0) } @@ -508,7 +508,7 @@ public fun Double.downTo(to: Int): DoubleProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Float.downTo(to: Int): FloatProgression { +public infix fun Float.downTo(to: Int): FloatProgression { return FloatProgression(this, to.toFloat(), -1.0F) } @@ -516,7 +516,7 @@ public fun Float.downTo(to: Int): FloatProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Int.downTo(to: Long): LongProgression { +public infix fun Int.downTo(to: Long): LongProgression { return LongProgression(this.toLong(), to, -1L) } @@ -524,7 +524,7 @@ public fun Int.downTo(to: Long): LongProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Long.downTo(to: Long): LongProgression { +public infix fun Long.downTo(to: Long): LongProgression { return LongProgression(this, to, -1L) } @@ -532,7 +532,7 @@ public fun Long.downTo(to: Long): LongProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Byte.downTo(to: Long): LongProgression { +public infix fun Byte.downTo(to: Long): LongProgression { return LongProgression(this.toLong(), to, -1L) } @@ -540,7 +540,7 @@ public fun Byte.downTo(to: Long): LongProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Short.downTo(to: Long): LongProgression { +public infix fun Short.downTo(to: Long): LongProgression { return LongProgression(this.toLong(), to, -1L) } @@ -548,7 +548,7 @@ public fun Short.downTo(to: Long): LongProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Double.downTo(to: Long): DoubleProgression { +public infix fun Double.downTo(to: Long): DoubleProgression { return DoubleProgression(this, to.toDouble(), -1.0) } @@ -556,7 +556,7 @@ public fun Double.downTo(to: Long): DoubleProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Float.downTo(to: Long): FloatProgression { +public infix fun Float.downTo(to: Long): FloatProgression { return FloatProgression(this, to.toFloat(), -1.0F) } @@ -564,7 +564,7 @@ public fun Float.downTo(to: Long): FloatProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Int.downTo(to: Short): IntProgression { +public infix fun Int.downTo(to: Short): IntProgression { return IntProgression(this, to.toInt(), -1) } @@ -572,7 +572,7 @@ public fun Int.downTo(to: Short): IntProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Long.downTo(to: Short): LongProgression { +public infix fun Long.downTo(to: Short): LongProgression { return LongProgression(this, to.toLong(), -1L) } @@ -580,7 +580,7 @@ public fun Long.downTo(to: Short): LongProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Byte.downTo(to: Short): ShortProgression { +public infix fun Byte.downTo(to: Short): ShortProgression { return ShortProgression(this.toShort(), to, -1) } @@ -588,7 +588,7 @@ public fun Byte.downTo(to: Short): ShortProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Short.downTo(to: Short): ShortProgression { +public infix fun Short.downTo(to: Short): ShortProgression { return ShortProgression(this, to, -1) } @@ -596,7 +596,7 @@ public fun Short.downTo(to: Short): ShortProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Double.downTo(to: Short): DoubleProgression { +public infix fun Double.downTo(to: Short): DoubleProgression { return DoubleProgression(this, to.toDouble(), -1.0) } @@ -604,7 +604,7 @@ public fun Double.downTo(to: Short): DoubleProgression { * Returns a progression from this value down to the specified [to] value with the increment -1. * The [to] value has to be less than this value. */ -public fun Float.downTo(to: Short): FloatProgression { +public infix fun Float.downTo(to: Short): FloatProgression { return FloatProgression(this, to.toFloat(), -1.0F) } @@ -709,7 +709,7 @@ public fun ShortRange.reversed(): ShortProgression { /** * Returns a progression that goes over the same range with the given step. */ -public fun ByteProgression.step(step: Int): ByteProgression { +public infix fun ByteProgression.step(step: Int): ByteProgression { checkStepIsPositive(step > 0, step) return ByteProgression(start, end, if (increment > 0) step else -step) } @@ -717,7 +717,7 @@ public fun ByteProgression.step(step: Int): ByteProgression { /** * Returns a progression that goes over the same range with the given step. */ -public fun CharProgression.step(step: Int): CharProgression { +public infix fun CharProgression.step(step: Int): CharProgression { checkStepIsPositive(step > 0, step) return CharProgression(start, end, if (increment > 0) step else -step) } @@ -725,7 +725,7 @@ public fun CharProgression.step(step: Int): CharProgression { /** * Returns a progression that goes over the same range with the given step. */ -public fun DoubleProgression.step(step: Double): DoubleProgression { +public infix fun DoubleProgression.step(step: Double): DoubleProgression { checkStepIsPositive(step > 0, step) return DoubleProgression(start, end, if (increment > 0) step else -step) } @@ -733,7 +733,7 @@ public fun DoubleProgression.step(step: Double): DoubleProgression { /** * Returns a progression that goes over the same range with the given step. */ -public fun FloatProgression.step(step: Float): FloatProgression { +public infix fun FloatProgression.step(step: Float): FloatProgression { checkStepIsPositive(step > 0, step) return FloatProgression(start, end, if (increment > 0) step else -step) } @@ -741,7 +741,7 @@ public fun FloatProgression.step(step: Float): FloatProgression { /** * Returns a progression that goes over the same range with the given step. */ -public fun IntProgression.step(step: Int): IntProgression { +public infix fun IntProgression.step(step: Int): IntProgression { checkStepIsPositive(step > 0, step) return IntProgression(start, end, if (increment > 0) step else -step) } @@ -749,7 +749,7 @@ public fun IntProgression.step(step: Int): IntProgression { /** * Returns a progression that goes over the same range with the given step. */ -public fun LongProgression.step(step: Long): LongProgression { +public infix fun LongProgression.step(step: Long): LongProgression { checkStepIsPositive(step > 0, step) return LongProgression(start, end, if (increment > 0) step else -step) } @@ -757,7 +757,7 @@ public fun LongProgression.step(step: Long): LongProgression { /** * Returns a progression that goes over the same range with the given step. */ -public fun ShortProgression.step(step: Int): ShortProgression { +public infix fun ShortProgression.step(step: Int): ShortProgression { checkStepIsPositive(step > 0, step) return ShortProgression(start, end, if (increment > 0) step else -step) } @@ -765,7 +765,7 @@ public fun ShortProgression.step(step: Int): ShortProgression { /** * Returns a progression that goes over this range with given step. */ -public fun ByteRange.step(step: Int): ByteProgression { +public infix fun ByteRange.step(step: Int): ByteProgression { checkStepIsPositive(step > 0, step) return ByteProgression(start, end, step) } @@ -773,7 +773,7 @@ public fun ByteRange.step(step: Int): ByteProgression { /** * Returns a progression that goes over this range with given step. */ -public fun CharRange.step(step: Int): CharProgression { +public infix fun CharRange.step(step: Int): CharProgression { checkStepIsPositive(step > 0, step) return CharProgression(start, end, step) } @@ -781,7 +781,7 @@ public fun CharRange.step(step: Int): CharProgression { /** * Returns a progression that goes over this range with given step. */ -public fun DoubleRange.step(step: Double): DoubleProgression { +public infix fun DoubleRange.step(step: Double): DoubleProgression { if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN.") checkStepIsPositive(step > 0, step) return DoubleProgression(start, end, step) @@ -790,7 +790,7 @@ public fun DoubleRange.step(step: Double): DoubleProgression { /** * Returns a progression that goes over this range with given step. */ -public fun FloatRange.step(step: Float): FloatProgression { +public infix fun FloatRange.step(step: Float): FloatProgression { if (step.isNaN()) throw IllegalArgumentException("Step must not be NaN.") checkStepIsPositive(step > 0, step) return FloatProgression(start, end, step) @@ -799,7 +799,7 @@ public fun FloatRange.step(step: Float): FloatProgression { /** * Returns a progression that goes over this range with given step. */ -public fun IntRange.step(step: Int): IntProgression { +public infix fun IntRange.step(step: Int): IntProgression { checkStepIsPositive(step > 0, step) return IntProgression(start, end, step) } @@ -807,7 +807,7 @@ public fun IntRange.step(step: Int): IntProgression { /** * Returns a progression that goes over this range with given step. */ -public fun LongRange.step(step: Long): LongProgression { +public infix fun LongRange.step(step: Long): LongProgression { checkStepIsPositive(step > 0, step) return LongProgression(start, end, step) } @@ -815,7 +815,7 @@ public fun LongRange.step(step: Long): LongProgression { /** * Returns a progression that goes over this range with given step. */ -public fun ShortRange.step(step: Int): ShortProgression { +public infix fun ShortRange.step(step: Int): ShortProgression { checkStepIsPositive(step > 0, step) return ShortProgression(start, end, step) } @@ -823,14 +823,14 @@ public fun ShortRange.step(step: Int): ShortProgression { /** * Returns a range from this value up to but excluding the specified [to] value. */ -public fun Int.until(to: Byte): IntRange { +public infix fun Int.until(to: Byte): IntRange { return this .. (to.toInt() - 1).toInt() } /** * Returns a range from this value up to but excluding the specified [to] value. */ -public fun Long.until(to: Byte): LongRange { +public infix fun Long.until(to: Byte): LongRange { return this .. (to.toLong() - 1).toLong() } @@ -838,7 +838,7 @@ public fun Long.until(to: Byte): LongRange { * Returns a range from this value up to but excluding the specified [to] value. * The [to] value must be greater than [Byte.MIN_VALUE]. */ -public fun Byte.until(to: Byte): ByteRange { +public infix fun Byte.until(to: Byte): ByteRange { val to_ = (to - 1).toByte() if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.") return this .. to_ @@ -847,7 +847,7 @@ public fun Byte.until(to: Byte): ByteRange { /** * Returns a range from this value up to but excluding the specified [to] value. */ -public fun Short.until(to: Byte): ShortRange { +public infix fun Short.until(to: Byte): ShortRange { return this .. (to.toShort() - 1).toShort() } @@ -855,7 +855,7 @@ public fun Short.until(to: Byte): ShortRange { * Returns a range from this value up to but excluding the specified [to] value. * The [to] value must be greater than [Char.MIN_VALUE]. */ -public fun Char.until(to: Char): CharRange { +public infix fun Char.until(to: Char): CharRange { val to_ = (to.toInt() - 1).toChar() if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.") return this .. to_ @@ -865,7 +865,7 @@ public fun Char.until(to: Char): CharRange { * Returns a range from this value up to but excluding the specified [to] value. * The [to] value must be greater than [Int.MIN_VALUE]. */ -public fun Int.until(to: Int): IntRange { +public infix fun Int.until(to: Int): IntRange { val to_ = (to.toLong() - 1).toInt() if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.") return this .. to_ @@ -874,7 +874,7 @@ public fun Int.until(to: Int): IntRange { /** * Returns a range from this value up to but excluding the specified [to] value. */ -public fun Long.until(to: Int): LongRange { +public infix fun Long.until(to: Int): LongRange { return this .. (to.toLong() - 1).toLong() } @@ -882,7 +882,7 @@ public fun Long.until(to: Int): LongRange { * Returns a range from this value up to but excluding the specified [to] value. * The [to] value must be greater than [Int.MIN_VALUE]. */ -public fun Byte.until(to: Int): IntRange { +public infix fun Byte.until(to: Int): IntRange { val to_ = (to.toLong() - 1).toInt() if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.") return this.toInt() .. to_ @@ -892,7 +892,7 @@ public fun Byte.until(to: Int): IntRange { * Returns a range from this value up to but excluding the specified [to] value. * The [to] value must be greater than [Int.MIN_VALUE]. */ -public fun Short.until(to: Int): IntRange { +public infix fun Short.until(to: Int): IntRange { val to_ = (to.toLong() - 1).toInt() if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.") return this.toInt() .. to_ @@ -902,7 +902,7 @@ public fun Short.until(to: Int): IntRange { * Returns a range from this value up to but excluding the specified [to] value. * The [to] value must be greater than [Long.MIN_VALUE]. */ -public fun Int.until(to: Long): LongRange { +public infix fun Int.until(to: Long): LongRange { val to_ = (to - 1).toLong() if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.") return this.toLong() .. to_ @@ -912,7 +912,7 @@ public fun Int.until(to: Long): LongRange { * Returns a range from this value up to but excluding the specified [to] value. * The [to] value must be greater than [Long.MIN_VALUE]. */ -public fun Long.until(to: Long): LongRange { +public infix fun Long.until(to: Long): LongRange { val to_ = (to - 1).toLong() if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.") return this .. to_ @@ -922,7 +922,7 @@ public fun Long.until(to: Long): LongRange { * Returns a range from this value up to but excluding the specified [to] value. * The [to] value must be greater than [Long.MIN_VALUE]. */ -public fun Byte.until(to: Long): LongRange { +public infix fun Byte.until(to: Long): LongRange { val to_ = (to - 1).toLong() if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.") return this.toLong() .. to_ @@ -932,7 +932,7 @@ public fun Byte.until(to: Long): LongRange { * Returns a range from this value up to but excluding the specified [to] value. * The [to] value must be greater than [Long.MIN_VALUE]. */ -public fun Short.until(to: Long): LongRange { +public infix fun Short.until(to: Long): LongRange { val to_ = (to - 1).toLong() if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.") return this.toLong() .. to_ @@ -941,14 +941,14 @@ public fun Short.until(to: Long): LongRange { /** * Returns a range from this value up to but excluding the specified [to] value. */ -public fun Int.until(to: Short): IntRange { +public infix fun Int.until(to: Short): IntRange { return this .. (to.toInt() - 1).toInt() } /** * Returns a range from this value up to but excluding the specified [to] value. */ -public fun Long.until(to: Short): LongRange { +public infix fun Long.until(to: Short): LongRange { return this .. (to.toLong() - 1).toLong() } @@ -956,7 +956,7 @@ public fun Long.until(to: Short): LongRange { * Returns a range from this value up to but excluding the specified [to] value. * The [to] value must be greater than [Short.MIN_VALUE]. */ -public fun Byte.until(to: Short): ShortRange { +public infix fun Byte.until(to: Short): ShortRange { val to_ = (to - 1).toShort() if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.") return this.toShort() .. to_ @@ -966,7 +966,7 @@ public fun Byte.until(to: Short): ShortRange { * Returns a range from this value up to but excluding the specified [to] value. * The [to] value must be greater than [Short.MIN_VALUE]. */ -public fun Short.until(to: Short): ShortRange { +public infix fun Short.until(to: Short): ShortRange { val to_ = (to - 1).toShort() if (to_ > to) throw IllegalArgumentException("The to argument value '$to' was too small.") return this .. to_ diff --git a/libraries/stdlib/src/kotlin/util/Tuples.kt b/libraries/stdlib/src/kotlin/util/Tuples.kt index 0d271299d83..4336830a1f7 100644 --- a/libraries/stdlib/src/kotlin/util/Tuples.kt +++ b/libraries/stdlib/src/kotlin/util/Tuples.kt @@ -35,7 +35,7 @@ public data class Pair( * This can be useful for creating [Map] literals with less noise, for example: * @sample test.collections.MapTest.createUsingTo */ -public fun A.to(that: B): Pair = Pair(this, that) +public infix fun A.to(that: B): Pair = Pair(this, that) /** * Converts this pair into a list. diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Engine.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Engine.kt index 2d757ae94de..08463e98d69 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Engine.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Engine.kt @@ -109,6 +109,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") { val typeParams = ArrayList() val returns = FamilyProperty() val operator = FamilyProperty() + val infix = FamilyProperty() val body = object : FamilyProperty() { override fun onKeySet(key: Family) = include(key) } @@ -374,6 +375,8 @@ class GenericFunction(val signature: String, val keyword: String = "fun") { builder.append("public ") if (inline[f] == true) builder.append("inline ") + if (infix[f] == true) + builder.append("infix ") if (operator[f] == true) builder.append("operator ") diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Ranges.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Ranges.kt index 6716276725f..6e6d246c0a4 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Ranges.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Ranges.kt @@ -21,6 +21,8 @@ fun ranges(): List { } templates add f("step(step: SUM)") { + infix(true) + only(RangesOfPrimitives, ProgressionsOfPrimitives) exclude(PrimitiveType.Boolean) doc(ProgressionsOfPrimitives) { "Returns a progression that goes over the same range with the given step." } @@ -48,6 +50,8 @@ fun ranges(): List { } fun downTo(fromType: PrimitiveType, toType: PrimitiveType) = f("downTo(to: $toType)") { + infix(true) + sourceFile(SourceFile.Ranges) only(Primitives) only(fromType) @@ -81,6 +85,8 @@ fun ranges(): List { templates addAll primitivePermutations.map { downTo(it.first, it.second) } fun until(fromType: PrimitiveType, toType: PrimitiveType) = f("until(to: $toType)") { + infix(true) + sourceFile(SourceFile.Ranges) only(Primitives) only(fromType)