diff --git a/SKIE/acceptance-tests b/SKIE/acceptance-tests index d3330354..c0e7d102 160000 --- a/SKIE/acceptance-tests +++ b/SKIE/acceptance-tests @@ -1 +1 @@ -Subproject commit d33303548b35f1a3050354bbbff06b3ddda59256 +Subproject commit c0e7d10248e28454c9bef019ec2f0c0a1e6b4100 diff --git a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/features/functions/GlobalMembersConvertorDelegate.kt b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/features/functions/GlobalMembersConvertorDelegate.kt index a73922fa..d2ea6dc9 100644 --- a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/features/functions/GlobalMembersConvertorDelegate.kt +++ b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/features/functions/GlobalMembersConvertorDelegate.kt @@ -16,7 +16,17 @@ class GlobalMembersConvertorDelegate( private val parentProvider: FileScopeConversionParentProvider, ) : FileScopeConvertorDelegateScope { + private val restrictedPropertyNames = setOf( + "version" + ) + private val restrictedSelectors = setOf( + "setVersion:" + ) + fun generateGlobalFunctionWrapper(function: KirSimpleFunction) { + // Don't generate for names that aren't callable. + if (function.oirSimpleFunction.selector in restrictedSelectors) { return } + function.forEachAssociatedExportedSirDeclaration { generateGlobalFunctionWrapper(function, it) } @@ -49,6 +59,9 @@ class GlobalMembersConvertorDelegate( } fun generateGlobalPropertyWrapper(property: KirProperty) { + // Don't generate for names that aren't callable. + if (property.oirProperty.name in restrictedPropertyNames) { return } + property.forEachAssociatedExportedSirDeclaration { generateGlobalPropertyWrapper(property, it) } diff --git a/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/sir/RenameNonAsciiDeclarationPhase.kt b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/sir/RenameNonAsciiDeclarationPhase.kt new file mode 100644 index 00000000..4bcc04a5 --- /dev/null +++ b/SKIE/kotlin-compiler/core/src/commonMain/kotlin/co/touchlab/skie/phases/sir/RenameNonAsciiDeclarationPhase.kt @@ -0,0 +1,41 @@ +package co.touchlab.skie.phases.sir + +import co.touchlab.skie.oir.element.OirConstructor +import co.touchlab.skie.oir.element.OirProperty +import co.touchlab.skie.oir.element.OirSimpleFunction +import co.touchlab.skie.phases.SirPhase +import co.touchlab.skie.util.resolveCollisionWithWarning + +object RenameNonAsciiDeclarationPhase: SirPhase { + private val firstCharAllowedChars: Set = (('a'..'z') + ('A' .. 'Z') + '_').toSet() + private val nextCharAllowedChars: Set = firstCharAllowedChars + ('0' .. '9') + + context(SirPhase.Context) + override suspend fun execute() { + oirProvider.kotlinClassesAndProtocols + .filterNot { isValidAsciiIdentifier(it.originalSirClass.baseName) } + .forEach { + it.originalSirClass.baseName = it.name + } + } + + private fun isValidAsciiIdentifier(identifier: String): Boolean { + if (identifier.isEmpty()) { + return false + } + + identifier.forEachIndexed { index, c -> + if (index == 0) { + if (!firstCharAllowedChars.contains(c)) { + return false + } + } else { + if (!nextCharAllowedChars.contains(c)) { + return false + } + } + } + + return true + } +} diff --git a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/LinkerPhaseScheduler.kt b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/LinkerPhaseScheduler.kt index ef46ac71..63c4078c 100644 --- a/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/LinkerPhaseScheduler.kt +++ b/SKIE/kotlin-compiler/linker-plugin/src/kgp_common/kotlin/co/touchlab/skie/phases/LinkerPhaseScheduler.kt @@ -66,6 +66,7 @@ import co.touchlab.skie.phases.runtime.ConfigureStableNameTypeAliasesForKotlinRu import co.touchlab.skie.phases.runtime.KotlinRuntimeHidingPhase import co.touchlab.skie.phases.runtime.SwiftRuntimeGenerator import co.touchlab.skie.phases.sir.CommitSirIsReplacedPropertyPhase +import co.touchlab.skie.phases.sir.RenameNonAsciiDeclarationPhase import co.touchlab.skie.phases.sir.member.ConfigureInternalVisibilityForWrappedCallableDeclarationsPhase import co.touchlab.skie.phases.sir.member.CreateAsyncSirFunctionsPhase import co.touchlab.skie.phases.sir.member.CreateSirMembersPhase @@ -200,6 +201,7 @@ class LinkerPhaseScheduler : SkiePhaseScheduler { RenameTypesConflictingWithKeywordsPhase, RenameTypesConflictingWithKotlinModulePhase, + RenameNonAsciiDeclarationPhase, KotlinRuntimeHidingPhase, SwiftRuntimeGenerator,