Minor, relax parameter type of AsmUtil.putJavaLangClassInstance

This commit is contained in:
Alexander Udalov
2019-02-21 16:50:07 +01:00
parent afe3bed7e1
commit e3779b1883
7 changed files with 21 additions and 18 deletions
@@ -218,9 +218,9 @@ public class AsmUtil {
}
@NotNull
public static Type boxType(@NotNull Type type, @NotNull KotlinType kotlinType, @NotNull GenerationState state) {
public static Type boxType(@NotNull Type type, @NotNull KotlinType kotlinType, @NotNull KotlinTypeMapper typeMapper) {
if (InlineClassesUtilsKt.isInlineClassType(kotlinType)) {
return state.getTypeMapper().mapTypeAsDeclaration(kotlinType);
return typeMapper.mapTypeAsDeclaration(kotlinType);
}
Type boxedPrimitiveType = boxPrimitiveType(type);
@@ -1236,10 +1236,10 @@ public class AsmUtil {
@NotNull InstructionAdapter v,
@NotNull Type type,
@Nullable KotlinType kotlinType,
@NotNull GenerationState state
@NotNull KotlinTypeMapper typeMapper
) {
if (kotlinType != null && InlineClassesUtilsKt.isInlineClassType(kotlinType)) {
v.aconst(boxType(type, kotlinType, state));
v.aconst(boxType(type, kotlinType, typeMapper));
}
else if (isPrimitive(type)) {
v.getstatic(boxType(type).getInternalName(), "TYPE", "Ljava/lang/Class;");
@@ -399,16 +399,17 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
@NotNull CallableDescriptor descriptor,
@NotNull GenerationState state
) {
KotlinTypeMapper typeMapper = state.getTypeMapper();
DeclarationDescriptor container = descriptor.getContainingDeclaration();
if (container instanceof ClassDescriptor) {
// TODO: would it work for arrays?
SimpleType containerKotlinType = ((ClassDescriptor) container).getDefaultType();
Type containerType = state.getTypeMapper().mapClass((ClassDescriptor) container);
putJavaLangClassInstance(iv, containerType, containerKotlinType, state);
Type containerType = typeMapper.mapClass((ClassDescriptor) container);
putJavaLangClassInstance(iv, containerType, containerKotlinType, typeMapper);
}
else if (container instanceof PackageFragmentDescriptor) {
iv.aconst(state.getTypeMapper().mapOwner(descriptor));
iv.aconst(typeMapper.mapOwner(descriptor));
}
else if (descriptor instanceof VariableDescriptorWithAccessors) {
iv.aconst(state.getBindingContext().get(
@@ -3181,7 +3181,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
putReifiedOperationMarkerIfTypeIsReifiedParameter(type, ReifiedTypeInliner.OperationKind.JAVA_CLASS);
}
putJavaLangClassInstance(v, typeMapper.mapType(type), type, state);
putJavaLangClassInstance(v, typeMapper.mapType(type), type, typeMapper);
}
if (wrapIntoKClass) {
@@ -4468,7 +4468,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
KotlinType elementKotlinType = state.getModule().getBuiltIns().getArrayElementType(arrayKotlinType);
Type elementType;
if (KotlinBuiltIns.isArray(arrayKotlinType)) {
elementType = boxType(asmType(elementKotlinType), elementKotlinType, state);
elementType = boxType(asmType(elementKotlinType), elementKotlinType, typeMapper);
}
else {
elementType = correctElementType(arrayType);
@@ -713,7 +713,7 @@ class PsiInlineCodegen(
val receiverKotlinType = receiver.kotlinType
val boxedReceiver =
if (receiverKotlinType != null)
receiver.type.boxReceiverForBoundReference(receiverKotlinType, state)
receiver.type.boxReceiverForBoundReference(receiverKotlinType, state.typeMapper)
else
receiver.type.boxReceiverForBoundReference()
@@ -6,13 +6,15 @@
package org.jetbrains.kotlin.codegen.inline
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.codegen.*
import org.jetbrains.kotlin.codegen.AsmUtil
import org.jetbrains.kotlin.codegen.OwnerKind
import org.jetbrains.kotlin.codegen.PropertyReferenceCodegen
import org.jetbrains.kotlin.codegen.StackValue
import org.jetbrains.kotlin.codegen.binding.CalculatedClosure
import org.jetbrains.kotlin.codegen.binding.CodegenBinding
import org.jetbrains.kotlin.codegen.binding.CodegenBinding.*
import org.jetbrains.kotlin.codegen.binding.MutableClosure
import org.jetbrains.kotlin.codegen.context.EnclosedValueDescriptor
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.*
@@ -177,11 +179,11 @@ class DefaultLambda(
}
}
fun Type.boxReceiverForBoundReference() =
internal fun Type.boxReceiverForBoundReference() =
AsmUtil.boxType(this)
fun Type.boxReceiverForBoundReference(kotlinType: KotlinType, state: GenerationState) =
AsmUtil.boxType(this, kotlinType, state)
internal fun Type.boxReceiverForBoundReference(kotlinType: KotlinType, typeMapper: KotlinTypeMapper) =
AsmUtil.boxType(this, kotlinType, typeMapper)
abstract class ExpressionLambda(protected val typeMapper: KotlinTypeMapper, isCrossInline: Boolean) : LambdaInfo(isCrossInline) {
@@ -79,7 +79,7 @@ class ForInArrayLoopGenerator(
override fun assignToLoopParameter() {
val arrayElParamType =
if (KotlinBuiltIns.isArray(loopRangeType)) boxType(asmElementType, elementType, codegen.state) else asmElementType
if (KotlinBuiltIns.isArray(loopRangeType)) boxType(asmElementType, elementType, codegen.state.typeMapper) else asmElementType
v.load(arrayVar, OBJECT_TYPE)
v.load(indexVar, Type.INT_TYPE)
@@ -1185,7 +1185,7 @@ class ExpressionCodegen(
} else {
val classType = classReference.classType
if (classType is CrIrType) {
putJavaLangClassInstance(mv, classType.type, null, state)
putJavaLangClassInstance(mv, classType.type, null, typeMapper)
return
} else {
val kotlinType = classType.toKotlinType()
@@ -1194,7 +1194,7 @@ class ExpressionCodegen(
putReifiedOperationMarkerIfTypeIsReifiedParameter(kotlinType, ReifiedTypeInliner.OperationKind.JAVA_CLASS, mv, this)
}
putJavaLangClassInstance(mv, typeMapper.mapType(kotlinType), kotlinType, state)
putJavaLangClassInstance(mv, typeMapper.mapType(kotlinType), kotlinType, typeMapper)
}
}