StaticDelegationKind removed

This commit is contained in:
Mikhael Bogdanov
2013-10-10 16:15:01 +04:00
parent 89d99c6fc7
commit 8f8017981b
9 changed files with 42 additions and 54 deletions
@@ -147,7 +147,7 @@ public class AsmUtil {
}
public static boolean isStatic(OwnerKind kind) {
return kind == OwnerKind.NAMESPACE || kind instanceof OwnerKind.StaticDelegateKind || kind == OwnerKind.TRAIT_IMPL;
return kind == OwnerKind.NAMESPACE || kind == OwnerKind.TRAIT_IMPL;
}
public static int getMethodAsmFlags(FunctionDescriptor functionDescriptor, OwnerKind kind) {
@@ -123,7 +123,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
CalculatedClosure closure = bindingContext.get(CLOSURE, classDescriptor);
ClassContext objectContext = context.intoAnonymousClass(classDescriptor, this);
ImplementationBodyCodegen implementationBodyCodegen = new ImplementationBodyCodegen(objectDeclaration, objectContext, classBuilder, state, null);
ImplementationBodyCodegen implementationBodyCodegen =
new ImplementationBodyCodegen(objectDeclaration, objectContext, classBuilder, state, getParentCodegen());
implementationBodyCodegen.generate();
@@ -299,8 +300,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
ClassBuilder classBuilder = state.getFactory().newVisitor(asmType, declaration.getContainingFile());
ClassContext objectContext = context.intoAnonymousClass(descriptor, this);
new ImplementationBodyCodegen(declaration, objectContext, classBuilder, state, null).generate();
new ImplementationBodyCodegen(declaration, objectContext, classBuilder, state, getParentCodegen()).generate();
classBuilder.done();
return StackValue.none();
@@ -31,6 +31,8 @@ import org.jetbrains.asm4.commons.Method;
import org.jetbrains.jet.codegen.binding.CodegenBinding;
import org.jetbrains.jet.codegen.context.CodegenContext;
import org.jetbrains.jet.codegen.context.MethodContext;
import org.jetbrains.jet.codegen.context.NamespaceContext;
import org.jetbrains.jet.codegen.context.NamespaceFacadeContext;
import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind;
import org.jetbrains.jet.codegen.signature.JvmMethodParameterSignature;
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
@@ -110,9 +112,8 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
jvmSignature.getGenericsSignature(),
null);
OwnerKind contextKind = owner.getContextKind();
if (contextKind instanceof OwnerKind.StaticDelegateKind) {
Type ownerType = ((OwnerKind.StaticDelegateKind) contextKind).getOwnerClass();
if (owner instanceof NamespaceFacadeContext) {
Type ownerType = ((NamespaceFacadeContext) owner).getDelegateToClassType();
v.getMemberMap().recordSrcClassNameForCallable(functionDescriptor, shortNameByAsmType(ownerType));
}
else {
@@ -251,9 +252,8 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
Label methodBegin = new Label();
mv.visitLabel(methodBegin);
OwnerKind kind = context.getContextKind();
if (kind instanceof OwnerKind.StaticDelegateKind) {
generateStaticDelegateMethodBody(mv, signature.getAsmMethod(), (OwnerKind.StaticDelegateKind) kind);
if (context.getParentContext() instanceof NamespaceFacadeContext) {
generateStaticDelegateMethodBody(mv, signature.getAsmMethod(), (NamespaceFacadeContext) context.getParentContext());
}
else {
FrameMap frameMap = strategy.getFrameMap(typeMapper, context);
@@ -278,7 +278,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
Type thisType = getThisTypeForFunction(functionDescriptor, context);
generateLocalVariableTable(mv, signature, functionDescriptor, thisType, methodBegin, methodEnd, localVariableNames, labelsForSharedVars, kind);
generateLocalVariableTable(mv, signature, functionDescriptor, thisType, methodBegin, methodEnd, localVariableNames, labelsForSharedVars, context.getContextKind());
}
@NotNull
@@ -386,7 +386,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
private static void generateStaticDelegateMethodBody(
@NotNull MethodVisitor mv,
@NotNull Method asmMethod,
@NotNull OwnerKind.StaticDelegateKind dk
@NotNull NamespaceFacadeContext context
) {
InstructionAdapter iv = new InstructionAdapter(mv);
Type[] argTypes = asmMethod.getArgumentTypes();
@@ -402,7 +402,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
iv.load(k, argType);
k += argType.getSize();
}
iv.invokestatic(dk.getOwnerClass().getInternalName(), asmMethod.getName(), asmMethod.getDescriptor());
iv.invokestatic(context.getDelegateToClassType().getInternalName(), asmMethod.getName(), asmMethod.getDescriptor());
iv.areturn(asmMethod.getReturnType());
}
@@ -16,36 +16,10 @@
package org.jetbrains.jet.codegen;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.asm4.Type;
public enum OwnerKind {
NAMESPACE,
public class OwnerKind {
private final String name;
IMPLEMENTATION,
protected OwnerKind(@NotNull String name) {
this.name = name;
}
public static final OwnerKind NAMESPACE = new OwnerKind("namespace");
public static final OwnerKind IMPLEMENTATION = new OwnerKind("implementation");
public static final OwnerKind TRAIT_IMPL = new OwnerKind("trait implementation");
public static class StaticDelegateKind extends OwnerKind {
private final Type ownerClass;
public StaticDelegateKind(@NotNull Type ownerClass) {
super("staticDelegateKind");
this.ownerClass = ownerClass;
}
@NotNull
public Type getOwnerClass() {
return ownerClass;
}
}
@Override
public String toString() {
return "OwnerKind(" + name + ")";
}
TRAIT_IMPL;
}
@@ -26,6 +26,8 @@ import org.jetbrains.asm4.Type;
import org.jetbrains.asm4.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.context.CodegenContext;
import org.jetbrains.jet.codegen.context.FieldOwnerContext;
import org.jetbrains.jet.codegen.context.NamespaceContext;
import org.jetbrains.jet.codegen.context.NamespaceFacadeContext;
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.GenerationStateAware;
@@ -83,11 +85,12 @@ public class PropertyCodegen extends GenerationStateAware {
assert variableDescriptor instanceof PropertyDescriptor : "Property should have a property descriptor: " + variableDescriptor;
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) variableDescriptor;
assert kind instanceof OwnerKind.StaticDelegateKind || kind == OwnerKind.NAMESPACE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.TRAIT_IMPL
assert kind == OwnerKind.NAMESPACE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.TRAIT_IMPL
: "Generating property with a wrong kind (" + kind + "): " + propertyDescriptor;
if (kind instanceof OwnerKind.StaticDelegateKind) {
Type ownerType = ((OwnerKind.StaticDelegateKind) kind).getOwnerClass();
if (context instanceof NamespaceFacadeContext) {
Type ownerType = ((NamespaceFacadeContext) context).getDelegateToClassType();
v.getMemberMap().recordSrcClassNameForCallable(propertyDescriptor, shortNameByAsmType(ownerType));
}
else if (kind != OwnerKind.TRAIT_IMPL) {
@@ -52,6 +52,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
@Nullable
private final CodegenContext parentContext;
private final ClassDescriptor thisDescriptor;
public final MutableClosure closure;
@@ -148,12 +149,12 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
@NotNull
public FieldOwnerContext intoNamespace(@NotNull NamespaceDescriptor descriptor) {
return new NamespaceContext(descriptor, this, OwnerKind.NAMESPACE);
return new NamespaceContext(descriptor, this);
}
@NotNull
public FieldOwnerContext intoNamespaceFacade(@NotNull Type delegateTo, @NotNull NamespaceDescriptor descriptor) {
return new NamespaceFacadeContext(descriptor, this, new OwnerKind.StaticDelegateKind(delegateTo));
return new NamespaceFacadeContext(descriptor, this, delegateTo);
}
@NotNull
@@ -18,12 +18,14 @@ package org.jetbrains.jet.codegen.context;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.asm4.Type;
import org.jetbrains.jet.codegen.OwnerKind;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
public class NamespaceContext extends FieldOwnerContext<NamespaceDescriptor> {
public NamespaceContext(@NotNull NamespaceDescriptor contextDescriptor, @Nullable CodegenContext parent, @NotNull OwnerKind kind) {
super(contextDescriptor, kind, parent, null, null, null);
public NamespaceContext(@NotNull NamespaceDescriptor contextDescriptor, @Nullable CodegenContext parent) {
super(contextDescriptor, OwnerKind.NAMESPACE, parent, null, null, null);
}
@Override
@@ -18,16 +18,24 @@ package org.jetbrains.jet.codegen.context;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.codegen.OwnerKind;
import org.jetbrains.asm4.Type;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
public class NamespaceFacadeContext extends NamespaceContext {
private final Type delegateTo;
public NamespaceFacadeContext(
@NotNull NamespaceDescriptor contextDescriptor,
@Nullable CodegenContext parent,
@NotNull OwnerKind kind
@NotNull Type delegateTo
) {
super(contextDescriptor, parent, kind);
super(contextDescriptor, parent);
this.delegateTo = delegateTo;
}
@NotNull
public Type getDelegateToClassType() {
return delegateTo;
}
}
@@ -93,7 +93,7 @@ public class JetTypeMapper extends BindingTraceAware {
}
private static JetTypeMapperMode ownerKindToMapTypeMode(OwnerKind kind) {
if (kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.NAMESPACE || kind instanceof OwnerKind.StaticDelegateKind) {
if (kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.NAMESPACE) {
return JetTypeMapperMode.IMPL;
}
else if (kind == OwnerKind.TRAIT_IMPL) {