From 89398796c6695a50d9c571ef8960cf06a7bae6ba Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 6 Mar 2015 21:25:38 +0100 Subject: [PATCH] generate also the Char class --- core/builtins/native/kotlin/Char.kt | 86 ------------------- core/builtins/native/kotlin/Numbers.kt | 67 +++++++++++++++ .../kotlin/generators/builtins/numbers.kt | 28 ++++-- 3 files changed, 86 insertions(+), 95 deletions(-) delete mode 100644 core/builtins/native/kotlin/Char.kt diff --git a/core/builtins/native/kotlin/Char.kt b/core/builtins/native/kotlin/Char.kt deleted file mode 100644 index 8dc7a52b73d..00000000000 --- a/core/builtins/native/kotlin/Char.kt +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package kotlin - -/** - * Represents a singe 16-bit Unicode character. On the JVM, non-nullable values of this type are represented - * as values of the primitive type `char`. - */ -public class Char private () : Comparable { - public fun compareTo(other: Double): Int - public fun compareTo(other: Float) : Int - public fun compareTo(other: Long) : Int - public fun compareTo(other: Int) : Int - public fun compareTo(other: Short) : Int - public override fun compareTo(other: Char): Int - public fun compareTo(other: Byte) : Int - - public fun plus(other: Double): Double - public fun plus(other: Float) : Float - public fun plus(other: Long) : Long - public fun plus(other: Int) : Int - public fun plus(other: Short) : Int - public fun plus(other: Byte) : Int - // public fun plus(other: Char) : Int - - public fun minus(other: Double): Double - public fun minus(other: Float) : Float - public fun minus(other: Long) : Long - public fun minus(other: Int) : Int - public fun minus(other: Short) : Int - public fun minus(other: Byte) : Int - public fun minus(other: Char) : Int - - public fun times(other: Double): Double - public fun times(other: Float) : Float - public fun times(other: Long) : Long - public fun times(other: Int) : Int - public fun times(other: Short) : Int - public fun times(other: Byte) : Int - // public fun times(other: Char) : Int - - public fun div(other: Double): Double - public fun div(other: Float) : Float - public fun div(other: Long) : Long - public fun div(other: Int) : Int - public fun div(other: Short) : Int - public fun div(other: Byte) : Int - // public fun div(other: Char) : Int - - public fun mod(other: Double): Double - public fun mod(other: Float) : Float - public fun mod(other: Long) : Long - public fun mod(other: Int) : Int - public fun mod(other: Short) : Int - public fun mod(other: Byte) : Int - // public fun mod(other: Char) : Int - - public fun rangeTo(other: Char): CharRange - - public fun inc(): Char - public fun dec(): Char - public fun plus(): Int - public fun minus(): Int - - public fun toDouble(): Double - public fun toFloat(): Float - public fun toLong(): Long - public fun toInt(): Int - public fun toChar(): Char - public fun toShort(): Short - public fun toByte(): Byte -} diff --git a/core/builtins/native/kotlin/Numbers.kt b/core/builtins/native/kotlin/Numbers.kt index 5a7dfa8cc24..f775640081f 100644 --- a/core/builtins/native/kotlin/Numbers.kt +++ b/core/builtins/native/kotlin/Numbers.kt @@ -95,6 +95,73 @@ public class Byte private () : Number, Comparable { public override fun toDouble(): Double } +/** + * Represents a 16-bit Unicode character. + * On the JVM, non-nullable values of this type are represented as values of the primitive type `char`. + */ +public class Char private () : Comparable { + class object {} + + public fun compareTo(other: Byte): Int + public override fun compareTo(other: Char): Int + public fun compareTo(other: Short): Int + public fun compareTo(other: Int): Int + public fun compareTo(other: Long): Int + public fun compareTo(other: Float): Int + public fun compareTo(other: Double): Int + + public fun plus(other: Byte): Int + public fun plus(other: Short): Int + public fun plus(other: Int): Int + public fun plus(other: Long): Long + public fun plus(other: Float): Float + public fun plus(other: Double): Double + + public fun minus(other: Byte): Int + public fun minus(other: Char): Int + public fun minus(other: Short): Int + public fun minus(other: Int): Int + public fun minus(other: Long): Long + public fun minus(other: Float): Float + public fun minus(other: Double): Double + + public fun times(other: Byte): Int + public fun times(other: Short): Int + public fun times(other: Int): Int + public fun times(other: Long): Long + public fun times(other: Float): Float + public fun times(other: Double): Double + + public fun div(other: Byte): Int + public fun div(other: Short): Int + public fun div(other: Int): Int + public fun div(other: Long): Long + public fun div(other: Float): Float + public fun div(other: Double): Double + + public fun mod(other: Byte): Int + public fun mod(other: Short): Int + public fun mod(other: Int): Int + public fun mod(other: Long): Long + public fun mod(other: Float): Float + public fun mod(other: Double): Double + + public fun inc(): Char + public fun dec(): Char + public fun plus(): Int + public fun minus(): Int + + public fun rangeTo(other: Char): CharRange + + public override fun toByte(): Byte + public override fun toChar(): Char + public override fun toShort(): Short + public override fun toInt(): Int + public override fun toLong(): Long + public override fun toFloat(): Float + public override fun toDouble(): Double +} + /** * Represents a 16-bit signed integer. * On the JVM, non-nullable values of this type are represented as values of the primitive type `short`. diff --git a/generators/src/org/jetbrains/kotlin/generators/builtins/numbers.kt b/generators/src/org/jetbrains/kotlin/generators/builtins/numbers.kt index c546bfea299..8f6976094d2 100644 --- a/generators/src/org/jetbrains/kotlin/generators/builtins/numbers.kt +++ b/generators/src/org/jetbrains/kotlin/generators/builtins/numbers.kt @@ -31,16 +31,19 @@ class GenerateNumbers(out: PrintWriter) : BuiltInsSourceGenerator(out) { PrimitiveType.LONG to "64-bit signed integer", PrimitiveType.INT to "32-bit signed integer", PrimitiveType.SHORT to "16-bit signed integer", - PrimitiveType.BYTE to "8-bit signed integer" + PrimitiveType.BYTE to "8-bit signed integer", + PrimitiveType.CHAR to "16-bit Unicode character" ) - override fun generateBody() { - for (kind in PrimitiveType.values()) { - if (kind == PrimitiveType.BOOLEAN || kind == PrimitiveType.CHAR) continue + for (kind in PrimitiveType.exceptBoolean) { val className = kind.capitalized generateDoc(kind) - out.println("public class $className private () : Number, Comparable<$className> {") + out.print("public class $className private () : ") + if (kind != PrimitiveType.CHAR) { + out.print("Number, ") + } + out.println("Comparable<$className> {") out.print(" default object") if (kind == PrimitiveType.FLOAT || kind == PrimitiveType.DOUBLE) { @@ -88,6 +91,9 @@ class GenerateNumbers(out: PrintWriter) : BuiltInsSourceGenerator(out) { private fun generateOperator(name: String, thisKind: PrimitiveType) { for (otherKind in PrimitiveType.exceptBoolean) { + if (thisKind == PrimitiveType.CHAR && otherKind == PrimitiveType.CHAR && name != "minus") { + continue + } val returnType = getOperatorReturnType(thisKind, otherKind) out.println(" public fun $name(other: ${otherKind.capitalized}): $returnType") } @@ -95,9 +101,13 @@ class GenerateNumbers(out: PrintWriter) : BuiltInsSourceGenerator(out) { } private fun generateRangeTo(thisKind: PrimitiveType) { - for (otherKind in PrimitiveType.exceptBoolean) { - val returnType = if (otherKind.ordinal() > thisKind.ordinal()) otherKind else thisKind - out.println(" public fun rangeTo(other: ${otherKind.capitalized}): ${returnType.capitalized}Range") + if (thisKind == PrimitiveType.CHAR) { + out.println(" public fun rangeTo(other: Char): CharRange") + } else { + for (otherKind in PrimitiveType.exceptBoolean) { + val returnType = if (otherKind.ordinal() > thisKind.ordinal()) otherKind else thisKind + out.println(" public fun rangeTo(other: ${otherKind.capitalized}): ${returnType.capitalized}Range") + } } out.println() @@ -105,7 +115,7 @@ class GenerateNumbers(out: PrintWriter) : BuiltInsSourceGenerator(out) { private fun generateUnaryOperators(kind: PrimitiveType) { for (name in unaryOperators) { - val returnType = if (kind in listOf(PrimitiveType.SHORT, PrimitiveType.BYTE) && + val returnType = if (kind in listOf(PrimitiveType.SHORT, PrimitiveType.BYTE, PrimitiveType.CHAR) && name in listOf("plus", "minus")) "Int" else kind.capitalized out.println(" public fun $name(): $returnType") }