pass all CallableMethod data in constructor
This commit is contained in:
@@ -43,18 +43,26 @@ public class CallableMethod implements Callable {
|
|||||||
private final JvmClassName defaultImplParam;
|
private final JvmClassName defaultImplParam;
|
||||||
private final JvmMethodSignature signature;
|
private final JvmMethodSignature signature;
|
||||||
private final int invokeOpcode;
|
private final int invokeOpcode;
|
||||||
private ClassDescriptor thisClass = null;
|
private final ClassDescriptor thisClass;
|
||||||
|
|
||||||
private CallableDescriptor receiverFunction = null;
|
private final CallableDescriptor receiverFunction;
|
||||||
private Type generateCalleeType = null;
|
private final Type generateCalleeType;
|
||||||
|
|
||||||
public CallableMethod(@NotNull JvmClassName owner, @Nullable JvmClassName defaultImplOwner, @Nullable JvmClassName defaultImplParam,
|
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.owner = owner;
|
||||||
this.defaultImplOwner = defaultImplOwner;
|
this.defaultImplOwner = defaultImplOwner;
|
||||||
this.defaultImplParam = defaultImplParam;
|
this.defaultImplParam = defaultImplParam;
|
||||||
this.signature = signature;
|
this.signature = signature;
|
||||||
this.invokeOpcode = invokeOpcode;
|
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
|
@NotNull
|
||||||
@@ -79,10 +87,6 @@ public class CallableMethod implements Callable {
|
|||||||
return signature.getValueParameterTypes();
|
return signature.getValueParameterTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNeedsReceiver(@Nullable CallableDescriptor receiverClass) {
|
|
||||||
this.receiverFunction = receiverClass.getOriginal();
|
|
||||||
}
|
|
||||||
|
|
||||||
public JetType getThisType() {
|
public JetType getThisType() {
|
||||||
return thisClass.getDefaultType();
|
return thisClass.getDefaultType();
|
||||||
}
|
}
|
||||||
@@ -91,18 +95,10 @@ public class CallableMethod implements Callable {
|
|||||||
return receiverFunction.getReceiverParameter().getType();
|
return receiverFunction.getReceiverParameter().getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNeedsThis(@Nullable ClassDescriptor receiverClass) {
|
|
||||||
this.thisClass = receiverClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
void invoke(InstructionAdapter v) {
|
void invoke(InstructionAdapter v) {
|
||||||
v.visitMethodInsn(getInvokeOpcode(), owner.getInternalName(), getSignature().getAsmMethod().getName(), getSignature().getAsmMethod().getDescriptor());
|
v.visitMethodInsn(getInvokeOpcode(), owner.getInternalName(), getSignature().getAsmMethod().getName(), getSignature().getAsmMethod().getDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestGenerateCallee(Type objectType) {
|
|
||||||
generateCalleeType = objectType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Type getGenerateCalleeType() {
|
public Type getGenerateCalleeType() {
|
||||||
return generateCalleeType;
|
return generateCalleeType;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,12 +91,9 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
|
|||||||
public static CallableMethod asCallableMethod(FunctionDescriptor fd) {
|
public static CallableMethod asCallableMethod(FunctionDescriptor fd) {
|
||||||
JvmMethodSignature descriptor = erasedInvokeSignature(fd);
|
JvmMethodSignature descriptor = erasedInvokeSignature(fd);
|
||||||
JvmClassName owner = getInternalClassName(fd);
|
JvmClassName owner = getInternalClassName(fd);
|
||||||
final CallableMethod result = new CallableMethod(owner, null, null, descriptor, INVOKEVIRTUAL);
|
final CallableMethod result = new CallableMethod(
|
||||||
if (fd.getReceiverParameter().exists()) {
|
owner, null, null, descriptor, INVOKEVIRTUAL,
|
||||||
result.setNeedsReceiver(fd);
|
getInternalType(fd), fd.getReceiverParameter().exists() ? fd.getOriginal() : null, getInternalClassName(fd).getAsmType());
|
||||||
}
|
|
||||||
result.setNeedsThis(getInternalType(fd));
|
|
||||||
result.requestGenerateCallee(getInternalClassName(fd).getAsmType());
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -474,7 +474,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
signatureWriter.writeVoidReturn();
|
signatureWriter.writeVoidReturn();
|
||||||
|
|
||||||
constructorMethod = signatureWriter.makeJvmMethodSignature("<init>");
|
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 {
|
else {
|
||||||
callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor, kind, typeMapper.hasThis0(constructorDescriptor.getContainingDeclaration()));
|
callableMethod = typeMapper.mapToCallableMethod(constructorDescriptor, kind, typeMapper.hasThis0(constructorDescriptor.getContainingDeclaration()));
|
||||||
|
|||||||
@@ -601,13 +601,10 @@ public class JetTypeMapper {
|
|||||||
throw new UnsupportedOperationException("unknown function parent");
|
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
|
@NotNull
|
||||||
@@ -900,7 +897,7 @@ public class JetTypeMapper {
|
|||||||
throw new IllegalStateException("type must have been mapped to object: " + defaultType + ", actual: " + mapped);
|
throw new IllegalStateException("type must have been mapped to object: " + defaultType + ", actual: " + mapped);
|
||||||
}
|
}
|
||||||
JvmClassName owner = JvmClassName.byType(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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user