Minor refactoring of TImpl codegen
Use early returns, rename some variables, etc
This commit is contained in:
@@ -1351,31 +1351,34 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
|
||||
|
||||
private void generateDelegationToTraitImpl(FunctionDescriptor fun, @NotNull FunctionDescriptor inheritedFun) {
|
||||
private void generateDelegationToTraitImpl(@NotNull FunctionDescriptor fun, @NotNull FunctionDescriptor inheritedFun) {
|
||||
DeclarationDescriptor containingDeclaration = fun.getContainingDeclaration();
|
||||
if (containingDeclaration instanceof ClassDescriptor) {
|
||||
ClassDescriptor declaration = (ClassDescriptor) containingDeclaration;
|
||||
if (declaration.getKind() == ClassKind.TRAIT) {
|
||||
if (!(containingDeclaration instanceof ClassDescriptor)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ClassDescriptor containingClass = (ClassDescriptor) containingDeclaration;
|
||||
if (containingClass.getKind() != ClassKind.TRAIT) {
|
||||
return;
|
||||
}
|
||||
|
||||
int flags = ACC_PUBLIC; // TODO.
|
||||
|
||||
Method function;
|
||||
Method functionOriginal;
|
||||
if (fun instanceof PropertyAccessorDescriptor) {
|
||||
PropertyDescriptor property = ((PropertyAccessorDescriptor) fun).getCorrespondingProperty();
|
||||
PropertyDescriptor original = property.getOriginal();
|
||||
if (fun instanceof PropertyGetterDescriptor) {
|
||||
function = typeMapper.mapGetterSignature(property, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||
functionOriginal =
|
||||
typeMapper.mapGetterSignature(property.getOriginal(), OwnerKind.IMPLEMENTATION).getJvmMethodSignature()
|
||||
.getAsmMethod();
|
||||
functionOriginal = typeMapper.mapGetterSignature(original, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||
}
|
||||
else if (fun instanceof PropertySetterDescriptor) {
|
||||
function = typeMapper.mapSetterSignature(property, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||
functionOriginal =
|
||||
typeMapper.mapSetterSignature(property.getOriginal(), OwnerKind.IMPLEMENTATION).getJvmMethodSignature()
|
||||
.getAsmMethod();
|
||||
functionOriginal = typeMapper.mapSetterSignature(original, OwnerKind.IMPLEMENTATION).getJvmMethodSignature().getAsmMethod();
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Accessor is neither getter, nor setter, what is it?");
|
||||
throw new IllegalStateException("Accessor is neither getter, nor setter, what is it? " + fun);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1392,6 +1395,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
isCallInsideSameClassAsDeclared(inheritedFun, context),
|
||||
isCallInsideSameModuleAsDeclared(inheritedFun, context),
|
||||
OwnerKind.IMPLEMENTATION).getSignature();
|
||||
|
||||
JetMethodAnnotationWriter aw = JetMethodAnnotationWriter.visitAnnotation(mv);
|
||||
int kotlinFlags = getFlagsForVisibility(fun.getVisibility());
|
||||
if (fun instanceof PropertyAccessorDescriptor) {
|
||||
@@ -1400,8 +1404,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
aw.writePropertyType(jvmSignature.getKotlinReturnType());
|
||||
}
|
||||
else {
|
||||
JetType returnType = fun.getReturnType();
|
||||
assert returnType != null;
|
||||
aw.writeTypeParameters(jvmSignature.getKotlinTypeParameter());
|
||||
aw.writeReturnType(jvmSignature.getKotlinReturnType());
|
||||
}
|
||||
@@ -1415,8 +1417,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
|
||||
mv.visitCode();
|
||||
FrameMap frameMap = context.prepareFrame(state.getTypeMapper());
|
||||
ExpressionCodegen codegen =
|
||||
new ExpressionCodegen(mv, frameMap, jvmSignature.getAsmMethod().getReturnType(), context, state);
|
||||
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, jvmSignature.getAsmMethod().getReturnType(), context, state);
|
||||
codegen.generateThisOrOuter(descriptor, false); // ??? wouldn't it be addClosureToConstructorParameters good idea to put it?
|
||||
|
||||
Type[] argTypes = function.getArgumentTypes();
|
||||
@@ -1430,24 +1431,20 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
reg += argTypes[i].getSize();
|
||||
}
|
||||
|
||||
Type type = getTraitImplThisParameterType(declaration, typeMapper);
|
||||
Type type = getTraitImplThisParameterType(containingClass, typeMapper);
|
||||
String functionDescriptor = functionOriginal.getDescriptor().replace("(", "(" + type.getDescriptor());
|
||||
|
||||
String fdescriptor = functionOriginal.getDescriptor().replace("(", "(" + type.getDescriptor());
|
||||
Type type1 =
|
||||
typeMapper.mapType(((ClassDescriptor) fun.getContainingDeclaration()).getDefaultType(), JetTypeMapperMode.TRAIT_IMPL);
|
||||
iv.invokestatic(type1.getInternalName(), function.getName(), fdescriptor);
|
||||
if (function.getReturnType().getSort() == Type.OBJECT &&
|
||||
!function.getReturnType().equals(functionOriginal.getReturnType())) {
|
||||
iv.checkcast(function.getReturnType());
|
||||
}
|
||||
Type tImplType = typeMapper.mapType(containingClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL);
|
||||
|
||||
iv.invokestatic(tImplType.getInternalName(), function.getName(), functionDescriptor);
|
||||
StackValue.onStack(functionOriginal.getReturnType()).put(function.getReturnType(), iv);
|
||||
iv.areturn(function.getReturnType());
|
||||
|
||||
FunctionCodegen.endVisit(iv, "trait method", callableDescriptorToDeclaration(bindingContext, fun));
|
||||
}
|
||||
|
||||
FunctionCodegen.generateBridgeIfNeeded(context, state, v, function, fun);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void generateDelegatorToConstructorCall(
|
||||
InstructionAdapter iv, ExpressionCodegen codegen,
|
||||
|
||||
Reference in New Issue
Block a user