From d2f0448431c222e0874dcd130c2343fb43e70f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Doln=C3=ADk?= Date: Mon, 13 Nov 2023 19:09:14 +0100 Subject: [PATCH] Fix translation for ObjCProtocol. --- SKIE/acceptance-tests | 2 +- .../touchlab/skie/kir/descriptor/ExtraDescriptorBuiltins.kt | 4 ++++ .../kotlin/co/touchlab/skie/oir/builtin/OirBuiltins.kt | 5 +++++ .../kotlin/co/touchlab/skie/oir/element/OirClass.kt | 4 ++-- .../co/touchlab/skie/oir/type/SpecialReferenceOirType.kt | 2 -- .../touchlab/skie/oir/type/translation/OirTypeTranslator.kt | 2 +- .../kotlin/co/touchlab/skie/sir/type/SpecialSirType.kt | 4 ---- .../touchlab/skie/sir/type/translation/SirTypeTranslator.kt | 1 - 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/SKIE/acceptance-tests b/SKIE/acceptance-tests index 3711d1b7..96c4966f 160000 --- a/SKIE/acceptance-tests +++ b/SKIE/acceptance-tests @@ -1 +1 @@ -Subproject commit 3711d1b7abdb77feb8903035d596a7dceba00b9d +Subproject commit 96c4966fe6a592ef5c0dc0dcdf1a03550e7e005d diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/descriptor/ExtraDescriptorBuiltins.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/descriptor/ExtraDescriptorBuiltins.kt index 1f985f02..2acfcdb4 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/descriptor/ExtraDescriptorBuiltins.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/kir/descriptor/ExtraDescriptorBuiltins.kt @@ -14,6 +14,10 @@ class ExtraDescriptorBuiltins( private val Darwin = getModule("") + private val stdlib = getModule("") + + val Protocol: ClassDescriptor = getClass("kotlinx.cinterop.ObjCProtocol", stdlib) + val NSObject: ClassDescriptor = getClass("platform.darwin.NSObject", Darwin) val NSCopying: ClassDescriptor = getClass("platform.Foundation.NSCopyingProtocol", Foundation) diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/builtin/OirBuiltins.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/builtin/OirBuiltins.kt index 488b3bdb..a89ff5ca 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/builtin/OirBuiltins.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/builtin/OirBuiltins.kt @@ -15,6 +15,11 @@ class OirBuiltins( private val Foundation: OirModule.External = oirProvider.getExternalModule("Foundation") + val Protocol: OirClass = oirProvider.getExternalClass(extraDescriptorBuiltins.Protocol, Foundation).apply { + name = "Protocol" + kind = OirClass.Kind.Class + } + val NSObject: OirClass = oirProvider.getExternalClass(extraDescriptorBuiltins.NSObject, Foundation) val NSError: OirClass = oirProvider.getExternalClass(extraDescriptorBuiltins.NSError).apply { diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/element/OirClass.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/element/OirClass.kt index dcdbc2e2..0f194603 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/element/OirClass.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/element/OirClass.kt @@ -5,9 +5,9 @@ import co.touchlab.skie.oir.type.OirType import co.touchlab.skie.sir.element.SirClass class OirClass( - override val name: String, + override var name: String, override val parent: OirTopLevelDeclarationParent, - val kind: Kind, + var kind: Kind, ) : OirTypeDeclaration, OirCallableDeclarationParent { lateinit var originalSirClass: SirClass diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/type/SpecialReferenceOirType.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/type/SpecialReferenceOirType.kt index 103d261e..19de8d28 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/type/SpecialReferenceOirType.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/type/SpecialReferenceOirType.kt @@ -8,8 +8,6 @@ sealed class SpecialReferenceOirType(private val name: String) : NonNullReferenc object Class : SpecialReferenceOirType("Class") - object Protocol : SpecialReferenceOirType("Protocol") - override fun render(attrsAndName: String, needsNonnullAttribute: Boolean): String = name.withAttrsAndName(attrsAndName.plusNonnullAttributeIfNeeded(needsNonnullAttribute)) } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/type/translation/OirTypeTranslator.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/type/translation/OirTypeTranslator.kt index 7bd4c870..a9132cd5 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/type/translation/OirTypeTranslator.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/oir/type/translation/OirTypeTranslator.kt @@ -150,7 +150,7 @@ class OirTypeTranslator( // TODO: more precise types can be used. if (descriptor.isObjCMetaClass()) return SpecialReferenceOirType.Class - if (descriptor.isObjCProtocolClass()) return SpecialReferenceOirType.Protocol + if (descriptor.isObjCProtocolClass()) return oirBuiltins.Protocol.defaultType if (descriptor.isExternalObjCClass() || descriptor.isObjCForwardDeclaration()) { return oirProvider.getExternalClass(descriptor).defaultType diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/sir/type/SpecialSirType.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/sir/type/SpecialSirType.kt index 96f3774d..ce90bc3e 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/sir/type/SpecialSirType.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/sir/type/SpecialSirType.kt @@ -1,9 +1,7 @@ package co.touchlab.skie.sir.type import co.touchlab.skie.sir.element.SirTypeParameter -import co.touchlab.skie.util.swift.qualifiedLocalTypeName import io.outfoxx.swiftpoet.AnyTypeName -import io.outfoxx.swiftpoet.DeclaredTypeName import io.outfoxx.swiftpoet.SelfTypeName import io.outfoxx.swiftpoet.TypeName @@ -35,6 +33,4 @@ sealed class SpecialSirType( object Self : SpecialSirType(SelfTypeName.INSTANCE) object Any : SpecialSirType(AnyTypeName.INSTANCE) - - object Protocol : SpecialSirType(DeclaredTypeName.qualifiedLocalTypeName("Protocol")) } diff --git a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/sir/type/translation/SirTypeTranslator.kt b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/sir/type/translation/SirTypeTranslator.kt index 9fbaf900..206b1418 100644 --- a/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/sir/type/translation/SirTypeTranslator.kt +++ b/SKIE/compiler/kotlin-plugin/src/kgp_common/kotlin/co/touchlab/skie/sir/type/translation/SirTypeTranslator.kt @@ -116,7 +116,6 @@ class SirTypeTranslator( SpecialReferenceOirType.Class -> sirBuiltins.Swift.AnyClass.defaultType SpecialReferenceOirType.Id -> SpecialSirType.Any SpecialReferenceOirType.InstanceType -> SpecialSirType.Self - SpecialReferenceOirType.Protocol -> SpecialSirType.Protocol } private fun mapType(oirType: TypeParameterUsageOirType): SirType =