Minor. Drop 'CodegenBased.callableDescriptor' field and relevant generic parameter
It was redundant for most of subclasses
This commit is contained in:
@@ -1419,7 +1419,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
||||
assert descriptor != null : "Function is not resolved to descriptor: " + declaration.getText();
|
||||
|
||||
return genClosure(
|
||||
declaration, descriptor, new FunctionGenerationStrategy.FunctionDefault(state, descriptor, declaration), samType, null, null
|
||||
declaration, descriptor, new FunctionGenerationStrategy.FunctionDefault(state, declaration), samType, null, null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ public class FunctionCodegen {
|
||||
|
||||
if (owner.getContextKind() != OwnerKind.DEFAULT_IMPLS || function.hasBody()) {
|
||||
generateMethod(JvmDeclarationOriginKt.OtherOrigin(function, functionDescriptor), functionDescriptor,
|
||||
new FunctionGenerationStrategy.FunctionDefault(state, functionDescriptor, function));
|
||||
new FunctionGenerationStrategy.FunctionDefault(state, function));
|
||||
}
|
||||
|
||||
generateDefaultIfNeeded(owner.intoFunction(functionDescriptor), functionDescriptor, owner.getContextKind(),
|
||||
|
||||
@@ -33,15 +33,14 @@ public abstract class FunctionGenerationStrategy {
|
||||
@NotNull MemberCodegen<?> parentCodegen
|
||||
);
|
||||
|
||||
public static class FunctionDefault extends CodegenBased<CallableDescriptor> {
|
||||
public static class FunctionDefault extends CodegenBased {
|
||||
private final KtDeclarationWithBody declaration;
|
||||
|
||||
public FunctionDefault(
|
||||
@NotNull GenerationState state,
|
||||
@NotNull CallableDescriptor descriptor,
|
||||
@NotNull KtDeclarationWithBody declaration
|
||||
) {
|
||||
super(state, descriptor);
|
||||
super(state);
|
||||
this.declaration = declaration;
|
||||
}
|
||||
|
||||
@@ -51,13 +50,11 @@ public abstract class FunctionGenerationStrategy {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class CodegenBased<T extends CallableDescriptor> extends FunctionGenerationStrategy {
|
||||
public abstract static class CodegenBased extends FunctionGenerationStrategy {
|
||||
protected final GenerationState state;
|
||||
protected final T callableDescriptor;
|
||||
|
||||
public CodegenBased(@NotNull GenerationState state, @NotNull T callableDescriptor) {
|
||||
public CodegenBased(@NotNull GenerationState state) {
|
||||
this.state = state;
|
||||
this.callableDescriptor = callableDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-4
@@ -36,9 +36,10 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrategy.CodegenBased<FunctionDescriptor> {
|
||||
public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrategy.CodegenBased {
|
||||
private final ResolvedCall<?> resolvedCall;
|
||||
private final FunctionDescriptor referencedFunction;
|
||||
private final FunctionDescriptor functionDescriptor;
|
||||
private final Type receiverType; // non-null for bound references
|
||||
private final StackValue receiverValue;
|
||||
|
||||
@@ -49,9 +50,10 @@ public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrat
|
||||
@Nullable Type receiverType,
|
||||
@Nullable StackValue receiverValue
|
||||
) {
|
||||
super(state, functionDescriptor);
|
||||
super(state);
|
||||
this.resolvedCall = resolvedCall;
|
||||
this.referencedFunction = (FunctionDescriptor) resolvedCall.getResultingDescriptor();
|
||||
this.functionDescriptor = functionDescriptor;
|
||||
this.receiverType = receiverType;
|
||||
this.receiverValue = receiverValue;
|
||||
assert receiverType != null || receiverValue == null
|
||||
@@ -82,7 +84,7 @@ public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrat
|
||||
{
|
||||
argumentMap = new LinkedHashMap<ValueParameterDescriptor, ResolvedValueArgument>(fakeArguments.size());
|
||||
int index = 0;
|
||||
List<ValueParameterDescriptor> parameters = callableDescriptor.getValueParameters();
|
||||
List<ValueParameterDescriptor> parameters = functionDescriptor.getValueParameters();
|
||||
for (ValueArgument argument : fakeArguments) {
|
||||
argumentMap.put(parameters.get(index), new ExpressionValueArgument(argument));
|
||||
index++;
|
||||
@@ -154,7 +156,7 @@ public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrat
|
||||
(referencedFunction.getExtensionReceiverParameter() != null ? 1 : 0) -
|
||||
(receiverType != null ? 1 : 0);
|
||||
|
||||
List<ValueParameterDescriptor> parameters = CollectionsKt.drop(callableDescriptor.getValueParameters(), receivers);
|
||||
List<ValueParameterDescriptor> parameters = CollectionsKt.drop(functionDescriptor.getValueParameters(), receivers);
|
||||
for (int i = 0; i < parameters.size(); i++) {
|
||||
ValueParameterDescriptor parameter = parameters.get(i);
|
||||
ValueArgument fakeArgument = fakeArguments.get(i);
|
||||
|
||||
@@ -931,7 +931,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
private void generatePrimaryConstructor(final DelegationFieldsInfo delegationFieldsInfo) {
|
||||
if (isInterface(descriptor) || isAnnotationClass(descriptor)) return;
|
||||
|
||||
ConstructorDescriptor constructorDescriptor = descriptor.getUnsubstitutedPrimaryConstructor();
|
||||
final ConstructorDescriptor constructorDescriptor = descriptor.getUnsubstitutedPrimaryConstructor();
|
||||
if (constructorDescriptor == null) return;
|
||||
|
||||
ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor);
|
||||
@@ -940,10 +940,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
JvmDeclarationOrigin origin = JvmDeclarationOriginKt
|
||||
.OtherOrigin(primaryConstructor != null ? primaryConstructor : myClass, constructorDescriptor);
|
||||
functionCodegen.generateMethod(origin, constructorDescriptor, constructorContext,
|
||||
new FunctionGenerationStrategy.CodegenBased<ConstructorDescriptor>(state, constructorDescriptor) {
|
||||
new FunctionGenerationStrategy.CodegenBased(state) {
|
||||
@Override
|
||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
||||
generatePrimaryConstructorImpl(callableDescriptor, codegen, delegationFieldsInfo, primaryConstructor);
|
||||
generatePrimaryConstructorImpl(constructorDescriptor, codegen, delegationFieldsInfo, primaryConstructor);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -954,7 +954,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
new DefaultParameterValueSubstitutor(state).generatePrimaryConstructorOverloadsIfNeeded(constructorDescriptor, v, kind, myClass);
|
||||
}
|
||||
|
||||
private void generateSecondaryConstructor(@NotNull ConstructorDescriptor constructorDescriptor) {
|
||||
private void generateSecondaryConstructor(@NotNull final ConstructorDescriptor constructorDescriptor) {
|
||||
if (!canHaveDeclaredConstructors(descriptor)) return;
|
||||
|
||||
ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor);
|
||||
@@ -964,10 +964,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
functionCodegen.generateMethod(
|
||||
JvmDeclarationOriginKt.OtherOrigin(constructor, constructorDescriptor),
|
||||
constructorDescriptor, constructorContext,
|
||||
new FunctionGenerationStrategy.CodegenBased<ConstructorDescriptor>(state, constructorDescriptor) {
|
||||
new FunctionGenerationStrategy.CodegenBased(state) {
|
||||
@Override
|
||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
||||
generateSecondaryConstructorImpl(callableDescriptor, codegen);
|
||||
generateSecondaryConstructorImpl(constructorDescriptor, codegen);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -1335,7 +1335,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
functionCodegen.generateMethod(
|
||||
JvmDeclarationOriginKt.DelegationToTraitImpl(descriptorToDeclaration(traitFun), traitFun),
|
||||
inheritedFun,
|
||||
new FunctionGenerationStrategy.CodegenBased<FunctionDescriptor>(state, inheritedFun) {
|
||||
new FunctionGenerationStrategy.CodegenBased(state) {
|
||||
@Override
|
||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
||||
DeclarationDescriptor containingDeclaration = traitFun.getContainingDeclaration();
|
||||
|
||||
@@ -114,7 +114,7 @@ class InterfaceImplBodyCodegen(
|
||||
functionCodegen.generateMethod(
|
||||
DelegationToTraitImpl(DescriptorToSourceUtils.descriptorToDeclaration(descriptor), descriptor),
|
||||
descriptor,
|
||||
object : FunctionGenerationStrategy.CodegenBased<FunctionDescriptor>(state, descriptor) {
|
||||
object : FunctionGenerationStrategy.CodegenBased(state) {
|
||||
override fun doGenerateBody(codegen: ExpressionCodegen, signature: JvmMethodSignature) {
|
||||
val iv = codegen.v
|
||||
|
||||
@@ -126,7 +126,7 @@ class InterfaceImplBodyCodegen(
|
||||
throw AssertionError(
|
||||
"Method from super interface has a different signature.\n" +
|
||||
"This method:\n%s\n%s\n%s\nSuper method:\n%s\n%s\n%s".format(
|
||||
callableDescriptor, signature, myParameters, delegateTo, method, calleeParameters
|
||||
descriptor, signature, myParameters, delegateTo, method, calleeParameters
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class JvmStaticGenerator(
|
||||
codegen.functionCodegen.generateMethod(
|
||||
Synthetic(originElement, staticFunctionDescriptor),
|
||||
staticFunctionDescriptor,
|
||||
object : FunctionGenerationStrategy.CodegenBased<FunctionDescriptor>(state, descriptor) {
|
||||
object : FunctionGenerationStrategy.CodegenBased(state) {
|
||||
override fun doGenerateBody(codegen: ExpressionCodegen, signature: JvmMethodSignature) {
|
||||
val iv = codegen.v
|
||||
val classDescriptor = descriptor.containingDeclaration as ClassDescriptor
|
||||
@@ -57,7 +57,7 @@ class JvmStaticGenerator(
|
||||
}
|
||||
if (descriptor is PropertyAccessorDescriptor) {
|
||||
val propertyValue = codegen.intermediateValueForProperty(descriptor.correspondingProperty, false, null, StackValue.none())
|
||||
if (callableDescriptor is PropertyGetterDescriptor) {
|
||||
if (descriptor is PropertyGetterDescriptor) {
|
||||
propertyValue.put(signature.returnType, iv)
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -579,7 +579,7 @@ public abstract class MemberCodegen<T extends KtElement/* TODO: & JetDeclaration
|
||||
final FunctionDescriptor original = (FunctionDescriptor) accessorForCallableDescriptor.getCalleeDescriptor();
|
||||
functionCodegen.generateMethod(
|
||||
Synthetic(null, original), accessor,
|
||||
new FunctionGenerationStrategy.CodegenBased<FunctionDescriptor>(state, accessor) {
|
||||
new FunctionGenerationStrategy.CodegenBased(state) {
|
||||
@Override
|
||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
||||
markLineNumberForElement(element, codegen.v);
|
||||
@@ -595,9 +595,11 @@ public abstract class MemberCodegen<T extends KtElement/* TODO: & JetDeclaration
|
||||
final AccessorForPropertyDescriptor accessor = (AccessorForPropertyDescriptor) accessorForCallableDescriptor;
|
||||
final PropertyDescriptor original = accessor.getCalleeDescriptor();
|
||||
|
||||
class PropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased<PropertyAccessorDescriptor> {
|
||||
class PropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased {
|
||||
private final PropertyAccessorDescriptor callableDescriptor;
|
||||
public PropertyAccessorStrategy(@NotNull PropertyAccessorDescriptor callableDescriptor) {
|
||||
super(MemberCodegen.this.state, callableDescriptor);
|
||||
super(MemberCodegen.this.state);
|
||||
this.callableDescriptor = callableDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -430,7 +430,7 @@ public class PropertyCodegen {
|
||||
}
|
||||
}
|
||||
else {
|
||||
strategy = new FunctionGenerationStrategy.FunctionDefault(state, accessorDescriptor, accessor);
|
||||
strategy = new FunctionGenerationStrategy.FunctionDefault(state, accessor);
|
||||
}
|
||||
|
||||
functionCodegen.generateMethod(JvmDeclarationOriginKt.OtherOrigin(accessor != null ? accessor : p, accessorDescriptor), accessorDescriptor, strategy);
|
||||
@@ -467,15 +467,17 @@ public class PropertyCodegen {
|
||||
}
|
||||
|
||||
|
||||
private static class DefaultPropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased<PropertyAccessorDescriptor> {
|
||||
private static class DefaultPropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased {
|
||||
private final PropertyAccessorDescriptor propertyAccessorDescriptor;
|
||||
public DefaultPropertyAccessorStrategy(@NotNull GenerationState state, @NotNull PropertyAccessorDescriptor descriptor) {
|
||||
super(state, descriptor);
|
||||
super(state);
|
||||
propertyAccessorDescriptor = descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
||||
InstructionAdapter v = codegen.v;
|
||||
PropertyDescriptor propertyDescriptor = callableDescriptor.getCorrespondingProperty();
|
||||
PropertyDescriptor propertyDescriptor = propertyAccessorDescriptor.getCorrespondingProperty();
|
||||
StackValue property = codegen.intermediateValueForProperty(propertyDescriptor, true, null, StackValue.LOCAL_0);
|
||||
|
||||
PsiElement jetProperty = DescriptorToSourceUtils.descriptorToDeclaration(propertyDescriptor);
|
||||
@@ -483,22 +485,22 @@ public class PropertyCodegen {
|
||||
codegen.markLineNumber((KtElement) jetProperty, false);
|
||||
}
|
||||
|
||||
if (callableDescriptor instanceof PropertyGetterDescriptor) {
|
||||
if (propertyAccessorDescriptor instanceof PropertyGetterDescriptor) {
|
||||
Type type = signature.getReturnType();
|
||||
property.put(type, v);
|
||||
v.areturn(type);
|
||||
}
|
||||
else if (callableDescriptor instanceof PropertySetterDescriptor) {
|
||||
List<ValueParameterDescriptor> valueParameters = callableDescriptor.getValueParameters();
|
||||
assert valueParameters.size() == 1 : "Property setter should have only one value parameter but has " + callableDescriptor;
|
||||
else if (propertyAccessorDescriptor instanceof PropertySetterDescriptor) {
|
||||
List<ValueParameterDescriptor> valueParameters = propertyAccessorDescriptor.getValueParameters();
|
||||
assert valueParameters.size() == 1 : "Property setter should have only one value parameter but has " + propertyAccessorDescriptor;
|
||||
int parameterIndex = codegen.lookupLocalIndex(valueParameters.get(0));
|
||||
assert parameterIndex >= 0 : "Local index for setter parameter should be positive or zero: " + callableDescriptor;
|
||||
assert parameterIndex >= 0 : "Local index for setter parameter should be positive or zero: " + propertyAccessorDescriptor;
|
||||
Type type = codegen.typeMapper.mapType(propertyDescriptor);
|
||||
property.store(StackValue.local(parameterIndex, type), codegen.v);
|
||||
v.visitInsn(RETURN);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Unknown property accessor: " + callableDescriptor);
|
||||
throw new IllegalStateException("Unknown property accessor: " + propertyAccessorDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -545,12 +547,14 @@ public class PropertyCodegen {
|
||||
return codegen.invokeFunction(resolvedCall, delegatedProperty);
|
||||
}
|
||||
|
||||
private static class DelegatedPropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased<PropertyAccessorDescriptor> {
|
||||
private static class DelegatedPropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased {
|
||||
private final int index;
|
||||
private final PropertyAccessorDescriptor propertyAccessorDescriptor;
|
||||
|
||||
public DelegatedPropertyAccessorStrategy(@NotNull GenerationState state, @NotNull PropertyAccessorDescriptor descriptor, int index) {
|
||||
super(state, descriptor);
|
||||
super(state);
|
||||
this.index = index;
|
||||
propertyAccessorDescriptor = descriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -559,10 +563,10 @@ public class PropertyCodegen {
|
||||
|
||||
BindingContext bindingContext = state.getBindingContext();
|
||||
ResolvedCall<FunctionDescriptor> resolvedCall =
|
||||
bindingContext.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, callableDescriptor);
|
||||
bindingContext.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, propertyAccessorDescriptor);
|
||||
assert resolvedCall != null : "Resolve call should be recorded for delegate call " + signature.toString();
|
||||
|
||||
StackValue lastValue = invokeDelegatedPropertyConventionMethod(callableDescriptor.getCorrespondingProperty(),
|
||||
StackValue lastValue = invokeDelegatedPropertyConventionMethod(propertyAccessorDescriptor.getCorrespondingProperty(),
|
||||
codegen, state.getTypeMapper(), resolvedCall, index, 1);
|
||||
Type asmType = signature.getReturnType();
|
||||
lastValue.put(asmType, v);
|
||||
|
||||
@@ -509,7 +509,7 @@ public class InlineCodegen extends CallGenerator {
|
||||
);
|
||||
}
|
||||
else {
|
||||
strategy = new FunctionGenerationStrategy.FunctionDefault(state, descriptor, (KtDeclarationWithBody) expression);
|
||||
strategy = new FunctionGenerationStrategy.FunctionDefault(state, (KtDeclarationWithBody) expression);
|
||||
}
|
||||
|
||||
FunctionCodegen.generateMethodBody(adapter, descriptor, context, jvmMethodSignature, strategy, parentCodegen);
|
||||
|
||||
Reference in New Issue
Block a user