Remove OwnerKind.DelegateKind
It's not used anywhere anymore. Add another assertion to checkMustGenerateCode()
This commit is contained in:
@@ -196,11 +196,8 @@ public class CodegenUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void checkMustGenerateCode(CallableMemberDescriptor descriptor) {
|
public static void checkMustGenerateCode(CallableMemberDescriptor descriptor) {
|
||||||
if (descriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
|
if (descriptor.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
|
||||||
throw new IllegalStateException("must not generate code for fake overrides");
|
throw new IllegalStateException("Must not generate code for descriptor: " + descriptor);
|
||||||
}
|
|
||||||
if (descriptor.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
|
|
||||||
throw new IllegalStateException("code generation for synthesized members should be handled separately");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,10 +93,6 @@ public class FunctionCodegen extends GenerationStateAware {
|
|||||||
checkMustGenerateCode(functionDescriptor);
|
checkMustGenerateCode(functionDescriptor);
|
||||||
|
|
||||||
OwnerKind kind = owner.getContextKind();
|
OwnerKind kind = owner.getContextKind();
|
||||||
if (!isStatic(kind) &&
|
|
||||||
(kind instanceof OwnerKind.DelegateKind) != (functionDescriptor.getKind() == FunctionDescriptor.Kind.DELEGATION)) {
|
|
||||||
throw new IllegalStateException("Mismatching kind in " + functionDescriptor + "; context kind: " + kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||||
needJetAnnotations = false;
|
needJetAnnotations = false;
|
||||||
@@ -188,9 +184,6 @@ public class FunctionCodegen extends GenerationStateAware {
|
|||||||
if (kind instanceof OwnerKind.StaticDelegateKind) {
|
if (kind instanceof OwnerKind.StaticDelegateKind) {
|
||||||
generateStaticDelegateMethodBody(mv, asmMethod, (OwnerKind.StaticDelegateKind) kind);
|
generateStaticDelegateMethodBody(mv, asmMethod, (OwnerKind.StaticDelegateKind) kind);
|
||||||
}
|
}
|
||||||
else if (kind instanceof OwnerKind.DelegateKind) {
|
|
||||||
generateDelegateMethodBody(mv, asmMethod, (OwnerKind.DelegateKind) kind);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
FrameMap frameMap = context.prepareFrame(typeMapper);
|
FrameMap frameMap = context.prepareFrame(typeMapper);
|
||||||
|
|
||||||
@@ -317,24 +310,6 @@ public class FunctionCodegen extends GenerationStateAware {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateDelegateMethodBody(
|
|
||||||
@NotNull MethodVisitor mv,
|
|
||||||
@NotNull Method asmMethod,
|
|
||||||
@NotNull OwnerKind.DelegateKind dk
|
|
||||||
) {
|
|
||||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
|
||||||
Type[] argTypes = asmMethod.getArgumentTypes();
|
|
||||||
|
|
||||||
iv.load(0, OBJECT_TYPE);
|
|
||||||
dk.getDelegate().put(OBJECT_TYPE, iv);
|
|
||||||
for (int i = 0; i < argTypes.length; i++) {
|
|
||||||
Type argType = argTypes[i];
|
|
||||||
iv.load(i + 1, argType);
|
|
||||||
}
|
|
||||||
iv.invokeinterface(dk.getOwnerClass(), asmMethod.getName(), asmMethod.getDescriptor());
|
|
||||||
iv.areturn(asmMethod.getReturnType());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateStaticDelegateMethodBody(
|
private void generateStaticDelegateMethodBody(
|
||||||
@NotNull MethodVisitor mv,
|
@NotNull MethodVisitor mv,
|
||||||
@NotNull Method asmMethod,
|
@NotNull Method asmMethod,
|
||||||
|
|||||||
@@ -30,25 +30,6 @@ public class OwnerKind {
|
|||||||
public static final OwnerKind IMPLEMENTATION = new OwnerKind("implementation");
|
public static final OwnerKind IMPLEMENTATION = new OwnerKind("implementation");
|
||||||
public static final OwnerKind TRAIT_IMPL = new OwnerKind("trait implementation");
|
public static final OwnerKind TRAIT_IMPL = new OwnerKind("trait implementation");
|
||||||
|
|
||||||
public static class DelegateKind extends OwnerKind {
|
|
||||||
private final StackValue delegate;
|
|
||||||
private final String ownerClass;
|
|
||||||
|
|
||||||
public DelegateKind(StackValue delegate, String ownerClass) {
|
|
||||||
super("delegateKind");
|
|
||||||
this.delegate = delegate;
|
|
||||||
this.ownerClass = ownerClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StackValue getDelegate() {
|
|
||||||
return delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOwnerClass() {
|
|
||||||
return ownerClass;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class StaticDelegateKind extends OwnerKind {
|
public static class StaticDelegateKind extends OwnerKind {
|
||||||
private final String ownerClass;
|
private final String ownerClass;
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
PsiElement psiElement = descriptorToDeclaration(bindingContext, propertyDescriptor.getContainingDeclaration());
|
PsiElement psiElement = descriptorToDeclaration(bindingContext, propertyDescriptor.getContainingDeclaration());
|
||||||
boolean isTrait = psiElement instanceof JetClass && ((JetClass) psiElement).isTrait();
|
boolean isTrait = psiElement instanceof JetClass && ((JetClass) psiElement).isTrait();
|
||||||
if (isTrait && !(kind instanceof OwnerKind.DelegateKind)) {
|
if (isTrait) {
|
||||||
flags |= ACC_ABSTRACT;
|
flags |= ACC_ABSTRACT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
AnnotationCodegen.forMethod(mv, typeMapper).genAnnotations(getter);
|
AnnotationCodegen.forMethod(mv, typeMapper).genAnnotations(getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.getClassBuilderMode() != ClassBuilderMode.SIGNATURES && (!isTrait || kind instanceof OwnerKind.DelegateKind)) {
|
if (state.getClassBuilderMode() != ClassBuilderMode.SIGNATURES && !isTrait) {
|
||||||
if (propertyDescriptor.getModality() != Modality.ABSTRACT) {
|
if (propertyDescriptor.getModality() != Modality.ABSTRACT) {
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
||||||
@@ -215,22 +215,11 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
}
|
}
|
||||||
final Type type = typeMapper.mapType(propertyDescriptor);
|
final Type type = typeMapper.mapType(propertyDescriptor);
|
||||||
|
|
||||||
if ((kind instanceof OwnerKind.DelegateKind) != (propertyDescriptor.getKind() == FunctionDescriptor.Kind.DELEGATION)) {
|
iv.visitFieldInsn(
|
||||||
throw new IllegalStateException("mismatching kind in " + propertyDescriptor);
|
kind == OwnerKind.NAMESPACE ? GETSTATIC : GETFIELD,
|
||||||
}
|
typeMapper.getOwner(propertyDescriptor, kind).getInternalName(),
|
||||||
|
propertyDescriptor.getName().getName(),
|
||||||
if (kind instanceof OwnerKind.DelegateKind) {
|
type.getDescriptor());
|
||||||
OwnerKind.DelegateKind dk = (OwnerKind.DelegateKind) kind;
|
|
||||||
dk.getDelegate().put(OBJECT_TYPE, iv);
|
|
||||||
iv.invokeinterface(dk.getOwnerClass(), getterName, descriptor);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
iv.visitFieldInsn(
|
|
||||||
kind == OwnerKind.NAMESPACE ? GETSTATIC : GETFIELD,
|
|
||||||
typeMapper.getOwner(propertyDescriptor, kind).getInternalName(),
|
|
||||||
propertyDescriptor.getName().getName(),
|
|
||||||
type.getDescriptor());
|
|
||||||
}
|
|
||||||
iv.areturn(type);
|
iv.areturn(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,7 +260,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
PsiElement psiElement = descriptorToDeclaration(bindingContext, propertyDescriptor.getContainingDeclaration());
|
PsiElement psiElement = descriptorToDeclaration(bindingContext, propertyDescriptor.getContainingDeclaration());
|
||||||
boolean isTrait = psiElement instanceof JetClass && ((JetClass) psiElement).isTrait();
|
boolean isTrait = psiElement instanceof JetClass && ((JetClass) psiElement).isTrait();
|
||||||
if (isTrait && !(kind instanceof OwnerKind.DelegateKind)) {
|
if (isTrait) {
|
||||||
flags |= ACC_ABSTRACT;
|
flags |= ACC_ABSTRACT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +278,7 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
assert !setter.hasBody();
|
assert !setter.hasBody();
|
||||||
AnnotationCodegen.forMethod(mv, typeMapper).genAnnotations(setter);
|
AnnotationCodegen.forMethod(mv, typeMapper).genAnnotations(setter);
|
||||||
|
|
||||||
if (state.getClassBuilderMode() != ClassBuilderMode.SIGNATURES && (!isTrait || kind instanceof OwnerKind.DelegateKind)) {
|
if (state.getClassBuilderMode() != ClassBuilderMode.SIGNATURES && (!isTrait)) {
|
||||||
if (propertyDescriptor.getModality() != Modality.ABSTRACT) {
|
if (propertyDescriptor.getModality() != Modality.ABSTRACT) {
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
|
||||||
@@ -304,25 +293,11 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
paramCode = 1;
|
paramCode = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((kind instanceof OwnerKind.DelegateKind) != (propertyDescriptor.getKind() == FunctionDescriptor.Kind.DELEGATION)) {
|
iv.load(paramCode, type);
|
||||||
throw new IllegalStateException("mismatching kind in " + propertyDescriptor);
|
iv.visitFieldInsn(kind == OwnerKind.NAMESPACE ? PUTSTATIC : PUTFIELD,
|
||||||
}
|
typeMapper.getOwner(propertyDescriptor, kind).getInternalName(),
|
||||||
|
propertyDescriptor.getName().getName(),
|
||||||
if (kind instanceof OwnerKind.DelegateKind) {
|
type.getDescriptor());
|
||||||
OwnerKind.DelegateKind dk = (OwnerKind.DelegateKind) kind;
|
|
||||||
iv.load(0, OBJECT_TYPE);
|
|
||||||
dk.getDelegate().put(OBJECT_TYPE, iv);
|
|
||||||
|
|
||||||
iv.load(paramCode, type);
|
|
||||||
iv.invokeinterface(dk.getOwnerClass(), setterName(propertyDescriptor.getName()), descriptor);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
iv.load(paramCode, type);
|
|
||||||
iv.visitFieldInsn(kind == OwnerKind.NAMESPACE ? PUTSTATIC : PUTFIELD,
|
|
||||||
typeMapper.getOwner(propertyDescriptor, kind).getInternalName(),
|
|
||||||
propertyDescriptor.getName().getName(),
|
|
||||||
type.getDescriptor());
|
|
||||||
}
|
|
||||||
|
|
||||||
iv.visitInsn(RETURN);
|
iv.visitInsn(RETURN);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,14 +75,9 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
else if (containingDeclaration instanceof ClassDescriptor) {
|
else if (containingDeclaration instanceof ClassDescriptor) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||||
if (kind instanceof OwnerKind.DelegateKind) {
|
if (classDescriptor.getKind() == ClassKind.OBJECT) {
|
||||||
mapTypeMode = JetTypeMapperMode.IMPL;
|
mapTypeMode = JetTypeMapperMode.IMPL;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if (classDescriptor.getKind() == ClassKind.OBJECT) {
|
|
||||||
mapTypeMode = JetTypeMapperMode.IMPL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Type asmType = mapType(classDescriptor.getDefaultType(), mapTypeMode);
|
Type asmType = mapType(classDescriptor.getDefaultType(), mapTypeMode);
|
||||||
if (asmType.getSort() != Type.OBJECT) {
|
if (asmType.getSort() != Type.OBJECT) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
|
|||||||
Reference in New Issue
Block a user