Delete JetTypeMapperMode.TRAIT_IMPL
The code is much easier with a simple method mapTraitImpl
This commit is contained in:
@@ -161,8 +161,7 @@ public final class ClassFileFactory extends GenerationStateAware {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ClassBuilder forTraitImplementation(@NotNull ClassDescriptor aClass, @NotNull GenerationState state, @NotNull PsiFile file) {
|
public ClassBuilder forTraitImplementation(@NotNull ClassDescriptor aClass, @NotNull GenerationState state, @NotNull PsiFile file) {
|
||||||
Type type = state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL);
|
return newVisitor(state.getTypeMapper().mapTraitImpl(aClass), file);
|
||||||
return newVisitor(type, file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<File> toIoFilesIgnoringNonPhysical(Collection<? extends PsiFile> psiFiles) {
|
private static Collection<File> toIoFilesIgnoringNonPhysical(Collection<? extends PsiFile> psiFiles) {
|
||||||
|
|||||||
@@ -1502,9 +1502,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
Type type = getTraitImplThisParameterType(containingClass, typeMapper);
|
Type type = getTraitImplThisParameterType(containingClass, typeMapper);
|
||||||
String functionDescriptor = methodInTrait.getDescriptor().replace("(", "(" + type.getDescriptor());
|
String functionDescriptor = methodInTrait.getDescriptor().replace("(", "(" + type.getDescriptor());
|
||||||
|
|
||||||
Type tImplType = typeMapper.mapType(containingClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL);
|
iv.invokestatic(typeMapper.mapTraitImpl(containingClass).getInternalName(), methodToGenerate.getName(), functionDescriptor);
|
||||||
|
|
||||||
iv.invokestatic(tImplType.getInternalName(), methodToGenerate.getName(), functionDescriptor);
|
|
||||||
StackValue.onStack(methodInTrait.getReturnType()).put(returnType, iv);
|
StackValue.onStack(methodInTrait.getReturnType()).put(returnType, iv);
|
||||||
iv.areturn(returnType);
|
iv.areturn(returnType);
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.asm4.commons.Method;
|
import org.jetbrains.asm4.commons.Method;
|
||||||
import org.jetbrains.jet.codegen.context.ClassContext;
|
import org.jetbrains.jet.codegen.context.ClassContext;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||||
@@ -47,7 +46,7 @@ public class TraitImplBodyCodegen extends ClassBodyCodegen {
|
|||||||
protected void generateDeclaration() {
|
protected void generateDeclaration() {
|
||||||
v.defineClass(myClass, V1_6,
|
v.defineClass(myClass, V1_6,
|
||||||
ACC_PUBLIC | ACC_FINAL,
|
ACC_PUBLIC | ACC_FINAL,
|
||||||
jvmName(),
|
typeMapper.mapTraitImpl(descriptor).getInternalName(),
|
||||||
null,
|
null,
|
||||||
"java/lang/Object",
|
"java/lang/Object",
|
||||||
new String[0]
|
new String[0]
|
||||||
@@ -73,9 +72,4 @@ public class TraitImplBodyCodegen extends ClassBodyCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private String jvmName() {
|
|
||||||
return typeMapper.mapType(descriptor.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL).getInternalName();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,23 +66,17 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Type getOwner(DeclarationDescriptor descriptor, OwnerKind kind, boolean isInsideModule) {
|
public Type getOwner(@NotNull DeclarationDescriptor descriptor, @NotNull OwnerKind kind, boolean isInsideModule) {
|
||||||
JetTypeMapperMode mapTypeMode = ownerKindToMapTypeMode(kind);
|
|
||||||
|
|
||||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||||
if (containingDeclaration instanceof NamespaceDescriptor) {
|
if (containingDeclaration instanceof NamespaceDescriptor) {
|
||||||
return asmTypeForNamespace((NamespaceDescriptor) containingDeclaration, descriptor, isInsideModule);
|
return asmTypeForNamespace((NamespaceDescriptor) containingDeclaration, descriptor, isInsideModule);
|
||||||
}
|
}
|
||||||
else if (containingDeclaration instanceof ClassDescriptor) {
|
else if (containingDeclaration instanceof ClassDescriptor) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||||
if (classDescriptor.getKind() == ClassKind.OBJECT) {
|
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||||
mapTypeMode = JetTypeMapperMode.IMPL;
|
return mapTraitImpl(classDescriptor);
|
||||||
}
|
}
|
||||||
Type asmType = mapType(classDescriptor.getDefaultType(), mapTypeMode);
|
return mapType(classDescriptor.getDefaultType(), JetTypeMapperMode.IMPL);
|
||||||
if (asmType.getSort() != Type.OBJECT) {
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
|
||||||
return asmType;
|
|
||||||
}
|
}
|
||||||
else if (containingDeclaration instanceof ScriptDescriptor) {
|
else if (containingDeclaration instanceof ScriptDescriptor) {
|
||||||
return asmTypeForScriptDescriptor(bindingContext, (ScriptDescriptor) containingDeclaration);
|
return asmTypeForScriptDescriptor(bindingContext, (ScriptDescriptor) containingDeclaration);
|
||||||
@@ -92,18 +86,6 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JetTypeMapperMode ownerKindToMapTypeMode(OwnerKind kind) {
|
|
||||||
if (kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.NAMESPACE) {
|
|
||||||
return JetTypeMapperMode.IMPL;
|
|
||||||
}
|
|
||||||
else if (kind == OwnerKind.TRAIT_IMPL) {
|
|
||||||
return JetTypeMapperMode.TRAIT_IMPL;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalStateException("must not call this method with kind = " + kind);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JavaNamespaceKind getNsKind(@NotNull NamespaceDescriptor ns) {
|
private JavaNamespaceKind getNsKind(@NotNull NamespaceDescriptor ns) {
|
||||||
JavaNamespaceKind javaNamespaceKind = bindingContext.get(JavaBindingContext.JAVA_NAMESPACE_KIND, ns);
|
JavaNamespaceKind javaNamespaceKind = bindingContext.get(JavaBindingContext.JAVA_NAMESPACE_KIND, ns);
|
||||||
@@ -273,9 +255,6 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
else if (kind == JetTypeMapperMode.TYPE_PARAMETER || kind == JetTypeMapperMode.SUPER_TYPE) {
|
else if (kind == JetTypeMapperMode.TYPE_PARAMETER || kind == JetTypeMapperMode.SUPER_TYPE) {
|
||||||
return mapKnownAsmType(jetType, boxType(known), signatureVisitor, howThisTypeIsUsed, arrayParameter, projectionsAllowed);
|
return mapKnownAsmType(jetType, boxType(known), signatureVisitor, howThisTypeIsUsed, arrayParameter, projectionsAllowed);
|
||||||
}
|
}
|
||||||
else if (kind == JetTypeMapperMode.TRAIT_IMPL) {
|
|
||||||
throw new IllegalStateException("TRAIT_IMPL is not possible for " + jetType);
|
|
||||||
}
|
|
||||||
else if (kind == JetTypeMapperMode.IMPL) {
|
else if (kind == JetTypeMapperMode.IMPL) {
|
||||||
// TODO: enable and fix tests
|
// TODO: enable and fix tests
|
||||||
//throw new IllegalStateException("must not map known type to IMPL when not compiling builtins: " + jetType);
|
//throw new IllegalStateException("must not map known type to IMPL when not compiling builtins: " + jetType);
|
||||||
@@ -330,17 +309,8 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (descriptor instanceof ClassDescriptor) {
|
if (descriptor instanceof ClassDescriptor) {
|
||||||
Type descriptorAsmType = getAsmType(bindingTrace, descriptor);
|
Type asmType = getAsmType(bindingTrace, descriptor);
|
||||||
Type asmType;
|
|
||||||
if (kind == JetTypeMapperMode.TRAIT_IMPL) {
|
|
||||||
asmType = Type.getObjectType(descriptorAsmType.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
asmType = descriptorAsmType;
|
|
||||||
}
|
|
||||||
|
|
||||||
writeGenericType(signatureVisitor, asmType, jetType, howThisTypeIsUsed, projectionsAllowed);
|
writeGenericType(signatureVisitor, asmType, jetType, howThisTypeIsUsed, projectionsAllowed);
|
||||||
|
|
||||||
return asmType;
|
return asmType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,6 +326,11 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
throw new UnsupportedOperationException("Unknown type " + jetType);
|
throw new UnsupportedOperationException("Unknown type " + jetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public Type mapTraitImpl(@NotNull ClassDescriptor descriptor) {
|
||||||
|
return Type.getObjectType(getAsmType(bindingTrace, descriptor).getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
||||||
|
}
|
||||||
|
|
||||||
private String generateErrorMessageForErrorType(@NotNull DeclarationDescriptor descriptor) {
|
private String generateErrorMessageForErrorType(@NotNull DeclarationDescriptor descriptor) {
|
||||||
PsiElement declarationElement = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
PsiElement declarationElement = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
||||||
PsiElement parentDeclarationElement = null;
|
PsiElement parentDeclarationElement = null;
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ public enum JetTypeMapperMode {
|
|||||||
* foo.Bar is mapped to Lfoo/Bar;
|
* foo.Bar is mapped to Lfoo/Bar;
|
||||||
*/
|
*/
|
||||||
IMPL,
|
IMPL,
|
||||||
/**
|
|
||||||
* foo.Bar is mapped to Lfoo/Bar$TImpl;
|
|
||||||
*/
|
|
||||||
TRAIT_IMPL,
|
|
||||||
/**
|
/**
|
||||||
* jet.Int is mapped to I
|
* jet.Int is mapped to I
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -169,14 +169,12 @@ public class JetPositionManager implements PositionManager {
|
|||||||
if (classDescriptor == null) {
|
if (classDescriptor == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
JetTypeMapperMode mode;
|
|
||||||
if (jetClass instanceof JetClass && ((JetClass) jetClass).isTrait()) {
|
if (jetClass instanceof JetClass && ((JetClass) jetClass).isTrait()) {
|
||||||
mode = JetTypeMapperMode.TRAIT_IMPL;
|
return typeMapper.mapTraitImpl(classDescriptor).getInternalName();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
mode = JetTypeMapperMode.IMPL;
|
return typeMapper.mapType(classDescriptor.getDefaultType(), JetTypeMapperMode.IMPL).getInternalName();
|
||||||
}
|
|
||||||
return typeMapper.mapType(classDescriptor.getDefaultType(), mode).getInternalName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JetTypeMapper prepareTypeMapper(final JetFile file) {
|
private JetTypeMapper prepareTypeMapper(final JetFile file) {
|
||||||
|
|||||||
Reference in New Issue
Block a user