Get rid of a questionable TImpl hack in ImplementationBodyCodegen
Move getTraitImplThisParameterType closer to the only left usage in JetTypeMapper
This commit is contained in:
@@ -50,7 +50,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.codegen.JvmCodegenUtil.getSuperClass;
|
||||
import static org.jetbrains.jet.codegen.JvmCodegenUtil.isInterface;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.*;
|
||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE;
|
||||
@@ -320,16 +319,6 @@ public class AsmUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Type getTraitImplThisParameterType(@NotNull ClassDescriptor traitDescriptor, @NotNull JetTypeMapper typeMapper) {
|
||||
JetType jetType = getSuperClass(traitDescriptor);
|
||||
Type type = typeMapper.mapType(jetType);
|
||||
if (type.getInternalName().equals("java/lang/Object")) {
|
||||
return typeMapper.mapType(traitDescriptor.getDefaultType());
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
private static Type stringValueOfType(Type type) {
|
||||
int sort = type.getSort();
|
||||
return sort == Type.OBJECT || sort == Type.ARRAY
|
||||
|
||||
@@ -1497,27 +1497,25 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
@Override
|
||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
||||
DeclarationDescriptor containingDeclaration = traitFun.getContainingDeclaration();
|
||||
if (!(containingDeclaration instanceof ClassDescriptor)) return;
|
||||
ClassDescriptor containingTrait = (ClassDescriptor) containingDeclaration;
|
||||
if (containingTrait.getKind() != ClassKind.TRAIT) return;
|
||||
if (!DescriptorUtils.isTrait(containingDeclaration)) return;
|
||||
Type traitImplType = typeMapper.mapTraitImpl((ClassDescriptor) containingDeclaration);
|
||||
|
||||
Method traitMethod = typeMapper.mapSignature(traitFun.getOriginal()).getAsmMethod();
|
||||
Method traitMethod = typeMapper.mapSignature(traitFun.getOriginal(), OwnerKind.TRAIT_IMPL).getAsmMethod();
|
||||
|
||||
Type[] argTypes = signature.getAsmMethod().getArgumentTypes();
|
||||
Type[] originalArgTypes = traitMethod.getArgumentTypes();
|
||||
assert originalArgTypes.length == argTypes.length + 1 :
|
||||
"Invalid trait implementation signature: " + signature + " vs " + traitMethod + " for " + traitFun;
|
||||
|
||||
InstructionAdapter iv = codegen.v;
|
||||
iv.load(0, OBJECT_TYPE);
|
||||
for (int i = 0, reg = 1; i < argTypes.length; i++) {
|
||||
StackValue.local(reg, argTypes[i]).put(originalArgTypes[i], iv);
|
||||
StackValue.local(reg, argTypes[i]).put(originalArgTypes[i + 1], iv);
|
||||
//noinspection AssignmentToForLoopParameter
|
||||
reg += argTypes[i].getSize();
|
||||
}
|
||||
|
||||
Type type = getTraitImplThisParameterType(containingTrait, typeMapper);
|
||||
String desc = traitMethod.getDescriptor().replace("(", "(" + type.getDescriptor());
|
||||
|
||||
iv.invokestatic(typeMapper.mapTraitImpl(containingTrait).getInternalName(), traitMethod.getName(), desc);
|
||||
iv.invokestatic(traitImplType.getInternalName(), traitMethod.getName(), traitMethod.getDescriptor());
|
||||
|
||||
Type returnType = signature.getReturnType();
|
||||
StackValue.onStack(traitMethod.getReturnType()).put(returnType, iv);
|
||||
|
||||
@@ -81,16 +81,6 @@ public class JvmCodegenUtil {
|
||||
return stack.empty() ? null : stack.peek();
|
||||
}
|
||||
|
||||
public static JetType getSuperClass(ClassDescriptor classDescriptor) {
|
||||
List<ClassDescriptor> superclassDescriptors = DescriptorUtils.getSuperclassDescriptors(classDescriptor);
|
||||
for (ClassDescriptor descriptor : superclassDescriptors) {
|
||||
if (descriptor.getKind() != ClassKind.TRAIT) {
|
||||
return descriptor.getDefaultType();
|
||||
}
|
||||
}
|
||||
return KotlinBuiltIns.getInstance().getAnyType();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FunctionDescriptor getDeclaredFunctionByRawSignature(
|
||||
@NotNull ClassDescriptor owner,
|
||||
|
||||
@@ -60,7 +60,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.*;
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.boxType;
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.isStatic;
|
||||
import static org.jetbrains.jet.codegen.JvmCodegenUtil.*;
|
||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.isVarCapturedInClosure;
|
||||
@@ -661,16 +662,26 @@ public class JetTypeMapper {
|
||||
@NotNull OwnerKind kind,
|
||||
@NotNull BothSignatureWriter sw
|
||||
) {
|
||||
Type thisType;
|
||||
ClassDescriptor thisType;
|
||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
thisType = getTraitImplThisParameterType((ClassDescriptor) descriptor.getContainingDeclaration(), this);
|
||||
thisType = getTraitImplThisParameterClass((ClassDescriptor) descriptor.getContainingDeclaration());
|
||||
}
|
||||
else if (isAccessor(descriptor) && descriptor.getExpectedThisObject() != null) {
|
||||
thisType = mapClass((ClassifierDescriptor) descriptor.getContainingDeclaration());
|
||||
thisType = (ClassDescriptor) descriptor.getContainingDeclaration();
|
||||
}
|
||||
else return;
|
||||
|
||||
writeParameter(sw, JvmMethodParameterKind.THIS, thisType);
|
||||
writeParameter(sw, JvmMethodParameterKind.THIS, thisType.getDefaultType());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ClassDescriptor getTraitImplThisParameterClass(@NotNull ClassDescriptor traitDescriptor) {
|
||||
for (ClassDescriptor descriptor : DescriptorUtils.getSuperclassDescriptors(traitDescriptor)) {
|
||||
if (descriptor.getKind() != ClassKind.TRAIT) {
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
return traitDescriptor;
|
||||
}
|
||||
|
||||
public void writeFormalTypeParameters(@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull BothSignatureWriter sw) {
|
||||
|
||||
Reference in New Issue
Block a user