Add a convenient method JvmMethodSignature.getReturnType()

This commit is contained in:
Alexander Udalov
2013-12-26 19:13:31 +04:00
parent fe96e64bd4
commit 28d2306aa1
6 changed files with 32 additions and 37 deletions
@@ -146,7 +146,7 @@ public class CallableMethod implements Callable {
}
public Type getReturnType() {
return signature.getAsmMethod().getReturnType();
return signature.getReturnType();
}
@Override
@@ -2007,7 +2007,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
CallableMethod callableMethod = (CallableMethod) callable;
invokeMethodWithArguments(callableMethod, resolvedCall, receiver);
Type returnType = typeMapper.mapReturnType(resolvedCall.getResultingDescriptor());
StackValue.coerce(callableMethod.getSignature().getAsmMethod().getReturnType(), returnType, v);
StackValue.coerce(callableMethod.getSignature().getReturnType(), returnType, v);
return StackValue.onStack(returnType);
}
else {
@@ -464,29 +464,25 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
int flags = getVisibilityAccessFlag(constructorDescriptor);
MethodVisitor mv = classBuilder.newMethod(null, flags, "<init>", "()V", null, null);
if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES) {
return;
}
else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
InstructionAdapter v = new InstructionAdapter(mv);
mv.visitCode();
if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES) return;
Type methodOwner = method.getOwner();
Method jvmSignature = method.getSignature().getAsmMethod();
v.load(0, methodOwner); // Load this on stack
InstructionAdapter v = new InstructionAdapter(mv);
mv.visitCode();
int mask = 0;
for (ValueParameterDescriptor parameterDescriptor : constructorDescriptor.getValueParameters()) {
Type paramType = state.getTypeMapper().mapType(parameterDescriptor.getType());
pushDefaultValueOnStack(paramType, v);
mask |= (1 << parameterDescriptor.getIndex());
}
v.iconst(mask);
String desc = jvmSignature.getDescriptor().replace(")", "I)");
v.invokespecial(methodOwner.getInternalName(), "<init>", desc);
v.areturn(Type.VOID_TYPE);
endVisit(mv, "default constructor for " + methodOwner.getInternalName(), null);
Type methodOwner = method.getOwner();
v.load(0, methodOwner); // Load this on stack
int mask = 0;
for (ValueParameterDescriptor parameterDescriptor : constructorDescriptor.getValueParameters()) {
Type paramType = state.getTypeMapper().mapType(parameterDescriptor.getType());
pushDefaultValueOnStack(paramType, v);
mask |= (1 << parameterDescriptor.getIndex());
}
v.iconst(mask);
String desc = method.getSignature().getAsmMethod().getDescriptor().replace(")", "I)");
v.invokespecial(methodOwner.getInternalName(), "<init>", desc);
v.areturn(Type.VOID_TYPE);
endVisit(mv, "default constructor for " + methodOwner.getInternalName(), null);
}
void generateDefaultIfNeeded(
@@ -559,10 +555,9 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
frameMap.enterTemp(OBJECT_TYPE);
}
Method jvmSignature = signature.getAsmMethod();
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, jvmSignature.getReturnType(), methodContext, state, getParentCodegen());
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, signature.getReturnType(), methodContext, state, getParentCodegen());
Type[] argTypes = jvmSignature.getArgumentTypes();
Type[] argTypes = signature.getAsmMethod().getArgumentTypes();
List<ValueParameterDescriptor> paramDescrs = functionDescriptor.getValueParameters();
Iterator<ValueParameterDescriptor> iterator = paramDescrs.iterator();
@@ -616,7 +611,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
iv.visitMethodInsn(method.getInvokeOpcode(), method.getOwner().getInternalName(), method.getSignature().getAsmMethod().getName(),
method.getSignature().getAsmMethod().getDescriptor());
iv.areturn(jvmSignature.getReturnType());
iv.areturn(signature.getReturnType());
endVisit(mv, "default method", callableDescriptorToDeclaration(state.getBindingContext(), functionDescriptor));
}
@@ -26,9 +26,6 @@ import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody;
import java.util.ArrayList;
import java.util.Collection;
public abstract class FunctionGenerationStrategy {
private FrameMap frameMap;
@@ -88,7 +85,7 @@ public abstract class FunctionGenerationStrategy {
@Nullable MemberCodegen parentCodegen
) {
ExpressionCodegen codegen = new ExpressionCodegen(mv, getFrameMap(state.getTypeMapper(), context),
signature.getAsmMethod().getReturnType(), context, state, parentCodegen);
signature.getReturnType(), context, state, parentCodegen);
doGenerateBody(codegen, signature);
}
@@ -796,7 +796,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
@NotNull MethodContext context,
@Nullable MemberCodegen parentCodegen
) {
Type componentType = signature.getAsmMethod().getReturnType();
Type componentType = signature.getReturnType();
InstructionAdapter iv = new InstructionAdapter(mv);
if (!componentType.equals(Type.VOID_TYPE)) {
iv.load(0, classAsmType);
@@ -930,8 +930,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
@Override
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
generateMethodCallTo(original, codegen.v);
codegen.v.areturn(signature.getAsmMethod().getReturnType());
codegen.v.areturn(signature.getReturnType());
}
});
}
@@ -953,7 +952,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
iv.load(0, OBJECT_TYPE);
}
property.put(property.type, iv);
iv.areturn(signature.getAsmMethod().getReturnType());
iv.areturn(signature.getReturnType());
}
});
@@ -979,7 +978,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
property.store(property.type, iv);
iv.areturn(signature.getAsmMethod().getReturnType());
iv.areturn(signature.getReturnType());
}
});
}
@@ -996,8 +995,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
typeMapper.mapToCallableMethod((ConstructorDescriptor) functionDescriptor) :
typeMapper.mapToCallableMethod(functionDescriptor, callFromAccessor, context);
Method method = callableMethod.getSignature().getAsmMethod();
Type[] argTypes = method.getArgumentTypes();
Type[] argTypes = callableMethod.getSignature().getAsmMethod().getArgumentTypes();
int reg = 1;
if (isConstructor) {
@@ -57,6 +57,11 @@ public class JvmMethodSignature {
return kotlinParameterTypes;
}
@NotNull
public Type getReturnType() {
return asmMethod.getReturnType();
}
@NotNull
public List<Type> getValueParameterTypes() {
List<Type> r = new ArrayList<Type>(kotlinParameterTypes.size());