[stdlib] Merge js-ir specific sources into common js sources

This commit is contained in:
Ilya Gorbunov
2023-10-06 22:20:58 +02:00
committed by Space Team
parent f00d4022c4
commit 911fa3bbbb
55 changed files with 54 additions and 65 deletions
+224
View File
@@ -0,0 +1,224 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress(
"NON_ABSTRACT_FUNCTION_WITH_NO_BODY",
"MUST_BE_INITIALIZED_OR_BE_ABSTRACT",
"EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE",
"PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED",
"WRONG_MODIFIER_TARGET",
"UNUSED_PARAMETER"
)
package kotlin
/**
* An array of bytes. When targeting the JVM, instances of this class are represented as `byte[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
public class ByteArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function.
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Byte)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Byte
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Byte): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): ByteIterator
}
/**
* An array of chars. When targeting the JVM, instances of this class are represented as `char[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to null char (`\u0000').
*/
public class CharArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function.
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Char)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Char
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Char): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): CharIterator
}
/**
* An array of shorts. When targeting the JVM, instances of this class are represented as `short[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
public class ShortArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function.
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Short)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Short
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Short): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): ShortIterator
}
/**
* An array of ints. When targeting the JVM, instances of this class are represented as `int[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
public class IntArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function.
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Int)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Int
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Int): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): IntIterator
}
/**
* An array of longs. When targeting the JVM, instances of this class are represented as `long[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
public class LongArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function.
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Long)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Long
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Long): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): LongIterator
}
/**
* An array of floats. When targeting the JVM, instances of this class are represented as `float[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
public class FloatArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function.
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Float)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Float
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Float): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): FloatIterator
}
/**
* An array of doubles. When targeting the JVM, instances of this class are represented as `double[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
public class DoubleArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function.
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Double)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Double
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Double): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): DoubleIterator
}
/**
* An array of booleans. When targeting the JVM, instances of this class are represented as `boolean[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to `false`.
*/
public class BooleanArray(size: Int) {
/**
* Creates a new array of the specified [size], where each element is calculated by calling the specified
* [init] function.
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*/
public inline constructor(size: Int, init: (Int) -> Boolean)
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): Boolean
/** Sets the element at the given [index] to the given [value]. This method can be called using the index operator. */
public operator fun set(index: Int, value: Boolean): Unit
/** Returns the number of elements in the array. */
public val size: Int
/** Creates an iterator over the elements of the array. */
public operator fun iterator(): BooleanIterator
}
+50
View File
@@ -0,0 +1,50 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
// Auto-generated file. DO NOT EDIT!
// Generated by org.jetbrains.kotlin.generators.builtins.numbers.primitives.JsBooleanGenerator
@file:Suppress("NON_ABSTRACT_FUNCTION_WITH_NO_BODY", "UNUSED_PARAMETER")
package kotlin
/** Represents a value which is either `true` or `false`. */
public class Boolean private constructor() : Comparable<Boolean> {
@SinceKotlin("1.3")
companion object {}
/** Returns the inverse of this boolean. */
@kotlin.internal.IntrinsicConstEvaluation
public operator fun not(): Boolean
/**
* Performs a logical `and` operation between this Boolean and the [other] one. Unlike the `&&` operator,
* this function does not perform short-circuit evaluation. Both `this` and [other] will always be evaluated.
*/
@kotlin.internal.IntrinsicConstEvaluation
public infix fun and(other: Boolean): Boolean
/**
* Performs a logical `or` operation between this Boolean and the [other] one. Unlike the `||` operator,
* this function does not perform short-circuit evaluation. Both `this` and [other] will always be evaluated.
*/
@kotlin.internal.IntrinsicConstEvaluation
public infix fun or(other: Boolean): Boolean
/** Performs a logical `xor` operation between this Boolean and the [other] one. */
@kotlin.internal.IntrinsicConstEvaluation
public infix fun xor(other: Boolean): Boolean
@kotlin.internal.IntrinsicConstEvaluation
public override fun compareTo(other: Boolean): Int
@kotlin.internal.IntrinsicConstEvaluation
public override fun toString(): String
@kotlin.internal.IntrinsicConstEvaluation
public override fun equals(other: Any?): Boolean
public override fun hashCode(): Int
}
+197
View File
@@ -0,0 +1,197 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
// Auto-generated file. DO NOT EDIT!
// Generated by org.jetbrains.kotlin.generators.builtins.numbers.primitives.JsCharGenerator
package kotlin
// Char is a magic class.
// Char is defined as a regular class, but we lower it as a value class.
// See [org.jetbrains.kotlin.ir.backend.js.utils.JsInlineClassesUtils.isClassInlineLike] for explanation.
/** Represents a 16-bit Unicode character. */
public class Char
@kotlin.internal.LowPriorityInOverloadResolution
internal constructor(private val value: Int) : Comparable<Char> {
@SinceKotlin("1.5")
@WasExperimental(ExperimentalStdlibApi::class)
public constructor(code: UShort) : this(code.toInt())
/**
* 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 it's less than other,
* or a positive number if it's greater than other.
*/
@kotlin.internal.IntrinsicConstEvaluation
public override fun compareTo(other: Char): Int =
value - other.value
/** Adds the other Int value to this value resulting a Char. */
@kotlin.internal.IntrinsicConstEvaluation
public operator fun plus(other: Int): Char =
(value + other).toChar()
/** Subtracts the other Char value from this value resulting an Int. */
@kotlin.internal.IntrinsicConstEvaluation
public operator fun minus(other: Char): Int =
value - other.value
/** Subtracts the other Int value from this value resulting a Char. */
@kotlin.internal.IntrinsicConstEvaluation
public operator fun minus(other: Int): Char =
(value - other).toChar()
/**
* Returns this value incremented by one.
*
* @sample samples.misc.Builtins.inc
*/
public operator fun inc(): Char =
(value + 1).toChar()
/**
* Returns this value decremented by one.
*
* @sample samples.misc.Builtins.dec
*/
public operator fun dec(): Char =
(value - 1).toChar()
/** Creates a range from this value to the specified [other] value. */
public operator fun rangeTo(other: Char): CharRange =
CharRange(this, other)
/**
* Creates a range from this value up to but excluding the specified [other] value.
*
* If the [other] value is less than or equal to `this` value, then the returned range is empty.
*/
@SinceKotlin("1.9")
@WasExperimental(ExperimentalStdlibApi::class)
public operator fun rangeUntil(other: Char): CharRange =
this until other
/** Returns the value of this character as a `Byte`. */
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toByte()"))
@DeprecatedSinceKotlin(warningSince = "1.5")
@kotlin.internal.IntrinsicConstEvaluation
public fun toByte(): Byte =
value.toByte()
/** Returns the value of this character as a `Char`. */
@kotlin.internal.IntrinsicConstEvaluation
public fun toChar(): Char =
this
/** Returns the value of this character as a `Short`. */
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toShort()"))
@DeprecatedSinceKotlin(warningSince = "1.5")
@kotlin.internal.IntrinsicConstEvaluation
public fun toShort(): Short =
value.toShort()
/** Returns the value of this character as a `Int`. */
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code"))
@DeprecatedSinceKotlin(warningSince = "1.5")
@kotlin.internal.IntrinsicConstEvaluation
public fun toInt(): Int =
value
/** Returns the value of this character as a `Long`. */
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toLong()"))
@DeprecatedSinceKotlin(warningSince = "1.5")
@kotlin.internal.IntrinsicConstEvaluation
public fun toLong(): Long =
value.toLong()
/** Returns the value of this character as a `Float`. */
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toFloat()"))
@DeprecatedSinceKotlin(warningSince = "1.5")
@kotlin.internal.IntrinsicConstEvaluation
public fun toFloat(): Float =
value.toFloat()
/** Returns the value of this character as a `Double`. */
@Deprecated("Conversion of Char to Number is deprecated. Use Char.code property instead.", ReplaceWith("this.code.toDouble()"))
@DeprecatedSinceKotlin(warningSince = "1.5")
@kotlin.internal.IntrinsicConstEvaluation
public fun toDouble(): Double =
value.toDouble()
// TODO implicit usages of toString and valueOf must be covered in DCE
@kotlin.internal.IntrinsicConstEvaluation
@Suppress("JS_NAME_PROHIBITED_FOR_OVERRIDE")
@JsName("toString")
public override fun toString(): String {
return js("String").fromCharCode(value).unsafeCast<String>()
}
@kotlin.internal.IntrinsicConstEvaluation
public override fun equals(other: Any?): Boolean {
if (other !is Char) return false
return this.value == other.value
}
public override fun hashCode(): Int =
value
companion object {
/**
* The minimum value of a character code unit.
*/
@SinceKotlin("1.3")
public const val MIN_VALUE: Char = '\u0000'
/**
* The maximum value of a character code unit.
*/
@SinceKotlin("1.3")
public const val MAX_VALUE: Char = '\uFFFF'
/**
* The minimum value of a Unicode high-surrogate code unit.
*/
public const val MIN_HIGH_SURROGATE: Char = '\uD800'
/**
* The maximum value of a Unicode high-surrogate code unit.
*/
public const val MAX_HIGH_SURROGATE: Char = '\uDBFF'
/**
* The minimum value of a Unicode low-surrogate code unit.
*/
public const val MIN_LOW_SURROGATE: Char = '\uDC00'
/**
* The maximum value of a Unicode low-surrogate code unit.
*/
public const val MAX_LOW_SURROGATE: Char = '\uDFFF'
/**
* The minimum value of a Unicode surrogate code unit.
*/
public const val MIN_SURROGATE: Char = MIN_HIGH_SURROGATE
/**
* The maximum value of a Unicode surrogate code unit.
*/
public const val MAX_SURROGATE: Char = MAX_LOW_SURROGATE
/**
* The number of bytes used to represent a Char in a binary form.
*/
@SinceKotlin("1.3")
public const val SIZE_BYTES: Int = 2
/**
* The number of bits used to represent a Char in a binary form.
*/
@SinceKotlin("1.3")
public const val SIZE_BITS: Int = 16
}
}
+435
View File
@@ -0,0 +1,435 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress(
"NON_ABSTRACT_FUNCTION_WITH_NO_BODY",
"MUST_BE_INITIALIZED_OR_BE_ABSTRACT",
"EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE",
"PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED",
"WRONG_MODIFIER_TARGET"
)
/*
* 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.collections
/**
* Classes that inherit from this interface can be represented as a sequence of elements that can
* be iterated over.
* @param T the type of element being iterated over. The iterator is covariant in its element type.
*/
public interface Iterable<out T> {
/**
* Returns an iterator over the elements of this object.
*/
public operator fun iterator(): Iterator<T>
}
/**
* Classes that inherit from this interface can be represented as a sequence of elements that can
* be iterated over and that supports removing elements during iteration.
* @param T the type of element being iterated over. The mutable iterator is invariant in its element type.
*/
public interface MutableIterable<out T> : Iterable<T> {
/**
* Returns an iterator over the elements of this sequence that supports removing elements during iteration.
*/
override fun iterator(): MutableIterator<T>
}
/**
* A generic collection of elements. Methods in this interface support only read-only access to the collection;
* read/write access is supported through the [MutableCollection] interface.
* @param E the type of elements contained in the collection. The collection is covariant in its element type.
*/
public interface Collection<out E> : Iterable<E> {
// Query Operations
/**
* Returns the size of the collection.
*/
public val size: Int
/**
* Returns `true` if the collection is empty (contains no elements), `false` otherwise.
*/
public fun isEmpty(): Boolean
/**
* Checks if the specified element is contained in this collection.
*/
public operator fun contains(element: @UnsafeVariance E): Boolean
override fun iterator(): Iterator<E>
// Bulk Operations
/**
* Checks if all elements in the specified collection are contained in this collection.
*/
public fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean
}
/**
* A generic collection of elements that supports adding and removing elements.
*
* @param E the type of elements contained in the collection. The mutable collection is invariant in its element type.
*/
public interface MutableCollection<E> : Collection<E>, MutableIterable<E> {
// Query Operations
override fun iterator(): MutableIterator<E>
// Modification Operations
/**
* Adds the specified element to the collection.
*
* @return `true` if the element has been added, `false` if the collection does not support duplicates
* and the element is already contained in the collection.
*/
public fun add(element: E): Boolean
/**
* Removes a single instance of the specified element from this
* collection, if it is present.
*
* @return `true` if the element has been successfully removed; `false` if it was not present in the collection.
*/
public fun remove(element: E): Boolean
// Bulk Modification Operations
/**
* Adds all of the elements of the specified collection to this collection.
*
* @return `true` if any of the specified elements was added to the collection, `false` if the collection was not modified.
*/
public fun addAll(elements: Collection<E>): Boolean
/**
* Removes all of this collection's elements that are also contained in the specified collection.
*
* @return `true` if any of the specified elements was removed from the collection, `false` if the collection was not modified.
*/
public fun removeAll(elements: Collection<E>): Boolean
/**
* Retains only the elements in this collection that are contained in the specified collection.
*
* @return `true` if any element was removed from the collection, `false` if the collection was not modified.
*/
public fun retainAll(elements: Collection<E>): Boolean
/**
* Removes all elements from this collection.
*/
public fun clear(): Unit
}
/**
* A generic ordered collection of elements. Methods in this interface support only read-only access to the list;
* read/write access is supported through the [MutableList] interface.
* @param E the type of elements contained in the list. The list is covariant in its element type.
*/
public interface List<out E> : Collection<E> {
// Query Operations
override val size: Int
override fun isEmpty(): Boolean
override fun contains(element: @UnsafeVariance E): Boolean
override fun iterator(): Iterator<E>
// Bulk Operations
override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean
// Positional Access Operations
/**
* Returns the element at the specified index in the list.
*/
public operator fun get(index: Int): E
// Search Operations
/**
* Returns the index of the first occurrence of the specified element in the list, or -1 if the specified
* element is not contained in the list.
*/
public fun indexOf(element: @UnsafeVariance E): Int
/**
* Returns the index of the last occurrence of the specified element in the list, or -1 if the specified
* element is not contained in the list.
*/
public fun lastIndexOf(element: @UnsafeVariance E): Int
// List Iterators
/**
* Returns a list iterator over the elements in this list (in proper sequence).
*/
public fun listIterator(): ListIterator<E>
/**
* Returns a list iterator over the elements in this list (in proper sequence), starting at the specified [index].
*/
public fun listIterator(index: Int): ListIterator<E>
// View
/**
* Returns a view of the portion of this list between the specified [fromIndex] (inclusive) and [toIndex] (exclusive).
* The returned list is backed by this list, so non-structural changes in the returned list are reflected in this list, and vice-versa.
*
* Structural changes in the base list make the behavior of the view undefined.
*/
public fun subList(fromIndex: Int, toIndex: Int): List<E>
}
/**
* A generic ordered collection of elements that supports adding and removing elements.
* @param E the type of elements contained in the list. The mutable list is invariant in its element type.
*/
public interface MutableList<E> : List<E>, MutableCollection<E> {
// Modification Operations
/**
* Adds the specified element to the end of this list.
*
* @return `true` because the list is always modified as the result of this operation.
*/
override fun add(element: E): Boolean
override fun remove(element: E): Boolean
// Bulk Modification Operations
/**
* Adds all of the elements of the specified collection to the end of this list.
*
* The elements are appended in the order they appear in the [elements] collection.
*
* @return `true` if the list was changed as the result of the operation.
*/
override fun addAll(elements: Collection<E>): Boolean
/**
* Inserts all of the elements of the specified collection [elements] into this list at the specified [index].
*
* @return `true` if the list was changed as the result of the operation.
*/
public fun addAll(index: Int, elements: Collection<E>): Boolean
override fun removeAll(elements: Collection<E>): Boolean
override fun retainAll(elements: Collection<E>): Boolean
override fun clear(): Unit
// Positional Access Operations
/**
* Replaces the element at the specified position in this list with the specified element.
*
* @return the element previously at the specified position.
*/
public operator fun set(index: Int, element: E): E
/**
* Inserts an element into the list at the specified [index].
*/
public fun add(index: Int, element: E): Unit
/**
* Removes an element at the specified [index] from the list.
*
* @return the element that has been removed.
*/
public fun removeAt(index: Int): E
// List Iterators
override fun listIterator(): MutableListIterator<E>
override fun listIterator(index: Int): MutableListIterator<E>
// View
override fun subList(fromIndex: Int, toIndex: Int): MutableList<E>
}
/**
* A generic unordered collection of elements that does not support duplicate elements.
* Methods in this interface support only read-only access to the set;
* read/write access is supported through the [MutableSet] interface.
* @param E the type of elements contained in the set. The set is covariant in its element type.
*/
public interface Set<out E> : Collection<E> {
// Query Operations
override val size: Int
override fun isEmpty(): Boolean
override fun contains(element: @UnsafeVariance E): Boolean
override fun iterator(): Iterator<E>
// Bulk Operations
override fun containsAll(elements: Collection<@UnsafeVariance E>): Boolean
}
/**
* A generic unordered collection of elements that does not support duplicate elements, and supports
* adding and removing elements.
* @param E the type of elements contained in the set. The mutable set is invariant in its element type.
*/
public interface MutableSet<E> : Set<E>, MutableCollection<E> {
// Query Operations
override fun iterator(): MutableIterator<E>
// Modification Operations
/**
* Adds the specified element to the set.
*
* @return `true` if the element has been added, `false` if the element is already contained in the set.
*/
override fun add(element: E): Boolean
override fun remove(element: E): Boolean
// Bulk Modification Operations
override fun addAll(elements: Collection<E>): Boolean
override fun removeAll(elements: Collection<E>): Boolean
override fun retainAll(elements: Collection<E>): Boolean
override fun clear(): Unit
}
/**
* A collection that holds pairs of objects (keys and values) and supports efficiently retrieving
* the value corresponding to each key. Map keys are unique; the map holds only one value for each key.
* Methods in this interface support only read-only access to the map; read-write access is supported through
* the [MutableMap] interface.
* @param K the type of map keys. The map is invariant in its key type, as it
* can accept key as a parameter (of [containsKey] for example) and return it in [keys] set.
* @param V the type of map values. The map is covariant in its value type.
*/
public interface Map<K, out V> {
// Query Operations
/**
* Returns the number of key/value pairs in the map.
*/
public val size: Int
/**
* Returns `true` if the map is empty (contains no elements), `false` otherwise.
*/
public fun isEmpty(): Boolean
/**
* Returns `true` if the map contains the specified [key].
*/
public fun containsKey(key: K): Boolean
/**
* Returns `true` if the map maps one or more keys to the specified [value].
*/
public fun containsValue(value: @UnsafeVariance V): Boolean
/**
* Returns the value corresponding to the given [key], or `null` if such a key is not present in the map.
*/
public operator fun get(key: K): V?
// Views
/**
* Returns a read-only [Set] of all keys in this map.
*/
public val keys: Set<K>
/**
* Returns a read-only [Collection] of all values in this map. Note that this collection may contain duplicate values.
*/
public val values: Collection<V>
/**
* Returns a read-only [Set] of all key/value pairs in this map.
*/
public val entries: Set<Map.Entry<K, V>>
/**
* Represents a key/value pair held by a [Map].
*/
public interface Entry<out K, out V> {
/**
* Returns the key of this key/value pair.
*/
public val key: K
/**
* Returns the value of this key/value pair.
*/
public val value: V
}
}
/**
* A modifiable collection that holds pairs of objects (keys and values) and supports efficiently retrieving
* the value corresponding to each key. Map keys are unique; the map holds only one value for each key.
* @param K the type of map keys. The map is invariant in its key type.
* @param V the type of map values. The mutable map is invariant in its value type.
*/
public interface MutableMap<K, V> : Map<K, V> {
// Modification Operations
/**
* Associates the specified [value] with the specified [key] in the map.
*
* @return the previous value associated with the key, or `null` if the key was not present in the map.
*/
public fun put(key: K, value: V): V?
/**
* Removes the specified key and its corresponding value from this map.
*
* @return the previous value associated with the key, or `null` if the key was not present in the map.
*/
public fun remove(key: K): V?
// Bulk Modification Operations
/**
* Updates this map with key/value pairs from the specified map [from].
*/
public fun putAll(from: Map<out K, V>): Unit
/**
* Removes all elements from this map.
*/
public fun clear(): Unit
// Views
/**
* Returns a [MutableSet] of all keys in this map.
*/
override val keys: MutableSet<K>
/**
* Returns a [MutableCollection] of all values in this map. Note that this collection may contain duplicate values.
*/
override val values: MutableCollection<V>
/**
* Returns a [MutableSet] of all key/value pairs in this map.
*/
override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
/**
* Represents a key/value pair held by a [MutableMap].
*/
public interface MutableEntry<K, V> : Map.Entry<K, V> {
/**
* Changes the value associated with the key of this entry.
*
* @return the previous value corresponding to the key.
*/
public fun setValue(newValue: V): V
}
}
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin
import kotlin.js.*
abstract class Enum<E : Enum<E>>(@kotlin.internal.IntrinsicConstEvaluation val name: String, val ordinal: Int) : Comparable<E> {
final override fun compareTo(other: E) = ordinal.compareTo(other.ordinal)
final override fun equals(other: Any?) = this === other
final override fun hashCode(): Int = identityHashCode(this)
override fun toString() = name
companion object
}
+90
View File
@@ -0,0 +1,90 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("NOTHING_TO_INLINE")
package kotlin
import kotlin.js.*
/**
* Returns a string representation of the object. Can be called with a null receiver, in which case
* it returns the string "null".
*/
public fun Any?.toString(): String = this?.toString() ?: "null"
/**
* Concatenates this string with the string representation of the given [other] object. If either the receiver
* or the [other] object are null, they are represented as the string "null".
*/
public operator fun String?.plus(other: Any?): String =
(this?.toString() ?: "null").plus(other?.toString() ?: "null")
/**
* Returns an array of objects of the given type with the given [size], initialized with null values.
*/
public inline fun <T> arrayOfNulls(size: Int): Array<T?> = fillArrayVal<T?>(Array<T?>(size), null)
/**
* Returns an array containing the specified elements.
*/
public inline fun <T> arrayOf(vararg elements: T): Array<T> = elements.unsafeCast<Array<T>>()
/**
* Returns an array containing the specified [Double] numbers.
*/
public inline fun doubleArrayOf(vararg elements: Double): DoubleArray = elements
/**
* Returns an array containing the specified [Float] numbers.
*/
public inline fun floatArrayOf(vararg elements: Float): FloatArray = elements
/**
* Returns an array containing the specified [Long] numbers.
*/
public inline fun longArrayOf(vararg elements: Long): LongArray = elements
/**
* Returns an array containing the specified [Int] numbers.
*/
public inline fun intArrayOf(vararg elements: Int): IntArray = elements
/**
* Returns an array containing the specified characters.
*/
public inline fun charArrayOf(vararg elements: Char): CharArray = elements
/**
* Returns an array containing the specified [Short] numbers.
*/
public inline fun shortArrayOf(vararg elements: Short): ShortArray = elements
/**
* Returns an array containing the specified [Byte] numbers.
*/
public inline fun byteArrayOf(vararg elements: Byte): ByteArray = elements
/**
* Returns an array containing the specified boolean values.
*/
public inline fun booleanArrayOf(vararg elements: Boolean): BooleanArray = elements
// Use non-inline calls to enumValuesIntrinsic and enumValueOfIntrinsic calls in order
// for compiler to replace them with method calls of concrete enum classes after inlining.
// TODO: Figure out better solution (Inline hacks? Dynamic calls to stable mangled names?)
/**
* Returns an array containing enum T entries.
*/
@SinceKotlin("1.1")
public inline fun <reified T : Enum<T>> enumValues(): Array<T> = enumValuesIntrinsic<T>()
/**
* Returns an enum entry with specified name.
*/
@SinceKotlin("1.1")
public inline fun <reified T : Enum<T>> enumValueOf(name: String): T = enumValueOfIntrinsic<T>(name)
File diff suppressed because it is too large Load Diff
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:Suppress("NON_ABSTRACT_FUNCTION_WITH_NO_BODY", "MUST_BE_INITIALIZED_OR_BE_ABSTRACT", "UNUSED_PARAMETER")
package kotlin
/**
* The `String` class represents character strings. All string literals in Kotlin programs, such as `"abc"`, are
* implemented as instances of this class.
*/
public class String : Comparable<String>, CharSequence {
companion object {}
/**
* Returns a string obtained by concatenating this string with the string representation of the given [other] object.
*/
@kotlin.internal.IntrinsicConstEvaluation
public operator fun plus(other: Any?): String
@kotlin.internal.IntrinsicConstEvaluation
public override val length: Int
/**
* Returns the character of this string at the specified [index].
*
* If the [index] is out of bounds of this string, throws an [IndexOutOfBoundsException] except in Kotlin/JS
* where the behavior is unspecified.
*/
@kotlin.internal.IntrinsicConstEvaluation
public override fun get(index: Int): Char
public override fun subSequence(startIndex: Int, endIndex: Int): CharSequence
@kotlin.internal.IntrinsicConstEvaluation
public override fun compareTo(other: String): Int
@kotlin.internal.IntrinsicConstEvaluation
public override fun equals(other: Any?): Boolean
public override fun hashCode(): Int
@kotlin.internal.IntrinsicConstEvaluation
public override fun toString(): String
}
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin
/**
* The base class for all errors and exceptions. Only instances of this class can be thrown or caught.
*
* @param message the detail message string.
* @param cause the cause of this throwable.
*/
@JsName("Error")
public external open class Throwable {
public open val message: String?
public open val cause: Throwable?
public constructor(message: String?, cause: Throwable?)
public constructor(message: String?)
public constructor(cause: Throwable?)
public constructor()
// TODO: add specialized version to runtime
// public override fun equals(other: Any?): Boolean
// public override fun hashCode(): Int
public override fun toString(): String
}