Rewrote annotations building from descriptors to IR
This commit is contained in:
+10
-18
@@ -12,14 +12,12 @@ import org.jetbrains.kotlin.backend.common.lower.at
|
|||||||
import org.jetbrains.kotlin.backend.common.lower.irNot
|
import org.jetbrains.kotlin.backend.common.lower.irNot
|
||||||
import org.jetbrains.kotlin.backend.konan.PrimitiveBinaryType
|
import org.jetbrains.kotlin.backend.konan.PrimitiveBinaryType
|
||||||
import org.jetbrains.kotlin.backend.konan.RuntimeNames
|
import org.jetbrains.kotlin.backend.konan.RuntimeNames
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.createAnnotation
|
|
||||||
import org.jetbrains.kotlin.backend.konan.ir.*
|
import org.jetbrains.kotlin.backend.konan.ir.*
|
||||||
import org.jetbrains.kotlin.backend.konan.isObjCMetaClass
|
import org.jetbrains.kotlin.backend.konan.isObjCMetaClass
|
||||||
import org.jetbrains.kotlin.builtins.UnsignedType
|
import org.jetbrains.kotlin.builtins.UnsignedType
|
||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
@@ -534,19 +532,7 @@ private fun KotlinStubs.createFakeKotlinExternalFunction(
|
|||||||
cFunctionName: String,
|
cFunctionName: String,
|
||||||
isObjCMethod: Boolean
|
isObjCMethod: Boolean
|
||||||
): IrSimpleFunction {
|
): IrSimpleFunction {
|
||||||
val objCMethodImpAnnotation = if (isObjCMethod) {
|
val bridgeDescriptor = WrappedSimpleFunctionDescriptor()
|
||||||
val methodInfo = signature.getObjCMethodInfo()!!
|
|
||||||
createObjCMethodImpAnnotation(methodInfo.selector, methodInfo.encoding, symbols)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
val bridgeAnnotations = Annotations.create(
|
|
||||||
listOfNotNull(
|
|
||||||
createAnnotation(symbols.symbolName.descriptor, "value" to cFunctionName),
|
|
||||||
objCMethodImpAnnotation
|
|
||||||
)
|
|
||||||
)
|
|
||||||
val bridgeDescriptor = WrappedSimpleFunctionDescriptor(bridgeAnnotations)
|
|
||||||
val bridge = IrFunctionImpl(
|
val bridge = IrFunctionImpl(
|
||||||
UNDEFINED_OFFSET,
|
UNDEFINED_OFFSET,
|
||||||
UNDEFINED_OFFSET,
|
UNDEFINED_OFFSET,
|
||||||
@@ -563,12 +549,18 @@ private fun KotlinStubs.createFakeKotlinExternalFunction(
|
|||||||
)
|
)
|
||||||
bridgeDescriptor.bind(bridge)
|
bridgeDescriptor.bind(bridge)
|
||||||
|
|
||||||
|
bridge.annotations += buildSimpleAnnotation(irBuiltIns, UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||||
|
symbols.symbolName.owner, cFunctionName)
|
||||||
|
|
||||||
|
if (isObjCMethod) {
|
||||||
|
val methodInfo = signature.getObjCMethodInfo()!!
|
||||||
|
bridge.annotations += buildSimpleAnnotation(irBuiltIns, UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||||
|
symbols.objCMethodImp.owner, methodInfo.selector, methodInfo.encoding)
|
||||||
|
}
|
||||||
|
|
||||||
return bridge
|
return bridge
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createObjCMethodImpAnnotation(selector: String, encoding: String, symbols: KonanSymbols) =
|
|
||||||
createAnnotation(symbols.objCMethodImp.descriptor, "selector" to selector, "encoding" to encoding)
|
|
||||||
|
|
||||||
private val cCall = RuntimeNames.cCall
|
private val cCall = RuntimeNames.cCall
|
||||||
|
|
||||||
private fun IrType.isUnsigned(unsignedType: UnsignedType) = this is IrSimpleType && !this.hasQuestionMark &&
|
private fun IrType.isUnsigned(unsignedType: UnsignedType) = this is IrSimpleType && !this.hasQuestionMark &&
|
||||||
|
|||||||
+11
-19
@@ -5,20 +5,17 @@ import org.jetbrains.kotlin.backend.common.descriptors.WrappedValueParameterDesc
|
|||||||
import org.jetbrains.kotlin.backend.common.ir.simpleFunctions
|
import org.jetbrains.kotlin.backend.common.ir.simpleFunctions
|
||||||
import org.jetbrains.kotlin.backend.common.lower.irBlock
|
import org.jetbrains.kotlin.backend.common.lower.irBlock
|
||||||
import org.jetbrains.kotlin.backend.common.lower.irThrow
|
import org.jetbrains.kotlin.backend.common.lower.irThrow
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.createAnnotation
|
|
||||||
import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
|
import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
|
||||||
|
import org.jetbrains.kotlin.backend.konan.ir.buildSimpleAnnotation
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.builders.*
|
import org.jetbrains.kotlin.ir.builders.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrTryImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrTryImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||||
@@ -72,7 +69,7 @@ internal class KotlinBridgeBuilder(
|
|||||||
isExternal: Boolean
|
isExternal: Boolean
|
||||||
) {
|
) {
|
||||||
private var counter = 0
|
private var counter = 0
|
||||||
private val bridge: IrFunction = createKotlinBridge(startOffset, endOffset, cName, stubs.symbols, isExternal)
|
private val bridge: IrFunction = createKotlinBridge(startOffset, endOffset, cName, stubs, isExternal)
|
||||||
val irBuilder: IrBuilderWithScope = irBuilder(stubs.irBuiltIns, bridge.symbol).at(startOffset, endOffset)
|
val irBuilder: IrBuilderWithScope = irBuilder(stubs.irBuiltIns, bridge.symbol).at(startOffset, endOffset)
|
||||||
|
|
||||||
fun addParameter(type: IrType): IrValueParameter {
|
fun addParameter(type: IrType): IrValueParameter {
|
||||||
@@ -102,19 +99,10 @@ private fun createKotlinBridge(
|
|||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
endOffset: Int,
|
endOffset: Int,
|
||||||
cBridgeName: String,
|
cBridgeName: String,
|
||||||
symbols: KonanSymbols,
|
stubs: KotlinStubs,
|
||||||
isExternal: Boolean
|
isExternal: Boolean
|
||||||
): IrFunctionImpl {
|
): IrFunctionImpl {
|
||||||
val bridgeAnnotations = Annotations.create(
|
val bridgeDescriptor = WrappedSimpleFunctionDescriptor()
|
||||||
listOf(
|
|
||||||
if (isExternal) {
|
|
||||||
createAnnotation(symbols.symbolName.descriptor, "value" to cBridgeName)
|
|
||||||
} else {
|
|
||||||
createAnnotation(symbols.exportForCppRuntime.descriptor, "name" to cBridgeName)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
val bridgeDescriptor = WrappedSimpleFunctionDescriptor(bridgeAnnotations)
|
|
||||||
val bridge = IrFunctionImpl(
|
val bridge = IrFunctionImpl(
|
||||||
startOffset,
|
startOffset,
|
||||||
endOffset,
|
endOffset,
|
||||||
@@ -131,9 +119,13 @@ private fun createKotlinBridge(
|
|||||||
)
|
)
|
||||||
bridgeDescriptor.bind(bridge)
|
bridgeDescriptor.bind(bridge)
|
||||||
if (isExternal) {
|
if (isExternal) {
|
||||||
val constructor = symbols.filterExceptions.owner.constructors.single()
|
bridge.annotations += buildSimpleAnnotation(stubs.irBuiltIns, startOffset, endOffset,
|
||||||
bridge.annotations +=
|
stubs.symbols.symbolName.owner, cBridgeName)
|
||||||
IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, constructor.returnType, constructor.symbol)
|
bridge.annotations += buildSimpleAnnotation(stubs.irBuiltIns, startOffset, endOffset,
|
||||||
|
stubs.symbols.filterExceptions.owner)
|
||||||
|
} else {
|
||||||
|
bridge.annotations += buildSimpleAnnotation(stubs.irBuiltIns, startOffset, endOffset,
|
||||||
|
stubs.symbols.exportForCppRuntime.owner, cBridgeName)
|
||||||
}
|
}
|
||||||
return bridge
|
return bridge
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-3
@@ -7,18 +7,19 @@ package org.jetbrains.kotlin.backend.konan.ir
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.atMostOne
|
import org.jetbrains.kotlin.backend.common.atMostOne
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.getArgumentValueOrNull
|
import org.jetbrains.kotlin.backend.konan.descriptors.getArgumentValueOrNull
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.isInterface
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrConst
|
import org.jetbrains.kotlin.ir.expressions.IrConst
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
||||||
import org.jetbrains.kotlin.ir.types.isMarkedNullable
|
import org.jetbrains.kotlin.ir.types.isMarkedNullable
|
||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
@@ -124,3 +125,16 @@ val IrDeclaration.isGetter get() = this is IrSimpleFunction && this == this.corr
|
|||||||
val IrDeclaration.isSetter get() = this is IrSimpleFunction && this == this.correspondingProperty?.setter
|
val IrDeclaration.isSetter get() = this is IrSimpleFunction && this == this.correspondingProperty?.setter
|
||||||
|
|
||||||
val IrDeclaration.isAccessor get() = this.isGetter || this.isSetter
|
val IrDeclaration.isAccessor get() = this.isGetter || this.isSetter
|
||||||
|
|
||||||
|
fun buildSimpleAnnotation(irBuiltIns: IrBuiltIns, startOffset: Int, endOffset: Int,
|
||||||
|
annotationClass: IrClass, vararg args: String): IrConstructorCall {
|
||||||
|
val constructor = annotationClass.constructors.single()
|
||||||
|
return IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, constructor.returnType, constructor.symbol).apply {
|
||||||
|
args.forEachIndexed { index, arg ->
|
||||||
|
assert(constructor.valueParameters[index].type == irBuiltIns.stringType) {
|
||||||
|
"String type expected but was ${constructor.valueParameters[index].type}"
|
||||||
|
}
|
||||||
|
putValueArgument(index, IrConstImpl.string(startOffset, endOffset, irBuiltIns.stringType, arg))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-5
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.backend.konan.llvm.llvmSymbolOrigin
|
|||||||
import org.jetbrains.kotlin.backend.konan.llvm.tryGetIntrinsicType
|
import org.jetbrains.kotlin.backend.konan.llvm.tryGetIntrinsicType
|
||||||
import org.jetbrains.kotlin.builtins.UnsignedTypes
|
import org.jetbrains.kotlin.builtins.UnsignedTypes
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
@@ -390,12 +389,9 @@ internal class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Annotations to be detected in KotlinObjCClassInfoGenerator:
|
|
||||||
val annotations = createObjCMethodImpAnnotations(selector = selector, encoding = signatureEncoding)
|
|
||||||
|
|
||||||
val newDescriptor = SimpleFunctionDescriptorImpl.create(
|
val newDescriptor = SimpleFunctionDescriptorImpl.create(
|
||||||
function.descriptor.containingDeclaration,
|
function.descriptor.containingDeclaration,
|
||||||
annotations,
|
Annotations.EMPTY,
|
||||||
("imp:" + selector).synthesizedName,
|
("imp:" + selector).synthesizedName,
|
||||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||||
SourceElement.NO_SOURCE
|
SourceElement.NO_SOURCE
|
||||||
@@ -444,6 +440,11 @@ internal class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Annotations to be detected in KotlinObjCClassInfoGenerator:
|
||||||
|
|
||||||
|
newFunction.annotations += buildSimpleAnnotation(context.irBuiltIns, function.startOffset, function.endOffset,
|
||||||
|
symbols.objCMethodImp.owner, selector, signatureEncoding)
|
||||||
|
|
||||||
val builder = context.createIrBuilder(newFunction.symbol)
|
val builder = context.createIrBuilder(newFunction.symbol)
|
||||||
newFunction.body = builder.irBlockBody(newFunction) {
|
newFunction.body = builder.irBlockBody(newFunction) {
|
||||||
+irCall(function).apply {
|
+irCall(function).apply {
|
||||||
|
|||||||
Reference in New Issue
Block a user