Minor refactoring in JetTypeMapper.mapReturnType

This commit is contained in:
Alexander Udalov
2013-12-27 14:05:00 +04:00
parent d8c5b0236d
commit fe96e64bd4
4 changed files with 16 additions and 25 deletions
@@ -532,7 +532,7 @@ public class AsmUtil {
JetType type = descriptor.getReturnType();
if (type == null || isNullableType(type)) return;
Type asmType = state.getTypeMapper().mapReturnType(type);
Type asmType = state.getTypeMapper().mapReturnType(descriptor);
if (asmType.getSort() == Type.OBJECT || asmType.getSort() == Type.ARRAY) {
v.dup();
v.visitLdcInsn(descriptor.getContainingDeclaration().getName().asString());
@@ -2006,8 +2006,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (callable instanceof CallableMethod) {
CallableMethod callableMethod = (CallableMethod) callable;
invokeMethodWithArguments(callableMethod, resolvedCall, receiver);
//noinspection ConstantConditions
Type returnType = typeMapper.mapReturnType(resolvedCall.getResultingDescriptor().getReturnType());
Type returnType = typeMapper.mapReturnType(resolvedCall.getResultingDescriptor());
StackValue.coerce(callableMethod.getSignature().getAsmMethod().getReturnType(), returnType, v);
return StackValue.onStack(returnType);
}
@@ -788,13 +788,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
private void generateComponentFunction(@NotNull FunctionDescriptor function, @NotNull final ValueParameterDescriptor parameter) {
JetType returnType = function.getReturnType();
assert returnType != null : "Return type of component function should not be null: " + function;
final Type componentType = typeMapper.mapReturnType(returnType);
JvmMethodSignature signature = typeMapper.mapSignature(function);
functionCodegen.generateMethod(myClass, signature, function, new FunctionGenerationStrategy() {
functionCodegen.generateMethod(myClass, typeMapper.mapSignature(function), function, new FunctionGenerationStrategy() {
@Override
public void generateBody(
@NotNull MethodVisitor mv,
@@ -802,6 +796,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
@NotNull MethodContext context,
@Nullable MemberCodegen parentCodegen
) {
Type componentType = signature.getAsmMethod().getReturnType();
InstructionAdapter iv = new InstructionAdapter(mv);
if (!componentType.equals(Type.VOID_TYPE)) {
iv.load(0, classAsmType);
@@ -143,19 +143,23 @@ public class JetTypeMapper extends BindingTraceAware {
}
@NotNull
public Type mapReturnType(@NotNull JetType jetType) {
return mapReturnType(jetType, null);
public Type mapReturnType(@NotNull CallableDescriptor descriptor) {
return mapReturnType(descriptor, null);
}
@NotNull
private Type mapReturnType(@NotNull JetType jetType, @Nullable BothSignatureWriter signatureVisitor) {
if (jetType.equals(KotlinBuiltIns.getInstance().getUnitType())) {
if (signatureVisitor != null) {
signatureVisitor.writeAsmType(Type.VOID_TYPE);
private Type mapReturnType(@NotNull CallableDescriptor descriptor, @Nullable BothSignatureWriter sw) {
JetType returnType = descriptor.getReturnType();
assert returnType != null : "Function has no return type: " + descriptor;
if (returnType.equals(KotlinBuiltIns.getInstance().getUnitType()) && !(descriptor instanceof PropertyGetterDescriptor)) {
if (sw != null) {
sw.writeAsmType(Type.VOID_TYPE);
}
return Type.VOID_TYPE;
}
return mapType(jetType, signatureVisitor, JetTypeMapperMode.VALUE, Variance.OUT_VARIANCE, false);
else {
return mapType(returnType, sw, JetTypeMapperMode.VALUE, Variance.OUT_VARIANCE, false);
}
}
@NotNull
@@ -602,14 +606,7 @@ public class JetTypeMapper extends BindingTraceAware {
}
sw.writeReturnType();
JetType returnType = f.getReturnType();
assert returnType != null : "Function " + f + " has no return type";
if (f instanceof PropertyGetterDescriptor) {
mapType(returnType, sw, JetTypeMapperMode.VALUE, Variance.OUT_VARIANCE, false);
}
else {
mapReturnType(returnType, sw);
}
mapReturnType(f, sw);
sw.writeReturnTypeEnd();
}