From cbc404324c1b9d03243041691c424ac7a085e6c4 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Fri, 24 Aug 2018 18:46:00 +0300 Subject: [PATCH] Gross stdlib cleanup (part 3). (#1929) --- .../kotlin/backend/konan/CAdapterGenerator.kt | 6 +- .../konan/irasdescriptors/FakeIrUtils.kt | 1 - .../backend/konan/lower/BridgesBuilding.kt | 2 +- .../konan/lower/CallableReferenceLowering.kt | 3 +- backend.native/tests/build.gradle | 2 - .../tests/harmony_regex/AllCodePointsTest.kt | 2 +- .../tests/produce_dynamic/simple/hello.kt | 4 +- backend.native/tests/runtime/basic/hash0.kt | 3 +- .../tests/runtime/basic/tostring2.kt | 2 +- runtime/src/main/cpp/Arrays.cpp | 44 +++++++-- runtime/src/main/kotlin/kotlin/Array.kt | 3 +- runtime/src/main/kotlin/kotlin/Boolean.kt | 4 +- runtime/src/main/kotlin/kotlin/Char.kt | 6 +- runtime/src/main/kotlin/kotlin/Comparator.kt | 4 +- runtime/src/main/kotlin/kotlin/Enum.kt | 5 +- runtime/src/main/kotlin/kotlin/Functions.kt | 48 +++++----- runtime/src/main/kotlin/kotlin/Lazy.kt | 6 +- runtime/src/main/kotlin/kotlin/Primitives.kt | 7 +- runtime/src/main/kotlin/kotlin/String.kt | 7 +- .../main/kotlin/kotlin/SuspendFunctions.kt | 48 +++++----- .../kotlin/kotlin/collections/ArrayUtil.kt | 4 +- .../main/kotlin/kotlin/native/Annotations.kt | 6 +- .../main/kotlin/kotlin/{ => native}/BitSet.kt | 3 +- runtime/src/main/kotlin/kotlin/native/Text.kt | 62 +++++++++++++ .../main/kotlin/kotlin/native/TypedArrays.kt | 44 +++++---- .../src/main/kotlin/kotlin/random/Random.kt | 2 +- .../main/kotlin/kotlin/ranges/Progressions.kt | 33 +++---- .../kotlin/reflect/KAnnotatedElement.kt | 7 +- .../main/kotlin/kotlin/reflect/KCallable.kt | 51 ----------- .../src/main/kotlin/kotlin/reflect/KClass.kt | 89 ------------------- .../kotlin/reflect/KDeclarationContainer.kt | 7 +- .../main/kotlin/kotlin/reflect/KProperty.kt | 72 ++------------- .../src/main/kotlin/kotlin/reflect/KType.kt | 11 --- .../src/main/kotlin/kotlin/test/Annotation.kt | 16 ++-- .../src/main/kotlin/kotlin/test/Assertions.kt | 48 +++++----- .../kotlin/kotlin/test/DefaultAsserter.kt | 2 +- .../src/main/kotlin/kotlin/text/Appendable.kt | 2 +- .../main/kotlin/kotlin/text/CharCategory.kt | 2 - .../kotlin/text/PatternSyntaxException.kt | 27 +++--- runtime/src/main/kotlin/kotlin/text/Regex.kt | 4 +- .../main/kotlin/kotlin/text/StringBuilder.kt | 59 +----------- .../kotlin/kotlin/text/StringBuilderNative.kt | 1 - .../src/main/kotlin/kotlin/text/Strings.kt | 1 - .../main/kotlin/kotlin/text/regex/Lexer.kt | 2 +- .../main/kotlin/kotlin/text/regex/Pattern.kt | 2 +- .../regex/sets/HangulDecomposedCharSet.kt | 4 +- .../text/regex/sets/SupplementaryCharSet.kt | 2 +- runtime/src/main/kotlin/kotlin/util/Sort.kt | 7 -- 48 files changed, 280 insertions(+), 497 deletions(-) rename runtime/src/main/kotlin/kotlin/{ => native}/BitSet.kt (99%) create mode 100644 runtime/src/main/kotlin/kotlin/native/Text.kt diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterGenerator.kt index f32276c2e14..c189c5acee5 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/CAdapterGenerator.kt @@ -147,7 +147,7 @@ private fun AnnotationDescriptor.properValue(key: String) = private fun functionImplName(descriptor: DeclarationDescriptor, default: String, shortName: Boolean): String { assert(descriptor is FunctionDescriptor) val annotation = descriptor.annotations.findAnnotation(cnameAnnotation) ?: return default - val key = if (shortName) "shortName" else "fullName" + val key = if (shortName) "shortName" else "externName" val value = annotation.properValue(key) return value.takeIf { value != null && value.isNotEmpty() } ?: default } @@ -262,8 +262,8 @@ private class ExportedElement(val kind: ElementKind, if (declaration !is FunctionDescriptor || !declaration.annotations.hasAnnotation(cnameAnnotation)) return false val annotation = declaration.annotations.findAnnotation(cnameAnnotation)!! - val fullName = annotation.properValue("fullName") - return fullName != null && fullName.isNotEmpty() + val externName = annotation.properValue("externName") + return externName != null && externName.isNotEmpty() } val isClass = declaration is ClassDescriptor && declaration.kind != ClassKind.ENUM_ENTRY val isEnumEntry = declaration is ClassDescriptor && declaration.kind == ClassKind.ENUM_ENTRY diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/irasdescriptors/FakeIrUtils.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/irasdescriptors/FakeIrUtils.kt index 8cd28d11806..1795d0d4a56 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/irasdescriptors/FakeIrUtils.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/irasdescriptors/FakeIrUtils.kt @@ -29,7 +29,6 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.module // TODO: port this code to IR. internal val IrDeclaration.isAnonymousObject get() = DescriptorUtils.isAnonymousObject(this.descriptor) -internal val IrFunction.isExternal get() = this.descriptor.isExternal internal val IrDeclaration.isLocal get() = DescriptorUtils.isLocal(this.descriptor) internal val IrDeclaration.module get() = this.descriptor.module diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/BridgesBuilding.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/BridgesBuilding.kt index 03a766a2ce6..c989738c04c 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/BridgesBuilding.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/BridgesBuilding.kt @@ -245,7 +245,7 @@ private fun Context.buildBridge(startOffset: Int, endOffset: Int, val delegatingCall = IrCallImpl( startOffset, endOffset, - (targetSymbol.owner as IrFunction).returnType, + targetSymbol.owner.returnType, targetSymbol, targetSymbol.descriptor, superQualifierSymbol = superQualifierSymbol /* Call non-virtually */ diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/CallableReferenceLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/CallableReferenceLowering.kt index 57ca68d5441..d457ccffc7e 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/CallableReferenceLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/CallableReferenceLowering.kt @@ -183,13 +183,12 @@ internal class CallableReferenceLowering(val context: Context): FileLoweringPass superTypes += functionIrClass.symbol.typeWith(functionClassTypeParameters) var suspendFunctionIrClass: IrClass? = null - var suspendFunctionClassTypeParameters: List? = null val lastParameterType = unboundFunctionParameters.lastOrNull()?.type if (lastParameterType != null && lastParameterType.classifierOrNull?.descriptor == continuationClassDescriptor) { lastParameterType as IrSimpleType // If the last parameter is Continuation<> inherit from SuspendFunction. suspendFunctionIrClass = context.ir.symbols.suspendFunctions[numberOfParameters - 1].owner - suspendFunctionClassTypeParameters = functionParameterTypes.dropLast(1) + + var suspendFunctionClassTypeParameters = functionParameterTypes.dropLast(1) + (lastParameterType.arguments.single().typeOrNull ?: context.irBuiltIns.anyNType) superTypes += suspendFunctionIrClass.symbol.typeWith(suspendFunctionClassTypeParameters) } diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 0cb04e50587..e1006bcc8ee 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -1452,8 +1452,6 @@ task array3(type: RunKonanTest) { } task typed_array0(type: RunKonanTest) { - // MIPS target is big-endian. - disabled = (project.testTarget == 'linux_mips32') goldValue = "OK\n" source = "runtime/collections/typed_array0.kt" } diff --git a/backend.native/tests/harmony_regex/AllCodePointsTest.kt b/backend.native/tests/harmony_regex/AllCodePointsTest.kt index a5c99b4e5af..532d2958f12 100644 --- a/backend.native/tests/harmony_regex/AllCodePointsTest.kt +++ b/backend.native/tests/harmony_regex/AllCodePointsTest.kt @@ -27,7 +27,7 @@ class AllCodePointsTest { fun codePointToString(codePoint: Int): String { val charArray = Char.toChars(codePoint) - return fromCharArray(charArray, 0, charArray.size) + return String(charArray, 0, charArray.size) } // TODO: Here is a performance problem: an execution of this test requires much more time than it in Kotlin/JVM. diff --git a/backend.native/tests/produce_dynamic/simple/hello.kt b/backend.native/tests/produce_dynamic/simple/hello.kt index 4213c7b97e5..46c14ce6846 100644 --- a/backend.native/tests/produce_dynamic/simple/hello.kt +++ b/backend.native/tests/produce_dynamic/simple/hello.kt @@ -15,12 +15,12 @@ open class Base { open fun fooParam(arg0: String, arg1: Int) = println("Base.fooParam: $arg0 $arg1") - @CName(fullName = "", shortName = "strangeName") fun странноеИмя() = 111 + @CName(externName = "", shortName = "strangeName") fun странноеИмя() = 111 } // Top level functions. -@CName(fullName = "topLevelFunctionFromC", shortName = "topLevelFunctionFromCShort") +@CName(externName = "topLevelFunctionFromC", shortName = "topLevelFunctionFromCShort") fun topLevelFunction(x1: Int, x2: Int) = x1 - x2 @CName("topLevelFunctionVoidFromC") diff --git a/backend.native/tests/runtime/basic/hash0.kt b/backend.native/tests/runtime/basic/hash0.kt index 5a710e39cd8..a13db9104eb 100644 --- a/backend.native/tests/runtime/basic/hash0.kt +++ b/backend.native/tests/runtime/basic/hash0.kt @@ -17,6 +17,5 @@ import kotlin.test.* a[2] = 'l' a[3] = 'l' a[4] = 'o' - // Note that it uses private Konan API. - println("Hello".hashCode() == fromCharArray(a, 0, 5).hashCode()) + println("Hello".hashCode() == String(a, 0, 5).hashCode()) } \ No newline at end of file diff --git a/backend.native/tests/runtime/basic/tostring2.kt b/backend.native/tests/runtime/basic/tostring2.kt index 0867f0c842b..ce91c69c8be 100644 --- a/backend.native/tests/runtime/basic/tostring2.kt +++ b/backend.native/tests/runtime/basic/tostring2.kt @@ -10,5 +10,5 @@ import kotlin.test.* print(" ") } println() - println(fromCharArray(array, 0, array.size)) + println(String(array, 0, array.size)) } \ No newline at end of file diff --git a/runtime/src/main/cpp/Arrays.cpp b/runtime/src/main/cpp/Arrays.cpp index 8e424544b42..523c15ef20f 100644 --- a/runtime/src/main/cpp/Arrays.cpp +++ b/runtime/src/main/cpp/Arrays.cpp @@ -146,7 +146,12 @@ KChar Kotlin_ByteArray_getCharAt(KConstRef thiz, KInt index) { if (static_cast(index + 1) >= array->count_) { ThrowArrayIndexOutOfBoundsException(); } - return *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)); + auto result = *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)); +#if __BIG_ENDIAN__ + return __builtin_bswap16(result); +#else + return result; +#endif } KShort Kotlin_ByteArray_getShortAt(KConstRef thiz, KInt index) { @@ -154,7 +159,12 @@ KShort Kotlin_ByteArray_getShortAt(KConstRef thiz, KInt index) { if (static_cast(index + 1) >= array->count_) { ThrowArrayIndexOutOfBoundsException(); } - return *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)); + auto result = *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)); +#if __BIG_ENDIAN__ + return __builtin_bswap16(result); +#else + return result; +#endif } KInt Kotlin_ByteArray_getIntAt(KConstRef thiz, KInt index) { @@ -162,7 +172,12 @@ KInt Kotlin_ByteArray_getIntAt(KConstRef thiz, KInt index) { if (static_cast(index + 3) >= array->count_) { ThrowArrayIndexOutOfBoundsException(); } - return *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)); + auto result = *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)); +#if __BIG_ENDIAN__ + return __builtin_bswap32(result); +#else + return result; +#endif } KLong Kotlin_ByteArray_getLongAt(KConstRef thiz, KInt index) { @@ -170,7 +185,13 @@ KLong Kotlin_ByteArray_getLongAt(KConstRef thiz, KInt index) { if (static_cast(index + 7) >= array->count_) { ThrowArrayIndexOutOfBoundsException(); } - return *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)); + + auto result = *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)); +#if __BIG_ENDIAN__ + return __builtin_bswap64(result); +#else + return result; +#endif } KFloat Kotlin_ByteArray_getFloatAt(KConstRef thiz, KInt index) { @@ -178,7 +199,8 @@ KFloat Kotlin_ByteArray_getFloatAt(KConstRef thiz, KInt index) { if (static_cast(index + 3) >= array->count_) { ThrowArrayIndexOutOfBoundsException(); } - return *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)); + auto result = *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)); + return result; } KDouble Kotlin_ByteArray_getDoubleAt(KConstRef thiz, KInt index) { @@ -195,6 +217,9 @@ void Kotlin_ByteArray_setCharAt(KRef thiz, KInt index, KChar value) { ThrowArrayIndexOutOfBoundsException(); } mutabilityCheck(thiz); +#if __BIG_ENDIAN__ + value = __builtin_bswap16(value); +#endif *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)) = value; } @@ -204,6 +229,9 @@ void Kotlin_ByteArray_setShortAt(KRef thiz, KInt index, KShort value) { ThrowArrayIndexOutOfBoundsException(); } mutabilityCheck(thiz); +#if __BIG_ENDIAN__ + value = __builtin_bswap16(value); +#endif *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)) = value; } @@ -213,6 +241,9 @@ void Kotlin_ByteArray_setIntAt(KRef thiz, KInt index, KInt value) { ThrowArrayIndexOutOfBoundsException(); } mutabilityCheck(thiz); +#if __BIG_ENDIAN__ + value = __builtin_bswap32(value); +#endif *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)) = value; } @@ -222,6 +253,9 @@ void Kotlin_ByteArray_setLongAt(KRef thiz, KInt index, KLong value) { ThrowArrayIndexOutOfBoundsException(); } mutabilityCheck(thiz); +#if __BIG_ENDIAN__ + value = __builtin_bswap64(value); +#endif *reinterpret_cast(ByteArrayAddressOfElementAt(array, index)) = value; } diff --git a/runtime/src/main/kotlin/kotlin/Array.kt b/runtime/src/main/kotlin/kotlin/Array.kt index 5ec529d2b1a..67734523ed9 100644 --- a/runtime/src/main/kotlin/kotlin/Array.kt +++ b/runtime/src/main/kotlin/kotlin/Array.kt @@ -23,7 +23,7 @@ import kotlin.native.internal.PointsTo @ExportTypeInfo("theArrayTypeInfo") public final class Array { - // Constructors are handled with compiler magic. + @InlineConstructor @Suppress("TYPE_PARAMETER_AS_REIFIED") public constructor(size: Int, init: (Int) -> T): this(size) { @@ -52,7 +52,6 @@ public final class Array { return IteratorImpl(this) } - // Konan-specific. @SymbolName("Kotlin_Array_getArrayLength") external private fun getArrayLength(): Int } diff --git a/runtime/src/main/kotlin/kotlin/Boolean.kt b/runtime/src/main/kotlin/kotlin/Boolean.kt index a315ba66ca7..94ceb64a1a5 100644 --- a/runtime/src/main/kotlin/kotlin/Boolean.kt +++ b/runtime/src/main/kotlin/kotlin/Boolean.kt @@ -20,7 +20,8 @@ package kotlin * Represents a value which is either `true` or `false`. On the JVM, non-nullable values of this type are * represented as values of the primitive type `boolean`. */ -public final class Boolean private constructor(private val value: kotlin.native.internal.BooleanValue) : Comparable { +public class Boolean private constructor( + private val value: kotlin.native.internal.BooleanValue) : Comparable { @SinceKotlin("1.3") companion object {} @@ -52,7 +53,6 @@ public final class Boolean private constructor(private val value: kotlin.native. @SymbolName("Kotlin_Boolean_compareTo_Boolean") external public override fun compareTo(other: Boolean): Int - // Konan-specific. public fun equals(other: Boolean): Boolean = kotlin.native.internal.areEqualByValue(this, other) public override fun equals(other: Any?): Boolean = diff --git a/runtime/src/main/kotlin/kotlin/Char.kt b/runtime/src/main/kotlin/kotlin/Char.kt index 06095a60d65..0d79511cdda 100644 --- a/runtime/src/main/kotlin/kotlin/Char.kt +++ b/runtime/src/main/kotlin/kotlin/Char.kt @@ -18,10 +18,9 @@ package kotlin /** * 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 final class Char private constructor(private val value: kotlin.native.internal.ShortValue) : Comparable { - +public class Char private constructor( + private val value: kotlin.native.internal.ShortValue) : Comparable { /** * Compares this value with the specified value for order. * Returns zero if this value is equal to the specified other value, a negative number if its less than other, @@ -155,7 +154,6 @@ public final class Char private constructor(private val value: kotlin.native.int public const val MAX_RADIX: Int = 36 } - // Konan-specific. public fun equals(other: Char): Boolean = this == other public override fun equals(other: Any?): Boolean = diff --git a/runtime/src/main/kotlin/kotlin/Comparator.kt b/runtime/src/main/kotlin/kotlin/Comparator.kt index 38558de9122..ec91e117000 100644 --- a/runtime/src/main/kotlin/kotlin/Comparator.kt +++ b/runtime/src/main/kotlin/kotlin/Comparator.kt @@ -16,11 +16,11 @@ package kotlin -actual interface Comparator { +actual public interface Comparator { actual fun compare(a: T, b: T): Int } -actual inline fun Comparator(crossinline comparison: (a: T, b: T) -> Int): Comparator { +actual public inline fun Comparator(crossinline comparison: (a: T, b: T) -> Int): Comparator { return object: Comparator { override fun compare(a: T, b: T) = comparison(a, b) } diff --git a/runtime/src/main/kotlin/kotlin/Enum.kt b/runtime/src/main/kotlin/kotlin/Enum.kt index 0bc4c519ae1..05690ddba4a 100644 --- a/runtime/src/main/kotlin/kotlin/Enum.kt +++ b/runtime/src/main/kotlin/kotlin/Enum.kt @@ -22,6 +22,7 @@ package kotlin * information on enum classes. */ public abstract class Enum>(public val name: String, public val ordinal: Int): Comparable { + public companion object { } @@ -49,10 +50,10 @@ public abstract class Enum>(public val name: String, public val ordin } @Suppress("UNUSED_PARAMETER") -fun > enumValueOf(name: String): T { +public fun > enumValueOf(name: String): T { throw Exception("Call to this function should've been lowered") } -fun > enumValues(): Array { +public fun > enumValues(): Array { throw Exception("Call to this function should've been lowered") } diff --git a/runtime/src/main/kotlin/kotlin/Functions.kt b/runtime/src/main/kotlin/kotlin/Functions.kt index a2a455f16de..0537814bd3c 100644 --- a/runtime/src/main/kotlin/kotlin/Functions.kt +++ b/runtime/src/main/kotlin/kotlin/Functions.kt @@ -16,96 +16,94 @@ package kotlin -// (0..22).joinToString("\n") { i -> "interface Function$i<${(1..i).joinToString("") { j -> "in P$j, " }}out R> : Function {\n operator fun invoke(${(1..i).joinToString { j -> "p$j: P$j" }}): R\n}\n" } - -interface Function0 : Function { +public interface Function0 : Function { operator fun invoke(): R } -interface Function1 : Function { +public interface Function1 : Function { operator fun invoke(p1: P1): R } -interface Function2 : Function { +public interface Function2 : Function { operator fun invoke(p1: P1, p2: P2): R } -interface Function3 : Function { +public interface Function3 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3): R } -interface Function4 : Function { +public interface Function4 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4): R } -interface Function5 : Function { +public interface Function5 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): R } -interface Function6 : Function { +public interface Function6 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): R } -interface Function7 : Function { +public interface Function7 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): R } -interface Function8 : Function { +public interface Function8 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): R } -interface Function9 : Function { +public interface Function9 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): R } -interface Function10 : Function { +public interface Function10 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10): R } -interface Function11 : Function { +public interface Function11 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11): R } -interface Function12 : Function { +public interface Function12 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12): R } -interface Function13 : Function { +public interface Function13 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13): R } -interface Function14 : Function { +public interface Function14 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14): R } -interface Function15 : Function { +public interface Function15 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15): R } -interface Function16 : Function { +public interface Function16 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16): R } -interface Function17 : Function { +public interface Function17 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17): R } -interface Function18 : Function { +public interface Function18 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18): R } -interface Function19 : Function { +public interface Function19 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19): R } -interface Function20 : Function { +public interface Function20 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20): R } -interface Function21 : Function { +public interface Function21 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21): R } -interface Function22 : Function { +public interface Function22 : Function { operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22): R } diff --git a/runtime/src/main/kotlin/kotlin/Lazy.kt b/runtime/src/main/kotlin/kotlin/Lazy.kt index e8dc2e51dfe..e8ffb1795fb 100644 --- a/runtime/src/main/kotlin/kotlin/Lazy.kt +++ b/runtime/src/main/kotlin/kotlin/Lazy.kt @@ -44,8 +44,8 @@ public actual fun lazy(initializer: () -> T): Lazy = FreezeAwareLazyImpl( @FixmeConcurrency public actual fun lazy(mode: LazyThreadSafetyMode, initializer: () -> T): Lazy = when (mode) { - LazyThreadSafetyMode.SYNCHRONIZED -> TODO() // was SynchronizedLazyImpl(initializer) - LazyThreadSafetyMode.PUBLICATION -> TODO() // was SafePublicationLazyImpl(initializer) + LazyThreadSafetyMode.SYNCHRONIZED -> throw UnsupportedOperationException() + LazyThreadSafetyMode.PUBLICATION -> throw UnsupportedOperationException() LazyThreadSafetyMode.NONE -> UnsafeLazyImpl(initializer) } @@ -62,4 +62,4 @@ public actual fun lazy(mode: LazyThreadSafetyMode, initializer: () -> T): La */ @FixmeConcurrency @Suppress("UNUSED_PARAMETER") -public actual fun lazy(lock: Any?, initializer: () -> T): Lazy = TODO() // was SynchronizedLazyImpl(initializer, lock) \ No newline at end of file +public actual fun lazy(lock: Any?, initializer: () -> T): Lazy = throw UnsupportedOperationException() \ No newline at end of file diff --git a/runtime/src/main/kotlin/kotlin/Primitives.kt b/runtime/src/main/kotlin/kotlin/Primitives.kt index 134fff37d12..5fa73c5d4a1 100644 --- a/runtime/src/main/kotlin/kotlin/Primitives.kt +++ b/runtime/src/main/kotlin/kotlin/Primitives.kt @@ -20,9 +20,9 @@ import kotlin.native.internal.NumberConverter /** * Represents a 8-bit signed integer. - * On the JVM, non-nullable values of this type are represented as values of the primitive type `byte`. */ public final class Byte private constructor(private val value: kotlin.native.internal.ByteValue) : Number(), Comparable { + companion object { /** * A constant holding the minimum value an instance of Byte can have. @@ -246,7 +246,6 @@ public final class Byte private constructor(private val value: kotlin.native.int /** * Represents a 16-bit signed integer. - * On the JVM, non-nullable values of this type are represented as values of the primitive type `short`. */ public final class Short private constructor(private val value: kotlin.native.internal.ShortValue) : Number(), Comparable { companion object { @@ -472,7 +471,6 @@ public final class Short private constructor(private val value: kotlin.native.in /** * Represents a 32-bit signed integer. - * On the JVM, non-nullable values of this type are represented as values of the primitive type `int`. */ public final class Int private constructor(private val value: kotlin.native.internal.IntValue) : Number(), Comparable { companion object { @@ -720,7 +718,6 @@ public final class Int private constructor(private val value: kotlin.native.inte /** * Represents a 64-bit signed integer. - * On the JVM, non-nullable values of this type are represented as values of the primitive type `long`. */ public final class Long private constructor(private val value: kotlin.native.internal.LongValue) : Number(), Comparable { companion object { @@ -968,7 +965,6 @@ public final class Long private constructor(private val value: kotlin.native.int /** * Represents a single-precision 32-bit IEEE 754 floating point number. - * On the JVM, non-nullable values of this type are represented as values of the primitive type `float`. */ public final class Float private constructor(private val value: kotlin.native.internal.FloatValue) : Number(), Comparable { companion object { @@ -1188,7 +1184,6 @@ public final class Float private constructor(private val value: kotlin.native.in /** * Represents a double-precision 64-bit IEEE 754 floating point number. - * On the JVM, non-nullable values of this type are represented as values of the primitive type `double`. */ public final class Double private constructor(private val value: kotlin.native.internal.DoubleValue) : Number(), Comparable { companion object { diff --git a/runtime/src/main/kotlin/kotlin/String.kt b/runtime/src/main/kotlin/kotlin/String.kt index dde413beee1..4f89c672dea 100644 --- a/runtime/src/main/kotlin/kotlin/String.kt +++ b/runtime/src/main/kotlin/kotlin/String.kt @@ -58,11 +58,8 @@ public final class String : Comparable, CharSequence { external public override fun equals(other: Any?): Boolean } -// TODO: in big Kotlin this operations are in kotlin.kotlin_builtins. -private fun nullString() = "null" - public operator fun kotlin.String?.plus(other: kotlin.Any?): kotlin.String = - (this?.toString() ?: nullString()).plus(other?.toString() ?: nullString()) + (this?.toString() ?: "null").plus(other?.toString() ?: "null") -public fun Any?.toString() = this?.toString() ?: nullString() \ No newline at end of file +public fun Any?.toString() = this?.toString() ?: "null" \ No newline at end of file diff --git a/runtime/src/main/kotlin/kotlin/SuspendFunctions.kt b/runtime/src/main/kotlin/kotlin/SuspendFunctions.kt index b34b6cd5ad1..859568d36a3 100644 --- a/runtime/src/main/kotlin/kotlin/SuspendFunctions.kt +++ b/runtime/src/main/kotlin/kotlin/SuspendFunctions.kt @@ -16,96 +16,94 @@ package kotlin -// (0..22).joinToString("\n") { i -> "interface SuspendFunction$i<${(1..i).joinToString("") { j -> "in P$j, " }}out R> : SuspendFunction {\n operator suspend fun invoke(${(1..i).joinToString { j -> "p$j: P$j" }}): R\n}\n" } - -interface SuspendFunction0 : SuspendFunction { +public interface SuspendFunction0 : SuspendFunction { operator suspend fun invoke(): R } -interface SuspendFunction1 : SuspendFunction { +public interface SuspendFunction1 : SuspendFunction { operator suspend fun invoke(p1: P1): R } -interface SuspendFunction2 : SuspendFunction { +public interface SuspendFunction2 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2): R } -interface SuspendFunction3 : SuspendFunction { +public interface SuspendFunction3 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3): R } -interface SuspendFunction4 : SuspendFunction { +public interface SuspendFunction4 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4): R } -interface SuspendFunction5 : SuspendFunction { +public interface SuspendFunction5 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): R } -interface SuspendFunction6 : SuspendFunction { +public interface SuspendFunction6 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): R } -interface SuspendFunction7 : SuspendFunction { +public interface SuspendFunction7 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): R } -interface SuspendFunction8 : SuspendFunction { +public interface SuspendFunction8 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): R } -interface SuspendFunction9 : SuspendFunction { +public interface SuspendFunction9 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9): R } -interface SuspendFunction10 : SuspendFunction { +public interface SuspendFunction10 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10): R } -interface SuspendFunction11 : SuspendFunction { +public interface SuspendFunction11 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11): R } -interface SuspendFunction12 : SuspendFunction { +public interface SuspendFunction12 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12): R } -interface SuspendFunction13 : SuspendFunction { +public interface SuspendFunction13 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13): R } -interface SuspendFunction14 : SuspendFunction { +public interface SuspendFunction14 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14): R } -interface SuspendFunction15 : SuspendFunction { +public interface SuspendFunction15 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15): R } -interface SuspendFunction16 : SuspendFunction { +public interface SuspendFunction16 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16): R } -interface SuspendFunction17 : SuspendFunction { +public interface SuspendFunction17 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17): R } -interface SuspendFunction18 : SuspendFunction { +public interface SuspendFunction18 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18): R } -interface SuspendFunction19 : SuspendFunction { +public interface SuspendFunction19 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19): R } -interface SuspendFunction20 : SuspendFunction { +public interface SuspendFunction20 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20): R } -interface SuspendFunction21 : SuspendFunction { +public interface SuspendFunction21 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21): R } -interface SuspendFunction22 : SuspendFunction { +public interface SuspendFunction22 : SuspendFunction { operator suspend fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22): R } diff --git a/runtime/src/main/kotlin/kotlin/collections/ArrayUtil.kt b/runtime/src/main/kotlin/kotlin/collections/ArrayUtil.kt index 5db849a0645..79f34ab4f28 100644 --- a/runtime/src/main/kotlin/kotlin/collections/ArrayUtil.kt +++ b/runtime/src/main/kotlin/kotlin/collections/ArrayUtil.kt @@ -307,7 +307,9 @@ external private fun copyImpl(array: BooleanArray, fromIndex: Int, * Copies a range of array elements at a specified [fromIndex] (inclusive) to [toIndex] (exclusive) range of indices * to another [destination] array starting at [destinationIndex]. */ -fun Array.copyRangeTo(destination: Array, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) { +@PublishedApi +internal fun Array.copyRangeTo( + destination: Array, fromIndex: Int, toIndex: Int, destinationIndex: Int = 0) { copyImpl(@Suppress("UNCHECKED_CAST") (this as Array), fromIndex, @Suppress("UNCHECKED_CAST") (destination as Array), destinationIndex, toIndex - fromIndex) diff --git a/runtime/src/main/kotlin/kotlin/native/Annotations.kt b/runtime/src/main/kotlin/kotlin/native/Annotations.kt index 00a78dfb81c..7f86eb31480 100644 --- a/runtime/src/main/kotlin/kotlin/native/Annotations.kt +++ b/runtime/src/main/kotlin/kotlin/native/Annotations.kt @@ -71,9 +71,9 @@ public annotation class SharedImmutable /** * Makes top level function available from C/C++ code with the given name. - * `fullName` controls the name of top level function, `shortName` controls the short name. - * If `fullName` is empty, no top level declaration is being created. + * `externName` controls the name of top level function, `shortName` controls the short name. + * If `externName` is empty, no top level declaration is being created. */ @Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.BINARY) -public annotation class CName(val fullName: String = "", val shortName: String = "") \ No newline at end of file +public annotation class CName(val externName: String = "", val shortName: String = "") \ No newline at end of file diff --git a/runtime/src/main/kotlin/kotlin/BitSet.kt b/runtime/src/main/kotlin/kotlin/native/BitSet.kt similarity index 99% rename from runtime/src/main/kotlin/kotlin/BitSet.kt rename to runtime/src/main/kotlin/kotlin/native/BitSet.kt index 85fe144bc69..b0fe4406679 100644 --- a/runtime/src/main/kotlin/kotlin/BitSet.kt +++ b/runtime/src/main/kotlin/kotlin/native/BitSet.kt @@ -14,12 +14,11 @@ * limitations under the License. */ -package kotlin +package kotlin.native /** * A vector of bits growing if necessary and allowing one to set/clear/read bits from it by a bit index. */ -// TODO: make me internal! public class BitSet(size: Int = ELEMENT_SIZE) { companion object { diff --git a/runtime/src/main/kotlin/kotlin/native/Text.kt b/runtime/src/main/kotlin/kotlin/native/Text.kt new file mode 100644 index 00000000000..f9bf68801a6 --- /dev/null +++ b/runtime/src/main/kotlin/kotlin/native/Text.kt @@ -0,0 +1,62 @@ +/* + * Copyright 2010-2018 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.native + +/** + * Converts an UTF-8 array into a [String]. Replaces invalid input sequences with a default character. + */ +public fun ByteArray.stringFromUtf8(start: Int = 0, size: Int = this.size) : String = + stringFromUtf8Impl(start, size) + +@SymbolName("Kotlin_ByteArray_stringFromUtf8") +private external fun ByteArray.stringFromUtf8Impl(start: Int, size: Int) : String + +/** + * Converts an UTF-8 array into a [String]. Throws [IllegalCharacterConversionException] if the input is invalid. + */ +public fun ByteArray.stringFromUtf8OrThrow(start: Int = 0, size: Int = this.size) : String = + stringFromUtf8OrThrowImpl(start, size) + +@SymbolName("Kotlin_ByteArray_stringFromUtf8OrThrow") +private external fun ByteArray.stringFromUtf8OrThrowImpl(start: Int, size: Int) : String + +/** + * Converts a [String] into an UTF-8 array. Replaces invalid input sequences with a default character. + */ +public fun String.toUtf8(start: Int = 0, size: Int = this.length) : ByteArray = + toUtf8Impl(start, size) + +@SymbolName("Kotlin_String_toUtf8") +private external fun String.toUtf8Impl(start: Int, size: Int) : ByteArray + +/** + * Converts a [String] into an UTF-8 array. Throws [IllegalCharacterConversionException] if the input is invalid. + */ +public fun String.toUtf8OrThrow(start: Int = 0, size: Int = this.length) : ByteArray = + toUtf8OrThrowImpl(start, size) + +@SymbolName("Kotlin_String_toUtf8OrThrow") +private external fun String.toUtf8OrThrowImpl(start: Int, size: Int) : ByteArray + +@SymbolName("Kotlin_String_fromCharArray") +internal external fun fromCharArray(array: CharArray, start: Int, size: Int) : String + +@SymbolName("Kotlin_StringBuilder_insertString") +internal external fun insertString(array: CharArray, start: Int, value: String): Int + +@SymbolName("Kotlin_StringBuilder_insertInt") +internal external fun insertInt(array: CharArray, start: Int, value: Int): Int \ No newline at end of file diff --git a/runtime/src/main/kotlin/kotlin/native/TypedArrays.kt b/runtime/src/main/kotlin/kotlin/native/TypedArrays.kt index 6e614f5dd15..ef53df0b101 100644 --- a/runtime/src/main/kotlin/kotlin/native/TypedArrays.kt +++ b/runtime/src/main/kotlin/kotlin/native/TypedArrays.kt @@ -17,63 +17,69 @@ package kotlin.native import kotlin.native.SymbolName -fun ByteArray.ubyteAt(index: Int): UByte = UByte(get(index)) +/** + * Those operations allows to extract primitive values out of the byte buffers. + * Data is treated as if it was in Least-Significant-Byte first (little-endian) byte order. + * If index is outside of array boundaries - ArrayIndexOutOfBoundsException is thrown. + */ +@ExperimentalUnsignedTypes +public fun ByteArray.ubyteAt(index: Int): UByte = UByte(get(index)) @SymbolName("Kotlin_ByteArray_getCharAt") -external fun ByteArray.charAt(index: Int): Char +public external fun ByteArray.charAt(index: Int): Char @SymbolName("Kotlin_ByteArray_getShortAt") -external fun ByteArray.shortAt(index: Int): Short +public external fun ByteArray.shortAt(index: Int): Short @SymbolName("Kotlin_ByteArray_getShortAt") @ExperimentalUnsignedTypes -external fun ByteArray.ushortAt(index: Int): UShort +public external fun ByteArray.ushortAt(index: Int): UShort @SymbolName("Kotlin_ByteArray_getIntAt") -external fun ByteArray.intAt(index: Int): Int +public external fun ByteArray.intAt(index: Int): Int @SymbolName("Kotlin_ByteArray_getIntAt") @ExperimentalUnsignedTypes -external fun ByteArray.uintAt(index: Int): UInt +public external fun ByteArray.uintAt(index: Int): UInt @SymbolName("Kotlin_ByteArray_getLongAt") -external fun ByteArray.longAt(index: Int): Long +public external fun ByteArray.longAt(index: Int): Long @SymbolName("Kotlin_ByteArray_getLongAt") @ExperimentalUnsignedTypes -external fun ByteArray.ulongAt(index: Int): ULong +public external fun ByteArray.ulongAt(index: Int): ULong @SymbolName("Kotlin_ByteArray_getFloatAt") -external fun ByteArray.floatAt(index: Int): Float +public external fun ByteArray.floatAt(index: Int): Float @SymbolName("Kotlin_ByteArray_getDoubleAt") -external fun ByteArray.doubleAt(index: Int): Double +public external fun ByteArray.doubleAt(index: Int): Double @SymbolName("Kotlin_ByteArray_setCharAt") -external fun ByteArray.setCharAt(index: Int, value: Char) +public external fun ByteArray.setCharAt(index: Int, value: Char) @SymbolName("Kotlin_ByteArray_setShortAt") -external fun ByteArray.setShortAt(index: Int, value: Short) +public external fun ByteArray.setShortAt(index: Int, value: Short) @SymbolName("Kotlin_ByteArray_setShortAt") @ExperimentalUnsignedTypes -external fun ByteArray.setUShortAt(index: Int, value: UShort) +public external fun ByteArray.setUShortAt(index: Int, value: UShort) @SymbolName("Kotlin_ByteArray_setIntAt") -external fun ByteArray.setIntAt(index: Int, value: Int) +public external fun ByteArray.setIntAt(index: Int, value: Int) @SymbolName("Kotlin_ByteArray_setIntAt") -external fun ByteArray.setUIntAt(index: Int, value: UInt) +public external fun ByteArray.setUIntAt(index: Int, value: UInt) @SymbolName("Kotlin_ByteArray_setLongAt") -external fun ByteArray.setLongAt(index: Int, value: Long) +public external fun ByteArray.setLongAt(index: Int, value: Long) @SymbolName("Kotlin_ByteArray_setLongAt") @ExperimentalUnsignedTypes -external fun ByteArray.setULongAt(index: Int, value: ULong) +public external fun ByteArray.setULongAt(index: Int, value: ULong) @SymbolName("Kotlin_ByteArray_setFloatAt") -external fun ByteArray.setFloatAt(index: Int, value: Float) +public external fun ByteArray.setFloatAt(index: Int, value: Float) @SymbolName("Kotlin_ByteArray_setDoubleAt") -external fun ByteArray.setDoubleAt(index: Int, value: Double) +public external fun ByteArray.setDoubleAt(index: Int, value: Double) diff --git a/runtime/src/main/kotlin/kotlin/random/Random.kt b/runtime/src/main/kotlin/kotlin/random/Random.kt index 171f2b83483..716b69bd2d7 100644 --- a/runtime/src/main/kotlin/kotlin/random/Random.kt +++ b/runtime/src/main/kotlin/kotlin/random/Random.kt @@ -18,7 +18,7 @@ package kotlin.random import kotlin.native.concurrent.AtomicLong import kotlin.system.getTimeNanos -abstract class NativeRandom { +public abstract class NativeRandom { /** * A default pseudo-random linear congruential generator. */ diff --git a/runtime/src/main/kotlin/kotlin/ranges/Progressions.kt b/runtime/src/main/kotlin/kotlin/ranges/Progressions.kt index 932639b382e..43e231bd8af 100644 --- a/runtime/src/main/kotlin/kotlin/ranges/Progressions.kt +++ b/runtime/src/main/kotlin/kotlin/ranges/Progressions.kt @@ -21,13 +21,9 @@ import kotlin.internal.getProgressionLastElement /** * A progression of values of type `Char`. */ -public open class CharProgression -internal constructor -( - start: Char, - endInclusive: Char, - step: Int -) : Iterable { +public open class CharProgression internal constructor( + start: Char, endInclusive: Char, step: Int) : Iterable { + init { if (step == 0) throw kotlin.IllegalArgumentException("Step must be non-zero") } @@ -75,13 +71,9 @@ internal constructor /** * A progression of values of type `Int`. */ -public open class IntProgression -internal constructor -( - start: Int, - endInclusive: Int, - step: Int -) : Iterable { +public open class IntProgression internal constructor( + start: Int, endInclusive: Int, step: Int) : Iterable { + init { if (step == 0) throw kotlin.IllegalArgumentException("Step must be non-zero") } @@ -122,20 +114,17 @@ internal constructor * The progression starts with the [rangeStart] value and goes toward the [rangeEnd] value not excluding it, with the specified [step]. * In order to go backwards the [step] must be negative. */ - public fun fromClosedRange(rangeStart: Int, rangeEnd: Int, step: Int): IntProgression = IntProgression(rangeStart, rangeEnd, step) + public fun fromClosedRange(rangeStart: Int, rangeEnd: Int, step: Int): IntProgression = + IntProgression(rangeStart, rangeEnd, step) } } /** * A progression of values of type `Long`. */ -public open class LongProgression -internal constructor -( - start: Long, - endInclusive: Long, - step: Long -) : Iterable { +public open class LongProgression internal constructor( + start: Long, endInclusive: Long, step: Long) : Iterable { + init { if (step == 0L) throw kotlin.IllegalArgumentException("Step must be non-zero") } diff --git a/runtime/src/main/kotlin/kotlin/reflect/KAnnotatedElement.kt b/runtime/src/main/kotlin/kotlin/reflect/KAnnotatedElement.kt index 9a30cff9788..10eb9e8666b 100644 --- a/runtime/src/main/kotlin/kotlin/reflect/KAnnotatedElement.kt +++ b/runtime/src/main/kotlin/kotlin/reflect/KAnnotatedElement.kt @@ -24,9 +24,4 @@ import kotlin.native.internal.FixmeReflection * for more information. */ @FixmeReflection -public interface KAnnotatedElement { -// /** -// * Annotations which are present on this element. -// */ -// public val annotations: List -} \ No newline at end of file +public interface KAnnotatedElement \ No newline at end of file diff --git a/runtime/src/main/kotlin/kotlin/reflect/KCallable.kt b/runtime/src/main/kotlin/kotlin/reflect/KCallable.kt index f1bf8c5710e..096f6dd8348 100644 --- a/runtime/src/main/kotlin/kotlin/reflect/KCallable.kt +++ b/runtime/src/main/kotlin/kotlin/reflect/KCallable.kt @@ -35,59 +35,8 @@ public interface KCallable : KAnnotatedElement { */ public val name: String -// /** -// * Parameters required to make a call to this callable. -// * If this callable requires a `this` instance or an extension receiver parameter, -// * they come first in the list in that order. -// */ -// public val parameters: List - /** * The type of values returned by this callable. */ public val returnType: KType - -// /** -// * The list of type parameters of this callable. -// */ -// @SinceKotlin("1.1") -// public val typeParameters: List -// -// /** -// * Calls this callable with the specified list of arguments and returns the result. -// * Throws an exception if the number of specified arguments is not equal to the size of [parameters], -// * or if their types do not match the types of the parameters. -// */ -// public fun call(vararg args: Any?): R -// -// /** -// * Calls this callable with the specified mapping of parameters to arguments and returns the result. -// * If a parameter is not found in the mapping and is not optional (as per [KParameter.isOptional]), -// * or its type does not match the type of the provided value, an exception is thrown. -// */ -// public fun callBy(args: Map): R -// -// /** -// * Visibility of this callable, or `null` if its visibility cannot be represented in Kotlin. -// */ -// @SinceKotlin("1.1") -// public val visibility: KVisibility? -// -// /** -// * `true` if this callable is `final`. -// */ -// @SinceKotlin("1.1") -// public val isFinal: Boolean -// -// /** -// * `true` if this callable is `open`. -// */ -// @SinceKotlin("1.1") -// public val isOpen: Boolean -// -// /** -// * `true` if this callable is `abstract`. -// */ -// @SinceKotlin("1.1") -// public val isAbstract: Boolean } diff --git a/runtime/src/main/kotlin/kotlin/reflect/KClass.kt b/runtime/src/main/kotlin/kotlin/reflect/KClass.kt index aa92833e67a..4369b2c3568 100644 --- a/runtime/src/main/kotlin/kotlin/reflect/KClass.kt +++ b/runtime/src/main/kotlin/kotlin/reflect/KClass.kt @@ -37,101 +37,12 @@ public interface KClass : KDeclarationContainer, KAnnotatedElement, KCl */ public val qualifiedName: String? -// /** -// * All functions and properties accessible in this class, including those declared in this class -// * and all of its superclasses. Does not include constructors. -// */ -// override val members: Collection> -// -// /** -// * All constructors declared in this class. -// */ -// public val constructors: Collection> -// -// /** -// * All classes declared inside this class. This includes both inner and static nested classes. -// */ -// public val nestedClasses: Collection> -// -// /** -// * The instance of the object declaration, or `null` if this class is not an object declaration. -// */ -// public val objectInstance: T? - /** * Returns `true` if [value] is an instance of this class on a given platform. */ @SinceKotlin("1.1") public fun isInstance(value: Any?): Boolean -// /** -// * The list of type parameters of this class. This list does *not* include type parameters of outer classes. -// */ -// @SinceKotlin("1.1") -// public val typeParameters: List -// -// /** -// * The list of immediate supertypes of this class, in the order they are listed in the source code. -// */ -// @SinceKotlin("1.1") -// public val supertypes: List -// -// /** -// * Visibility of this class, or `null` if its visibility cannot be represented in Kotlin. -// */ -// @SinceKotlin("1.1") -// public val visibility: KVisibility? -// -// /** -// * `true` if this class is `final`. -// */ -// @SinceKotlin("1.1") -// public val isFinal: Boolean -// -// /** -// * `true` if this class is `open`. -// */ -// @SinceKotlin("1.1") -// public val isOpen: Boolean -// -// /** -// * `true` if this class is `abstract`. -// */ -// @SinceKotlin("1.1") -// public val isAbstract: Boolean -// -// /** -// * `true` if this class is `sealed`. -// * See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/classes.html#sealed-classes) -// * for more information. -// */ -// @SinceKotlin("1.1") -// public val isSealed: Boolean -// -// /** -// * `true` if this class is a data class. -// * See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/data-classes.html) -// * for more information. -// */ -// @SinceKotlin("1.1") -// public val isData: Boolean -// -// /** -// * `true` if this class is an inner class. -// * See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/nested-classes.html#inner-classes) -// * for more information. -// */ -// @SinceKotlin("1.1") -// public val isInner: Boolean -// -// /** -// * `true` if this class is a companion object. -// * See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/object-declarations.html#companion-objects) -// * for more information. -// */ -// @SinceKotlin("1.1") -// public val isCompanion: Boolean - /** * Returns `true` if this [KClass] instance represents the same Kotlin class as the class represented by [other]. * On JVM this means that all of the following conditions are satisfied: diff --git a/runtime/src/main/kotlin/kotlin/reflect/KDeclarationContainer.kt b/runtime/src/main/kotlin/kotlin/reflect/KDeclarationContainer.kt index 6ccdd96884b..bfbbd2a150d 100644 --- a/runtime/src/main/kotlin/kotlin/reflect/KDeclarationContainer.kt +++ b/runtime/src/main/kotlin/kotlin/reflect/KDeclarationContainer.kt @@ -20,9 +20,4 @@ package kotlin.reflect * Represents an entity which may contain declarations of any other entities, * such as a class or a package. */ -public interface KDeclarationContainer { -// /** -// * All functions and properties accessible in this container. -// */ -// public val members: Collection> -} +public interface KDeclarationContainer \ No newline at end of file diff --git a/runtime/src/main/kotlin/kotlin/reflect/KProperty.kt b/runtime/src/main/kotlin/kotlin/reflect/KProperty.kt index f9aeb32e4cc..5aed3b9c668 100644 --- a/runtime/src/main/kotlin/kotlin/reflect/KProperty.kt +++ b/runtime/src/main/kotlin/kotlin/reflect/KProperty.kt @@ -27,97 +27,35 @@ import kotlin.native.internal.FixmeReflection * @param R the type of the property. */ @FixmeReflection -public interface KProperty : KCallable { -// /** -// * `true` if this property is `lateinit`. -// * See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/properties.html#late-initialized-properties) -// * for more information. -// */ -// @SinceKotlin("1.1") -// public val isLateinit: Boolean -// -// /** -// * `true` if this property is `const`. -// * See the [Kotlin language documentation](https://kotlinlang.org/docs/reference/properties.html#compile-time-constants) -// * for more information. -// */ -// @SinceKotlin("1.1") -// public val isConst: Boolean -// -// /** The getter of this property, used to obtain the value of the property. */ -// public val getter: Getter -// -// /** -// * Represents a property accessor, which is a `get` or `set` method declared alongside the property. -// * See the [Kotlin language documentation](http://kotlinlang.org/docs/reference/properties.html#getters-and-setters) -// * for more information. -// * -// * @param R the type of the property, which it is an accessor of. -// */ -// public interface Accessor { -// /** The property which this accessor is originated from. */ -// public val property: KProperty -// } -// -// /** -// * Getter of the property is a `get` method declared alongside the property. -// */ -// public interface Getter : Accessor, KFunction -} +public interface KProperty : KCallable -// @FixmeReflection public interface KProperty0 : kotlin.reflect.KProperty, () -> R { -// public abstract val getter: kotlin.reflect.KProperty1.Getter public abstract fun get(): R - public override abstract operator fun invoke(): R -// @kotlin.SinceKotlin public abstract fun getDelegate(receiver: T): kotlin.Any? -// -// public interface Getter : kotlin.reflect.KProperty.Getter, (T) -> R { -// } + public override abstract operator fun invoke(): R } @FixmeReflection public interface KProperty1 : kotlin.reflect.KProperty, (T) -> R { -// public abstract val getter: kotlin.reflect.KProperty1.Getter - public abstract fun get(p1: T): R - public override abstract operator fun invoke(p1: T): R -// @kotlin.SinceKotlin public abstract fun getDelegate(receiver: T): kotlin.Any? -// -// public interface Getter : kotlin.reflect.KProperty.Getter, (T) -> R { -// } + public override abstract operator fun invoke(p1: T): R } @FixmeReflection public interface KProperty2 : kotlin.reflect.KProperty, (T1, T2) -> R { -// public abstract val getter: kotlin.reflect.KProperty1.Getter - public abstract fun get(p1: T1, p2: T2): R - public override abstract operator fun invoke(p1: T1, p2: T2): R -// @kotlin.SinceKotlin public abstract fun getDelegate(receiver: T): kotlin.Any? -// -// public interface Getter : kotlin.reflect.KProperty.Getter, (T) -> R { -// } + public override abstract operator fun invoke(p1: T1, p2: T2): R } /** * Represents a property declared as a `var`. */ @FixmeReflection -public interface KMutableProperty : KProperty { -// /** The setter of this mutable property, used to change the value of the property. */ -// public val setter: Setter -// -// /** -// * Setter of the property is a `set` method declared alongside the property. -// */ -// public interface Setter : KProperty.Accessor, KFunction -} +public interface KMutableProperty : KProperty @FixmeReflection public interface KMutableProperty0 : KProperty0, KMutableProperty { diff --git a/runtime/src/main/kotlin/kotlin/reflect/KType.kt b/runtime/src/main/kotlin/kotlin/reflect/KType.kt index 3c83d4e004b..cf3e2b2dae0 100644 --- a/runtime/src/main/kotlin/kotlin/reflect/KType.kt +++ b/runtime/src/main/kotlin/kotlin/reflect/KType.kt @@ -30,17 +30,6 @@ public interface KType { @SinceKotlin("1.1") public val classifier: KClassifier? - /** - * Type arguments passed for the parameters of the classifier in this type. - * For example, in the type `Array` the only type argument is `out Number`. - * - * In case this type is based on an inner class, the returned list contains the type arguments provided for the innermost class first, - * then its outer class, and so on. - * For example, in the type `Outer.Inner` the returned list is `[C, D, A, B]`. - */ -// @SinceKotlin("1.1") -// public val arguments: List - /** * `true` if this type was marked nullable in the source code. * diff --git a/runtime/src/main/kotlin/kotlin/test/Annotation.kt b/runtime/src/main/kotlin/kotlin/test/Annotation.kt index 7a2933acafd..157188dcfc1 100644 --- a/runtime/src/main/kotlin/kotlin/test/Annotation.kt +++ b/runtime/src/main/kotlin/kotlin/test/Annotation.kt @@ -21,28 +21,28 @@ package kotlin.test */ @Retention(AnnotationRetention.SOURCE) @Target(AnnotationTarget.FUNCTION) -annotation class Test +public annotation class Test /** * Marks a function to be executed before a suite. Not supported in Kotlin/Common. */ @Retention(AnnotationRetention.SOURCE) @Target(AnnotationTarget.FUNCTION) -annotation class BeforeClass +public annotation class BeforeClass /** * Marks a function to be executed after a suite. Not supported in Kotlin/Common. */ @Retention(AnnotationRetention.SOURCE) @Target(AnnotationTarget.FUNCTION) -annotation class AfterClass +public annotation class AfterClass /** * Marks a function to be executed before a test. */ @Retention(AnnotationRetention.SOURCE) @Target(AnnotationTarget.FUNCTION) -annotation class BeforeEach +public annotation class BeforeEach /** @@ -50,14 +50,14 @@ annotation class BeforeEach */ @Retention(AnnotationRetention.SOURCE) @Target(AnnotationTarget.FUNCTION) -annotation class AfterEach +public annotation class AfterEach /** * Marks a test or a suite as ignored/pending. */ @Retention(AnnotationRetention.SOURCE) @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION) -annotation class Ignore +public annotation class Ignore -typealias AfterTest = AfterEach -typealias BeforeTest = BeforeEach +public typealias AfterTest = AfterEach +public typealias BeforeTest = BeforeEach diff --git a/runtime/src/main/kotlin/kotlin/test/Assertions.kt b/runtime/src/main/kotlin/kotlin/test/Assertions.kt index e11aadd3206..9ce8da4b501 100644 --- a/runtime/src/main/kotlin/kotlin/test/Assertions.kt +++ b/runtime/src/main/kotlin/kotlin/test/Assertions.kt @@ -15,7 +15,7 @@ */ /** - * A number of common helper methods for writing unit tests. Copied from Kotlin repo. + * A number of common helper methods for writing unit tests. */ @file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") @@ -28,56 +28,56 @@ import kotlin.reflect.KClass /** * Current adapter providing assertion implementations */ -val asserter: Asserter +private val asserter: Asserter get() = _asserter ?: lookupAsserter() /** Used to override current asserter internally */ internal var _asserter: Asserter? = null /** Asserts that the given [block] returns `true`. */ -fun assertTrue(message: String? = null, block: () -> Boolean): Unit = assertTrue(block(), message) +public fun assertTrue(message: String? = null, block: () -> Boolean): Unit = assertTrue(block(), message) /** Asserts that the expression is `true` with an optional [message]. */ -fun assertTrue(actual: Boolean, message: String? = null) { +public fun assertTrue(actual: Boolean, message: String? = null) { return asserter.assertTrue(message ?: "Expected value to be true.", actual) } /** Asserts that the given [block] returns `false`. */ -fun assertFalse(message: String? = null, block: () -> Boolean): Unit = assertFalse(block(), message) +public fun assertFalse(message: String? = null, block: () -> Boolean): Unit = assertFalse(block(), message) /** Asserts that the expression is `false` with an optional [message]. */ -fun assertFalse(actual: Boolean, message: String? = null) { +public fun assertFalse(actual: Boolean, message: String? = null) { return asserter.assertTrue(message ?: "Expected value to be false.", !actual) } /** Asserts that the [expected] value is equal to the [actual] value, with an optional [message]. */ -fun <@OnlyInputTypes T> assertEquals(expected: T, actual: T, message: String? = null) { +public fun <@OnlyInputTypes T> assertEquals(expected: T, actual: T, message: String? = null) { asserter.assertEquals(message, expected, actual) } /** Asserts that the [actual] value is not equal to the illegal value, with an optional [message]. */ -fun <@OnlyInputTypes T> assertNotEquals(illegal: T, actual: T, message: String? = null) { +public fun <@OnlyInputTypes T> assertNotEquals(illegal: T, actual: T, message: String? = null) { asserter.assertNotEquals(message, illegal, actual) } /** Asserts that [expected] is the same instance as [actual], with an optional [message]. */ -fun <@OnlyInputTypes T> assertSame(expected: T, actual: T, message: String? = null) { +public fun <@OnlyInputTypes T> assertSame(expected: T, actual: T, message: String? = null) { asserter.assertSame(message, expected, actual) } /** Asserts that [actual] is not the same instance as [illegal], with an optional [message]. */ -fun <@OnlyInputTypes T> assertNotSame(illegal: T, actual: T, message: String? = null) { +public fun <@OnlyInputTypes T> assertNotSame(illegal: T, actual: T, message: String? = null) { asserter.assertNotSame(message, illegal, actual) } /** Asserts that the [actual] value is not `null`, with an optional [message]. */ -fun assertNotNull(actual: T?, message: String? = null): T { +public fun assertNotNull(actual: T?, message: String? = null): T { asserter.assertNotNull(message, actual) return actual!! } /** Asserts that the [actual] value is not `null`, with an optional [message] and a function [block] to process the not-null value. */ -fun assertNotNull(actual: T?, message: String? = null, block: (T) -> R) { +public fun assertNotNull(actual: T?, message: String? = null, block: (T) -> R) { asserter.assertNotNull(message, actual) if (actual != null) { block(actual) @@ -85,31 +85,31 @@ fun assertNotNull(actual: T?, message: String? = null, block: (T) - } /** Asserts that the [actual] value is `null`, with an optional [message]. */ -fun assertNull(actual: Any?, message: String? = null) { +public fun assertNull(actual: Any?, message: String? = null) { asserter.assertNull(message, actual) } /** Marks a test as having failed if this point in the execution path is reached, with an optional [message]. */ -fun fail(message: String? = null): Nothing { +public fun fail(message: String? = null): Nothing { asserter.fail(message) } /** Asserts that given function [block] returns the given [expected] value. */ -fun <@OnlyInputTypes T> expect(expected: T, block: () -> T) { +public fun <@OnlyInputTypes T> expect(expected: T, block: () -> T) { assertEquals(expected, block()) } /** Asserts that given function [block] returns the given [expected] value and use the given [message] if it fails. */ -fun <@OnlyInputTypes T> expect(expected: T, message: String?, block: () -> T) { +public fun <@OnlyInputTypes T> expect(expected: T, message: String?, block: () -> T) { assertEquals(expected, block(), message) } /** Asserts that given function [block] fails by throwing an exception. */ -fun assertFails(block: () -> Unit): Throwable = assertFails(null, block) +public fun assertFails(block: () -> Unit): Throwable = assertFails(null, block) /** Asserts that given function [block] fails by throwing an exception. */ @SinceKotlin("1.1") -fun assertFails(message: String?, block: () -> Unit): Throwable { +public fun assertFails(message: String?, block: () -> Unit): Throwable { try { block() } catch (e: Throwable) { @@ -123,11 +123,11 @@ fun assertFails(message: String?, block: () -> Unit): Throwable { * Since inline method doesn't allow to trace where it was invoked, it is required to pass a [message] to distinguish this method call from others. */ @InlineOnly -inline fun assertFailsWith(message: String? = null, noinline block: () -> Unit) : T = +public inline fun assertFailsWith(message: String? = null, noinline block: () -> Unit) : T = assertFailsWith(T::class, message, block) /** Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. */ -fun assertFailsWith(exceptionClass: KClass, block: () -> Unit): T = +public fun assertFailsWith(exceptionClass: KClass, block: () -> Unit): T = assertFailsWith(exceptionClass, null, block) @@ -137,12 +137,12 @@ fun assertFailsWith(exceptionClass: KClass, block: () -> Unit * to implement in your unit test output */ @Suppress("UNUSED_PARAMETER") -inline fun todo(block: () -> Unit) { +public inline fun todo(block: () -> Unit) { println("TODO") } /** Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. */ -fun assertFailsWith(exceptionClass: KClass, message: String?, block: () -> Unit): T { +public fun assertFailsWith(exceptionClass: KClass, message: String?, block: () -> Unit): T { try { block() } catch (e: Throwable) { @@ -164,7 +164,7 @@ fun assertFailsWith(exceptionClass: KClass, message: String?, /** * Abstracts the logic for performing assertions. */ -interface Asserter { +public interface Asserter { /** * Fails the current test with the specified message. * @@ -251,7 +251,7 @@ interface Asserter { /** * Checks applicability and provides Asserter instance */ -interface AsserterContributor { +public interface AsserterContributor { /** * Provides [Asserter] instance or `null` depends on the current context. * diff --git a/runtime/src/main/kotlin/kotlin/test/DefaultAsserter.kt b/runtime/src/main/kotlin/kotlin/test/DefaultAsserter.kt index 07ba9dc61eb..038929a999a 100644 --- a/runtime/src/main/kotlin/kotlin/test/DefaultAsserter.kt +++ b/runtime/src/main/kotlin/kotlin/test/DefaultAsserter.kt @@ -19,7 +19,7 @@ package kotlin.test /** * Default [Asserter] implementation for Kotlin/Native. */ -object DefaultAsserter : Asserter { +public object DefaultAsserter : Asserter { override fun fail(message: String?): Nothing { if (message == null) throw AssertionError() diff --git a/runtime/src/main/kotlin/kotlin/text/Appendable.kt b/runtime/src/main/kotlin/kotlin/text/Appendable.kt index a3085f808a1..85f0a3cb390 100644 --- a/runtime/src/main/kotlin/kotlin/text/Appendable.kt +++ b/runtime/src/main/kotlin/kotlin/text/Appendable.kt @@ -16,7 +16,7 @@ package kotlin.text -actual interface Appendable { +public actual interface Appendable { actual fun append(c: Char): Appendable actual fun append(csq: CharSequence?): Appendable actual fun append(csq: CharSequence?, start: Int, end: Int): Appendable diff --git a/runtime/src/main/kotlin/kotlin/text/CharCategory.kt b/runtime/src/main/kotlin/kotlin/text/CharCategory.kt index c5fe028ac05..e8277a8903e 100644 --- a/runtime/src/main/kotlin/kotlin/text/CharCategory.kt +++ b/runtime/src/main/kotlin/kotlin/text/CharCategory.kt @@ -13,10 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package kotlin.text -// The values duplicate constants defined in KString.cpp. /** * Represents the character general category in the Unicode specification. */ diff --git a/runtime/src/main/kotlin/kotlin/text/PatternSyntaxException.kt b/runtime/src/main/kotlin/kotlin/text/PatternSyntaxException.kt index 522d72e5daf..f4a93c76b74 100644 --- a/runtime/src/main/kotlin/kotlin/text/PatternSyntaxException.kt +++ b/runtime/src/main/kotlin/kotlin/text/PatternSyntaxException.kt @@ -1,18 +1,17 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 + * Copyright 2010-2018 JetBrains s.r.o. * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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 * - * 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. + * 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.text @@ -21,8 +20,6 @@ package kotlin.text * Encapsulates a syntax error that occurred during the compilation of a * [Pattern]. Might include a detailed description, the original regular * expression, and the index at which the error occurred. - * - */ -class PatternSyntaxException(val description: String = "", val pattern: String = "", index: Int = -1) +internal class PatternSyntaxException(val description: String = "", val pattern: String = "", index: Int = -1) : IllegalArgumentException("Error in \"$pattern\" ($index). $description") diff --git a/runtime/src/main/kotlin/kotlin/text/Regex.kt b/runtime/src/main/kotlin/kotlin/text/Regex.kt index d617cb9fa36..4e2fa501c3b 100644 --- a/runtime/src/main/kotlin/kotlin/text/Regex.kt +++ b/runtime/src/main/kotlin/kotlin/text/Regex.kt @@ -31,7 +31,7 @@ private fun fromInt(value: Int): Set = /** * Provides enumeration values to use to set regular expression options. */ -actual enum class RegexOption(override val value: Int, override val mask: Int = value) : FlagEnum { +actual public enum class RegexOption(override val value: Int, override val mask: Int = value) : FlagEnum { // common /** Enables case-insensitive matching. Case comparison is Unicode-aware. */ @@ -79,7 +79,7 @@ actual data class MatchGroup(actual val value: String, val range: IntRange) * * For pattern syntax reference see [Pattern] */ -actual class Regex internal constructor(internal val nativePattern: Pattern) { +actual public class Regex internal constructor(internal val nativePattern: Pattern) { enum class Mode { FIND, MATCH diff --git a/runtime/src/main/kotlin/kotlin/text/StringBuilder.kt b/runtime/src/main/kotlin/kotlin/text/StringBuilder.kt index d0f1f7fe59a..f793940c5f6 100644 --- a/runtime/src/main/kotlin/kotlin/text/StringBuilder.kt +++ b/runtime/src/main/kotlin/kotlin/text/StringBuilder.kt @@ -16,14 +16,6 @@ package kotlin.text -// ByteArray -> String (UTF-8 -> UTF-16) - -@Deprecated("Use ByteArray.stringFromUtf8()", ReplaceWith("array.stringFromUtf8(start, end)")) -fun fromUtf8Array(array: ByteArray, start: Int, size: Int) = array.stringFromUtf8Impl(start, size) - -@Deprecated("Use String.toUtf8()", ReplaceWith("string.toUtf8(start, end)")) -fun toUtf8Array(string: String, start: Int, size: Int) : ByteArray = string.toUtf8(start, size) - /** * Clears the content of this string builder making it empty. * @@ -32,53 +24,6 @@ fun toUtf8Array(string: String, start: Int, size: Int) : ByteArray = string.toUt @SinceKotlin("1.3") public actual fun StringBuilder.clear(): StringBuilder = apply { setLength(0) } -/** - * Converts an UTF-8 array into a [String]. Replaces invalid input sequences with a default character. - */ -fun ByteArray.stringFromUtf8(start: Int = 0, size: Int = this.size) : String = - stringFromUtf8Impl(start, size) - -@SymbolName("Kotlin_ByteArray_stringFromUtf8") -private external fun ByteArray.stringFromUtf8Impl(start: Int, size: Int) : String - -/** - * Converts an UTF-8 array into a [String]. Throws [IllegalCharacterConversionException] if the input is invalid. - */ -fun ByteArray.stringFromUtf8OrThrow(start: Int = 0, size: Int = this.size) : String = - stringFromUtf8OrThrowImpl(start, size) - -@SymbolName("Kotlin_ByteArray_stringFromUtf8OrThrow") -private external fun ByteArray.stringFromUtf8OrThrowImpl(start: Int, size: Int) : String - -// String -> ByteArray (UTF-16 -> UTF-8) -/** - * Converts a [String] into an UTF-8 array. Replaces invalid input sequences with a default character. - */ -fun String.toUtf8(start: Int = 0, size: Int = this.length) : ByteArray = - toUtf8Impl(start, size) - -@SymbolName("Kotlin_String_toUtf8") -private external fun String.toUtf8Impl(start: Int, size: Int) : ByteArray - -/** - * Converts a [String] into an UTF-8 array. Throws [IllegalCharacterConversionException] if the input is invalid. - */ -fun String.toUtf8OrThrow(start: Int = 0, size: Int = this.length) : ByteArray = - toUtf8OrThrowImpl(start, size) - -@SymbolName("Kotlin_String_toUtf8OrThrow") -private external fun String.toUtf8OrThrowImpl(start: Int, size: Int) : ByteArray - -// TODO: make it somewhat private? -@SymbolName("Kotlin_String_fromCharArray") -external fun fromCharArray(array: CharArray, start: Int, size: Int) : String - -@SymbolName("Kotlin_StringBuilder_insertString") -private external fun insertString(array: CharArray, start: Int, value: String): Int - -@SymbolName("Kotlin_StringBuilder_insertInt") -private external fun insertInt(array: CharArray, start: Int, value: Int): Int - /** * Sets the character at the specified [index] to the specified [value]. */ @@ -86,8 +31,8 @@ private external fun insertInt(array: CharArray, start: Int, value: Int): Int public inline operator fun StringBuilder.set(index: Int, value: Char): Unit = this.setCharAt(index, value) actual class StringBuilder private constructor ( - private var array: CharArray -) : CharSequence, Appendable { + private var array: CharArray) : CharSequence, Appendable { + actual constructor() : this(10) actual constructor(capacity: Int) : this(CharArray(capacity)) diff --git a/runtime/src/main/kotlin/kotlin/text/StringBuilderNative.kt b/runtime/src/main/kotlin/kotlin/text/StringBuilderNative.kt index 7fbb609549b..d0507cfe3fb 100644 --- a/runtime/src/main/kotlin/kotlin/text/StringBuilderNative.kt +++ b/runtime/src/main/kotlin/kotlin/text/StringBuilderNative.kt @@ -16,7 +16,6 @@ package kotlin.text - fun StringBuilder.appendln(it: String) = append(it).appendln() fun StringBuilder.appendln(it: Boolean) = append(it).appendln() fun StringBuilder.appendln(it: Byte) = append(it).appendln() diff --git a/runtime/src/main/kotlin/kotlin/text/Strings.kt b/runtime/src/main/kotlin/kotlin/text/Strings.kt index 617c035d7e4..db491885bef 100644 --- a/runtime/src/main/kotlin/kotlin/text/Strings.kt +++ b/runtime/src/main/kotlin/kotlin/text/Strings.kt @@ -48,7 +48,6 @@ public actual fun CharSequence.repeat(n: Int): String { /** * Converts the characters in the specified array to a string. */ -// external fun fromCharArray(array: CharArray, start: Int, size: Int) : String public actual fun String(chars: CharArray): String = fromCharArray(chars, 0, chars.size) /** diff --git a/runtime/src/main/kotlin/kotlin/text/regex/Lexer.kt b/runtime/src/main/kotlin/kotlin/text/regex/Lexer.kt index d41aa41ebeb..17f1be8e9fb 100644 --- a/runtime/src/main/kotlin/kotlin/text/regex/Lexer.kt +++ b/runtime/src/main/kotlin/kotlin/text/regex/Lexer.kt @@ -460,7 +460,7 @@ internal class Lexer(val patternString: String, flags: Int) { // Word/whitespace/digit. 'w', 's', 'd', 'W', 'S', 'D' -> { lookAheadSpecialToken = AbstractCharClass.getPredefinedClass( - fromCharArray(pattern, prevNonWhitespaceIndex, 1), + String(pattern, prevNonWhitespaceIndex, 1), false ) lookAhead = 0 diff --git a/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt b/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt index 11a37ed4fdd..6a689024a7a 100644 --- a/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt +++ b/runtime/src/main/kotlin/kotlin/text/regex/Pattern.kt @@ -802,7 +802,7 @@ internal class Pattern(val pattern: String, flags: Int = 0) { val isSupplCodePoint = Char.isSupplementaryCodePoint(ch) return when { - isSupplCodePoint -> SequenceSet(fromCharArray(Char.toChars(ch), 0, 2), hasFlag(CASE_INSENSITIVE)) + isSupplCodePoint -> SequenceSet(String(Char.toChars(ch), 0, 2), hasFlag(CASE_INSENSITIVE)) ch.toChar().isLowSurrogate() -> LowSurrogateCharSet(ch.toChar()) ch.toChar().isHighSurrogate() -> HighSurrogateCharSet(ch.toChar()) else -> CharSet(ch.toChar(), hasFlag(CASE_INSENSITIVE)) diff --git a/runtime/src/main/kotlin/kotlin/text/regex/sets/HangulDecomposedCharSet.kt b/runtime/src/main/kotlin/kotlin/text/regex/sets/HangulDecomposedCharSet.kt index dc704cdc9be..089f4fff338 100644 --- a/runtime/src/main/kotlin/kotlin/text/regex/sets/HangulDecomposedCharSet.kt +++ b/runtime/src/main/kotlin/kotlin/text/regex/sets/HangulDecomposedCharSet.kt @@ -33,6 +33,8 @@ package kotlin.text.regex +import kotlin.text.* + /** * Represents canonical decomposition of Hangul syllable. Is used when * CANON_EQ flag of Pattern class is specified. @@ -52,7 +54,7 @@ internal class HangulDecomposedCharSet( * String representing syllable */ private val decomposedCharUTF16: String by lazy { - fromCharArray(decomposedChar, 0, decomposedChar.size) + String(decomposedChar, 0, decomposedChar.size) } override val name: String diff --git a/runtime/src/main/kotlin/kotlin/text/regex/sets/SupplementaryCharSet.kt b/runtime/src/main/kotlin/kotlin/text/regex/sets/SupplementaryCharSet.kt index 67ee68394d6..fa9553f2824 100644 --- a/runtime/src/main/kotlin/kotlin/text/regex/sets/SupplementaryCharSet.kt +++ b/runtime/src/main/kotlin/kotlin/text/regex/sets/SupplementaryCharSet.kt @@ -102,7 +102,7 @@ package kotlin.text.regex * Represents node accepting single supplementary codepoint. */ internal class SupplementaryCharSet(val codePoint: Int, ignoreCase: Boolean) - : SequenceSet(fromCharArray(Char.toChars(codePoint), 0, 2), ignoreCase) { + : SequenceSet(String(Char.toChars(codePoint), 0, 2), ignoreCase) { override val name: String get() = patternString diff --git a/runtime/src/main/kotlin/kotlin/util/Sort.kt b/runtime/src/main/kotlin/kotlin/util/Sort.kt index 0a959d7ef85..5b4075f94d0 100644 --- a/runtime/src/main/kotlin/kotlin/util/Sort.kt +++ b/runtime/src/main/kotlin/kotlin/util/Sort.kt @@ -18,13 +18,6 @@ package kotlin.util import kotlin.comparisons.* -// TODO: Implement sort for primitives with a custom comparator. - -// Array ============================================================================= -// We use merge because the quick sort may cause segfaults if -// the comparator or the comparable implementation is incorrect (e.g. if it never returns 0). - -// Sort of comparables. private fun > mergeSort(array: Array, start: Int, endInclusive: Int) { @Suppress("UNCHECKED_CAST") val buffer = arrayOfNulls(array.size) as Array