Add specific ObjCMethodSpec kind for object instance getters
This helps to drop usages of obsolete "IrDeclaration.descriptor" from ObjCExportCodeGenerator
This commit is contained in:
committed by
Vasily Levchenko
parent
e305710d91
commit
ca2df3cead
+11
-20
@@ -1257,6 +1257,13 @@ private fun ObjCExportCodeGenerator.createTypeAdapter(
|
||||
is ObjCClassMethodForKotlinEnumValues -> {
|
||||
classAdapters += createEnumValuesAdapter(it.valuesFunctionSymbol.owner, it.selector)
|
||||
}
|
||||
is ObjCGetterForObjectInstance -> {
|
||||
classAdapters += if (irClass.isUnit()) {
|
||||
createUnitInstanceAdapter(it.selector)
|
||||
} else {
|
||||
createObjectInstanceAdapter(irClass, it.selector)
|
||||
}
|
||||
}
|
||||
is ObjCMethodForKotlinMethod -> {} // Handled below.
|
||||
}.let {} // Force exhaustive.
|
||||
}
|
||||
@@ -1309,19 +1316,6 @@ private fun ObjCExportCodeGenerator.createTypeAdapter(
|
||||
else -> Pair(emptyList(), -1)
|
||||
}
|
||||
|
||||
when (irClass.kind) {
|
||||
ClassKind.OBJECT -> {
|
||||
classAdapters += if (irClass.isUnit()) {
|
||||
createUnitInstanceAdapter()
|
||||
} else {
|
||||
createObjectInstanceAdapter(irClass)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
// Nothing special.
|
||||
}
|
||||
}
|
||||
|
||||
return ObjCTypeAdapter(
|
||||
irClass,
|
||||
typeInfo,
|
||||
@@ -1464,23 +1458,20 @@ private fun ObjCExportCodeGenerator.objCToKotlinMethodAdapter(
|
||||
return ObjCToKotlinMethodAdapter(selector, getEncoding(methodBridge), constPointer(imp))
|
||||
}
|
||||
|
||||
private fun ObjCExportCodeGenerator.createUnitInstanceAdapter() =
|
||||
generateObjCToKotlinSyntheticGetter(
|
||||
namer.getObjectInstanceSelector(context.builtIns.unit)
|
||||
) {
|
||||
private fun ObjCExportCodeGenerator.createUnitInstanceAdapter(selector: String) =
|
||||
generateObjCToKotlinSyntheticGetter(selector) {
|
||||
initRuntimeIfNeeded() // For instance methods it gets called when allocating.
|
||||
|
||||
ret(callFromBridge(context.llvm.Kotlin_ObjCExport_convertUnit, listOf(codegen.theUnitInstanceRef.llvm)))
|
||||
}
|
||||
|
||||
private fun ObjCExportCodeGenerator.createObjectInstanceAdapter(
|
||||
irClass: IrClass
|
||||
irClass: IrClass,
|
||||
selector: String
|
||||
): ObjCExportCodeGenerator.ObjCToKotlinMethodAdapter {
|
||||
assert(irClass.kind == ClassKind.OBJECT)
|
||||
assert(!irClass.isUnit())
|
||||
|
||||
val selector = namer.getObjectInstanceSelector(irClass.descriptor)
|
||||
|
||||
return generateObjCToKotlinSyntheticGetter(selector) {
|
||||
initRuntimeIfNeeded() // For instance methods it gets called when allocating.
|
||||
val value = getObjectValue(irClass, startLocationInfo = null, exceptionHandler = ExceptionHandler.Caller)
|
||||
|
||||
+6
@@ -63,6 +63,10 @@ internal fun ObjCExportedInterface.createCodeSpec(symbolTable: SymbolTable): Obj
|
||||
}
|
||||
}
|
||||
|
||||
if (descriptor.kind == ClassKind.OBJECT) {
|
||||
methods += ObjCGetterForObjectInstance(namer.getObjectInstanceSelector(descriptor))
|
||||
}
|
||||
|
||||
if (descriptor.kind == ClassKind.ENUM_CLASS) {
|
||||
descriptor.enumEntries.mapTo(methods) {
|
||||
ObjCGetterForKotlinEnumEntry(symbolTable.referenceEnumEntry(it))
|
||||
@@ -112,6 +116,8 @@ internal class ObjCClassMethodForKotlinEnumValues(
|
||||
val selector: String
|
||||
) : ObjCMethodSpec()
|
||||
|
||||
internal class ObjCGetterForObjectInstance(val selector: String) : ObjCMethodSpec()
|
||||
|
||||
internal sealed class ObjCTypeSpec(val binaryName: String)
|
||||
|
||||
internal sealed class ObjCTypeForKotlinType(
|
||||
|
||||
Reference in New Issue
Block a user