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