Minor, beautify code in StackValue.CallReceiver
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethod;
|
||||
@@ -337,6 +338,7 @@ public abstract class StackValue {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
@Contract("null -> false")
|
||||
private static boolean isLocalFunCall(@Nullable CallableMethod callableMethod) {
|
||||
return callableMethod != null && callableMethod.getGenerateCalleeType() != null;
|
||||
}
|
||||
@@ -1078,19 +1080,19 @@ public abstract class StackValue {
|
||||
|
||||
public static class CallReceiver extends StackValue {
|
||||
private final ResolvedCall<?> resolvedCall;
|
||||
final StackValue receiver;
|
||||
private final StackValue receiver;
|
||||
private final ExpressionCodegen codegen;
|
||||
private final CallableMethod callableMethod;
|
||||
private final boolean putReceiverArgumentOnStack;
|
||||
|
||||
public CallReceiver(
|
||||
ResolvedCall<?> resolvedCall,
|
||||
StackValue receiver,
|
||||
ExpressionCodegen codegen,
|
||||
CallableMethod callableMethod,
|
||||
@NotNull ResolvedCall<?> resolvedCall,
|
||||
@NotNull StackValue receiver,
|
||||
@NotNull ExpressionCodegen codegen,
|
||||
@Nullable CallableMethod callableMethod,
|
||||
boolean putReceiverArgumentOnStack
|
||||
) {
|
||||
super(calcType(resolvedCall, codegen, callableMethod));
|
||||
super(calcType(resolvedCall, codegen.typeMapper, callableMethod));
|
||||
this.resolvedCall = resolvedCall;
|
||||
this.receiver = receiver;
|
||||
this.codegen = codegen;
|
||||
@@ -1098,33 +1100,27 @@ public abstract class StackValue {
|
||||
this.putReceiverArgumentOnStack = putReceiverArgumentOnStack;
|
||||
}
|
||||
|
||||
private static Type calcType(ResolvedCall<?> resolvedCall, ExpressionCodegen codegen, CallableMethod callableMethod) {
|
||||
ReceiverValue thisObject = resolvedCall.getThisObject();
|
||||
ReceiverValue receiverArgument = resolvedCall.getReceiverArgument();
|
||||
|
||||
private static Type calcType(
|
||||
@NotNull ResolvedCall<?> resolvedCall,
|
||||
@NotNull JetTypeMapper typeMapper,
|
||||
@Nullable CallableMethod callableMethod
|
||||
) {
|
||||
CallableDescriptor descriptor = resolvedCall.getResultingDescriptor();
|
||||
|
||||
if (receiverArgument.exists()) {
|
||||
if (callableMethod != null) {
|
||||
return callableMethod.getReceiverClass();
|
||||
}
|
||||
else {
|
||||
return codegen.typeMapper.mapType(descriptor.getReceiverParameter().getType());
|
||||
}
|
||||
} else if (thisObject.exists()) {
|
||||
if (callableMethod != null) {
|
||||
return callableMethod.getThisType();
|
||||
}
|
||||
else {
|
||||
return codegen.typeMapper.mapType(descriptor.getExpectedThisObject().getType());
|
||||
}
|
||||
ReceiverParameterDescriptor expectedThisObject = descriptor.getExpectedThisObject();
|
||||
ReceiverParameterDescriptor receiverParameter = descriptor.getReceiverParameter();
|
||||
|
||||
if (receiverParameter != null) {
|
||||
return callableMethod != null ? callableMethod.getReceiverClass() : typeMapper.mapType(receiverParameter.getType());
|
||||
}
|
||||
else if (expectedThisObject != null) {
|
||||
return callableMethod != null ? callableMethod.getThisType() : typeMapper.mapType(expectedThisObject.getType());
|
||||
}
|
||||
else if (isLocalFunCall(callableMethod)) {
|
||||
return callableMethod.getGenerateCalleeType();
|
||||
}
|
||||
else {
|
||||
return Type.VOID_TYPE;
|
||||
}
|
||||
|
||||
return Type.VOID_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1136,8 +1132,11 @@ public abstract class StackValue {
|
||||
int depth;
|
||||
if (thisObject.exists()) {
|
||||
if (receiverArgument.exists()) {
|
||||
Type resultType = callableMethod != null ? callableMethod.getOwner() : codegen.typeMapper
|
||||
.mapType(descriptor.getExpectedThisObject().getType());
|
||||
//noinspection ConstantConditions
|
||||
Type resultType =
|
||||
callableMethod != null ?
|
||||
callableMethod.getOwner() :
|
||||
codegen.typeMapper.mapType(descriptor.getExpectedThisObject().getType());
|
||||
|
||||
codegen.generateFromResolvedCall(thisObject, resultType);
|
||||
}
|
||||
@@ -1146,8 +1145,10 @@ public abstract class StackValue {
|
||||
}
|
||||
|
||||
depth = 1;
|
||||
} else if (isLocalFunCall(callableMethod)) {
|
||||
assert receiver == none() || receiverArgument.exists(): "Receiver should be present only for local extension function: " + callableMethod;
|
||||
}
|
||||
else if (isLocalFunCall(callableMethod)) {
|
||||
assert receiver == none() || receiverArgument.exists() :
|
||||
"Receiver should be present only for local extension function: " + callableMethod;
|
||||
StackValue value = codegen.findLocalOrCapturedValue(descriptor.getOriginal());
|
||||
assert value != null : "Local fun should be found in locals or in captured params: " + resolvedCall;
|
||||
value.put(callableMethod.getGenerateCalleeType(), v);
|
||||
@@ -1164,8 +1165,11 @@ public abstract class StackValue {
|
||||
}
|
||||
|
||||
private void genReceiver(
|
||||
InstructionAdapter v, ReceiverValue receiverArgument, Type type,
|
||||
@Nullable ReceiverParameterDescriptor receiverParameter, int depth
|
||||
@NotNull InstructionAdapter v,
|
||||
@NotNull ReceiverValue receiverArgument,
|
||||
@NotNull Type type,
|
||||
@Nullable ReceiverParameterDescriptor receiverParameter,
|
||||
int depth
|
||||
) {
|
||||
if (receiver == StackValue.none()) {
|
||||
if (receiverParameter != null) {
|
||||
|
||||
Reference in New Issue
Block a user