diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java index 12df7864a8a..8286b76fd88 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java @@ -196,11 +196,8 @@ public class CodegenUtil { } public static void checkMustGenerateCode(CallableMemberDescriptor descriptor) { - if (descriptor.getKind() == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) { - throw new IllegalStateException("must not generate code for fake overrides"); - } - if (descriptor.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) { - throw new IllegalStateException("code generation for synthesized members should be handled separately"); + if (descriptor.getKind() != CallableMemberDescriptor.Kind.DECLARATION) { + throw new IllegalStateException("Must not generate code for descriptor: " + descriptor); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 73886cb7f5e..80c36cc90bf 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -93,10 +93,6 @@ public class FunctionCodegen extends GenerationStateAware { checkMustGenerateCode(functionDescriptor); 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) { needJetAnnotations = false; @@ -188,9 +184,6 @@ public class FunctionCodegen extends GenerationStateAware { if (kind instanceof OwnerKind.StaticDelegateKind) { generateStaticDelegateMethodBody(mv, asmMethod, (OwnerKind.StaticDelegateKind) kind); } - else if (kind instanceof OwnerKind.DelegateKind) { - generateDelegateMethodBody(mv, asmMethod, (OwnerKind.DelegateKind) kind); - } else { 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( @NotNull MethodVisitor mv, @NotNull Method asmMethod, diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/OwnerKind.java b/compiler/backend/src/org/jetbrains/jet/codegen/OwnerKind.java index 2afa8c5228e..6e9fcd9beb6 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/OwnerKind.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/OwnerKind.java @@ -30,25 +30,6 @@ public class OwnerKind { public static final OwnerKind IMPLEMENTATION = new OwnerKind("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 { private final String ownerClass; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java index 3871e4c084e..ee375f61897 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java @@ -180,7 +180,7 @@ public class PropertyCodegen extends GenerationStateAware { PsiElement psiElement = descriptorToDeclaration(bindingContext, propertyDescriptor.getContainingDeclaration()); boolean isTrait = psiElement instanceof JetClass && ((JetClass) psiElement).isTrait(); - if (isTrait && !(kind instanceof OwnerKind.DelegateKind)) { + if (isTrait) { flags |= ACC_ABSTRACT; } @@ -202,7 +202,7 @@ public class PropertyCodegen extends GenerationStateAware { 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) { mv.visitCode(); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { @@ -215,22 +215,11 @@ public class PropertyCodegen extends GenerationStateAware { } final Type type = typeMapper.mapType(propertyDescriptor); - if ((kind instanceof OwnerKind.DelegateKind) != (propertyDescriptor.getKind() == FunctionDescriptor.Kind.DELEGATION)) { - throw new IllegalStateException("mismatching kind in " + propertyDescriptor); - } - - if (kind instanceof OwnerKind.DelegateKind) { - 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.visitFieldInsn( + kind == OwnerKind.NAMESPACE ? GETSTATIC : GETFIELD, + typeMapper.getOwner(propertyDescriptor, kind).getInternalName(), + propertyDescriptor.getName().getName(), + type.getDescriptor()); iv.areturn(type); } } @@ -271,7 +260,7 @@ public class PropertyCodegen extends GenerationStateAware { PsiElement psiElement = descriptorToDeclaration(bindingContext, propertyDescriptor.getContainingDeclaration()); boolean isTrait = psiElement instanceof JetClass && ((JetClass) psiElement).isTrait(); - if (isTrait && !(kind instanceof OwnerKind.DelegateKind)) { + if (isTrait) { flags |= ACC_ABSTRACT; } @@ -289,7 +278,7 @@ public class PropertyCodegen extends GenerationStateAware { assert !setter.hasBody(); 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) { mv.visitCode(); if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) { @@ -304,25 +293,11 @@ public class PropertyCodegen extends GenerationStateAware { paramCode = 1; } - if ((kind instanceof OwnerKind.DelegateKind) != (propertyDescriptor.getKind() == FunctionDescriptor.Kind.DELEGATION)) { - throw new IllegalStateException("mismatching kind in " + propertyDescriptor); - } - - if (kind instanceof OwnerKind.DelegateKind) { - 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.load(paramCode, type); + iv.visitFieldInsn(kind == OwnerKind.NAMESPACE ? PUTSTATIC : PUTFIELD, + typeMapper.getOwner(propertyDescriptor, kind).getInternalName(), + propertyDescriptor.getName().getName(), + type.getDescriptor()); iv.visitInsn(RETURN); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java index 97d7f05d69c..a26e52396cc 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java @@ -75,14 +75,9 @@ public class JetTypeMapper extends BindingTraceAware { } else if (containingDeclaration instanceof ClassDescriptor) { ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration; - if (kind instanceof OwnerKind.DelegateKind) { + if (classDescriptor.getKind() == ClassKind.OBJECT) { mapTypeMode = JetTypeMapperMode.IMPL; } - else { - if (classDescriptor.getKind() == ClassKind.OBJECT) { - mapTypeMode = JetTypeMapperMode.IMPL; - } - } Type asmType = mapType(classDescriptor.getDefaultType(), mapTypeMode); if (asmType.getSort() != Type.OBJECT) { throw new IllegalStateException();