Delete different mapSignature() overloads
JetTypeMapper now is fully aware of the name it should choose for the mapped method. The only exception is SAM conversion in ClosureCodegen, where the name must be replaced
This commit is contained in:
@@ -113,10 +113,8 @@ public class ClosureCodegen extends ParentCodegenAwareImpl {
|
||||
);
|
||||
cv.visitSource(fun.getContainingFile().getName(), null);
|
||||
|
||||
|
||||
generateBridge(interfaceFunction, cv);
|
||||
|
||||
JvmMethodSignature jvmMethodSignature = typeMapper.mapSignature(interfaceFunction.getName(), funDescriptor);
|
||||
JvmMethodSignature jvmMethodSignature = typeMapper.mapSignature(funDescriptor).replaceName(interfaceFunction.getName().toString());
|
||||
generateBridge(cv, typeMapper.mapSignature(interfaceFunction).getAsmMethod(), jvmMethodSignature.getAsmMethod());
|
||||
|
||||
FunctionCodegen fc = new FunctionCodegen(context, cv, state, getParentCodegen());
|
||||
fc.generateMethod(fun, jvmMethodSignature, funDescriptor, strategy);
|
||||
@@ -130,7 +128,7 @@ public class ClosureCodegen extends ParentCodegenAwareImpl {
|
||||
genClosureFields(closure, cv, typeMapper);
|
||||
|
||||
fc.generateDefaultIfNeeded(context.intoFunction(funDescriptor),
|
||||
typeMapper.mapSignature(Name.identifier("invoke"), funDescriptor),
|
||||
typeMapper.mapSignature(funDescriptor),
|
||||
funDescriptor,
|
||||
context.getContextKind(),
|
||||
DefaultParameterValueLoader.DEFAULT);
|
||||
@@ -171,44 +169,38 @@ public class ClosureCodegen extends ParentCodegenAwareImpl {
|
||||
}
|
||||
}
|
||||
|
||||
private void generateBridge(@NotNull FunctionDescriptor interfaceFunction, @NotNull ClassBuilder cv) {
|
||||
Method bridge = typeMapper.mapSignature(interfaceFunction).getAsmMethod();
|
||||
private void generateBridge(@NotNull ClassBuilder cv, @NotNull Method bridge, @NotNull Method delegate) {
|
||||
if (bridge.equals(delegate)) return;
|
||||
|
||||
Method delegate = typeMapper.mapSignature(interfaceFunction.getName(), funDescriptor).getAsmMethod();
|
||||
MethodVisitor mv =
|
||||
cv.newMethod(fun, ACC_PUBLIC | ACC_BRIDGE, bridge.getName(), bridge.getDescriptor(), null, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
|
||||
if (bridge.getDescriptor().equals(delegate.getDescriptor())) {
|
||||
return;
|
||||
if (state.getClassBuilderMode() != ClassBuilderMode.FULL) return;
|
||||
|
||||
mv.visitCode();
|
||||
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
iv.load(0, asmType);
|
||||
|
||||
ReceiverParameterDescriptor receiver = funDescriptor.getReceiverParameter();
|
||||
int count = 1;
|
||||
if (receiver != null) {
|
||||
StackValue.local(count, bridge.getArgumentTypes()[count - 1]).put(typeMapper.mapType(receiver.getType()), iv);
|
||||
count++;
|
||||
}
|
||||
|
||||
MethodVisitor mv = cv.newMethod(fun, ACC_PUBLIC | ACC_BRIDGE, interfaceFunction.getName().asString(),
|
||||
bridge.getDescriptor(), null, ArrayUtil.EMPTY_STRING_ARRAY);
|
||||
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||
mv.visitCode();
|
||||
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
|
||||
iv.load(0, asmType);
|
||||
|
||||
ReceiverParameterDescriptor receiver = funDescriptor.getReceiverParameter();
|
||||
int count = 1;
|
||||
if (receiver != null) {
|
||||
StackValue.local(count, bridge.getArgumentTypes()[count - 1]).put(typeMapper.mapType(receiver.getType()), iv);
|
||||
count++;
|
||||
}
|
||||
|
||||
List<ValueParameterDescriptor> params = funDescriptor.getValueParameters();
|
||||
for (ValueParameterDescriptor param : params) {
|
||||
StackValue.local(count, bridge.getArgumentTypes()[count - 1]).put(typeMapper.mapType(param.getType()), iv);
|
||||
count++;
|
||||
}
|
||||
|
||||
iv.invokevirtual(asmType.getInternalName(), interfaceFunction.getName().asString(), delegate.getDescriptor());
|
||||
StackValue.onStack(delegate.getReturnType()).put(bridge.getReturnType(), iv);
|
||||
|
||||
iv.areturn(bridge.getReturnType());
|
||||
|
||||
FunctionCodegen.endVisit(mv, "bridge", fun);
|
||||
List<ValueParameterDescriptor> params = funDescriptor.getValueParameters();
|
||||
for (ValueParameterDescriptor param : params) {
|
||||
StackValue.local(count, bridge.getArgumentTypes()[count - 1]).put(typeMapper.mapType(param.getType()), iv);
|
||||
count++;
|
||||
}
|
||||
|
||||
iv.invokevirtual(asmType.getInternalName(), delegate.getName(), delegate.getDescriptor());
|
||||
StackValue.onStack(delegate.getReturnType()).put(bridge.getReturnType(), iv);
|
||||
|
||||
iv.areturn(bridge.getReturnType());
|
||||
|
||||
FunctionCodegen.endVisit(mv, "bridge", fun);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -68,6 +68,13 @@ public class JvmMethodSignature {
|
||||
return r;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature replaceName(@NotNull String newName) {
|
||||
return newName.equals(asmMethod.getName()) ?
|
||||
this :
|
||||
new JvmMethodSignature(new Method(newName, asmMethod.getDescriptor()), genericsSignature, kotlinParameterTypes);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return asmMethod.getName();
|
||||
|
||||
@@ -43,7 +43,6 @@ import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaPackageFragmentDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.java.mapping.KotlinToJavaTypesMap;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
@@ -433,7 +432,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
owner = asmTypeForAnonymousClass(bindingContext, functionDescriptor);
|
||||
ownerForDefaultImpl = ownerForDefaultParam = thisClass = owner;
|
||||
invokeOpcode = INVOKEVIRTUAL;
|
||||
descriptor = mapSignature("invoke", functionDescriptor, kind);
|
||||
descriptor = mapSignature(functionDescriptor, kind);
|
||||
calleeType = owner;
|
||||
}
|
||||
else if (functionParent instanceof PackageFragmentDescriptor) {
|
||||
@@ -563,23 +562,13 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapSignature(@NotNull FunctionDescriptor descriptor) {
|
||||
return mapSignature(descriptor, OwnerKind.IMPLEMENTATION);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapSignature(@NotNull FunctionDescriptor f, @NotNull OwnerKind kind) {
|
||||
return mapSignature(mapFunctionName(f), f, kind);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapSignature(@NotNull Name functionName, @NotNull FunctionDescriptor f) {
|
||||
return mapSignature(functionName.asString(), f, OwnerKind.IMPLEMENTATION);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JvmMethodSignature mapSignature(@NotNull FunctionDescriptor f) {
|
||||
return mapSignature(mapFunctionName(f), f, OwnerKind.IMPLEMENTATION);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JvmMethodSignature mapSignature(@NotNull String methodName, @NotNull FunctionDescriptor f, @NotNull OwnerKind kind) {
|
||||
BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
|
||||
|
||||
writeFormalTypeParameters(f.getTypeParameters(), signatureVisitor);
|
||||
@@ -603,7 +592,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
signatureVisitor.writeReturnTypeEnd();
|
||||
}
|
||||
|
||||
return signatureVisitor.makeJvmMethodSignature(methodName);
|
||||
return signatureVisitor.makeJvmMethodSignature(mapFunctionName(f));
|
||||
}
|
||||
|
||||
private static void writeVoidReturn(@NotNull BothSignatureWriter signatureVisitor) {
|
||||
|
||||
Reference in New Issue
Block a user