Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make more declarations internal #196

Merged
merged 7 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlin.contracts.contract
*/
@OptIn(ExperimentalContracts::class)
@Suppress("NOTHING_TO_INLINE", "KotlinRedundantDiagnosticSuppress")
public inline fun assert(condition: Boolean, message: String? = null) {
internal inline fun assert(condition: Boolean, message: String? = null) {
contract {
returns() implies condition
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ internal const val MIN_LOW_SURROGATE: Int = 0xDC00
internal const val HIGH_SURROGATE_ENCODE_OFFSET: Int =
(MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT_ ushr 10))

public fun isBmpCodePoint(codePoint: Int): Boolean =
internal inline fun isBmpCodePoint(codePoint: Int): Boolean =
codePoint ushr 16 == 0

public fun highSurrogate(codePoint: Int): Char =
internal inline fun highSurrogate(codePoint: Int): Char =
((codePoint ushr 10) + HIGH_SURROGATE_ENCODE_OFFSET).toChar()

public fun lowSurrogate(codePoint: Int): Char =
internal inline fun lowSurrogate(codePoint: Int): Char =
((codePoint and 0x3FF) + MIN_LOW_SURROGATE).toChar()

public fun isValidCodePoint(codePoint: Int): Boolean =
internal inline fun isValidCodePoint(codePoint: Int): Boolean =
codePoint in 0..MAX_CODE_POINT_
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.
package com.strumenta.antlrkotlin.runtime

public object Collections {
public fun <T : Comparable<T>> min(collection: Collection<T>): T =
internal object Collections {
fun <T : Comparable<T>> min(collection: Collection<T>): T =
collection.minOrNull() ?: throw NoSuchElementException()

public fun <T : Comparable<T>> max(collection: Collection<T>): T =
fun <T : Comparable<T>> max(collection: Collection<T>): T =
collection.maxOrNull() ?: throw NoSuchElementException()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.
package com.strumenta.antlrkotlin.runtime

public expect class CopyOnWriteArrayList<E>() : MutableList<E> {
internal expect class CopyOnWriteArrayList<E>() : MutableList<E> {
// Convenience constructor to avoid initializing with mutable state
public constructor(elements: Collection<E>)
constructor(elements: Collection<E>)

override val size: Int
override fun contains(element: E): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.
package com.strumenta.antlrkotlin.runtime

public expect class IdentityHashMap<K, V>() : MutableMap<K, V> {
internal expect class IdentityHashMap<K, V>() : MutableMap<K, V> {
override val size: Int
override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
override val keys: MutableSet<K>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ package com.strumenta.antlrkotlin.runtime
// Also, how are we going to use the "lock" parameter?
// Probably it makes sense to just tell consumers the
// Kotlin Native implementation is not thread safe.
public expect inline fun <R> synchronized(lock: Any, block: () -> R): R
internal expect inline fun <R> synchronized(lock: Any, block: () -> R): R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.
package com.strumenta.antlrkotlin.runtime

public expect class WeakHashMap<K, V>() : MutableMap<K, V> {
internal expect class WeakHashMap<K, V>() : MutableMap<K, V> {
override val size: Int
override val entries: MutableSet<MutableMap.MutableEntry<K, V>>
override val keys: MutableSet<K>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ public abstract class PredictionContext protected constructor(
public fun getCachedContext(
context: PredictionContext,
contextCache: PredictionContextCache,
visited: IdentityHashMap<PredictionContext, PredictionContext>,
visited: MutableMap<PredictionContext, PredictionContext>,
): PredictionContext {
if (context.isEmpty) {
return context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
package com.strumenta.antlrkotlin.runtime

// Note(Edoardo): JS is single threaded, so a normal list is good enough
public actual typealias CopyOnWriteArrayList<E> = ArrayList<E>
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias CopyOnWriteArrayList<E> = ArrayList<E>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlin.contracts.contract

// Not necessary for JavaScript. Single threaded.
@OptIn(ExperimentalContracts::class)
public actual inline fun <R> synchronized(lock: Any, block: () -> R): R {
internal actual inline fun <R> synchronized(lock: Any, block: () -> R): R {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2017-present Strumenta and contributors, licensed under Apache 2.0.
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.

package com.strumenta.antlrkotlin.runtime

// Note(Edoardo): this is implemented as an HashMap in the JS target,
// so let's keep it as it is
public actual typealias WeakHashMap<K, V> = HashMap<K, V>
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias WeakHashMap<K, V> = HashMap<K, V>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package com.strumenta.antlrkotlin.runtime
import js.collections.JsMap
import kotlin.collections.MutableMap.MutableEntry as ME

public actual class IdentityHashMap<K, V> : MutableMap<K, V> {
internal actual class IdentityHashMap<K, V> : MutableMap<K, V> {
private val jsMap = JsMap<K, V>()

actual override val size: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.
package com.strumenta.antlrkotlin.runtime

public actual typealias CopyOnWriteArrayList<E> = java.util.concurrent.CopyOnWriteArrayList<E>
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias CopyOnWriteArrayList<E> = java.util.concurrent.CopyOnWriteArrayList<E>
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ package com.strumenta.antlrkotlin.runtime

import java.util.IdentityHashMap as JavaIdentityHashMap

public actual typealias IdentityHashMap<K, V> = JavaIdentityHashMap<K, V>
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias IdentityHashMap<K, V> = JavaIdentityHashMap<K, V>
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.
package com.strumenta.antlrkotlin.runtime

public actual inline fun <R> synchronized(lock: Any, block: () -> R): R =
internal actual inline fun <R> synchronized(lock: Any, block: () -> R): R =
kotlin.synchronized(lock, block)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2017-present Strumenta and contributors, licensed under Apache 2.0.
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.

package com.strumenta.antlrkotlin.runtime

import java.util.WeakHashMap as JavaWeakHashMap

public actual typealias WeakHashMap<K, V> = JavaWeakHashMap<K, V>
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias WeakHashMap<K, V> = JavaWeakHashMap<K, V>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
package com.strumenta.antlrkotlin.runtime

// TODO(Edoardo): make thread safe at some point
public actual typealias CopyOnWriteArrayList<E> = ArrayList<E>
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias CopyOnWriteArrayList<E> = ArrayList<E>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
package com.strumenta.antlrkotlin.runtime

// TODO(Edoardo): implement real identity comparison
public actual typealias IdentityHashMap<K, V> = HashMap<K, V>
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias IdentityHashMap<K, V> = HashMap<K, V>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

@OptIn(ExperimentalContracts::class)
public actual inline fun <R> synchronized(lock: Any, block: () -> R): R {
internal actual inline fun <R> synchronized(lock: Any, block: () -> R): R {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2017-present Strumenta and contributors, licensed under Apache 2.0.
// Copyright 2024-present Strumenta and contributors, licensed under BSD 3-Clause.

package com.strumenta.antlrkotlin.runtime

// TODO(Edoardo): implement real weak keys.
// See kotlinlang.org/api/latest/jvm/stdlib/kotlin.native.ref
// for classes and functions useful for a possible implementation
public actual typealias WeakHashMap<K, V> = HashMap<K, V>
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias WeakHashMap<K, V> = HashMap<K, V>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
package com.strumenta.antlrkotlin.runtime

// TODO(Edoardo): implement real identity comparison
public actual typealias IdentityHashMap<K, V> = HashMap<K, V>
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias IdentityHashMap<K, V> = HashMap<K, V>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
package com.strumenta.antlrkotlin.runtime

// Note(Edoardo): WASI is single threaded at the moment, so a normal list is good enough
public actual typealias CopyOnWriteArrayList<E> = ArrayList<E>
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias CopyOnWriteArrayList<E> = ArrayList<E>
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
package com.strumenta.antlrkotlin.runtime

// TODO(Edoardo): implement real identity comparison
public actual typealias IdentityHashMap<K, V> = HashMap<K, V>
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias IdentityHashMap<K, V> = HashMap<K, V>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlin.contracts.contract

// Not necessary for WASI. Single threaded.
@OptIn(ExperimentalContracts::class)
public actual inline fun <R> synchronized(lock: Any, block: () -> R): R {
internal actual inline fun <R> synchronized(lock: Any, block: () -> R): R {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
package com.strumenta.antlrkotlin.runtime

// TODO(Edoardo): implement real weak keys
public actual typealias WeakHashMap<K, V> = HashMap<K, V>
@Suppress("ACTUAL_WITHOUT_EXPECT")
internal actual typealias WeakHashMap<K, V> = HashMap<K, V>
Loading