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