Skip to content

Commit

Permalink
Fix setVersion and unicode class names bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
TadeasKriz committed Sep 11, 2024
1 parent ff246a3 commit f0e82a5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SKIE/acceptance-tests
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Char> = (('a'..'z') + ('A' .. 'Z') + '_').toSet()
private val nextCharAllowedChars: Set<Char> = 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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -200,6 +201,7 @@ class LinkerPhaseScheduler : SkiePhaseScheduler {

RenameTypesConflictingWithKeywordsPhase,
RenameTypesConflictingWithKotlinModulePhase,
RenameNonAsciiDeclarationPhase,

KotlinRuntimeHidingPhase,
SwiftRuntimeGenerator,
Expand Down

0 comments on commit f0e82a5

Please sign in to comment.