Eliminated a little more descriptor usage.

This commit is contained in:
Alexander Gorshenev
2019-01-24 16:56:26 +03:00
committed by alexander-gorshenev
parent ce0451e5c8
commit 5fa37aa800
2 changed files with 16 additions and 7 deletions
@@ -6,7 +6,6 @@ import org.jetbrains.kotlin.backend.common.lower.irNot
import org.jetbrains.kotlin.backend.konan.PrimitiveBinaryType
import org.jetbrains.kotlin.backend.konan.RuntimeNames
import org.jetbrains.kotlin.backend.konan.descriptors.createAnnotation
import org.jetbrains.kotlin.backend.konan.descriptors.getStringValue
import org.jetbrains.kotlin.backend.konan.ir.KonanSymbols
import org.jetbrains.kotlin.backend.konan.irasdescriptors.*
import org.jetbrains.kotlin.builtins.UnsignedType
@@ -162,7 +161,7 @@ internal fun KotlinStubs.generateCCall(expression: IrCall, builder: IrBuilderWit
if (isInvoke) {
callBuilder.cBridgeBodyLines.add(0, "$targetFunctionVariable = ${targetPtrParameter!!};")
} else {
val cCallSymbolName = callee.descriptor.annotations.findAnnotation(cCall)!!.getStringValue("id")
val cCallSymbolName = callee.annotations.getAnnotationArgumentValue<String>(cCall, "id")!!
cLines += "extern const $targetFunctionVariable __asm(\"$cCallSymbolName\");" // Exported from cinterop stubs.
}
@@ -345,15 +344,13 @@ private fun IrType.isCEnumType(): Boolean {
}
private fun IrValueParameter.isWCStringParameter() =
this.descriptor.annotations.hasAnnotation(cCall.child(Name.identifier("WCString")))
this.annotations.hasAnnotation(cCall.child(Name.identifier("WCString")))
private fun IrValueParameter.isCStringParameter() =
this.descriptor.annotations.hasAnnotation(cCall.child(Name.identifier("CString")))
this.annotations.hasAnnotation(cCall.child(Name.identifier("CString")))
private fun getStructSpelling(kotlinClass: IrClass): String? =
kotlinClass.descriptor.annotations
.findAnnotation(FqName("kotlinx.cinterop.internal.CStruct"))
?.getStringValue("spelling")
kotlinClass.annotations.getAnnotationArgumentValue(FqName("kotlinx.cinterop.internal.CStruct"), "spelling")
private fun getCStructType(kotlinClass: IrClass): CType? =
getStructSpelling(kotlinClass)?.let { CTypes.simple(it) }
@@ -166,6 +166,18 @@ fun List<IrCall>.findAnnotation(fqName: FqName): IrCall? = this.firstOrNull {
it.annotationClass.fqNameSafe == fqName
}
fun <T> List<IrCall>.getAnnotationArgumentValue(fqName: FqName, argumentName: String): T? {
val annotation = this.findAnnotation(fqName) ?: return null
for (index in 0 until annotation.valueArgumentsCount) {
val parameter = annotation.symbol.owner.valueParameters[index]
if (parameter.name == Name.identifier(argumentName)) {
val actual = annotation.getValueArgument(index) as? IrConst<T>
return actual?.value
}
}
return null
}
fun IrValueParameter.isInlineParameter(): Boolean =
!this.isNoinline && (this.type.isFunction() || this.type.isSuspendFunction()) && !this.type.isMarkedNullable()