pass all CallableMethod data in constructor

This commit is contained in:
Stepan Koltsov
2012-06-01 19:18:56 +04:00
parent 3512415f3f
commit ebd04ad046
4 changed files with 20 additions and 30 deletions
@@ -43,18 +43,26 @@ public class CallableMethod implements Callable {
private final JvmClassName defaultImplParam;
private final JvmMethodSignature signature;
private final int invokeOpcode;
private ClassDescriptor thisClass = null;
private final ClassDescriptor thisClass;
private CallableDescriptor receiverFunction = null;
private Type generateCalleeType = null;
private final CallableDescriptor receiverFunction;
private final Type generateCalleeType;
public CallableMethod(@NotNull JvmClassName owner, @Nullable JvmClassName defaultImplOwner, @Nullable JvmClassName defaultImplParam,
JvmMethodSignature signature, int invokeOpcode) {
JvmMethodSignature signature, int invokeOpcode,
@Nullable ClassDescriptor thisClass, @Nullable CallableDescriptor receiverFunction, @Nullable Type generateCalleeType) {
this.owner = owner;
this.defaultImplOwner = defaultImplOwner;
this.defaultImplParam = defaultImplParam;
this.signature = signature;
this.invokeOpcode = invokeOpcode;
this.thisClass = thisClass;
this.receiverFunction = receiverFunction;
this.generateCalleeType = generateCalleeType;
if (receiverFunction != null && receiverFunction.getOriginal() != receiverFunction) {
throw new IllegalArgumentException("receiver function parameter must be original: " + receiverFunction);
}
}
@NotNull
@@ -79,10 +87,6 @@ public class CallableMethod implements Callable {
return signature.getValueParameterTypes();
}
public void setNeedsReceiver(@Nullable CallableDescriptor receiverClass) {
this.receiverFunction = receiverClass.getOriginal();
}
public JetType getThisType() {
return thisClass.getDefaultType();
}
@@ -91,18 +95,10 @@ public class CallableMethod implements Callable {
return receiverFunction.getReceiverParameter().getType();
}
public void setNeedsThis(@Nullable ClassDescriptor receiverClass) {
this.thisClass = receiverClass;
}
void invoke(InstructionAdapter v) {
v.visitMethodInsn(getInvokeOpcode(), owner.getInternalName(), getSignature().getAsmMethod().getName(), getSignature().getAsmMethod().getDescriptor());
}
public void requestGenerateCallee(Type objectType) {
generateCalleeType = objectType;
}
public Type getGenerateCalleeType() {
return generateCalleeType;
}
@@ -91,12 +91,9 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
public static CallableMethod asCallableMethod(FunctionDescriptor fd) {
JvmMethodSignature descriptor = erasedInvokeSignature(fd);
JvmClassName owner = getInternalClassName(fd);
final CallableMethod result = new CallableMethod(owner, null, null, descriptor, INVOKEVIRTUAL);
if (fd.getReceiverParameter().exists()) {
result.setNeedsReceiver(fd);
}
result.setNeedsThis(getInternalType(fd));
result.requestGenerateCallee(getInternalClassName(fd).getAsmType());
final CallableMethod result = new CallableMethod(
owner, null, null, descriptor, INVOKEVIRTUAL,
getInternalType(fd), fd.getReceiverParameter().exists() ? fd.getOriginal() : null, getInternalClassName(fd).getAsmType());
return result;
}
@@ -474,7 +474,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
signatureWriter.writeVoidReturn();
constructorMethod = signatureWriter.makeJvmMethodSignature("<init>");
callableMethod = new CallableMethod(JvmClassName.byInternalName("Ignored"), null, null, constructorMethod, INVOKESPECIAL);
callableMethod = new CallableMethod(JvmClassName.byInternalName("Ignored"), null, null, constructorMethod, INVOKESPECIAL, null, null, null);
}
else {
callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor, kind, typeMapper.hasThis0(constructorDescriptor.getContainingDeclaration()));
@@ -601,13 +601,10 @@ public class JetTypeMapper {
throw new UnsupportedOperationException("unknown function parent");
}
final CallableMethod result = new CallableMethod(owner, ownerForDefaultImpl, ownerForDefaultParam, descriptor, invokeOpcode);
result.setNeedsThis(thisClass);
if(functionDescriptor.getReceiverParameter().exists()) {
result.setNeedsReceiver(functionDescriptor);
}
return result;
return new CallableMethod(
owner, ownerForDefaultImpl, ownerForDefaultParam, descriptor, invokeOpcode,
thisClass, functionDescriptor.getReceiverParameter().exists() ? functionDescriptor.getOriginal() : null, null);
}
@NotNull
@@ -900,7 +897,7 @@ public class JetTypeMapper {
throw new IllegalStateException("type must have been mapped to object: " + defaultType + ", actual: " + mapped);
}
JvmClassName owner = JvmClassName.byType(mapped);
return new CallableMethod(owner, owner, owner, method, INVOKESPECIAL);
return new CallableMethod(owner, owner, owner, method, INVOKESPECIAL, null, null, null);
}