Simplify mapToCallableMethod

This commit is contained in:
Alexander Udalov
2014-04-23 19:52:59 +04:00
parent 722c15b747
commit ff8e282c4a
@@ -394,13 +394,13 @@ public class JetTypeMapper extends BindingTraceAware {
@NotNull @NotNull
public CallableMethod mapToCallableMethod( public CallableMethod mapToCallableMethod(
@NotNull FunctionDescriptor functionDescriptor, @NotNull FunctionDescriptor descriptor,
boolean superCall, boolean superCall,
@NotNull CodegenContext<?> context @NotNull CodegenContext<?> context
) { ) {
DeclarationDescriptor functionParent = functionDescriptor.getOriginal().getContainingDeclaration(); DeclarationDescriptor functionParent = descriptor.getOriginal().getContainingDeclaration();
functionDescriptor = unwrapFakeOverride(functionDescriptor.getOriginal()); FunctionDescriptor functionDescriptor = unwrapFakeOverride(descriptor.getOriginal());
JvmMethodSignature signature; JvmMethodSignature signature;
Type owner; Type owner;
@@ -418,43 +418,37 @@ public class JetTypeMapper extends BindingTraceAware {
boolean originalIsInterface = isInterface(declarationOwner); boolean originalIsInterface = isInterface(declarationOwner);
boolean currentIsInterface = isInterface(currentOwner); boolean currentIsInterface = isInterface(currentOwner);
ClassDescriptor receiver; boolean isInterface = currentIsInterface && originalIsInterface;
if (currentIsInterface && !originalIsInterface) {
receiver = declarationOwner;
}
else {
receiver = currentOwner;
}
boolean isInterface = originalIsInterface && currentIsInterface; ClassDescriptor ownerForDefault = (ClassDescriptor) findBaseDeclaration(functionDescriptor).getContainingDeclaration();
ownerForDefaultParam = mapClass(ownerForDefault);
ownerForDefaultImpl = isInterface(ownerForDefault) ? mapTraitImpl(ownerForDefault) : ownerForDefaultParam;
ClassDescriptor declarationOwnerForDefault = (ClassDescriptor) findBaseDeclaration(functionDescriptor).getContainingDeclaration(); if (isInterface && superCall) {
ownerForDefaultParam = mapClass(declarationOwnerForDefault); invokeOpcode = INVOKESTATIC;
ownerForDefaultImpl = isInterface(declarationOwnerForDefault) ? mapTraitImpl(declarationOwnerForDefault) : ownerForDefaultParam; signature = mapSignature(functionDescriptor, OwnerKind.TRAIT_IMPL);
if (isInterface) { owner = mapTraitImpl(currentOwner);
invokeOpcode = superCall ? INVOKESTATIC : INVOKEINTERFACE; thisClass = mapClass(currentOwner);
} }
else { else {
if (isAccessor(functionDescriptor)) { if (isAccessor(functionDescriptor)) {
invokeOpcode = INVOKESTATIC; invokeOpcode = INVOKESTATIC;
} }
else if (isInterface) {
invokeOpcode = INVOKEINTERFACE;
}
else { else {
boolean isPrivateFunInvocation = isCallInsideSameClassAsDeclared(functionDescriptor, context) && boolean isPrivateFunInvocation = isCallInsideSameClassAsDeclared(functionDescriptor, context) &&
functionDescriptor.getVisibility() == Visibilities.PRIVATE; functionDescriptor.getVisibility() == Visibilities.PRIVATE;
invokeOpcode = superCall || isPrivateFunInvocation ? INVOKESPECIAL : INVOKEVIRTUAL; invokeOpcode = superCall || isPrivateFunInvocation ? INVOKESPECIAL : INVOKEVIRTUAL;
} }
}
if (isInterface && superCall) {
signature = mapSignature(functionDescriptor, OwnerKind.TRAIT_IMPL);
owner = mapTraitImpl(receiver);
}
else {
signature = mapSignature(functionDescriptor.getOriginal()); signature = mapSignature(functionDescriptor.getOriginal());
owner = mapClass(receiver);
}
thisClass = mapType(receiver.getDefaultType()); ClassDescriptor receiver = currentIsInterface && !originalIsInterface ? declarationOwner : currentOwner;
owner = mapClass(receiver);
thisClass = owner;
}
} }
else { else {
signature = mapSignature(functionDescriptor.getOriginal()); signature = mapSignature(functionDescriptor.getOriginal());