StaticDelegationKind removed
This commit is contained in:
@@ -147,7 +147,7 @@ public class AsmUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isStatic(OwnerKind kind) {
|
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) {
|
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);
|
CalculatedClosure closure = bindingContext.get(CLOSURE, classDescriptor);
|
||||||
|
|
||||||
ClassContext objectContext = context.intoAnonymousClass(classDescriptor, this);
|
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();
|
implementationBodyCodegen.generate();
|
||||||
|
|
||||||
@@ -299,8 +300,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
ClassBuilder classBuilder = state.getFactory().newVisitor(asmType, declaration.getContainingFile());
|
ClassBuilder classBuilder = state.getFactory().newVisitor(asmType, declaration.getContainingFile());
|
||||||
|
|
||||||
ClassContext objectContext = context.intoAnonymousClass(descriptor, this);
|
ClassContext objectContext = context.intoAnonymousClass(descriptor, this);
|
||||||
|
new ImplementationBodyCodegen(declaration, objectContext, classBuilder, state, getParentCodegen()).generate();
|
||||||
new ImplementationBodyCodegen(declaration, objectContext, classBuilder, state, null).generate();
|
|
||||||
classBuilder.done();
|
classBuilder.done();
|
||||||
|
|
||||||
return StackValue.none();
|
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.binding.CodegenBinding;
|
||||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||||
import org.jetbrains.jet.codegen.context.MethodContext;
|
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.JvmMethodParameterKind;
|
||||||
import org.jetbrains.jet.codegen.signature.JvmMethodParameterSignature;
|
import org.jetbrains.jet.codegen.signature.JvmMethodParameterSignature;
|
||||||
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
||||||
@@ -110,9 +112,8 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
jvmSignature.getGenericsSignature(),
|
jvmSignature.getGenericsSignature(),
|
||||||
null);
|
null);
|
||||||
|
|
||||||
OwnerKind contextKind = owner.getContextKind();
|
if (owner instanceof NamespaceFacadeContext) {
|
||||||
if (contextKind instanceof OwnerKind.StaticDelegateKind) {
|
Type ownerType = ((NamespaceFacadeContext) owner).getDelegateToClassType();
|
||||||
Type ownerType = ((OwnerKind.StaticDelegateKind) contextKind).getOwnerClass();
|
|
||||||
v.getMemberMap().recordSrcClassNameForCallable(functionDescriptor, shortNameByAsmType(ownerType));
|
v.getMemberMap().recordSrcClassNameForCallable(functionDescriptor, shortNameByAsmType(ownerType));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -251,9 +252,8 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
Label methodBegin = new Label();
|
Label methodBegin = new Label();
|
||||||
mv.visitLabel(methodBegin);
|
mv.visitLabel(methodBegin);
|
||||||
|
|
||||||
OwnerKind kind = context.getContextKind();
|
if (context.getParentContext() instanceof NamespaceFacadeContext) {
|
||||||
if (kind instanceof OwnerKind.StaticDelegateKind) {
|
generateStaticDelegateMethodBody(mv, signature.getAsmMethod(), (NamespaceFacadeContext) context.getParentContext());
|
||||||
generateStaticDelegateMethodBody(mv, signature.getAsmMethod(), (OwnerKind.StaticDelegateKind) kind);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
FrameMap frameMap = strategy.getFrameMap(typeMapper, context);
|
FrameMap frameMap = strategy.getFrameMap(typeMapper, context);
|
||||||
@@ -278,7 +278,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
|
|
||||||
|
|
||||||
Type thisType = getThisTypeForFunction(functionDescriptor, context);
|
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
|
@NotNull
|
||||||
@@ -386,7 +386,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
private static void generateStaticDelegateMethodBody(
|
private static void generateStaticDelegateMethodBody(
|
||||||
@NotNull MethodVisitor mv,
|
@NotNull MethodVisitor mv,
|
||||||
@NotNull Method asmMethod,
|
@NotNull Method asmMethod,
|
||||||
@NotNull OwnerKind.StaticDelegateKind dk
|
@NotNull NamespaceFacadeContext context
|
||||||
) {
|
) {
|
||||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||||
Type[] argTypes = asmMethod.getArgumentTypes();
|
Type[] argTypes = asmMethod.getArgumentTypes();
|
||||||
@@ -402,7 +402,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
|
|||||||
iv.load(k, argType);
|
iv.load(k, argType);
|
||||||
k += argType.getSize();
|
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());
|
iv.areturn(asmMethod.getReturnType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,36 +16,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
public enum OwnerKind {
|
||||||
import org.jetbrains.asm4.Type;
|
NAMESPACE,
|
||||||
|
|
||||||
public class OwnerKind {
|
IMPLEMENTATION,
|
||||||
private final String name;
|
|
||||||
|
|
||||||
protected OwnerKind(@NotNull String name) {
|
TRAIT_IMPL;
|
||||||
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 + ")";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||||
import org.jetbrains.jet.codegen.context.FieldOwnerContext;
|
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.signature.JvmMethodSignature;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationStateAware;
|
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;
|
assert variableDescriptor instanceof PropertyDescriptor : "Property should have a property descriptor: " + variableDescriptor;
|
||||||
|
|
||||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) 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;
|
: "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));
|
v.getMemberMap().recordSrcClassNameForCallable(propertyDescriptor, shortNameByAsmType(ownerType));
|
||||||
}
|
}
|
||||||
else if (kind != OwnerKind.TRAIT_IMPL) {
|
else if (kind != OwnerKind.TRAIT_IMPL) {
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private final CodegenContext parentContext;
|
private final CodegenContext parentContext;
|
||||||
|
|
||||||
private final ClassDescriptor thisDescriptor;
|
private final ClassDescriptor thisDescriptor;
|
||||||
|
|
||||||
public final MutableClosure closure;
|
public final MutableClosure closure;
|
||||||
@@ -148,12 +149,12 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public FieldOwnerContext intoNamespace(@NotNull NamespaceDescriptor descriptor) {
|
public FieldOwnerContext intoNamespace(@NotNull NamespaceDescriptor descriptor) {
|
||||||
return new NamespaceContext(descriptor, this, OwnerKind.NAMESPACE);
|
return new NamespaceContext(descriptor, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public FieldOwnerContext intoNamespaceFacade(@NotNull Type delegateTo, @NotNull NamespaceDescriptor descriptor) {
|
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
|
@NotNull
|
||||||
|
|||||||
@@ -18,12 +18,14 @@ package org.jetbrains.jet.codegen.context;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.jet.codegen.OwnerKind;
|
import org.jetbrains.jet.codegen.OwnerKind;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
|
|
||||||
public class NamespaceContext extends FieldOwnerContext<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
|
@Override
|
||||||
|
|||||||
@@ -18,16 +18,24 @@ package org.jetbrains.jet.codegen.context;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.codegen.OwnerKind;
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
|
|
||||||
public class NamespaceFacadeContext extends NamespaceContext {
|
public class NamespaceFacadeContext extends NamespaceContext {
|
||||||
|
|
||||||
|
private final Type delegateTo;
|
||||||
|
|
||||||
public NamespaceFacadeContext(
|
public NamespaceFacadeContext(
|
||||||
@NotNull NamespaceDescriptor contextDescriptor,
|
@NotNull NamespaceDescriptor contextDescriptor,
|
||||||
@Nullable CodegenContext parent,
|
@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) {
|
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;
|
return JetTypeMapperMode.IMPL;
|
||||||
}
|
}
|
||||||
else if (kind == OwnerKind.TRAIT_IMPL) {
|
else if (kind == OwnerKind.TRAIT_IMPL) {
|
||||||
|
|||||||
Reference in New Issue
Block a user