Move call receiver wrapping and generation to pushArgumentsWithCallReceiver

This commit is contained in:
Mikhael Bogdanov
2014-03-27 11:58:53 +04:00
parent e1e2855887
commit 94e4c2f0c1
2 changed files with 29 additions and 26 deletions
@@ -1356,7 +1356,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
Type[] argumentTypes = superCallable.getAsmMethod().getArgumentTypes(); Type[] argumentTypes = superCallable.getAsmMethod().getArgumentTypes();
ResolvedCall<?> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, superCall.getCalleeExpression()); ResolvedCall<?> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, superCall.getCalleeExpression());
assert resolvedCall != null; assert resolvedCall != null;
pushMethodArguments(resolvedCall, Arrays.asList(argumentTypes), defaultCallGenerator); pushMethodArgumentsWithoutCallReceiver(resolvedCall, Arrays.asList(argumentTypes), false, defaultCallGenerator);
} }
v.invokespecial(type.getInternalName(), "<init>", constructor.getAsmMethod().getDescriptor()); v.invokespecial(type.getInternalName(), "<init>", constructor.getAsmMethod().getDescriptor());
@@ -2113,33 +2113,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
resolvedCall = ((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall(); resolvedCall = ((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall();
} }
if (!(descriptor instanceof ConstructorDescriptor)) { // otherwise already
receiver = StackValue.receiver(resolvedCall, receiver, this, callableMethod);
receiver.put(receiver.type, v);
}
assert callGenerator == defaultCallGenerator || !hasDefaultArguments(resolvedCall) && !tailRecursionCodegen.isTailRecursion(resolvedCall) : assert callGenerator == defaultCallGenerator || !hasDefaultArguments(resolvedCall) && !tailRecursionCodegen.isTailRecursion(resolvedCall) :
"Method with defaults or tail recursive couldn't be inlined " + descriptor; "Method with defaults or tail recursive couldn't be inlined " + descriptor;
pushArgumentsAndInvoke(resolvedCall, callableMethod, callGenerator); int mask = pushMethodArgumentsWithCallReceiver(receiver, resolvedCall, callableMethod, false, callGenerator);
}
private void pushArgumentsAndInvoke(@NotNull ResolvedCall<?> resolvedCall, @NotNull CallableMethod callable, @NotNull CallGenerator callGenerator) {
callGenerator.putHiddenParams();
int mask = pushMethodArguments(resolvedCall, callable.getValueParameterTypes(), callGenerator);
if (tailRecursionCodegen.isTailRecursion(resolvedCall)) { if (tailRecursionCodegen.isTailRecursion(resolvedCall)) {
tailRecursionCodegen.generateTailRecursion(resolvedCall); tailRecursionCodegen.generateTailRecursion(resolvedCall);
return; return;
} }
callGenerator.genCall(callable, resolvedCall, mask, this); callGenerator.genCall(callableMethod, resolvedCall, mask, this);
}
private void genThisAndReceiverFromResolvedCall(StackValue receiver, ResolvedCall<?> resolvedCall, CallableMethod callableMethod) {
receiver = StackValue.receiver(resolvedCall, receiver, this, callableMethod);
receiver.put(receiver.type, v);
} }
public void generateFromResolvedCall(@NotNull ReceiverValue descriptor, @NotNull Type type) { public void generateFromResolvedCall(@NotNull ReceiverValue descriptor, @NotNull Type type) {
@@ -2294,11 +2278,31 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return false; return false;
} }
public int pushMethodArguments(@NotNull ResolvedCall<?> resolvedCall, List<Type> valueParameterTypes, @NotNull CallGenerator callGenerator) { public int pushMethodArgumentsWithCallReceiver(
return pushMethodArguments(resolvedCall, valueParameterTypes, false, callGenerator); @Nullable StackValue receiver,
@NotNull ResolvedCall<?> resolvedCall,
@NotNull CallableMethod callableMethod,
boolean skipLast,
@NotNull CallGenerator callGenerator
) {
CallableDescriptor descriptor = resolvedCall.getResultingDescriptor();
if (!(descriptor instanceof ConstructorDescriptor)) { // otherwise already
receiver = StackValue.receiver(resolvedCall, receiver, this, callableMethod);
receiver.put(receiver.type, v);
}
callGenerator.putHiddenParams();
return pushMethodArgumentsWithoutCallReceiver(resolvedCall, callableMethod.getValueParameterTypes(), skipLast, callGenerator);
} }
private int pushMethodArguments(@NotNull ResolvedCall<?> resolvedCall, List<Type> valueParameterTypes, boolean skipLast, @NotNull CallGenerator callGenerator) { public int pushMethodArgumentsWithoutCallReceiver(
@NotNull ResolvedCall<?> resolvedCall,
List<Type> valueParameterTypes,
boolean skipLast,
@NotNull CallGenerator callGenerator
) {
List<ResolvedValueArgument> valueArguments = resolvedCall.getValueArgumentsByIndex(); List<ResolvedValueArgument> valueArguments = resolvedCall.getValueArgumentsByIndex();
CallableDescriptor fd = resolvedCall.getResultingDescriptor(); CallableDescriptor fd = resolvedCall.getResultingDescriptor();
if (valueArguments == null) { if (valueArguments == null) {
@@ -3389,9 +3393,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
Type[] argumentTypes = asmMethod.getArgumentTypes(); Type[] argumentTypes = asmMethod.getArgumentTypes();
if (callable instanceof CallableMethod) { if (callable instanceof CallableMethod) {
genThisAndReceiverFromResolvedCall(receiver, resolvedCall, (CallableMethod) callable);
boolean skipLast = !isGetter; boolean skipLast = !isGetter;
pushMethodArguments(resolvedCall, ((CallableMethod) callable).getValueParameterTypes(), skipLast, defaultCallGenerator); pushMethodArgumentsWithCallReceiver(receiver, resolvedCall, (CallableMethod) callable, skipLast, defaultCallGenerator);
} }
else { else {
gen(array, arrayType); // intrinsic method gen(array, arrayType); // intrinsic method
@@ -43,7 +43,7 @@ public class StupidSync extends IntrinsicMethod {
@NotNull Type returnType, @NotNull Type returnType,
@Nullable PsiElement element, @Nullable PsiElement element,
@Nullable List<JetExpression> arguments, @Nullable List<JetExpression> arguments,
StackValue receiver @Nullable StackValue receiver
) { ) {
assert element != null : "Element should not be null"; assert element != null : "Element should not be null";
ResolvedCall<?> resolvedCall = ResolvedCall<?> resolvedCall =
@@ -51,7 +51,7 @@ public class StupidSync extends IntrinsicMethod {
assert resolvedCall != null : "Resolved call for " + element.getText() + " should be not null"; assert resolvedCall != null : "Resolved call for " + element.getText() + " should be not null";
codegen.pushMethodArguments(resolvedCall, Arrays.asList(OBJECT_TYPE, FUNCTION0_TYPE), codegen.defaultCallGenerator); codegen.pushMethodArgumentsWithoutCallReceiver(resolvedCall, Arrays.asList(OBJECT_TYPE, FUNCTION0_TYPE), false, codegen.defaultCallGenerator);
v.invokestatic("kotlin/jvm/internal/Intrinsics", "stupidSync", Type.getMethodDescriptor(OBJECT_TYPE, OBJECT_TYPE, FUNCTION0_TYPE)); v.invokestatic("kotlin/jvm/internal/Intrinsics", "stupidSync", Type.getMethodDescriptor(OBJECT_TYPE, OBJECT_TYPE, FUNCTION0_TYPE));
return OBJECT_TYPE; return OBJECT_TYPE;
} }