Simplify type mapping for builtin types
This commit is contained in:
@@ -113,10 +113,6 @@ public class JetTypeMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private enum JetTypeMapperMode {
|
private enum JetTypeMapperMode {
|
||||||
/**
|
|
||||||
* foo.Bar is mapped to Lfoo/Bar;
|
|
||||||
*/
|
|
||||||
IMPL,
|
|
||||||
/**
|
/**
|
||||||
* kotlin.Int is mapped to I
|
* kotlin.Int is mapped to I
|
||||||
*/
|
*/
|
||||||
@@ -141,9 +137,13 @@ public class JetTypeMapper {
|
|||||||
*/
|
*/
|
||||||
TYPE_PARAMETER_FOR_ANNOTATION;
|
TYPE_PARAMETER_FOR_ANNOTATION;
|
||||||
|
|
||||||
boolean isForAnnotation() {
|
private boolean isForAnnotation() {
|
||||||
return this == VALUE_FOR_ANNOTATION || this == TYPE_PARAMETER_FOR_ANNOTATION;
|
return this == VALUE_FOR_ANNOTATION || this == TYPE_PARAMETER_FOR_ANNOTATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean needPrimitiveBoxing() {
|
||||||
|
return this == TYPE_PARAMETER || this == SUPER_TYPE || this == TYPE_PARAMETER_FOR_ANNOTATION;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -385,7 +385,7 @@ public class JetTypeMapper {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Type mapClass(@NotNull ClassifierDescriptor classifier) {
|
public Type mapClass(@NotNull ClassifierDescriptor classifier) {
|
||||||
return mapType(classifier.getDefaultType(), null, JetTypeMapperMode.IMPL);
|
return mapType(classifier.getDefaultType(), null, JetTypeMapperMode.VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -425,25 +425,13 @@ public class JetTypeMapper {
|
|||||||
@NotNull JetTypeMapperMode kind,
|
@NotNull JetTypeMapperMode kind,
|
||||||
@NotNull Variance howThisTypeIsUsed
|
@NotNull Variance howThisTypeIsUsed
|
||||||
) {
|
) {
|
||||||
Type known = mapBuiltinType(jetType);
|
Type builtinType = mapBuiltinType(jetType);
|
||||||
|
|
||||||
boolean projectionsAllowed = kind != JetTypeMapperMode.SUPER_TYPE;
|
boolean projectionsAllowed = kind != JetTypeMapperMode.SUPER_TYPE;
|
||||||
if (known != null) {
|
if (builtinType != null) {
|
||||||
if (kind == JetTypeMapperMode.VALUE || kind == JetTypeMapperMode.VALUE_FOR_ANNOTATION) {
|
Type asmType = kind.needPrimitiveBoxing() ? boxType(builtinType) : builtinType;
|
||||||
return mapKnownAsmType(jetType, known, signatureVisitor, howThisTypeIsUsed);
|
writeGenericType(jetType, asmType, signatureVisitor, howThisTypeIsUsed, projectionsAllowed);
|
||||||
}
|
return asmType;
|
||||||
else if (kind == JetTypeMapperMode.TYPE_PARAMETER || kind == JetTypeMapperMode.SUPER_TYPE ||
|
|
||||||
kind == JetTypeMapperMode.TYPE_PARAMETER_FOR_ANNOTATION) {
|
|
||||||
return mapKnownAsmType(jetType, boxType(known), signatureVisitor, howThisTypeIsUsed, projectionsAllowed);
|
|
||||||
}
|
|
||||||
else if (kind == JetTypeMapperMode.IMPL) {
|
|
||||||
// TODO: enable and fix tests
|
|
||||||
//throw new IllegalStateException("must not map known type to IMPL when not compiling builtins: " + jetType);
|
|
||||||
return mapKnownAsmType(jetType, known, signatureVisitor, howThisTypeIsUsed);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalStateException("unknown kind: " + kind);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeConstructor constructor = jetType.getConstructor();
|
TypeConstructor constructor = jetType.getConstructor();
|
||||||
@@ -502,7 +490,7 @@ public class JetTypeMapper {
|
|||||||
Type asmType = kind.isForAnnotation() && KotlinBuiltIns.isKClass((ClassDescriptor) descriptor) ?
|
Type asmType = kind.isForAnnotation() && KotlinBuiltIns.isKClass((ClassDescriptor) descriptor) ?
|
||||||
AsmTypes.JAVA_CLASS_TYPE :
|
AsmTypes.JAVA_CLASS_TYPE :
|
||||||
computeAsmType((ClassDescriptor) descriptor.getOriginal());
|
computeAsmType((ClassDescriptor) descriptor.getOriginal());
|
||||||
writeGenericType(signatureVisitor, asmType, jetType, howThisTypeIsUsed, projectionsAllowed);
|
writeGenericType(jetType, asmType, signatureVisitor, howThisTypeIsUsed, projectionsAllowed);
|
||||||
return asmType;
|
return asmType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -620,10 +608,10 @@ public class JetTypeMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void writeGenericType(
|
private void writeGenericType(
|
||||||
BothSignatureWriter signatureVisitor,
|
@NotNull KotlinType type,
|
||||||
Type asmType,
|
@NotNull Type asmType,
|
||||||
KotlinType type,
|
@Nullable BothSignatureWriter signatureVisitor,
|
||||||
Variance howThisTypeIsUsed,
|
@NotNull Variance howThisTypeIsUsed,
|
||||||
boolean projectionsAllowed
|
boolean projectionsAllowed
|
||||||
) {
|
) {
|
||||||
if (signatureVisitor != null) {
|
if (signatureVisitor != null) {
|
||||||
@@ -744,33 +732,6 @@ public class JetTypeMapper {
|
|||||||
return Variance.OUT_VARIANCE;
|
return Variance.OUT_VARIANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type mapKnownAsmType(
|
|
||||||
KotlinType jetType,
|
|
||||||
Type asmType,
|
|
||||||
@Nullable BothSignatureWriter signatureVisitor,
|
|
||||||
@NotNull Variance howThisTypeIsUsed
|
|
||||||
) {
|
|
||||||
return mapKnownAsmType(jetType, asmType, signatureVisitor, howThisTypeIsUsed, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Type mapKnownAsmType(
|
|
||||||
KotlinType jetType,
|
|
||||||
Type asmType,
|
|
||||||
@Nullable BothSignatureWriter signatureVisitor,
|
|
||||||
@NotNull Variance howThisTypeIsUsed,
|
|
||||||
boolean allowProjections
|
|
||||||
) {
|
|
||||||
if (signatureVisitor != null) {
|
|
||||||
if (jetType.getArguments().isEmpty()) {
|
|
||||||
signatureVisitor.writeAsmType(asmType);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
writeGenericType(signatureVisitor, asmType, jetType, howThisTypeIsUsed, allowProjections);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return asmType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CallableMethod mapToCallableMethod(@NotNull FunctionDescriptor descriptor, boolean superCall) {
|
public CallableMethod mapToCallableMethod(@NotNull FunctionDescriptor descriptor, boolean superCall) {
|
||||||
if (descriptor instanceof ConstructorDescriptor) {
|
if (descriptor instanceof ConstructorDescriptor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user