Refactoring: remove 'call' argument

when it can be taken from resolved call
This commit is contained in:
Svetlana Isakova
2014-07-04 19:36:03 +04:00
parent 53ee30992b
commit 6988725207
4 changed files with 21 additions and 25 deletions
@@ -44,7 +44,6 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.DescriptorUtils; import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.model.*; import org.jetbrains.jet.lang.resolve.calls.model.*;
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker; import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
@@ -615,7 +614,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
ResolvedCall<FunctionDescriptor> resolvedCall = bindingContext.get(COMPONENT_RESOLVED_CALL, variableDeclaration); ResolvedCall<FunctionDescriptor> resolvedCall = bindingContext.get(COMPONENT_RESOLVED_CALL, variableDeclaration);
assert resolvedCall != null : "Resolved call is null for " + variableDeclaration.getText(); assert resolvedCall != null : "Resolved call is null for " + variableDeclaration.getText();
Call call = makeFakeCall(new TransientReceiver(elementType)); Call call = makeFakeCall(new TransientReceiver(elementType));
invokeFunction(call, StackValue.local(loopParameterVar, asmElementType), resolvedCall); invokeFunction(call, resolvedCall, StackValue.local(loopParameterVar, asmElementType));
v.store(componentVarIndex, componentAsmType); v.store(componentVarIndex, componentAsmType);
} }
@@ -702,8 +701,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
iteratorVarIndex = createLoopTempVariable(asmTypeForIterator); iteratorVarIndex = createLoopTempVariable(asmTypeForIterator);
Call call = bindingContext.get(LOOP_RANGE_ITERATOR_CALL, forExpression.getLoopRange()); invokeFunction(iteratorCall, StackValue.none());
invokeFunction(call, StackValue.none(), iteratorCall);
v.store(iteratorVarIndex, asmTypeForIterator); v.store(iteratorVarIndex, asmTypeForIterator);
} }
@@ -720,7 +718,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, loopRange, LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, loopRange,
"No hasNext() function " + DiagnosticUtils.atLocation(loopRange)); "No hasNext() function " + DiagnosticUtils.atLocation(loopRange));
@SuppressWarnings("ConstantConditions") Call fakeCall = makeFakeCall(new TransientReceiver(iteratorCall.getResultingDescriptor().getReturnType())); @SuppressWarnings("ConstantConditions") Call fakeCall = makeFakeCall(new TransientReceiver(iteratorCall.getResultingDescriptor().getReturnType()));
invokeFunction(fakeCall, StackValue.local(iteratorVarIndex, asmTypeForIterator), hasNextCall); invokeFunction(fakeCall, hasNextCall, StackValue.local(iteratorVarIndex, asmTypeForIterator));
JetType type = hasNextCall.getResultingDescriptor().getReturnType(); JetType type = hasNextCall.getResultingDescriptor().getReturnType();
assert type != null && JetTypeChecker.DEFAULT.isSubtypeOf(type, KotlinBuiltIns.getInstance().getBooleanType()); assert type != null && JetTypeChecker.DEFAULT.isSubtypeOf(type, KotlinBuiltIns.getInstance().getBooleanType());
@@ -734,7 +732,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
protected void assignToLoopParameter() { protected void assignToLoopParameter() {
@SuppressWarnings("ConstantConditions") Call fakeCall = @SuppressWarnings("ConstantConditions") Call fakeCall =
makeFakeCall(new TransientReceiver(iteratorCall.getResultingDescriptor().getReturnType())); makeFakeCall(new TransientReceiver(iteratorCall.getResultingDescriptor().getReturnType()));
invokeFunction(fakeCall, StackValue.local(iteratorVarIndex, asmTypeForIterator), nextCall); invokeFunction(fakeCall, nextCall, StackValue.local(iteratorVarIndex, asmTypeForIterator));
//noinspection ConstantConditions //noinspection ConstantConditions
v.store(loopParameterVar, asmType(nextCall.getResultingDescriptor().getReturnType())); v.store(loopParameterVar, asmType(nextCall.getResultingDescriptor().getReturnType()));
} }
@@ -1941,7 +1939,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return generateNewCall(expression, resolvedCall, receiver); return generateNewCall(expression, resolvedCall, receiver);
} }
Call call = getCall(expression, bindingContext);
if (funDescriptor.getOriginal() instanceof SamConstructorDescriptor) { if (funDescriptor.getOriginal() instanceof SamConstructorDescriptor) {
//noinspection ConstantConditions //noinspection ConstantConditions
SamType samType = SamType.create(funDescriptor.getReturnType()); SamType samType = SamType.create(funDescriptor.getReturnType());
@@ -1949,7 +1946,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return invokeSamConstructor(expression, resolvedCall, samType); return invokeSamConstructor(expression, resolvedCall, samType);
} }
return invokeFunction(call, receiver, resolvedCall); return invokeFunction(resolvedCall, receiver);
} }
@NotNull @NotNull
@@ -2024,9 +2021,14 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
} }
@NotNull @NotNull
public StackValue invokeFunction(Call call, StackValue receiver, ResolvedCall<?> resolvedCall) { public StackValue invokeFunction(@NotNull ResolvedCall<?> resolvedCall, @NotNull StackValue receiver) {
return invokeFunction(resolvedCall.getCall(), resolvedCall, receiver);
}
@NotNull
public StackValue invokeFunction(@NotNull Call call, @NotNull ResolvedCall<?> resolvedCall, @NotNull StackValue receiver) {
if (resolvedCall instanceof VariableAsFunctionResolvedCall) { if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
return invokeFunction(call, receiver, ((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall()); return invokeFunction(call, ((VariableAsFunctionResolvedCall) resolvedCall).getFunctionCall(), receiver);
} }
FunctionDescriptor fd = (FunctionDescriptor) resolvedCall.getResultingDescriptor(); FunctionDescriptor fd = (FunctionDescriptor) resolvedCall.getResultingDescriptor();
@@ -2602,7 +2604,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
} }
else { else {
Call call = CallMaker.makeCall(fakeExpression, NO_RECEIVER, null, fakeExpression, fakeArguments); Call call = CallMaker.makeCall(fakeExpression, NO_RECEIVER, null, fakeExpression, fakeArguments);
result = codegen.invokeFunction(call, StackValue.none(), fakeResolvedCall); result = codegen.invokeFunction(call, fakeResolvedCall, StackValue.none());
} }
InstructionAdapter v = codegen.v; InstructionAdapter v = codegen.v;
@@ -2735,8 +2737,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return StackValue.onStack(returnType); return StackValue.onStack(returnType);
} }
Call call = getCall(reference, bindingContext); return invokeFunction(resolvedCall, receiver);
return invokeFunction(call, receiver, resolvedCall);
} }
} }
@@ -2747,7 +2748,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
} }
else { else {
ResolvedCall<? extends CallableDescriptor> resolvedCall = getResolvedCallWithAssert(operationReference, bindingContext); ResolvedCall<? extends CallableDescriptor> resolvedCall = getResolvedCallWithAssert(operationReference, bindingContext);
invokeFunction(resolvedCall.getCall(), StackValue.none(), resolvedCall); invokeFunction(resolvedCall, StackValue.none());
} }
if (operationReference.getReferencedNameElementType() == JetTokens.NOT_IN) { if (operationReference.getReferencedNameElementType() == JetTokens.NOT_IN) {
genInvertBoolean(v); genInvertBoolean(v);
@@ -2929,8 +2930,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
gen(right, type); gen(right, type);
} }
else { else {
Call call = getCall(expression, bindingContext); StackValue result = invokeFunction(resolvedCall, receiver);
StackValue result = invokeFunction(call, receiver, resolvedCall);
type = Type.INT_TYPE; type = Type.INT_TYPE;
result.put(type, v); result.put(type, v);
v.iconst(0); v.iconst(0);
@@ -3053,7 +3053,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext); ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
if (isPrimitiveNumberClassDescriptor(cls) || !(op.getName().asString().equals("inc") || op.getName().asString().equals("dec"))) { if (isPrimitiveNumberClassDescriptor(cls) || !(op.getName().asString().equals("inc") || op.getName().asString().equals("dec"))) {
return invokeFunction(resolvedCall.getCall(), receiver, resolvedCall); return invokeFunction(resolvedCall, receiver);
} }
CallableMethod callableMethod = (CallableMethod) callable; CallableMethod callableMethod = (CallableMethod) callable;
@@ -3213,7 +3213,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
ResolvedCall<FunctionDescriptor> resolvedCall = bindingContext.get(COMPONENT_RESOLVED_CALL, variableDeclaration); ResolvedCall<FunctionDescriptor> resolvedCall = bindingContext.get(COMPONENT_RESOLVED_CALL, variableDeclaration);
assert resolvedCall != null : "Resolved call is null for " + variableDeclaration.getText(); assert resolvedCall != null : "Resolved call is null for " + variableDeclaration.getText();
Call call = makeFakeCall(initializerAsReceiver); Call call = makeFakeCall(initializerAsReceiver);
invokeFunction(call, local, resolvedCall); invokeFunction(call, resolvedCall, local);
return null; return null;
} }
}); });
@@ -384,9 +384,7 @@ public class PropertyCodegen {
BindingContext bindingContext = state.getBindingContext(); BindingContext bindingContext = state.getBindingContext();
ResolvedCall<FunctionDescriptor> resolvedCall = ResolvedCall<FunctionDescriptor> resolvedCall =
bindingContext.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, callableDescriptor); bindingContext.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, callableDescriptor);
assert resolvedCall != null : "Resolve call should be recorded for delegate call " + signature.toString();
Call call = bindingContext.get(BindingContext.DELEGATED_PROPERTY_CALL, callableDescriptor);
assert call != null : "Call should be recorded for delegate call " + signature.toString();
if (codegen.getContext().getContextKind() != OwnerKind.PACKAGE) { if (codegen.getContext().getContextKind() != OwnerKind.PACKAGE) {
v.load(0, OBJECT_TYPE); v.load(0, OBJECT_TYPE);
@@ -405,7 +403,7 @@ public class PropertyCodegen {
} }
codegen.tempVariables.put( codegen.tempVariables.put(
call.getValueArguments().get(1).asElement(), resolvedCall.getCall().getValueArguments().get(1).asElement(),
new StackValue(PROPERTY_METADATA_TYPE) { new StackValue(PROPERTY_METADATA_TYPE) {
@Override @Override
public void put(Type type, InstructionAdapter v) { public void put(Type type, InstructionAdapter v) {
@@ -417,7 +415,7 @@ public class PropertyCodegen {
); );
StackValue delegatedProperty = codegen.intermediateValueForProperty(callableDescriptor.getCorrespondingProperty(), true, null); StackValue delegatedProperty = codegen.intermediateValueForProperty(callableDescriptor.getCorrespondingProperty(), true, null);
StackValue lastValue = codegen.invokeFunction(call, delegatedProperty, resolvedCall); StackValue lastValue = codegen.invokeFunction(resolvedCall, delegatedProperty);
Type asmType = signature.getReturnType(); Type asmType = signature.getReturnType();
lastValue.put(asmType, v); lastValue.put(asmType, v);
@@ -100,7 +100,6 @@ public interface BindingContext {
WritableSlice<JetExpression, DelegatingBindingTrace> TRACE_DELTAS_CACHE = Slices.createSimpleSlice(); WritableSlice<JetExpression, DelegatingBindingTrace> TRACE_DELTAS_CACHE = Slices.createSimpleSlice();
WritableSlice<JetExpression, ResolvedCall<FunctionDescriptor>> LOOP_RANGE_ITERATOR_RESOLVED_CALL = Slices.createSimpleSlice(); WritableSlice<JetExpression, ResolvedCall<FunctionDescriptor>> LOOP_RANGE_ITERATOR_RESOLVED_CALL = Slices.createSimpleSlice();
WritableSlice<JetExpression, Call> LOOP_RANGE_ITERATOR_CALL = Slices.createSimpleSlice();
WritableSlice<JetExpression, ResolvedCall<FunctionDescriptor>> LOOP_RANGE_HAS_NEXT_RESOLVED_CALL = Slices.createSimpleSlice(); WritableSlice<JetExpression, ResolvedCall<FunctionDescriptor>> LOOP_RANGE_HAS_NEXT_RESOLVED_CALL = Slices.createSimpleSlice();
WritableSlice<JetExpression, ResolvedCall<FunctionDescriptor>> LOOP_RANGE_NEXT_RESOLVED_CALL = Slices.createSimpleSlice(); WritableSlice<JetExpression, ResolvedCall<FunctionDescriptor>> LOOP_RANGE_NEXT_RESOLVED_CALL = Slices.createSimpleSlice();
@@ -93,7 +93,6 @@ public class ForLoopConventionsChecker {
if (iteratorResolutionResults.isSuccess()) { if (iteratorResolutionResults.isSuccess()) {
ResolvedCall<FunctionDescriptor> iteratorResolvedCall = iteratorResolutionResults.getResultingCall(); ResolvedCall<FunctionDescriptor> iteratorResolvedCall = iteratorResolutionResults.getResultingCall();
context.trace.record(LOOP_RANGE_ITERATOR_RESOLVED_CALL, loopRangeExpression, iteratorResolvedCall); context.trace.record(LOOP_RANGE_ITERATOR_RESOLVED_CALL, loopRangeExpression, iteratorResolvedCall);
context.trace.record(LOOP_RANGE_ITERATOR_CALL, loopRangeExpression, iteratorCall);
FunctionDescriptor iteratorFunction = iteratorResolvedCall.getResultingDescriptor(); FunctionDescriptor iteratorFunction = iteratorResolvedCall.getResultingDescriptor();
JetType iteratorType = iteratorFunction.getReturnType(); JetType iteratorType = iteratorFunction.getReturnType();