diff --git a/generators/builtins/primitives/BasePrimitivesGenerator.kt b/generators/builtins/primitives/BasePrimitivesGenerator.kt index 9b0e12a38f0..4824670b932 100644 --- a/generators/builtins/primitives/BasePrimitivesGenerator.kt +++ b/generators/builtins/primitives/BasePrimitivesGenerator.kt @@ -447,7 +447,10 @@ abstract class BasePrimitivesGenerator(private val writer: PrintWriter) : BuiltI } returnType = "${opReturnType.capitalized}Range" } - }.modifyGeneratedRangeTo(thisKind) + val thisCasted = "this${thisKind.castToIfNecessary(opReturnType)}" + val otherCasted = "other${otherKind.castToIfNecessary(opReturnType)}" + "${returnType}($thisCasted, $otherCasted)".addAsSingleLineBody(bodyOnNewLine = true) + }.modifyGeneratedRangeTo(thisKind, otherKind, opReturnType) } } @@ -477,7 +480,8 @@ abstract class BasePrimitivesGenerator(private val writer: PrintWriter) : BuiltI } returnType = "${opReturnType.capitalized}Range" } - }.modifyGeneratedRangeUntil(thisKind) + "this until $parameterName".addAsSingleLineBody(bodyOnNewLine = false) + }.modifyGeneratedRangeUntil(thisKind, otherKind, opReturnType) } } @@ -620,8 +624,8 @@ abstract class BasePrimitivesGenerator(private val writer: PrintWriter) : BuiltI internal open fun MethodBuilder.modifyGeneratedCompareTo(thisKind: PrimitiveType, otherKind: PrimitiveType) {} internal open fun MethodBuilder.modifyGeneratedBinaryOperation(thisKind: PrimitiveType, otherKind: PrimitiveType) {} internal open fun MethodBuilder.modifyGeneratedUnaryOperation(thisKind: PrimitiveType) {} - internal open fun MethodBuilder.modifyGeneratedRangeTo(thisKind: PrimitiveType) {} - internal open fun MethodBuilder.modifyGeneratedRangeUntil(thisKind: PrimitiveType) {} + internal open fun MethodBuilder.modifyGeneratedRangeTo(thisKind: PrimitiveType, otherKind: PrimitiveType, opReturnType: PrimitiveType) {} + internal open fun MethodBuilder.modifyGeneratedRangeUntil(thisKind: PrimitiveType, otherKind: PrimitiveType, opReturnType: PrimitiveType) {} internal open fun MethodBuilder.modifyGeneratedBitShiftOperators(thisKind: PrimitiveType) {} internal open fun MethodBuilder.modifyGeneratedBitwiseOperators(thisKind: PrimitiveType) {} internal open fun MethodBuilder.modifyGeneratedConversions(thisKind: PrimitiveType) {} diff --git a/generators/builtins/primitives/JsPrimitivesGenerator.kt b/generators/builtins/primitives/JsPrimitivesGenerator.kt index c2a2da56dc7..aabeea61e57 100644 --- a/generators/builtins/primitives/JsPrimitivesGenerator.kt +++ b/generators/builtins/primitives/JsPrimitivesGenerator.kt @@ -24,6 +24,10 @@ class JsPrimitivesGenerator(writer: PrintWriter) : BasePrimitivesGenerator(write } } + override fun MethodBuilder.modifyGeneratedRangeTo(thisKind: PrimitiveType, otherKind: PrimitiveType, opReturnType: PrimitiveType) { + noBody() + } + override fun ClassBuilder.generateAdditionalMethods(thisKind: PrimitiveType) { method { signature { @@ -33,8 +37,4 @@ class JsPrimitivesGenerator(writer: PrintWriter) : BasePrimitivesGenerator(write } } } - - override fun MethodBuilder.modifyGeneratedRangeUntil(thisKind: PrimitiveType) { - "this until $parameterName".addAsSingleLineBody(bodyOnNewLine = false) - } } \ No newline at end of file diff --git a/generators/builtins/primitives/JvmPrimitivesGenerator.kt b/generators/builtins/primitives/JvmPrimitivesGenerator.kt index 6e42f613145..10953e0988e 100644 --- a/generators/builtins/primitives/JvmPrimitivesGenerator.kt +++ b/generators/builtins/primitives/JvmPrimitivesGenerator.kt @@ -12,4 +12,12 @@ class JvmPrimitivesGenerator(writer: PrintWriter) : BasePrimitivesGenerator(writ override fun ClassBuilder.modifyGeneratedClass(thisKind: PrimitiveType) { appendDoc("On the JVM, non-nullable values of this type are represented as values of the primitive type `${thisKind.name.lowercase()}`.") } + + override fun MethodBuilder.modifyGeneratedRangeTo(thisKind: PrimitiveType, otherKind: PrimitiveType, opReturnType: PrimitiveType) { + noBody() + } + + override fun MethodBuilder.modifyGeneratedRangeUntil(thisKind: PrimitiveType, otherKind: PrimitiveType, opReturnType: PrimitiveType) { + noBody() + } } \ No newline at end of file diff --git a/generators/builtins/primitives/NativePrimitivesGenerator.kt b/generators/builtins/primitives/NativePrimitivesGenerator.kt index c26152c3a3c..e0f7a48b8e2 100644 --- a/generators/builtins/primitives/NativePrimitivesGenerator.kt +++ b/generators/builtins/primitives/NativePrimitivesGenerator.kt @@ -101,17 +101,6 @@ class NativePrimitivesGenerator(writer: PrintWriter) : BasePrimitivesGenerator(w "$sign$thisCasted".addAsSingleLineBody(bodyOnNewLine = true) } - override fun MethodBuilder.modifyGeneratedRangeTo(thisKind: PrimitiveType) { - val rangeType = PrimitiveType.valueOf(returnType.replace("Range", "").uppercase()) - val thisCasted = "this" + thisKind.castToIfNecessary(rangeType) - val otherCasted = parameterName + parameterType.toPrimitiveType().castToIfNecessary(rangeType) - "return ${returnType}($thisCasted, $otherCasted)".addAsMultiLineBody() - } - - override fun MethodBuilder.modifyGeneratedRangeUntil(thisKind: PrimitiveType) { - "this until $parameterName".addAsSingleLineBody(bodyOnNewLine = false) - } - override fun MethodBuilder.modifyGeneratedBitShiftOperators(thisKind: PrimitiveType) { setAsExternal() } diff --git a/generators/builtins/primitives/WasmPrimitivesGenerator.kt b/generators/builtins/primitives/WasmPrimitivesGenerator.kt index afa901ab94b..735f71d0c1c 100644 --- a/generators/builtins/primitives/WasmPrimitivesGenerator.kt +++ b/generators/builtins/primitives/WasmPrimitivesGenerator.kt @@ -153,17 +153,6 @@ class WasmPrimitivesGenerator(writer: PrintWriter) : BasePrimitivesGenerator(wri } } - override fun MethodBuilder.modifyGeneratedRangeTo(thisKind: PrimitiveType) { - val rangeType = PrimitiveType.valueOf(returnType.replace("Range", "").uppercase()) - val thisCasted = "this" + thisKind.castToIfNecessary(rangeType) - val otherCasted = parameterName + parameterType.toPrimitiveType().castToIfNecessary(rangeType) - "return ${returnType}($thisCasted, $otherCasted)".addAsMultiLineBody() - } - - override fun MethodBuilder.modifyGeneratedRangeUntil(thisKind: PrimitiveType) { - "this until $parameterName".addAsSingleLineBody(bodyOnNewLine = false) - } - override fun MethodBuilder.modifyGeneratedBitShiftOperators(thisKind: PrimitiveType) { if (thisKind == PrimitiveType.INT) { implementAsIntrinsic(thisKind, methodName) diff --git a/generators/builtins/primitives/builders.kt b/generators/builtins/primitives/builders.kt index 313a10f3215..92da015a8f5 100644 --- a/generators/builtins/primitives/builders.kt +++ b/generators/builtins/primitives/builders.kt @@ -273,6 +273,8 @@ internal class MethodBuilder : AnnotatedAndDocumented(), PrimitiveBuilder { } } + fun noBody() { body = null } + fun String.addAsSingleLineBody(bodyOnNewLine: Boolean = false) { val skip = if (bodyOnNewLine) "$END_LINE " else " " body = " =$skip$this" diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/Primitives.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/Primitives.kt index c5a4e0bc8e0..6470c5ec219 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/Primitives.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/Primitives.kt @@ -299,24 +299,20 @@ public final class Byte private constructor() : Number(), Comparable { -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()) - } + public operator fun rangeTo(other: Byte): IntRange = + 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()) - } + public operator fun rangeTo(other: Short): IntRange = + 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) - } + public operator fun rangeTo(other: Int): IntRange = + IntRange(this.toInt(), other) /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Long): LongRange { - return LongRange(this.toLong(), other) - } + public operator fun rangeTo(other: Long): LongRange = + LongRange(this.toLong(), other) /** * Creates a range from this value up to but excluding the specified [other] value. @@ -730,24 +726,20 @@ public final class Short private constructor() : Number(), Comparable { -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()) - } + public operator fun rangeTo(other: Byte): IntRange = + 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()) - } + public operator fun rangeTo(other: Short): IntRange = + 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) - } + public operator fun rangeTo(other: Int): IntRange = + IntRange(this.toInt(), other) /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Long): LongRange { - return LongRange(this.toLong(), other) - } + public operator fun rangeTo(other: Long): LongRange = + LongRange(this.toLong(), other) /** * Creates a range from this value up to but excluding the specified [other] value. @@ -1159,24 +1151,20 @@ public final class Int private constructor() : Number(), Comparable { external public operator fun unaryMinus(): Int /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Byte): IntRange { - return IntRange(this, other.toInt()) - } + public operator fun rangeTo(other: Byte): IntRange = + 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()) - } + public operator fun rangeTo(other: Short): IntRange = + 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) - } + public operator fun rangeTo(other: Int): IntRange = + IntRange(this, other) /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Long): LongRange { - return LongRange(this.toLong(), other) - } + public operator fun rangeTo(other: Long): LongRange = + LongRange(this.toLong(), other) /** * Creates a range from this value up to but excluding the specified [other] value. @@ -1641,24 +1629,20 @@ public final class Long private constructor() : Number(), Comparable { external public operator fun unaryMinus(): Long /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Byte): LongRange { - return LongRange(this, other.toLong()) - } + public operator fun rangeTo(other: Byte): LongRange = + LongRange(this, other.toLong()) /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Short): LongRange { - return LongRange(this, other.toLong()) - } + public operator fun rangeTo(other: Short): LongRange = + LongRange(this, other.toLong()) /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Int): LongRange { - return LongRange(this, other.toLong()) - } + public operator fun rangeTo(other: Int): LongRange = + LongRange(this, other.toLong()) /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Long): LongRange { - return LongRange(this, other) - } + public operator fun rangeTo(other: Long): LongRange = + LongRange(this, other) /** * Creates a range from this value up to but excluding the specified [other] value. diff --git a/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt b/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt index fad817170a7..1a33a53013b 100644 --- a/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt +++ b/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt @@ -299,24 +299,20 @@ public class Byte private constructor(private val value: Byte) : Number(), Compa -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()) - } + public operator fun rangeTo(other: Byte): IntRange = + 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()) - } + public operator fun rangeTo(other: Short): IntRange = + 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) - } + public operator fun rangeTo(other: Int): IntRange = + IntRange(this.toInt(), other) /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Long): LongRange { - return LongRange(this.toLong(), other) - } + public operator fun rangeTo(other: Long): LongRange = + LongRange(this.toLong(), other) /** * Creates a range from this value up to but excluding the specified [other] value. @@ -725,24 +721,20 @@ public class Short private constructor(private val value: Short) : Number(), Com -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()) - } + public operator fun rangeTo(other: Byte): IntRange = + 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()) - } + public operator fun rangeTo(other: Short): IntRange = + 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) - } + public operator fun rangeTo(other: Int): IntRange = + IntRange(this.toInt(), other) /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Long): LongRange { - return LongRange(this.toLong(), other) - } + public operator fun rangeTo(other: Long): LongRange = + LongRange(this.toLong(), other) /** * Creates a range from this value up to but excluding the specified [other] value. @@ -1154,24 +1146,20 @@ public class Int private constructor(private val value: Int) : Number(), Compara 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()) - } + public operator fun rangeTo(other: Byte): IntRange = + 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()) - } + public operator fun rangeTo(other: Short): IntRange = + 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) - } + public operator fun rangeTo(other: Int): IntRange = + IntRange(this, other) /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Long): LongRange { - return LongRange(this.toLong(), other) - } + public operator fun rangeTo(other: Long): LongRange = + LongRange(this.toLong(), other) /** * Creates a range from this value up to but excluding the specified [other] value. @@ -1656,24 +1644,20 @@ public class Long private constructor(private val value: Long) : Number(), Compa 0L - this /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Byte): LongRange { - return LongRange(this, other.toLong()) - } + public operator fun rangeTo(other: Byte): LongRange = + LongRange(this, other.toLong()) /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Short): LongRange { - return LongRange(this, other.toLong()) - } + public operator fun rangeTo(other: Short): LongRange = + LongRange(this, other.toLong()) /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Int): LongRange { - return LongRange(this, other.toLong()) - } + public operator fun rangeTo(other: Int): LongRange = + LongRange(this, other.toLong()) /** Creates a range from this value to the specified [other] value. */ - public operator fun rangeTo(other: Long): LongRange { - return LongRange(this, other) - } + public operator fun rangeTo(other: Long): LongRange = + LongRange(this, other) /** * Creates a range from this value up to but excluding the specified [other] value.