Simplify mapOwner/mapToCallableMethod
This commit is contained in:
@@ -65,7 +65,6 @@ import java.util.Set;
|
|||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.*;
|
import static org.jetbrains.jet.codegen.AsmUtil.*;
|
||||||
import static org.jetbrains.jet.codegen.JvmSerializationBindings.*;
|
import static org.jetbrains.jet.codegen.JvmSerializationBindings.*;
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass;
|
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun;
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun;
|
||||||
import static org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.DECLARATION;
|
import static org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.DECLARATION;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescriptorToDeclaration;
|
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescriptorToDeclaration;
|
||||||
@@ -553,20 +552,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
|
|
||||||
int flags = getVisibilityAccessFlag(functionDescriptor) | getDeprecatedAccessFlag(functionDescriptor);
|
int flags = getVisibilityAccessFlag(functionDescriptor) | getDeprecatedAccessFlag(functionDescriptor);
|
||||||
|
|
||||||
Type ownerType;
|
Type ownerType = typeMapper.mapOwner(functionDescriptor, true);
|
||||||
if (contextClass instanceof PackageFragmentDescriptor) {
|
|
||||||
ownerType = typeMapper.mapOwner(functionDescriptor, true);
|
|
||||||
}
|
|
||||||
else if (contextClass instanceof ClassDescriptor) {
|
|
||||||
ownerType = typeMapper.mapClass((ClassDescriptor) contextClass);
|
|
||||||
}
|
|
||||||
else if (isLocalNamedFun(functionDescriptor)) {
|
|
||||||
ownerType = asmTypeForAnonymousClass(bindingContext, functionDescriptor);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalStateException("Couldn't obtain owner type for " + functionDescriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
String descriptor = jvmSignature.getDescriptor().replace(")", "I)");
|
String descriptor = jvmSignature.getDescriptor().replace(")", "I)");
|
||||||
boolean isConstructor = "<init>".equals(jvmSignature.getName());
|
boolean isConstructor = "<init>".equals(jvmSignature.getName());
|
||||||
if (!isStatic && !isConstructor) {
|
if (!isStatic && !isConstructor) {
|
||||||
|
|||||||
@@ -90,6 +90,10 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Type mapOwner(@NotNull DeclarationDescriptor descriptor, boolean isInsideModule) {
|
public Type mapOwner(@NotNull DeclarationDescriptor descriptor, boolean isInsideModule) {
|
||||||
|
if (isLocalNamedFun(descriptor)) {
|
||||||
|
return asmTypeForAnonymousClass(bindingContext, (FunctionDescriptor) descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
||||||
if (container instanceof JavaClassStaticsPackageFragmentDescriptor) {
|
if (container instanceof JavaClassStaticsPackageFragmentDescriptor) {
|
||||||
return mapClass(((JavaClassStaticsPackageFragmentDescriptor) container).getCorrespondingClass());
|
return mapClass(((JavaClassStaticsPackageFragmentDescriptor) container).getCorrespondingClass());
|
||||||
@@ -398,44 +402,14 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
|
|
||||||
functionDescriptor = unwrapFakeOverride(functionDescriptor.getOriginal());
|
functionDescriptor = unwrapFakeOverride(functionDescriptor.getOriginal());
|
||||||
|
|
||||||
JvmMethodSignature descriptor = mapSignature(functionDescriptor.getOriginal());
|
JvmMethodSignature signature;
|
||||||
Type owner;
|
Type owner;
|
||||||
Type ownerForDefaultImpl;
|
Type ownerForDefaultImpl;
|
||||||
Type ownerForDefaultParam;
|
Type ownerForDefaultParam;
|
||||||
int invokeOpcode;
|
int invokeOpcode;
|
||||||
Type thisClass;
|
Type thisClass;
|
||||||
Type calleeType = null;
|
|
||||||
|
|
||||||
if (isLocalNamedFun(functionDescriptor)) {
|
|
||||||
functionDescriptor = functionDescriptor.getOriginal();
|
|
||||||
|
|
||||||
owner = asmTypeForAnonymousClass(bindingContext, functionDescriptor);
|
|
||||||
ownerForDefaultImpl = ownerForDefaultParam = thisClass = owner;
|
|
||||||
invokeOpcode = INVOKEVIRTUAL;
|
|
||||||
descriptor = mapSignature(functionDescriptor);
|
|
||||||
calleeType = owner;
|
|
||||||
}
|
|
||||||
else if (functionParent instanceof PackageFragmentDescriptor) {
|
|
||||||
assert !superCall;
|
|
||||||
owner = mapOwner(functionDescriptor, isCallInsideSameModuleAsDeclared(functionDescriptor, context));
|
|
||||||
ownerForDefaultImpl = ownerForDefaultParam = owner;
|
|
||||||
invokeOpcode = INVOKESTATIC;
|
|
||||||
thisClass = null;
|
|
||||||
}
|
|
||||||
else if (functionDescriptor instanceof ConstructorDescriptor) {
|
|
||||||
assert !superCall;
|
|
||||||
owner = mapClass((ClassDescriptor) functionParent);
|
|
||||||
ownerForDefaultImpl = ownerForDefaultParam = owner;
|
|
||||||
invokeOpcode = INVOKESPECIAL;
|
|
||||||
thisClass = null;
|
|
||||||
}
|
|
||||||
else if (functionParent instanceof ScriptDescriptor) {
|
|
||||||
thisClass = owner = ownerForDefaultParam = ownerForDefaultImpl =
|
|
||||||
asmTypeForScriptDescriptor(bindingContext, (ScriptDescriptor) functionParent);
|
|
||||||
invokeOpcode = INVOKEVIRTUAL;
|
|
||||||
}
|
|
||||||
else if (functionParent instanceof ClassDescriptor) {
|
|
||||||
|
|
||||||
|
if (functionParent instanceof ClassDescriptor) {
|
||||||
FunctionDescriptor declarationFunctionDescriptor = findAnyDeclaration(functionDescriptor);
|
FunctionDescriptor declarationFunctionDescriptor = findAnyDeclaration(functionDescriptor);
|
||||||
|
|
||||||
ClassDescriptor currentOwner = (ClassDescriptor) functionParent;
|
ClassDescriptor currentOwner = (ClassDescriptor) functionParent;
|
||||||
@@ -453,12 +427,10 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean isInterface = originalIsInterface && currentIsInterface;
|
boolean isInterface = originalIsInterface && currentIsInterface;
|
||||||
owner = mapClass(receiver);
|
|
||||||
|
|
||||||
ClassDescriptor declarationOwnerForDefault = (ClassDescriptor) findBaseDeclaration(functionDescriptor).getContainingDeclaration();
|
ClassDescriptor declarationOwnerForDefault = (ClassDescriptor) findBaseDeclaration(functionDescriptor).getContainingDeclaration();
|
||||||
ownerForDefaultParam = mapClass(declarationOwnerForDefault);
|
ownerForDefaultParam = mapClass(declarationOwnerForDefault);
|
||||||
ownerForDefaultImpl = Type.getObjectType(
|
ownerForDefaultImpl = isInterface(declarationOwnerForDefault) ? mapTraitImpl(declarationOwnerForDefault) : ownerForDefaultParam;
|
||||||
ownerForDefaultParam.getInternalName() + (isInterface(declarationOwnerForDefault) ? JvmAbi.TRAIT_IMPL_SUFFIX : ""));
|
|
||||||
if (isInterface) {
|
if (isInterface) {
|
||||||
invokeOpcode = superCall ? INVOKESTATIC : INVOKEINTERFACE;
|
invokeOpcode = superCall ? INVOKESTATIC : INVOKEINTERFACE;
|
||||||
}
|
}
|
||||||
@@ -474,15 +446,36 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isInterface && superCall) {
|
if (isInterface && superCall) {
|
||||||
descriptor = mapSignature(functionDescriptor, OwnerKind.TRAIT_IMPL);
|
signature = mapSignature(functionDescriptor, OwnerKind.TRAIT_IMPL);
|
||||||
owner = Type.getObjectType(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
owner = mapTraitImpl(receiver);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
signature = mapSignature(functionDescriptor.getOriginal());
|
||||||
|
owner = mapClass(receiver);
|
||||||
|
}
|
||||||
|
|
||||||
thisClass = mapType(receiver.getDefaultType());
|
thisClass = mapType(receiver.getDefaultType());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException("unknown function parent");
|
signature = mapSignature(functionDescriptor.getOriginal());
|
||||||
|
owner = mapOwner(functionDescriptor, isCallInsideSameModuleAsDeclared(functionDescriptor, context));
|
||||||
|
ownerForDefaultParam = owner;
|
||||||
|
ownerForDefaultImpl = owner;
|
||||||
|
if (functionParent instanceof PackageFragmentDescriptor) {
|
||||||
|
invokeOpcode = INVOKESTATIC;
|
||||||
|
thisClass = null;
|
||||||
|
}
|
||||||
|
else if (functionDescriptor instanceof ConstructorDescriptor) {
|
||||||
|
invokeOpcode = INVOKESPECIAL;
|
||||||
|
thisClass = null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
invokeOpcode = INVOKEVIRTUAL;
|
||||||
|
thisClass = owner;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Type calleeType = isLocalNamedFun(functionDescriptor) ? owner : null;
|
||||||
|
|
||||||
Type receiverParameterType;
|
Type receiverParameterType;
|
||||||
ReceiverParameterDescriptor receiverParameter = functionDescriptor.getOriginal().getReceiverParameter();
|
ReceiverParameterDescriptor receiverParameter = functionDescriptor.getOriginal().getReceiverParameter();
|
||||||
@@ -493,7 +486,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
receiverParameterType = null;
|
receiverParameterType = null;
|
||||||
}
|
}
|
||||||
return new CallableMethod(
|
return new CallableMethod(
|
||||||
owner, ownerForDefaultImpl, ownerForDefaultParam, descriptor, invokeOpcode,
|
owner, ownerForDefaultImpl, ownerForDefaultParam, signature, invokeOpcode,
|
||||||
thisClass, receiverParameterType, calleeType);
|
thisClass, receiverParameterType, calleeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user