Minor refactoring of TImpl codegen
Extract some methods
This commit is contained in:
@@ -37,7 +37,6 @@ import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
@@ -47,8 +46,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.asm4.Opcodes.*;
|
||||
import static org.jetbrains.jet.codegen.CodegenUtil.isInterface;
|
||||
import static org.jetbrains.jet.codegen.CodegenUtil.isNullableType;
|
||||
import static org.jetbrains.jet.codegen.CodegenUtil.*;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isClassObject;
|
||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE;
|
||||
|
||||
@@ -269,6 +267,16 @@ 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 stringValueOfOrStringBuilderAppendType(Type type) {
|
||||
int sort = type.getSort();
|
||||
return sort == Type.OBJECT || sort == Type.ARRAY
|
||||
|
||||
@@ -64,7 +64,6 @@ import static org.jetbrains.jet.codegen.AsmUtil.*;
|
||||
import static org.jetbrains.jet.codegen.CodegenUtil.*;
|
||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescriptorToDeclaration;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.*;
|
||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE;
|
||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||
@@ -1431,12 +1430,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
reg += argTypes[i].getSize();
|
||||
}
|
||||
|
||||
JetType jetType = CodegenUtil.getSuperClass(declaration);
|
||||
Type type = typeMapper.mapType(jetType, JetTypeMapperMode.IMPL);
|
||||
if (type.getInternalName().equals("java/lang/Object")) {
|
||||
jetType = declaration.getDefaultType();
|
||||
type = typeMapper.mapType(jetType, JetTypeMapperMode.IMPL);
|
||||
}
|
||||
Type type = getTraitImplThisParameterType(declaration, typeMapper);
|
||||
|
||||
String fdescriptor = functionOriginal.getDescriptor().replace("(", "(" + type.getDescriptor());
|
||||
Type type1 =
|
||||
|
||||
@@ -46,6 +46,7 @@ import java.util.Map;
|
||||
|
||||
import static org.jetbrains.asm4.Opcodes.*;
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.boxType;
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.getTraitImplThisParameterType;
|
||||
import static org.jetbrains.jet.codegen.CodegenUtil.*;
|
||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
|
||||
@@ -547,10 +548,11 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
thisClass, receiverParameterType, null);
|
||||
}
|
||||
|
||||
private static boolean isAccessor(FunctionDescriptor functionDescriptor) {
|
||||
return functionDescriptor instanceof AccessorForFunctionDescriptor ||
|
||||
functionDescriptor instanceof AccessorForPropertyDescriptor.Getter ||
|
||||
functionDescriptor instanceof AccessorForPropertyDescriptor.Setter;
|
||||
private static boolean isAccessor(@NotNull CallableMemberDescriptor descriptor) {
|
||||
return descriptor instanceof AccessorForFunctionDescriptor ||
|
||||
descriptor instanceof AccessorForPropertyDescriptor ||
|
||||
descriptor instanceof AccessorForPropertyDescriptor.Getter ||
|
||||
descriptor instanceof AccessorForPropertyDescriptor.Setter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -566,7 +568,6 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
}
|
||||
|
||||
private JvmMethodSignature mapSignature(FunctionDescriptor f, boolean needGenericSignature, OwnerKind kind) {
|
||||
|
||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
needGenericSignature = false;
|
||||
}
|
||||
@@ -575,35 +576,11 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
|
||||
writeFormalTypeParameters(f.getTypeParameters(), signatureVisitor);
|
||||
|
||||
JetType receiverType = DescriptorUtils.getReceiverParameterType(f.getReceiverParameter());
|
||||
List<ValueParameterDescriptor> parameters = f.getValueParameters();
|
||||
|
||||
signatureVisitor.writeParametersStart();
|
||||
writeThisIfNeeded(f, kind, signatureVisitor);
|
||||
writeReceiverIfNeeded(f.getReceiverParameter(), signatureVisitor);
|
||||
|
||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
ClassDescriptor containingDeclaration = (ClassDescriptor) f.getContainingDeclaration();
|
||||
JetType jetType = CodegenUtil.getSuperClass(containingDeclaration);
|
||||
Type type = mapType(jetType);
|
||||
if (type.getInternalName().equals("java/lang/Object")) {
|
||||
jetType = containingDeclaration.getDefaultType();
|
||||
type = mapType(jetType);
|
||||
}
|
||||
|
||||
signatureVisitor.writeParameterType(JvmMethodParameterKind.THIS);
|
||||
signatureVisitor.writeAsmType(type, jetType.isNullable());
|
||||
signatureVisitor.writeParameterTypeEnd();
|
||||
}
|
||||
else {
|
||||
writeThisForAccessorIfNeeded(f, signatureVisitor);
|
||||
}
|
||||
|
||||
if (receiverType != null) {
|
||||
signatureVisitor.writeParameterType(JvmMethodParameterKind.RECEIVER);
|
||||
mapType(receiverType, signatureVisitor, JetTypeMapperMode.VALUE);
|
||||
signatureVisitor.writeParameterTypeEnd();
|
||||
}
|
||||
|
||||
for (ValueParameterDescriptor parameter : parameters) {
|
||||
for (ValueParameterDescriptor parameter : f.getValueParameters()) {
|
||||
writeParameter(signatureVisitor, parameter.getType());
|
||||
}
|
||||
|
||||
@@ -622,10 +599,28 @@ public class JetTypeMapper extends BindingTraceAware {
|
||||
return signatureVisitor.makeJvmMethodSignature(f.getName().getName());
|
||||
}
|
||||
|
||||
private void writeThisForAccessorIfNeeded(FunctionDescriptor f, BothSignatureWriter signatureVisitor) {
|
||||
if (isAccessor(f) && f.getExpectedThisObject() != null) {
|
||||
private void writeThisIfNeeded(
|
||||
@NotNull CallableMemberDescriptor descriptor,
|
||||
@NotNull OwnerKind kind,
|
||||
@NotNull BothSignatureWriter signatureVisitor
|
||||
) {
|
||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||
ClassDescriptor containingDeclaration = (ClassDescriptor) descriptor.getContainingDeclaration();
|
||||
Type type = getTraitImplThisParameterType(containingDeclaration, this);
|
||||
|
||||
signatureVisitor.writeParameterType(JvmMethodParameterKind.THIS);
|
||||
mapType(((ClassifierDescriptor) f.getContainingDeclaration()).getDefaultType(), signatureVisitor, JetTypeMapperMode.VALUE);
|
||||
signatureVisitor.writeAsmType(type, false);
|
||||
signatureVisitor.writeParameterTypeEnd();
|
||||
}
|
||||
else {
|
||||
writeThisForAccessorIfNeeded(descriptor, signatureVisitor);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeThisForAccessorIfNeeded(@NotNull CallableMemberDescriptor descriptor, @NotNull BothSignatureWriter signatureVisitor) {
|
||||
if (isAccessor(descriptor) && descriptor.getExpectedThisObject() != null) {
|
||||
signatureVisitor.writeParameterType(JvmMethodParameterKind.THIS);
|
||||
mapType(((ClassifierDescriptor) descriptor.getContainingDeclaration()).getDefaultType(), signatureVisitor, JetTypeMapperMode.VALUE);
|
||||
signatureVisitor.writeParameterTypeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user