add list of value parameter types to CallableMethod

This commit is contained in:
Dmitry Jemerov
2011-06-30 20:16:43 +02:00
parent 81c623a156
commit 70dfda124e
4 changed files with 27 additions and 7 deletions
@@ -1,8 +1,11 @@
package org.jetbrains.jet.codegen;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.InstructionAdapter;
import org.objectweb.asm.commons.Method;
import java.util.List;
/**
* @author yole
*/
@@ -10,11 +13,13 @@ public class CallableMethod {
private final String owner;
private final Method descriptor;
private final int invokeOpcode;
private final List<Type> valueParameterTypes;
public CallableMethod(String owner, Method descriptor, int invokeOpcode) {
public CallableMethod(String owner, Method descriptor, int invokeOpcode, List<Type> valueParameterTypes) {
this.owner = owner;
this.descriptor = descriptor;
this.invokeOpcode = invokeOpcode;
this.valueParameterTypes = valueParameterTypes;
}
public String getOwner() {
@@ -29,6 +34,10 @@ public class CallableMethod {
return invokeOpcode;
}
public List<Type> getValueParameterTypes() {
return valueParameterTypes;
}
void invoke(InstructionAdapter v) {
v.visitMethodInsn(getInvokeOpcode(), getOwner(), getDescriptor().getName(), getDescriptor().getDescriptor());
}
@@ -795,7 +795,7 @@ public class ExpressionCodegen extends JetVisitor {
ensureReceiverOnStack(expression, (ClassDescriptor) functionParent);
}
pushMethodArguments(expression, callableMethod.getDescriptor());
pushMethodArguments(expression, callableMethod.getValueParameterTypes());
pushTypeArguments(expression);
callableMethod.invoke(v);
methodDescriptor = callableMethod.getDescriptor();
@@ -924,6 +924,14 @@ public class ExpressionCodegen extends JetVisitor {
}
}
private void pushMethodArguments(JetCall expression, List<Type> valueParameterTypes) {
List<JetArgument> args = expression.getValueArguments();
for (int i = 0, argsSize = args.size(); i < argsSize; i++) {
JetArgument arg = args.get(i);
gen(arg.getArgumentExpression(), valueParameterTypes.get(i));
}
}
private static Method getMethodDescriptor(PsiMethod method) {
Type returnType = method.isConstructor() ? Type.VOID_TYPE : psiTypeToAsm(method.getReturnType());
PsiParameter[] parameters = method.getParameterList().getParameters();
@@ -35,7 +35,7 @@ public class FunctionCodegen {
public void gen(JetNamedFunction f, OwnerKind kind) {
final JetTypeReference receiverTypeRef = f.getReceiverTypeRef();
final JetType receiverType = receiverTypeRef == null ? null : state.getBindingContext().resolveTypeReference(receiverTypeRef);
Method method = state.getTypeMapper().mapSignature(f);
Method method = state.getTypeMapper().mapToCallableMethod(f).getDescriptor();
final FunctionDescriptor functionDescriptor = state.getBindingContext().getFunctionDescriptor(f);
generateMethod(f, kind, method, receiverType, functionDescriptor.getValueParameters(),
functionDescriptor.getTypeParameters());
@@ -271,7 +271,7 @@ public class JetTypeMapper {
return type;
}
public Method mapSignature(JetNamedFunction f) {
private Method mapSignature(JetNamedFunction f, List<Type> valueParameterTypes) {
final JetTypeReference receiverTypeRef = f.getReceiverTypeRef();
final JetType receiverType = receiverTypeRef == null ? null : bindingContext.resolveTypeReference(receiverTypeRef);
final List<JetParameter> parameters = f.getValueParameters();
@@ -280,7 +280,9 @@ public class JetTypeMapper {
parameterTypes.add(mapType(receiverType));
}
for (JetParameter parameter : parameters) {
parameterTypes.add(mapType(bindingContext.resolveTypeReference(parameter.getTypeReference())));
final Type type = mapType(bindingContext.resolveTypeReference(parameter.getTypeReference()));
valueParameterTypes.add(type);
parameterTypes.add(type);
}
for (JetTypeParameter p: f.getTypeParameters()) {
parameterTypes.add(TYPE_TYPEINFO);
@@ -301,7 +303,8 @@ public class JetTypeMapper {
public CallableMethod mapToCallableMethod(JetNamedFunction f) {
final FunctionDescriptor functionDescriptor = bindingContext.getFunctionDescriptor(f);
final DeclarationDescriptor functionParent = functionDescriptor.getContainingDeclaration();
Method descriptor = mapSignature(f);
final List<Type> valueParameterTypes = new ArrayList<Type>();
Method descriptor = mapSignature(f, valueParameterTypes);
String owner;
int invokeOpcode;
if (functionParent instanceof NamespaceDescriptor) {
@@ -319,7 +322,7 @@ public class JetTypeMapper {
throw new UnsupportedOperationException("unknown function parent");
}
return new CallableMethod(owner, descriptor, invokeOpcode);
return new CallableMethod(owner, descriptor, invokeOpcode, valueParameterTypes);
}
public Method mapSignature(String name, FunctionDescriptor f) {