Skip to content

Commit

Permalink
Fix translation for ObjCProtocol.
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipDolnik committed Nov 13, 2023
1 parent 7cf51ea commit d2f0448
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion SKIE/acceptance-tests
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class ExtraDescriptorBuiltins(

private val Darwin = getModule("<org.jetbrains.kotlin.native.platform.darwin>")

private val stdlib = getModule("<stdlib>")

val Protocol: ClassDescriptor = getClass("kotlinx.cinterop.ObjCProtocol", stdlib)

val NSObject: ClassDescriptor = getClass("platform.darwin.NSObject", Darwin)

val NSCopying: ClassDescriptor = getClass("platform.Foundation.NSCopyingProtocol", Foundation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -35,6 +33,4 @@ sealed class SpecialSirType<SELF : SirType>(
object Self : SpecialSirType<Self>(SelfTypeName.INSTANCE)

object Any : SpecialSirType<Any>(AnyTypeName.INSTANCE)

object Protocol : SpecialSirType<Protocol>(DeclaredTypeName.qualifiedLocalTypeName("Protocol"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit d2f0448

Please sign in to comment.