Move some of relevant code to ReflectionSupport.kt
This commit is contained in:
committed by
SvyatoslavScherbina
parent
06bbf18ca7
commit
f704fd44af
-53
@@ -11,11 +11,7 @@ import org.jetbrains.kotlin.backend.common.descriptors.WrappedFieldDescriptor
|
|||||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||||
import org.jetbrains.kotlin.backend.common.lower.irBlock
|
import org.jetbrains.kotlin.backend.common.lower.irBlock
|
||||||
import org.jetbrains.kotlin.backend.konan.Context
|
import org.jetbrains.kotlin.backend.konan.Context
|
||||||
import org.jetbrains.kotlin.backend.konan.InteropFqNames
|
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
|
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
|
||||||
import org.jetbrains.kotlin.backend.konan.KonanBackendContext
|
|
||||||
import org.jetbrains.kotlin.backend.konan.ir.typeWithStarProjections
|
|
||||||
import org.jetbrains.kotlin.backend.konan.isObjCClass
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptorImpl
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
@@ -26,8 +22,6 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrLocalDelegatedPropertyReference
|
import org.jetbrains.kotlin.ir.expressions.IrLocalDelegatedPropertyReference
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrPropertyReference
|
import org.jetbrains.kotlin.ir.expressions.IrPropertyReference
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
@@ -36,8 +30,6 @@ import org.jetbrains.kotlin.ir.types.typeWith
|
|||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperClassifiers
|
|
||||||
|
|
||||||
internal class PropertyDelegationLowering(val context: Context) : FileLoweringPass {
|
internal class PropertyDelegationLowering(val context: Context) : FileLoweringPass {
|
||||||
private var tempIndex = 0
|
private var tempIndex = 0
|
||||||
@@ -303,48 +295,3 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
|
|||||||
private object DECLARATION_ORIGIN_KPROPERTIES_FOR_DELEGATION :
|
private object DECLARATION_ORIGIN_KPROPERTIES_FOR_DELEGATION :
|
||||||
IrDeclarationOriginImpl("KPROPERTIES_FOR_DELEGATION")
|
IrDeclarationOriginImpl("KPROPERTIES_FOR_DELEGATION")
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun IrBuilderWithScope.irKType(context: KonanBackendContext, type: IrType): IrExpression {
|
|
||||||
val kTypeImplSymbol = context.ir.symbols.kTypeImpl
|
|
||||||
val kTypeImplForGenericsSymbol = context.ir.symbols.kTypeImplForGenerics
|
|
||||||
|
|
||||||
val kTypeImplConstructorSymbol = kTypeImplSymbol.constructors.single()
|
|
||||||
val kTypeImplForGenericsConstructorSymbol = kTypeImplForGenericsSymbol.constructors.single()
|
|
||||||
|
|
||||||
val classifierOrNull = type.classifierOrNull
|
|
||||||
|
|
||||||
return if (classifierOrNull !is IrClassSymbol) {
|
|
||||||
// IrTypeParameterSymbol
|
|
||||||
irCall(kTypeImplForGenericsConstructorSymbol)
|
|
||||||
} else {
|
|
||||||
val returnKClass = irKClass(context, classifierOrNull)
|
|
||||||
irCall(kTypeImplConstructorSymbol).apply {
|
|
||||||
putValueArgument(0, returnKClass)
|
|
||||||
putValueArgument(1, irBoolean(type.isMarkedNullable()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun IrBuilderWithScope.irKClass(context: KonanBackendContext, symbol: IrClassifierSymbol): IrExpression {
|
|
||||||
val symbols = context.ir.symbols
|
|
||||||
return when {
|
|
||||||
symbol !is IrClassSymbol -> // E.g. for `T::class` in a body of an inline function itself.
|
|
||||||
irCall(symbols.ThrowNullPointerException.owner)
|
|
||||||
|
|
||||||
symbol.descriptor.isObjCClass() ->
|
|
||||||
irKClassUnsupported(context, "KClass for Objective-C classes is not supported yet")
|
|
||||||
|
|
||||||
symbol.descriptor.getAllSuperClassifiers().any {
|
|
||||||
it is ClassDescriptor && it.fqNameUnsafe == InteropFqNames.nativePointed
|
|
||||||
} -> irKClassUnsupported(context, "KClass for interop types is not supported yet")
|
|
||||||
|
|
||||||
else -> irCall(symbols.kClassImplConstructor.owner).apply {
|
|
||||||
putValueArgument(0, irCall(symbols.getClassTypeInfo, listOf(symbol.typeWithStarProjections)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun IrBuilderWithScope.irKClassUnsupported(context: KonanBackendContext, message: String) =
|
|
||||||
irCall(context.ir.symbols.kClassUnsupportedImplConstructor.owner).apply {
|
|
||||||
putValueArgument(0, irString(message))
|
|
||||||
}
|
|
||||||
|
|||||||
+71
@@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.backend.konan.lower
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.backend.konan.InteropFqNames
|
||||||
|
import org.jetbrains.kotlin.backend.konan.KonanBackendContext
|
||||||
|
import org.jetbrains.kotlin.backend.konan.ir.typeWithStarProjections
|
||||||
|
import org.jetbrains.kotlin.backend.konan.isObjCClass
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
|
||||||
|
import org.jetbrains.kotlin.ir.builders.irBoolean
|
||||||
|
import org.jetbrains.kotlin.ir.builders.irCall
|
||||||
|
import org.jetbrains.kotlin.ir.builders.irString
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
|
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||||
|
import org.jetbrains.kotlin.ir.types.isMarkedNullable
|
||||||
|
import org.jetbrains.kotlin.ir.util.constructors
|
||||||
|
import org.jetbrains.kotlin.ir.util.irCall
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||||
|
import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperClassifiers
|
||||||
|
|
||||||
|
internal fun IrBuilderWithScope.irKType(context: KonanBackendContext, type: IrType): IrExpression {
|
||||||
|
val kTypeImplSymbol = context.ir.symbols.kTypeImpl
|
||||||
|
val kTypeImplForGenericsSymbol = context.ir.symbols.kTypeImplForGenerics
|
||||||
|
|
||||||
|
val kTypeImplConstructorSymbol = kTypeImplSymbol.constructors.single()
|
||||||
|
val kTypeImplForGenericsConstructorSymbol = kTypeImplForGenericsSymbol.constructors.single()
|
||||||
|
|
||||||
|
val classifierOrNull = type.classifierOrNull
|
||||||
|
|
||||||
|
return if (classifierOrNull !is IrClassSymbol) {
|
||||||
|
// IrTypeParameterSymbol
|
||||||
|
irCall(kTypeImplForGenericsConstructorSymbol)
|
||||||
|
} else {
|
||||||
|
val returnKClass = irKClass(context, classifierOrNull)
|
||||||
|
irCall(kTypeImplConstructorSymbol).apply {
|
||||||
|
putValueArgument(0, returnKClass)
|
||||||
|
putValueArgument(1, irBoolean(type.isMarkedNullable()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun IrBuilderWithScope.irKClass(context: KonanBackendContext, symbol: IrClassifierSymbol): IrExpression {
|
||||||
|
val symbols = context.ir.symbols
|
||||||
|
return when {
|
||||||
|
symbol !is IrClassSymbol -> // E.g. for `T::class` in a body of an inline function itself.
|
||||||
|
irCall(symbols.ThrowNullPointerException.owner)
|
||||||
|
|
||||||
|
symbol.descriptor.isObjCClass() ->
|
||||||
|
irKClassUnsupported(context, "KClass for Objective-C classes is not supported yet")
|
||||||
|
|
||||||
|
symbol.descriptor.getAllSuperClassifiers().any {
|
||||||
|
it is ClassDescriptor && it.fqNameUnsafe == InteropFqNames.nativePointed
|
||||||
|
} -> irKClassUnsupported(context, "KClass for interop types is not supported yet")
|
||||||
|
|
||||||
|
else -> irCall(symbols.kClassImplConstructor.owner).apply {
|
||||||
|
putValueArgument(0, irCall(symbols.getClassTypeInfo, listOf(symbol.typeWithStarProjections)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun IrBuilderWithScope.irKClassUnsupported(context: KonanBackendContext, message: String) =
|
||||||
|
irCall(context.ir.symbols.kClassUnsupportedImplConstructor.owner).apply {
|
||||||
|
putValueArgument(0, irString(message))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user