Add classType property in IrClassReference, support class references in codegen
This commit is contained in:
+15
-11
@@ -21,8 +21,10 @@ import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.codegen.*
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil.*
|
||||
import org.jetbrains.kotlin.codegen.ExpressionCodegen.putReifiedOperationMarkerIfTypeIsReifiedParameter
|
||||
import org.jetbrains.kotlin.codegen.StackValue.*
|
||||
import org.jetbrains.kotlin.codegen.inline.NameGenerator
|
||||
import org.jetbrains.kotlin.codegen.inline.ReifiedTypeInliner
|
||||
import org.jetbrains.kotlin.codegen.inline.ReifiedTypeParametersUsages
|
||||
import org.jetbrains.kotlin.codegen.inline.TypeParameterMappings
|
||||
import org.jetbrains.kotlin.codegen.intrinsics.JavaClassProperty
|
||||
@@ -46,6 +48,7 @@ import org.jetbrains.kotlin.resolve.jvm.AsmTypes.JAVA_THROWABLE_TYPE
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.typesApproximation.approximateCapturedTypes
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import org.jetbrains.kotlin.utils.keysToMap
|
||||
@@ -889,21 +892,22 @@ class ExpressionCodegen(
|
||||
}
|
||||
|
||||
fun generateClassLiteralReference(
|
||||
receiverExpression: IrExpression,
|
||||
wrapIntoKClass: Boolean,
|
||||
data: BlockInfo
|
||||
classReference: IrExpression,
|
||||
wrapIntoKClass: Boolean,
|
||||
data: BlockInfo
|
||||
) {
|
||||
if (receiverExpression !is IrClassReference /* && DescriptorUtils.isObjectQualifier(receiverExpression.descriptor)*/) {
|
||||
assert(receiverExpression is IrGetClass)
|
||||
JavaClassProperty.generateImpl(mv, gen((receiverExpression as IrGetClass).argument, data))
|
||||
if (classReference !is IrClassReference /* && DescriptorUtils.isObjectQualifier(classReference.descriptor)*/) {
|
||||
assert(classReference is IrGetClass)
|
||||
JavaClassProperty.generateImpl(mv, gen((classReference as IrGetClass).argument, data))
|
||||
}
|
||||
else {
|
||||
// if (TypeUtils.isTypeParameter(type)) {
|
||||
// assert(TypeUtils.isReifiedTypeParameter(type)) { "Non-reified type parameter under ::class should be rejected by type checker: " + type }
|
||||
// putReifiedOperationMarkerIfTypeIsReifiedParameter(type, ReifiedTypeInliner.OperationKind.JAVA_CLASS)
|
||||
// }
|
||||
val type = classReference.classType
|
||||
if (TypeUtils.isTypeParameter(type)) {
|
||||
assert(TypeUtils.isReifiedTypeParameter(type)) { "Non-reified type parameter under ::class should be rejected by type checker: " + type }
|
||||
putReifiedOperationMarkerIfTypeIsReifiedParameter(type, ReifiedTypeInliner.OperationKind.JAVA_CLASS, mv, this)
|
||||
}
|
||||
|
||||
putJavaLangClassInstance(mv, typeMapper.mapType(receiverExpression.descriptor.defaultType))
|
||||
putJavaLangClassInstance(mv, typeMapper.mapType(type))
|
||||
}
|
||||
|
||||
if (wrapIntoKClass) {
|
||||
|
||||
+1
-2
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.KtClassLiteralExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.psi2ir.intermediate.TransientReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
@@ -46,7 +45,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
|
||||
val typeClass = typeConstructorDeclaration ?:
|
||||
throw AssertionError("Unexpected type constructor for ${lhs.type}: $typeConstructorDeclaration")
|
||||
IrClassReferenceImpl(ktClassLiteral.startOffset, ktClassLiteral.endOffset, resultType,
|
||||
context.symbolTable.referenceClassifier(typeClass))
|
||||
context.symbolTable.referenceClassifier(typeClass), lhs.type)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,12 @@ package org.jetbrains.kotlin.ir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
|
||||
interface IrClassReference : IrDeclarationReference {
|
||||
override val descriptor: ClassifierDescriptor
|
||||
override val symbol: IrClassifierSymbol
|
||||
val classType: KotlinType
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -30,7 +30,8 @@ class IrClassReferenceImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: KotlinType,
|
||||
symbol: IrClassifierSymbol
|
||||
symbol: IrClassifierSymbol,
|
||||
override val classType: KotlinType
|
||||
) : IrClassReference,
|
||||
IrTerminalDeclarationReferenceBase<IrClassifierSymbol, ClassifierDescriptor>(
|
||||
startOffset, endOffset, type,
|
||||
@@ -42,8 +43,9 @@ class IrClassReferenceImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: KotlinType,
|
||||
descriptor: ClassifierDescriptor
|
||||
) : this(startOffset, endOffset, type, createClassifierSymbolForClassReference(descriptor))
|
||||
descriptor: ClassifierDescriptor,
|
||||
classType: KotlinType
|
||||
) : this(startOffset, endOffset, type, createClassifierSymbolForClassReference(descriptor), classType)
|
||||
|
||||
override val descriptor: ClassifierDescriptor get() = symbol.descriptor
|
||||
|
||||
|
||||
@@ -446,7 +446,8 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
||||
IrClassReferenceImpl(
|
||||
expression.startOffset, expression.endOffset,
|
||||
expression.type,
|
||||
mapClassifierReference(expression.descriptor)
|
||||
mapClassifierReference(expression.descriptor),
|
||||
expression.classType
|
||||
)
|
||||
|
||||
override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall): IrInstanceInitializerCall =
|
||||
|
||||
@@ -410,7 +410,8 @@ open class DeepCopyIrTreeWithSymbols(private val symbolRemapper: SymbolRemapper)
|
||||
IrClassReferenceImpl(
|
||||
expression.startOffset, expression.endOffset,
|
||||
expression.type,
|
||||
symbolRemapper.getReferencedClassifier(expression.symbol)
|
||||
symbolRemapper.getReferencedClassifier(expression.symbol),
|
||||
expression.classType
|
||||
)
|
||||
|
||||
override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall): IrInstanceInitializerCall =
|
||||
|
||||
Reference in New Issue
Block a user