Merge two JetTypeMapper#mapToCallableMethod methods
This commit is contained in:
@@ -1472,7 +1472,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
ConstructorDescriptor constructorToCall = SamCodegenUtil.resolveSamAdapter(superConstructor);
|
||||
List<ValueParameterDescriptor> superValueParameters = superConstructor.getValueParameters();
|
||||
int params = superValueParameters.size();
|
||||
List<Type> superMappedTypes = typeMapper.mapToCallableMethod(constructorToCall).getValueParameterTypes();
|
||||
List<Type> superMappedTypes = typeMapper.mapToCallableMethod(constructorToCall, false).getValueParameterTypes();
|
||||
assert superMappedTypes.size() >= params : String
|
||||
.format("Incorrect number of mapped parameters vs arguments: %d < %d for %s",
|
||||
superMappedTypes.size(), params, classDescriptor);
|
||||
@@ -3414,7 +3414,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
pushClosureOnStack(constructor.getContainingDeclaration(), dispatchReceiver == null, defaultCallGenerator);
|
||||
|
||||
constructor = SamCodegenUtil.resolveSamAdapter(constructor);
|
||||
CallableMethod method = typeMapper.mapToCallableMethod(constructor);
|
||||
CallableMethod method = typeMapper.mapToCallableMethod(constructor, false);
|
||||
invokeMethodWithArguments(method, resolvedCall, StackValue.none());
|
||||
|
||||
return Unit.INSTANCE$;
|
||||
|
||||
@@ -664,13 +664,7 @@ public class FunctionCodegen {
|
||||
generator.putValueIfNeeded(parameterDescriptor, type, StackValue.local(parameterIndex, type));
|
||||
}
|
||||
|
||||
CallableMethod method;
|
||||
if (functionDescriptor instanceof ConstructorDescriptor) {
|
||||
method = state.getTypeMapper().mapToCallableMethod((ConstructorDescriptor) functionDescriptor);
|
||||
}
|
||||
else {
|
||||
method = state.getTypeMapper().mapToCallableMethod(functionDescriptor, false);
|
||||
}
|
||||
CallableMethod method = state.getTypeMapper().mapToCallableMethod(functionDescriptor, false);
|
||||
|
||||
generator.genCallWithoutAssertions(method, codegen);
|
||||
|
||||
|
||||
@@ -937,17 +937,16 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
@Nullable FunctionDescriptor accessorDescriptor,
|
||||
@NotNull InstructionAdapter iv
|
||||
) {
|
||||
boolean isConstructor = functionDescriptor instanceof ConstructorDescriptor;
|
||||
boolean accessorIsConstructor = accessorDescriptor instanceof AccessorForConstructorDescriptor;
|
||||
|
||||
boolean superCall = accessorDescriptor instanceof AccessorForCallableDescriptor &&
|
||||
((AccessorForCallableDescriptor) accessorDescriptor).getSuperCallExpression() != null;
|
||||
CallableMethod callableMethod = isConstructor ?
|
||||
typeMapper.mapToCallableMethod((ConstructorDescriptor) functionDescriptor) :
|
||||
typeMapper.mapToCallableMethod(functionDescriptor, superCall);
|
||||
CallableMethod callableMethod = typeMapper.mapToCallableMethod(
|
||||
functionDescriptor,
|
||||
accessorDescriptor instanceof AccessorForCallableDescriptor &&
|
||||
((AccessorForCallableDescriptor) accessorDescriptor).getSuperCallExpression() != null
|
||||
);
|
||||
|
||||
int reg = 1;
|
||||
if (isConstructor && !accessorIsConstructor) {
|
||||
|
||||
boolean accessorIsConstructor = accessorDescriptor instanceof AccessorForConstructorDescriptor;
|
||||
if (!accessorIsConstructor && functionDescriptor instanceof ConstructorDescriptor) {
|
||||
iv.anew(callableMethod.getOwner());
|
||||
iv.dup();
|
||||
reg = 0;
|
||||
@@ -1496,8 +1495,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
iv.load(0, OBJECT_TYPE);
|
||||
ConstructorDescriptor delegateConstructor = SamCodegenUtil.resolveSamAdapter(codegen.getConstructorDescriptor(delegationConstructorCall));
|
||||
|
||||
CallableMethod delegateConstructorCallable = typeMapper.mapToCallableMethod(delegateConstructor);
|
||||
CallableMethod callable = typeMapper.mapToCallableMethod(constructorDescriptor);
|
||||
CallableMethod delegateConstructorCallable = typeMapper.mapToCallableMethod(delegateConstructor, false);
|
||||
CallableMethod callable = typeMapper.mapToCallableMethod(constructorDescriptor, false);
|
||||
|
||||
List<JvmMethodParameterSignature> delegatingParameters = delegateConstructorCallable.getValueParameters();
|
||||
List<JvmMethodParameterSignature> parameters = callable.getValueParameters();
|
||||
@@ -1711,7 +1710,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
if (delegationSpecifiers.size() == 1 && !enumEntryNeedSubclass(bindingContext, enumEntry)) {
|
||||
ResolvedCall<?> resolvedCall = CallUtilPackage.getResolvedCallWithAssert(delegationSpecifiers.get(0), bindingContext);
|
||||
|
||||
CallableMethod method = typeMapper.mapToCallableMethod((ConstructorDescriptor) resolvedCall.getResultingDescriptor());
|
||||
CallableMethod method = typeMapper.mapToCallableMethod((ConstructorDescriptor) resolvedCall.getResultingDescriptor(), false);
|
||||
|
||||
codegen.invokeMethodWithArguments(method, resolvedCall, StackValue.none());
|
||||
}
|
||||
|
||||
@@ -593,6 +593,12 @@ public class JetTypeMapper {
|
||||
|
||||
@NotNull
|
||||
public CallableMethod mapToCallableMethod(@NotNull FunctionDescriptor descriptor, boolean superCall) {
|
||||
if (descriptor instanceof ConstructorDescriptor) {
|
||||
JvmMethodSignature method = mapSignature(descriptor);
|
||||
Type owner = mapClass(((ConstructorDescriptor) descriptor).getContainingDeclaration());
|
||||
return new CallableMethod(owner, owner, owner, method, INVOKESPECIAL, null, null, null);
|
||||
}
|
||||
|
||||
DeclarationDescriptor functionParent = descriptor.getOriginal().getContainingDeclaration();
|
||||
|
||||
FunctionDescriptor functionDescriptor = unwrapFakeOverride(descriptor.getOriginal());
|
||||
@@ -1113,17 +1119,6 @@ public class JetTypeMapper {
|
||||
return sw.makeJvmMethodSignature("<init>");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CallableMethod mapToCallableMethod(@NotNull ConstructorDescriptor descriptor) {
|
||||
JvmMethodSignature method = mapSignature(descriptor);
|
||||
ClassDescriptor container = descriptor.getContainingDeclaration();
|
||||
Type owner = mapClass(container);
|
||||
if (owner.getSort() != Type.OBJECT) {
|
||||
throw new IllegalStateException("type must have been mapped to object: " + container.getDefaultType() + ", actual: " + owner);
|
||||
}
|
||||
return new CallableMethod(owner, owner, owner, method, INVOKESPECIAL, null, null, null);
|
||||
}
|
||||
|
||||
public Type getSharedVarType(DeclarationDescriptor descriptor) {
|
||||
if (descriptor instanceof SimpleFunctionDescriptor && descriptor.getContainingDeclaration() instanceof FunctionDescriptor) {
|
||||
return asmTypeForAnonymousClass(bindingContext, (FunctionDescriptor) descriptor);
|
||||
|
||||
Reference in New Issue
Block a user