Move JetTypeMapperMode to JetTypeMapper class

This commit is contained in:
Alexander Udalov
2013-10-16 19:43:38 +04:00
parent af2a52bd4e
commit b4ecb36445
4 changed files with 35 additions and 59 deletions
@@ -31,9 +31,7 @@ import org.jetbrains.jet.codegen.context.LocalLookup;
import org.jetbrains.jet.codegen.signature.BothSignatureWriter;
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.GenerationStateAware;
import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
@@ -294,7 +292,7 @@ public class ClosureCodegen extends ParentCodegenAwareImpl {
BothSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS, true);
typeMapper.writeFormalTypeParameters(Collections.<TypeParameterDescriptor>emptyList(), sw);
sw.writeSuperclass();
typeMapper.mapType(supertype, sw, JetTypeMapperMode.SUPER_TYPE);
typeMapper.mapSupertype(supertype, sw);
sw.writeSuperclassEnd();
String signature = sw.makeJavaGenericSignature();
@@ -39,7 +39,6 @@ import org.jetbrains.jet.codegen.context.MethodContext;
import org.jetbrains.jet.codegen.signature.*;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
import org.jetbrains.jet.descriptors.serialization.BitEncoding;
import org.jetbrains.jet.descriptors.serialization.ClassData;
import org.jetbrains.jet.descriptors.serialization.DescriptorSerializer;
@@ -362,7 +361,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
signatureVisitor.writeClassEnd();
}
else {
typeMapper.mapType(superClassType, signatureVisitor, JetTypeMapperMode.SUPER_TYPE);
typeMapper.mapSupertype(superClassType, signatureVisitor);
}
signatureVisitor.writeSuperclassEnd();
}
@@ -377,7 +376,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
ClassDescriptor superClassDescriptor = (ClassDescriptor) superType.getConstructor().getDeclarationDescriptor();
if (isInterface(superClassDescriptor)) {
signatureVisitor.writeInterface();
Type jvmName = typeMapper.mapType(superType, signatureVisitor, JetTypeMapperMode.SUPER_TYPE);
Type jvmName = typeMapper.mapSupertype(superType, signatureVisitor);
signatureVisitor.writeInterfaceEnd();
superInterfacesLinkedHashSet.add(jvmName.getInternalName());
}
@@ -65,6 +65,26 @@ public class JetTypeMapper extends BindingTraceAware {
classBuilderMode = mode;
}
private enum JetTypeMapperMode {
/**
* foo.Bar is mapped to Lfoo/Bar;
*/
IMPL,
/**
* jet.Int is mapped to I
*/
VALUE,
/**
* jet.Int is mapped to Ljava/lang/Integer;
*/
TYPE_PARAMETER,
/**
* jet.Int is mapped to Ljava/lang/Integer;
* No projections allowed in immediate arguments
*/
SUPER_TYPE
}
@NotNull
public Type getOwner(@NotNull DeclarationDescriptor descriptor, @NotNull OwnerKind kind, boolean isInsideModule) {
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
@@ -189,12 +209,17 @@ public class JetTypeMapper extends BindingTraceAware {
}
return AsmTypeConstants.OBJECT_TYPE;
}
return mapType(jetType, signatureVisitor, JetTypeMapperMode.VALUE, Variance.OUT_VARIANCE);
return mapType(jetType, signatureVisitor, JetTypeMapperMode.VALUE, Variance.OUT_VARIANCE, false);
}
@NotNull
private Type mapType(@NotNull JetType jetType, @NotNull JetTypeMapperMode kind) {
return mapType(jetType, null, kind);
private Type mapType(@NotNull JetType jetType, @NotNull JetTypeMapperMode mode) {
return mapType(jetType, null, mode);
}
@NotNull
public Type mapSupertype(@NotNull JetType jetType, @Nullable BothSignatureWriter signatureVisitor) {
return mapType(jetType, signatureVisitor, JetTypeMapperMode.SUPER_TYPE);
}
@NotNull
@@ -214,21 +239,12 @@ public class JetTypeMapper extends BindingTraceAware {
@NotNull
public Type mapType(@NotNull ClassifierDescriptor classifierDescriptor) {
return mapType(classifierDescriptor.getDefaultType());
return mapType(classifierDescriptor.getDefaultType(), null, JetTypeMapperMode.VALUE);
}
@NotNull
public Type mapType(@NotNull JetType jetType, @Nullable BothSignatureWriter signatureVisitor, @NotNull JetTypeMapperMode kind) {
return mapType(jetType, signatureVisitor, kind, Variance.INVARIANT, false);
}
@NotNull
public Type mapType(
@NotNull JetType jetType,
@Nullable BothSignatureWriter signatureVisitor,
@NotNull JetTypeMapperMode kind,
@NotNull Variance howThisTypeIsUsed) {
return mapType(jetType, signatureVisitor, kind, howThisTypeIsUsed, false);
private Type mapType(@NotNull JetType jetType, @Nullable BothSignatureWriter signatureVisitor, @NotNull JetTypeMapperMode mode) {
return mapType(jetType, signatureVisitor, mode, Variance.INVARIANT, false);
}
@NotNull
@@ -751,7 +767,7 @@ public class JetTypeMapper extends BindingTraceAware {
writeReceiverIfNeeded(descriptor.getReceiverParameter(), signatureWriter);
signatureWriter.writeReturnType();
mapType(descriptor.getType(), signatureWriter, JetTypeMapperMode.VALUE, Variance.OUT_VARIANCE);
mapType(descriptor.getType(), signatureWriter, JetTypeMapperMode.VALUE, Variance.OUT_VARIANCE, false);
signatureWriter.writeReturnTypeEnd();
String name = getPropertyAccessorName(descriptor, true);
@@ -1,37 +0,0 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.codegen.state;
public enum JetTypeMapperMode {
/**
* foo.Bar is mapped to Lfoo/Bar;
*/
IMPL,
/**
* jet.Int is mapped to I
*/
VALUE,
/**
* jet.Int is mapped to Ljava/lang/Integer;
*/
TYPE_PARAMETER,
/**
* jet.Int is mapped to Ljava/lang/Integer;
* No projections allowed in immediate arguments
*/
SUPER_TYPE
}