ObjCExport: use ObjCExportFunctionGenerationContext when generating code
instead of its supertype, FunctionGenerationContext.
This commit is contained in:
committed by
Space
parent
e8e4a850d4
commit
bc2cc026db
+13
-13
@@ -156,7 +156,7 @@ internal open class ObjCExportCodeGeneratorBase(codegen: CodeGenerator) : ObjCCo
|
|||||||
rttiGenerator.dispose()
|
rttiGenerator.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FunctionGenerationContext.callFromBridge(
|
fun ObjCExportFunctionGenerationContext.callFromBridge(
|
||||||
llvmFunction: LLVMValueRef,
|
llvmFunction: LLVMValueRef,
|
||||||
args: List<LLVMValueRef>,
|
args: List<LLVMValueRef>,
|
||||||
resultLifetime: Lifetime = Lifetime.IRRELEVANT
|
resultLifetime: Lifetime = Lifetime.IRRELEVANT
|
||||||
@@ -173,7 +173,7 @@ internal open class ObjCExportCodeGeneratorBase(codegen: CodeGenerator) : ObjCCo
|
|||||||
// so it is correct to use [callAtFunctionScope] here.
|
// so it is correct to use [callAtFunctionScope] here.
|
||||||
// However, exception handling probably should be refactored
|
// However, exception handling probably should be refactored
|
||||||
// (e.g. moved from `IrToBitcode.kt` to [FunctionGenerationContext]).
|
// (e.g. moved from `IrToBitcode.kt` to [FunctionGenerationContext]).
|
||||||
fun FunctionGenerationContext.callFromBridge(
|
fun ObjCExportFunctionGenerationContext.callFromBridge(
|
||||||
function: LlvmCallable,
|
function: LlvmCallable,
|
||||||
args: List<LLVMValueRef>,
|
args: List<LLVMValueRef>,
|
||||||
resultLifetime: Lifetime = Lifetime.IRRELEVANT,
|
resultLifetime: Lifetime = Lifetime.IRRELEVANT,
|
||||||
@@ -186,13 +186,13 @@ internal open class ObjCExportCodeGeneratorBase(codegen: CodeGenerator) : ObjCCo
|
|||||||
return call(function, args, resultLifetime, exceptionHandler)
|
return call(function, args, resultLifetime, exceptionHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FunctionGenerationContext.kotlinReferenceToLocalObjC(value: LLVMValueRef) =
|
fun ObjCExportFunctionGenerationContext.kotlinReferenceToLocalObjC(value: LLVMValueRef) =
|
||||||
callFromBridge(context.llvm.Kotlin_ObjCExport_refToLocalObjC, listOf(value))
|
callFromBridge(context.llvm.Kotlin_ObjCExport_refToLocalObjC, listOf(value))
|
||||||
|
|
||||||
fun FunctionGenerationContext.kotlinReferenceToRetainedObjC(value: LLVMValueRef) =
|
fun ObjCExportFunctionGenerationContext.kotlinReferenceToRetainedObjC(value: LLVMValueRef) =
|
||||||
callFromBridge(context.llvm.Kotlin_ObjCExport_refToRetainedObjC, listOf(value))
|
callFromBridge(context.llvm.Kotlin_ObjCExport_refToRetainedObjC, listOf(value))
|
||||||
|
|
||||||
fun FunctionGenerationContext.objCReferenceToKotlin(value: LLVMValueRef, resultLifetime: Lifetime) =
|
fun ObjCExportFunctionGenerationContext.objCReferenceToKotlin(value: LLVMValueRef, resultLifetime: Lifetime) =
|
||||||
callFromBridge(context.llvm.Kotlin_ObjCExport_refFromObjC, listOf(value), resultLifetime)
|
callFromBridge(context.llvm.Kotlin_ObjCExport_refFromObjC, listOf(value), resultLifetime)
|
||||||
|
|
||||||
private val blockToKotlinFunctionConverterCache = mutableMapOf<BlockPointerBridge, LLVMValueRef>()
|
private val blockToKotlinFunctionConverterCache = mutableMapOf<BlockPointerBridge, LLVMValueRef>()
|
||||||
@@ -255,7 +255,7 @@ internal class ObjCExportCodeGenerator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Caution! Arbitrary methods shouldn't be called from Runnable thread state.
|
// Caution! Arbitrary methods shouldn't be called from Runnable thread state.
|
||||||
fun FunctionGenerationContext.genSendMessage(
|
fun ObjCExportFunctionGenerationContext.genSendMessage(
|
||||||
returnType: LlvmParamType,
|
returnType: LlvmParamType,
|
||||||
parameterTypes: List<LlvmParamType>,
|
parameterTypes: List<LlvmParamType>,
|
||||||
receiver: LLVMValueRef,
|
receiver: LLVMValueRef,
|
||||||
@@ -296,7 +296,7 @@ internal class ObjCExportCodeGenerator(
|
|||||||
ObjCValueType.FLOAT, ObjCValueType.DOUBLE, ObjCValueType.POINTER -> value
|
ObjCValueType.FLOAT, ObjCValueType.DOUBLE, ObjCValueType.POINTER -> value
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FunctionGenerationContext.objCBlockPointerToKotlin(
|
private fun ObjCExportFunctionGenerationContext.objCBlockPointerToKotlin(
|
||||||
value: LLVMValueRef,
|
value: LLVMValueRef,
|
||||||
typeBridge: BlockPointerBridge,
|
typeBridge: BlockPointerBridge,
|
||||||
resultLifetime: Lifetime
|
resultLifetime: Lifetime
|
||||||
@@ -306,17 +306,17 @@ internal class ObjCExportCodeGenerator(
|
|||||||
resultLifetime
|
resultLifetime
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun FunctionGenerationContext.kotlinFunctionToObjCBlockPointer(
|
private fun ObjCExportFunctionGenerationContext.kotlinFunctionToObjCBlockPointer(
|
||||||
typeBridge: BlockPointerBridge,
|
typeBridge: BlockPointerBridge,
|
||||||
value: LLVMValueRef
|
value: LLVMValueRef
|
||||||
) = callFromBridge(objcAutorelease, listOf(kotlinFunctionToRetainedObjCBlockPointer(typeBridge, value)))
|
) = callFromBridge(objcAutorelease, listOf(kotlinFunctionToRetainedObjCBlockPointer(typeBridge, value)))
|
||||||
|
|
||||||
internal fun FunctionGenerationContext.kotlinFunctionToRetainedObjCBlockPointer(
|
internal fun ObjCExportFunctionGenerationContext.kotlinFunctionToRetainedObjCBlockPointer(
|
||||||
typeBridge: BlockPointerBridge,
|
typeBridge: BlockPointerBridge,
|
||||||
value: LLVMValueRef
|
value: LLVMValueRef
|
||||||
) = callFromBridge(kotlinFunctionToRetainedBlockConverter(typeBridge), listOf(value))
|
) = callFromBridge(kotlinFunctionToRetainedBlockConverter(typeBridge), listOf(value))
|
||||||
|
|
||||||
fun FunctionGenerationContext.kotlinToLocalObjC(
|
fun ObjCExportFunctionGenerationContext.kotlinToLocalObjC(
|
||||||
value: LLVMValueRef,
|
value: LLVMValueRef,
|
||||||
typeBridge: TypeBridge
|
typeBridge: TypeBridge
|
||||||
): LLVMValueRef = if (LLVMTypeOf(value) == voidType) {
|
): LLVMValueRef = if (LLVMTypeOf(value) == voidType) {
|
||||||
@@ -329,7 +329,7 @@ internal class ObjCExportCodeGenerator(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FunctionGenerationContext.objCToKotlin(
|
fun ObjCExportFunctionGenerationContext.objCToKotlin(
|
||||||
value: LLVMValueRef,
|
value: LLVMValueRef,
|
||||||
typeBridge: TypeBridge,
|
typeBridge: TypeBridge,
|
||||||
resultLifetime: Lifetime
|
resultLifetime: Lifetime
|
||||||
@@ -343,7 +343,7 @@ internal class ObjCExportCodeGenerator(
|
|||||||
this.needsRuntimeInit = true
|
this.needsRuntimeInit = true
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun FunctionGenerationContext.convertKotlin(
|
inline fun ObjCExportFunctionGenerationContext.convertKotlin(
|
||||||
genValue: (Lifetime) -> LLVMValueRef,
|
genValue: (Lifetime) -> LLVMValueRef,
|
||||||
actualType: IrType,
|
actualType: IrType,
|
||||||
expectedType: IrType,
|
expectedType: IrType,
|
||||||
@@ -964,7 +964,7 @@ private fun ObjCExportCodeGenerator.generateObjCImp(
|
|||||||
methodBridge: MethodBridge,
|
methodBridge: MethodBridge,
|
||||||
isDirect: Boolean,
|
isDirect: Boolean,
|
||||||
baseMethod: IrFunction? = null,
|
baseMethod: IrFunction? = null,
|
||||||
callKotlin: FunctionGenerationContext.(
|
callKotlin: ObjCExportFunctionGenerationContext.(
|
||||||
args: List<LLVMValueRef>,
|
args: List<LLVMValueRef>,
|
||||||
resultLifetime: Lifetime,
|
resultLifetime: Lifetime,
|
||||||
exceptionHandler: ExceptionHandler
|
exceptionHandler: ExceptionHandler
|
||||||
|
|||||||
Reference in New Issue
Block a user