diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java index 4c5d8b83cb7..537a8e6b6cf 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClosureCodegen.java @@ -298,11 +298,9 @@ public class ClosureCodegen extends GenerationStateAware { BothSignatureWriter sw = new BothSignatureWriter(BothSignatureWriter.Mode.CLASS, true); typeMapper.writeFormalTypeParameters(Collections.emptyList(), sw); - sw.writeSupersStart(); sw.writeSuperclass(); typeMapper.mapType(supertype, sw, JetTypeMapperMode.TYPE_PARAMETER); sw.writeSuperclassEnd(); - sw.writeSupersEnd(); String signature = sw.makeJavaGenericSignature(); assert signature != null : "Closure superclass must have a generic signature: " + funDescriptor; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java index d65d20df493..06a0208adf2 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/CodegenUtil.java @@ -105,12 +105,8 @@ public class CodegenUtil { public static JvmMethodSignature erasedInvokeSignature(FunctionDescriptor fd) { - BothSignatureWriter signatureWriter = new BothSignatureWriter(BothSignatureWriter.Mode.METHOD, false); - signatureWriter.writeFormalTypeParametersStart(); - signatureWriter.writeFormalTypeParametersEnd(); - boolean isExtensionFunction = fd.getReceiverParameter() != null; int paramCount = fd.getValueParameters().size(); if (isExtensionFunction) { @@ -121,14 +117,12 @@ public class CodegenUtil { for (int i = 0; i < paramCount; ++i) { signatureWriter.writeParameterType(JvmMethodParameterKind.VALUE); - signatureWriter.writeAsmType(OBJECT_TYPE, true); + signatureWriter.writeAsmType(OBJECT_TYPE); signatureWriter.writeParameterTypeEnd(); } - signatureWriter.writeParametersEnd(); - signatureWriter.writeReturnType(); - signatureWriter.writeAsmType(OBJECT_TYPE, true); + signatureWriter.writeAsmType(OBJECT_TYPE); signatureWriter.writeReturnTypeEnd(); return signatureWriter.makeJvmMethodSignature("invoke"); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ConstructorFrameMap.java b/compiler/backend/src/org/jetbrains/jet/codegen/ConstructorFrameMap.java index 16157825090..506b8cbfb4d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ConstructorFrameMap.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ConstructorFrameMap.java @@ -21,8 +21,6 @@ import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind; import org.jetbrains.jet.codegen.signature.JvmMethodParameterSignature; import org.jetbrains.jet.codegen.signature.JvmMethodSignature; -import java.util.List; - import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE; public class ConstructorFrameMap extends FrameMap { @@ -31,18 +29,15 @@ public class ConstructorFrameMap extends FrameMap { public ConstructorFrameMap(@NotNull JvmMethodSignature signature) { enterTemp(OBJECT_TYPE); // this - List parameterTypes = signature.getKotlinParameterTypes(); - if (parameterTypes != null) { - for (JvmMethodParameterSignature parameterType : parameterTypes) { - if (parameterType.getKind() == JvmMethodParameterKind.OUTER) { - myOuterThisIndex = enterTemp(OBJECT_TYPE); // this0 - } - else if (parameterType.getKind() != JvmMethodParameterKind.VALUE) { - enterTemp(parameterType.getAsmType()); - } - else { - break; - } + for (JvmMethodParameterSignature parameterType : signature.getKotlinParameterTypes()) { + if (parameterType.getKind() == JvmMethodParameterKind.OUTER) { + myOuterThisIndex = enterTemp(OBJECT_TYPE); // this0 + } + else if (parameterType.getKind() != JvmMethodParameterKind.VALUE) { + enterTemp(parameterType.getAsmType()); + } + else { + break; } } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 0293cf26e12..d33cfd4d48b 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -355,12 +355,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { typeMapper.writeFormalTypeParameters(typeParameters, signatureVisitor); } - signatureVisitor.writeSupersStart(); - { // superclass signatureVisitor.writeSuperclass(); if (superClassType == null) { - signatureVisitor.writeClassBegin(superClassAsmType.getInternalName(), false, false); + signatureVisitor.writeClassBegin(superClassAsmType); signatureVisitor.writeClassEnd(); } else { @@ -388,16 +386,8 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { superInterfaces = new ArrayList(superInterfacesLinkedHashSet); } - signatureVisitor.writeSupersEnd(); - - return new JvmClassSignature(jvmName(), superClassAsmType.getInternalName(), superInterfaces, signatureVisitor.makeJavaGenericSignature()); - } - - private String jvmName() { - if (kind != OwnerKind.IMPLEMENTATION) { - throw new IllegalStateException("must not call this method with kind " + kind); - } - return classAsmType.getInternalName(); + return new JvmClassSignature(classAsmType.getInternalName(), superClassAsmType.getInternalName(), superInterfaces, + signatureVisitor.makeJavaGenericSignature()); } protected void getSuperClass() { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java b/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java index 6fa61d3933e..620f6746312 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java @@ -25,22 +25,13 @@ import org.jetbrains.asm4.signature.SignatureVisitor; import org.jetbrains.asm4.signature.SignatureWriter; import org.jetbrains.asm4.util.CheckSignatureAdapter; import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants; -import org.jetbrains.jet.lang.resolve.java.JetSignatureUtils; import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.types.Variance; -import org.jetbrains.jet.rt.signature.JetSignatureAdapter; -import org.jetbrains.jet.rt.signature.JetSignatureReader; -import org.jetbrains.jet.rt.signature.JetSignatureVariance; -import org.jetbrains.jet.rt.signature.JetSignatureWriter; import java.util.ArrayList; import java.util.List; - public class BothSignatureWriter { - - private static final boolean DEBUG_SIGNATURE_WRITER = true; - public enum Mode { METHOD(CheckSignatureAdapter.METHOD_SIGNATURE), CLASS(CheckSignatureAdapter.CLASS_SIGNATURE), @@ -53,27 +44,9 @@ public class BothSignatureWriter { } } - private enum State { - START, - TYPE_PARAMETERS, - - PARAMETERS, - PARAMETER, - RETURN_TYPE, - METHOD_END, - - FIELD, - FIELD_END, - - SUPERS, - CLASS_END, - } - private final SignatureWriter signatureWriter = new SignatureWriter(); private final SignatureVisitor signatureVisitor; - private JetSignatureWriter jetSignatureWriter; - private final List kotlinParameterTypes = new ArrayList(); private int jvmCurrentTypeArrayLevel; @@ -82,26 +55,16 @@ public class BothSignatureWriter { private JvmMethodParameterKind currentParameterKind; - private final Mode mode; private final boolean needGenerics; - private State state = State.START; - private boolean generic = false; public BothSignatureWriter(Mode mode, boolean needGenerics) { - this.mode = mode; this.needGenerics = needGenerics; - if (DEBUG_SIGNATURE_WRITER) { - signatureVisitor = new CheckSignatureAdapter(mode.asmType, signatureWriter); - } - else { - signatureVisitor = signatureWriter; - } + this.signatureVisitor = new CheckSignatureAdapter(mode.asmType, signatureWriter); } - // TODO: ignore when debugging is disabled private final Stack visitors = new Stack(); private void push(SignatureVisitor visitor) { @@ -112,96 +75,39 @@ public class BothSignatureWriter { visitors.pop(); } - private SignatureVisitor signatureVisitor() { return !visitors.isEmpty() ? visitors.peek() : signatureVisitor; } - private void checkTopLevel() { - if (DEBUG_SIGNATURE_WRITER) { - if (!visitors.isEmpty()) { - throw new IllegalStateException(); - } - } - } - - private void checkMode(Mode mode) { - if (DEBUG_SIGNATURE_WRITER) { - if (mode != this.mode) { - throw new IllegalStateException(); - } - } - } - - private void checkState(State state) { - if (DEBUG_SIGNATURE_WRITER) { - if (state != this.state) { - throw new IllegalStateException(); - } - if (jetSignatureWriter != null) { - throw new IllegalStateException(); - } - checkTopLevel(); - } - } - - private void transitionState(State from, State to) { - checkState(from); - state = to; - } - - public void writeAsmType(Type asmType, boolean nullable) { - writeAsmType(asmType, nullable, null); - } - /** * Shortcut */ - public void writeAsmType(Type asmType, boolean nullable, @Nullable String kotlinTypeName) { + public void writeAsmType(Type asmType) { switch (asmType.getSort()) { case Type.OBJECT: - writeClassBegin(asmType.getInternalName(), nullable, false, kotlinTypeName); + writeClassBegin(asmType); writeClassEnd(); return; case Type.ARRAY: - writeArrayType(nullable, Variance.INVARIANT); - writeAsmType(asmType.getElementType(), false, kotlinTypeName); + writeArrayType(); + writeAsmType(asmType.getElementType()); writeArrayEnd(); return; default: - String descriptor = asmType.getDescriptor(); - if (descriptor.length() != 1) { - throw new IllegalStateException(); - } - writeBaseType(descriptor.charAt(0), nullable); + signatureVisitor().visitBaseType(asmType.getDescriptor().charAt(0)); + writeAsmType0(asmType); } } - private void writeBaseType(char c, boolean nullable) { - if (nullable) { - throw new IllegalStateException(); - } - signatureVisitor().visitBaseType(c); - jetSignatureWriter.visitBaseType(c, nullable); - writeAsmType0(Type.getType(String.valueOf(c))); + public void writeNothing() { + signatureVisitor().visitBaseType('V'); + writeAsmType0(Type.VOID_TYPE); } - public void writeNothing(boolean nullable) { - if (nullable) { - signatureVisitor().visitClassType("java/lang/Object"); - signatureVisitor().visitEnd(); - } - else { - signatureVisitor().visitBaseType('V'); - } - jetSignatureWriter.visitClassType("jet/Nothing", nullable, false); - jetSignatureWriter.visitEnd(); - if (nullable) { - writeAsmType0(AsmTypeConstants.OBJECT_TYPE); - } - else { - writeAsmType0(Type.VOID_TYPE); - } + public void writeNullableNothing() { + signatureVisitor().visitClassType("java/lang/Object"); + signatureVisitor().visitEnd(); + writeAsmType0(AsmTypeConstants.OBJECT_TYPE); } private String makeArrayPrefix() { @@ -218,24 +124,17 @@ public class BothSignatureWriter { } } - public void writeClassBegin(String internalName, boolean nullable, boolean real) { - writeClassBegin(internalName, nullable, real, null); - } - - public void writeClassBegin(String internalName, boolean nullable, boolean real, @Nullable String kotlinTypeName) { - signatureVisitor().visitClassType(internalName); - jetSignatureWriter.visitClassType(kotlinTypeName == null ? internalName : kotlinTypeName, nullable, real); - writeAsmType0(Type.getObjectType(internalName)); + public void writeClassBegin(Type asmType) { + signatureVisitor().visitClassType(asmType.getInternalName()); + writeAsmType0(asmType); } public void writeClassEnd() { signatureVisitor().visitEnd(); - jetSignatureWriter.visitEnd(); } - public void writeArrayType(boolean nullable, Variance projectionKind) { + public void writeArrayType() { push(signatureVisitor().visitArrayType()); - jetSignatureWriter.visitArrayType(nullable, toJetSignatureVariance(projectionKind)); if (jvmCurrentType == null) { ++jvmCurrentTypeArrayLevel; } @@ -245,25 +144,18 @@ public class BothSignatureWriter { pop(); } - private static JetSignatureVariance toJetSignatureVariance(Variance variance) { + private static char toJvmVariance(@NotNull Variance variance) { switch (variance) { - case INVARIANT: - return JetSignatureVariance.INVARIANT; - case IN_VARIANCE: - return JetSignatureVariance.IN; - case OUT_VARIANCE: - return JetSignatureVariance.OUT; - default: - throw new IllegalStateException(); + case INVARIANT: return '='; + case IN_VARIANCE: return '-'; + case OUT_VARIANCE: return '+'; + default: throw new IllegalStateException("Unknown variance: " + variance); } } - public void writeTypeArgument(Variance projectionKindForKotlin, Variance projectionKindForJava) { - push(signatureVisitor().visitTypeArgument( - toJetSignatureVariance(projectionKindForJava).getChar() - )); + public void writeTypeArgument(@NotNull Variance projectionKind) { + push(signatureVisitor().visitTypeArgument(toJvmVariance(projectionKind))); - jetSignatureWriter.visitTypeArgument(toJetSignatureVariance(projectionKindForKotlin)); generic = true; } @@ -271,49 +163,20 @@ public class BothSignatureWriter { pop(); } - public void writeTypeVariable(Name name, boolean nullable, Type asmType) { + public void writeTypeVariable(Name name, Type asmType) { signatureVisitor().visitTypeVariable(name.asString()); - jetSignatureWriter.visitTypeVariable(name.asString(), nullable); generic = true; writeAsmType0(asmType); } - public void writeFormalTypeParameter(String name, Variance variance, boolean reified) { - checkTopLevel(); - + public void writeFormalTypeParameter(String name) { signatureVisitor().visitFormalTypeParameter(name); - jetSignatureWriter.visitFormalTypeParameter(name, JetSignatureUtils.translateVariance(variance), reified); generic = true; } - public void writeFormalTypeParameterEnd() { - jetSignatureWriter.visitFormalTypeParameterEnd(); - } - - public void writeFormalTypeParametersStart() { - checkTopLevel(); - transitionState(State.START, State.TYPE_PARAMETERS); - jetSignatureWriter = new JetSignatureWriter(); - } - - public void writeFormalTypeParametersEnd() { - jetSignatureWriter.visitSuperclass(); // just to call endFormals - - String kotlinClassParameters = jetSignatureWriter.toString(); - - jetSignatureWriter = null; - - if (DEBUG_SIGNATURE_WRITER) { - new JetSignatureReader(kotlinClassParameters).acceptFormalTypeParametersOnly(new JetSignatureAdapter()); - } - - checkState(State.TYPE_PARAMETERS); - } - public void writeClassBound() { push(signatureVisitor().visitClassBound()); - jetSignatureWriter.visitClassBound(); } public void writeClassBoundEnd() { @@ -322,7 +185,6 @@ public class BothSignatureWriter { public void writeInterfaceBound() { push(signatureVisitor().visitInterfaceBound()); - jetSignatureWriter.visitInterfaceBound(); } public void writeInterfaceBoundEnd() { @@ -330,30 +192,12 @@ public class BothSignatureWriter { } public void writeParametersStart() { - transitionState(State.TYPE_PARAMETERS, State.PARAMETERS); - // hacks jvmCurrentType = null; jvmCurrentTypeArrayLevel = 0; } - public void writeParametersEnd() { - checkState(State.PARAMETERS); - } - - public void writeFieldTypeStart() { - transitionState(State.START, State.FIELD); - jetSignatureWriter = new JetSignatureWriter(); - } - - public void writeFieldTypeEnd() { - jetSignatureWriter = null; - transitionState(State.FIELD, State.FIELD_END); - } - public void writeParameterType(JvmMethodParameterKind parameterKind) { - transitionState(State.PARAMETERS, State.PARAMETER); - // This magic mimics the behavior of javac that enum constructor have these synthetic parameters in erased signature, but doesn't // have them in generic signature. IDEA relies on this behavior. if (parameterKind == JvmMethodParameterKind.ENUM_NAME || parameterKind == JvmMethodParameterKind.ENUM_ORDINAL) { @@ -366,127 +210,50 @@ public class BothSignatureWriter { push(signatureVisitor().visitParameterType()); } - jetSignatureWriter = new JetSignatureWriter(); - if (jvmCurrentType != null || jvmCurrentTypeArrayLevel != 0) { - throw new IllegalStateException(); - } - - if (currentParameterKind != null) { - throw new IllegalStateException(); - } this.currentParameterKind = parameterKind; - - //jetSignatureWriter.visitParameterType(); } public void writeParameterTypeEnd() { pop(); - if (jvmCurrentType == null) { - throw new IllegalStateException(); - } - - String signature = jetSignatureWriter.toString(); - kotlinParameterTypes.add(new JvmMethodParameterSignature(jvmCurrentType, signature, currentParameterKind)); - - if (DEBUG_SIGNATURE_WRITER) { - new JetSignatureReader(signature).acceptTypeOnly(new JetSignatureAdapter()); - } + kotlinParameterTypes.add(new JvmMethodParameterSignature(jvmCurrentType, currentParameterKind)); currentParameterKind = null; jvmCurrentType = null; jvmCurrentTypeArrayLevel = 0; - - jetSignatureWriter = null; - transitionState(State.PARAMETER, State.PARAMETERS); } public void writeReturnType() { - transitionState(State.PARAMETERS, State.RETURN_TYPE); - - jetSignatureWriter = new JetSignatureWriter(); - - if (jvmCurrentType != null) { - throw new IllegalStateException(); - } - push(signatureVisitor().visitReturnType()); - //jetSignatureWriter.visitReturnType(); } public void writeReturnTypeEnd() { pop(); - String kotlinReturnType = jetSignatureWriter.toString(); - - if (jvmCurrentType == null) { - throw new IllegalStateException(); - } - jvmReturnType = jvmCurrentType; jvmCurrentType = null; jvmCurrentTypeArrayLevel = 0; - - if (DEBUG_SIGNATURE_WRITER) { - new JetSignatureReader(kotlinReturnType).acceptTypeOnly(new JetSignatureAdapter()); - } - - jetSignatureWriter = null; - transitionState(State.RETURN_TYPE, State.METHOD_END); - } - - public void writeVoidReturn() { - writeReturnType(); - writeAsmType(Type.VOID_TYPE, false); - writeReturnTypeEnd(); - } - - public void writeSupersStart() { - transitionState(State.TYPE_PARAMETERS, State.SUPERS); - jetSignatureWriter = new JetSignatureWriter(); - } - - public void writeSupersEnd() { - String kotlinClassSignature = jetSignatureWriter.toString(); - jetSignatureWriter = null; - - if (DEBUG_SIGNATURE_WRITER) { - new JetSignatureReader(kotlinClassSignature).accept(new JetSignatureAdapter()); - } - - transitionState(State.SUPERS, State.CLASS_END); } public void writeSuperclass() { push(signatureVisitor().visitSuperclass()); - jetSignatureWriter.visitSuperclass(); } public void writeSuperclassEnd() { pop(); - if (!visitors.isEmpty()) { - throw new IllegalStateException(); - } } public void writeInterface() { - checkTopLevel(); - checkMode(Mode.CLASS); - push(signatureVisitor().visitInterface()); - jetSignatureWriter.visitInterface(); } public void writeInterfaceEnd() { pop(); - if (!visitors.isEmpty()) { - throw new IllegalStateException(); - } } @NotNull - protected Method makeAsmMethod(String name) { + private Method makeAsmMethod(String name) { List jvmParameterTypes = new ArrayList(kotlinParameterTypes.size()); for (JvmMethodParameterSignature p : kotlinParameterTypes) { jvmParameterTypes.add(p.getAsmType()); @@ -496,26 +263,15 @@ public class BothSignatureWriter { @Nullable public String makeJavaGenericSignature() { - if (state != State.METHOD_END && state != State.CLASS_END && state != State.FIELD_END) { - throw new IllegalStateException(); - } - checkTopLevel(); return generic ? signatureWriter.toString() : null; } - @NotNull - protected List makeKotlinParameterTypes() { - checkState(State.METHOD_END); - // TODO: return nulls if equal to #makeJavaString - return kotlinParameterTypes; - } - @NotNull public JvmMethodSignature makeJvmMethodSignature(String name) { return new JvmMethodSignature( makeAsmMethod(name), needGenerics ? makeJavaGenericSignature() : null, - makeKotlinParameterTypes() + kotlinParameterTypes ); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/signature/JvmMethodParameterSignature.java b/compiler/backend/src/org/jetbrains/jet/codegen/signature/JvmMethodParameterSignature.java index ac0fbf5b7b0..6c01644ec47 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/signature/JvmMethodParameterSignature.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/signature/JvmMethodParameterSignature.java @@ -25,9 +25,7 @@ public class JvmMethodParameterSignature { @NotNull private final JvmMethodParameterKind kind; - public JvmMethodParameterSignature( - @NotNull Type asmType, @NotNull String kotlinSignature, @NotNull JvmMethodParameterKind kind - ) { + public JvmMethodParameterSignature(@NotNull Type asmType, @NotNull JvmMethodParameterKind kind) { this.asmType = asmType; this.kind = kind; } 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 c1420fcc804..bad2ade8d12 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/state/JetTypeMapper.java @@ -181,19 +181,19 @@ public class JetTypeMapper extends BindingTraceAware { private Type mapReturnType(@NotNull JetType jetType, @Nullable BothSignatureWriter signatureVisitor) { if (jetType.equals(KotlinBuiltIns.getInstance().getUnitType())) { if (signatureVisitor != null) { - signatureVisitor.writeAsmType(Type.VOID_TYPE, false); + signatureVisitor.writeAsmType(Type.VOID_TYPE); } return Type.VOID_TYPE; } else if (jetType.equals(KotlinBuiltIns.getInstance().getNothingType())) { if (signatureVisitor != null) { - signatureVisitor.writeNothing(false); + signatureVisitor.writeNothing(); } return Type.VOID_TYPE; } if (jetType.equals(KotlinBuiltIns.getInstance().getNullableNothingType())) { if (signatureVisitor != null) { - signatureVisitor.writeNothing(true); + signatureVisitor.writeNullableNothing(); } return AsmTypeConstants.OBJECT_TYPE; } @@ -289,7 +289,7 @@ public class JetTypeMapper extends BindingTraceAware { } Type asmType = Type.getObjectType("error/NonExistentClass"); if (signatureVisitor != null) { - signatureVisitor.writeAsmType(asmType, true); + signatureVisitor.writeAsmType(asmType); } checkValidType(asmType); return asmType; @@ -303,7 +303,7 @@ public class JetTypeMapper extends BindingTraceAware { JetType memberType = memberProjection.getType(); if (signatureVisitor != null) { - signatureVisitor.writeArrayType(jetType.isNullable(), memberProjection.getProjectionKind()); + signatureVisitor.writeArrayType(); mapType(memberType, signatureVisitor, JetTypeMapperMode.TYPE_PARAMETER, memberProjection.getProjectionKind(), true); signatureVisitor.writeArrayEnd(); } @@ -328,9 +328,8 @@ public class JetTypeMapper extends BindingTraceAware { else { asmType = name.getAsmType(); } - boolean forceReal = KotlinToJavaTypesMap.getInstance().isForceReal(name); - writeGenericType(signatureVisitor, asmType, jetType, forceReal, howThisTypeIsUsed); + writeGenericType(signatureVisitor, asmType, jetType, howThisTypeIsUsed); checkValidType(asmType); return asmType; @@ -340,7 +339,7 @@ public class JetTypeMapper extends BindingTraceAware { TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) descriptor; Type type = mapType(typeParameterDescriptor.getUpperBoundsAsType(), kind); if (signatureVisitor != null) { - signatureVisitor.writeTypeVariable(typeParameterDescriptor.getName(), jetType.isNullable(), type); + signatureVisitor.writeTypeVariable(typeParameterDescriptor.getName(), type); } checkValidType(type); return type; @@ -371,24 +370,21 @@ public class JetTypeMapper extends BindingTraceAware { BothSignatureWriter signatureVisitor, Type asmType, JetType jetType, - boolean forceReal, Variance howThisTypeIsUsed ) { if (signatureVisitor != null) { - String kotlinTypeName = getKotlinTypeNameForSignature(jetType, asmType); - signatureVisitor.writeClassBegin(asmType.getInternalName(), jetType.isNullable(), forceReal, kotlinTypeName); + signatureVisitor.writeClassBegin(asmType); List arguments = jetType.getArguments(); for (TypeParameterDescriptor parameter : jetType.getConstructor().getParameters()) { TypeProjection argument = arguments.get(parameter.getIndex()); - Variance projectionKindForKotlin = argument.getProjectionKind(); - Variance projectionKindForJava = getEffectiveVariance( + Variance projectionKind = getEffectiveVariance( parameter.getVariance(), - projectionKindForKotlin, + argument.getProjectionKind(), howThisTypeIsUsed ); - signatureVisitor.writeTypeArgument(projectionKindForKotlin, projectionKindForJava); + signatureVisitor.writeTypeArgument(projectionKind); mapType(argument.getType(), signatureVisitor, JetTypeMapperMode.TYPE_PARAMETER); signatureVisitor.writeTypeArgumentEnd(); @@ -434,40 +430,19 @@ public class JetTypeMapper extends BindingTraceAware { ) { if (signatureVisitor != null) { if (jetType.getArguments().isEmpty()) { - if (arrayParameter - && (howThisTypeIsUsed == Variance.IN_VARIANCE)) { + if (arrayParameter && howThisTypeIsUsed == Variance.IN_VARIANCE) { asmType = AsmTypeConstants.OBJECT_TYPE; } - String kotlinTypeName = getKotlinTypeNameForSignature(jetType, asmType, arrayParameter); - signatureVisitor.writeAsmType(asmType, jetType.isNullable(), kotlinTypeName); + signatureVisitor.writeAsmType(asmType); } else { - writeGenericType(signatureVisitor, asmType, jetType, false, howThisTypeIsUsed); + writeGenericType(signatureVisitor, asmType, jetType, howThisTypeIsUsed); } } checkValidType(asmType); return asmType; } - @Nullable - private static String getKotlinTypeNameForSignature(@NotNull JetType jetType, @NotNull Type asmType) { - return getKotlinTypeNameForSignature(jetType, asmType, false); - } - - @Nullable - private static String getKotlinTypeNameForSignature(@NotNull JetType jetType, @NotNull Type asmType, boolean arrayParameter) { - ClassifierDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor(); - if (descriptor == null) return null; - if (asmType.getSort() != Type.OBJECT) return null; - - JvmClassName jvmClassName = JvmClassName.byType(asmType); - if ((arrayParameter && JavaToKotlinClassMap.getInstance().mapPlatformClass(jvmClassName.getFqName()).size() >= 1) - || ((!arrayParameter) && JavaToKotlinClassMap.getInstance().mapPlatformClass(jvmClassName.getFqName()).size() > 1)) { - return JvmClassName.byClassDescriptor(descriptor).getSignatureName(); - } - return null; - } - private void checkValidType(@NotNull Type type) { if (!mapBuiltinsToJava) { String descriptor = type.getDescriptor(); @@ -653,10 +628,8 @@ public class JetTypeMapper extends BindingTraceAware { writeParameter(signatureVisitor, parameter.getType()); } - signatureVisitor.writeParametersEnd(); - if (f instanceof ConstructorDescriptor) { - signatureVisitor.writeVoidReturn(); + writeVoidReturn(signatureVisitor); } else { signatureVisitor.writeReturnType(); @@ -669,12 +642,16 @@ public class JetTypeMapper extends BindingTraceAware { return signatureVisitor.makeJvmMethodSignature(methodName); } + private static void writeVoidReturn(@NotNull BothSignatureWriter signatureVisitor) { + signatureVisitor.writeReturnType(); + signatureVisitor.writeAsmType(Type.VOID_TYPE); + signatureVisitor.writeReturnTypeEnd(); + } + @Nullable public String mapFieldSignature(@NotNull JetType backingFieldType) { BothSignatureWriter signatureVisitor = new BothSignatureWriter(BothSignatureWriter.Mode.TYPE, true); - signatureVisitor.writeFieldTypeStart(); mapType(backingFieldType, signatureVisitor, JetTypeMapperMode.VALUE); - signatureVisitor.writeFieldTypeEnd(); return signatureVisitor.makeJavaGenericSignature(); } @@ -688,7 +665,7 @@ public class JetTypeMapper extends BindingTraceAware { Type type = getTraitImplThisParameterType(containingDeclaration, this); signatureVisitor.writeParameterType(JvmMethodParameterKind.THIS); - signatureVisitor.writeAsmType(type, false); + signatureVisitor.writeAsmType(type); signatureVisitor.writeParameterTypeEnd(); } else { @@ -706,20 +683,15 @@ public class JetTypeMapper extends BindingTraceAware { public void writeFormalTypeParameters(List typeParameters, BothSignatureWriter signatureVisitor) { - if (signatureVisitor == null) { - return; - } + if (signatureVisitor == null) return; - signatureVisitor.writeFormalTypeParametersStart(); for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) { writeFormalTypeParameter(typeParameterDescriptor, signatureVisitor); } - signatureVisitor.writeFormalTypeParametersEnd(); } private void writeFormalTypeParameter(TypeParameterDescriptor typeParameterDescriptor, BothSignatureWriter signatureVisitor) { - signatureVisitor.writeFormalTypeParameter(typeParameterDescriptor.getName().asString(), typeParameterDescriptor.getVariance(), - typeParameterDescriptor.isReified()); + signatureVisitor.writeFormalTypeParameter(typeParameterDescriptor.getName().asString()); classBound: { @@ -755,11 +727,8 @@ public class JetTypeMapper extends BindingTraceAware { signatureVisitor.writeInterfaceBoundEnd(); } } - - signatureVisitor.writeFormalTypeParameterEnd(); } - private void writeReceiverIfNeeded(@Nullable ReceiverParameterDescriptor receiver, BothSignatureWriter signatureWriter) { if (receiver != null) { signatureWriter.writeParameterType(JvmMethodParameterKind.RECEIVER); @@ -787,7 +756,6 @@ public class JetTypeMapper extends BindingTraceAware { signatureWriter.writeParametersStart(); writeThisIfNeeded(descriptor, kind, signatureWriter); writeReceiverIfNeeded(descriptor.getReceiverParameter(), signatureWriter); - signatureWriter.writeParametersEnd(); signatureWriter.writeReturnType(); mapType(descriptor.getType(), signatureWriter, JetTypeMapperMode.VALUE, Variance.OUT_VARIANCE); @@ -811,9 +779,8 @@ public class JetTypeMapper extends BindingTraceAware { writeThisIfNeeded(descriptor, kind, signatureWriter); writeReceiverIfNeeded(descriptor.getReceiverParameter(), signatureWriter); writeParameter(signatureWriter, descriptor.getType()); - signatureWriter.writeParametersEnd(); - signatureWriter.writeVoidReturn(); + writeVoidReturn(signatureWriter); String name = getPropertyAccessorName(descriptor, false); return signatureWriter.makeJvmMethodSignature(name); @@ -881,7 +848,7 @@ public class JetTypeMapper extends BindingTraceAware { if (type != null) { signatureWriter.writeParameterType(JvmMethodParameterKind.SHARED_VAR); - signatureWriter.writeAsmType(type, false); + signatureWriter.writeAsmType(type); signatureWriter.writeParameterTypeEnd(); } } @@ -901,7 +868,7 @@ public class JetTypeMapper extends BindingTraceAware { if (types != null) { for (JvmMethodParameterSignature type : types) { signatureWriter.writeParameterType(JvmMethodParameterKind.SUPER_CALL_PARAM); - signatureWriter.writeAsmType(type.getAsmType(), false); + signatureWriter.writeAsmType(type.getAsmType()); signatureWriter.writeParameterTypeEnd(); } } @@ -914,9 +881,7 @@ public class JetTypeMapper extends BindingTraceAware { writeParameter(signatureWriter, parameter.getType()); } - signatureWriter.writeParametersEnd(); - - signatureWriter.writeVoidReturn(); + writeVoidReturn(signatureWriter); return signatureWriter.makeJvmMethodSignature(""); } @@ -941,9 +906,7 @@ public class JetTypeMapper extends BindingTraceAware { writeParameter(signatureWriter, valueParameter.getType()); } - signatureWriter.writeParametersEnd(); - - signatureWriter.writeVoidReturn(); + writeVoidReturn(signatureWriter); return signatureWriter.makeJvmMethodSignature(""); } diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java index 0276d99ab8a..48f043cdd77 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaTypeTransformer.java @@ -29,7 +29,6 @@ import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns; -import org.jetbrains.jet.rt.signature.JetSignatureReader; import javax.inject.Inject; import java.util.Collections; diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetSignatureUtils.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetSignatureUtils.java deleted file mode 100644 index 92c7a37b150..00000000000 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JetSignatureUtils.java +++ /dev/null @@ -1,41 +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.lang.resolve.java; - -import jet.typeinfo.TypeInfoVariance; -import org.jetbrains.jet.lang.types.Variance; - -public class JetSignatureUtils { - - static { - if (Variance.INVARIANT.ordinal() != TypeInfoVariance.INVARIANT.ordinal()) - throw new IllegalStateException(); - if (Variance.IN_VARIANCE.ordinal() != TypeInfoVariance.IN.ordinal()) - throw new IllegalStateException(); - if (Variance.OUT_VARIANCE.ordinal() != TypeInfoVariance.OUT.ordinal()) - throw new IllegalStateException(); - } - - public static TypeInfoVariance translateVariance(Variance variance) { - return TypeInfoVariance.values()[variance.ordinal()]; - } - - public static Variance translateVariance(TypeInfoVariance variance) { - return Variance.values()[variance.ordinal()]; - } - -} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java index 6a2f7f622b1..46dbb679296 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptor.java @@ -27,6 +27,7 @@ import java.util.Set; public interface TypeParameterDescriptor extends ClassifierDescriptor { boolean isReified(); + @NotNull Variance getVariance(); @NotNull diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/impl/TypeParameterDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/impl/TypeParameterDescriptorImpl.java index 36dc836625b..dbf5112a487 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/impl/TypeParameterDescriptorImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/impl/TypeParameterDescriptorImpl.java @@ -124,6 +124,7 @@ public class TypeParameterDescriptorImpl extends DeclarationDescriptorNonRootImp } @Override + @NotNull public Variance getVariance() { return variance; } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/AbstractLazyTypeParameterDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/AbstractLazyTypeParameterDescriptor.java index a840a56ec42..fbc55608ba4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/AbstractLazyTypeParameterDescriptor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/AbstractLazyTypeParameterDescriptor.java @@ -97,6 +97,7 @@ public abstract class AbstractLazyTypeParameterDescriptor implements TypeParamet return reified; } + @NotNull @Override public Variance getVariance() { return variance; diff --git a/runtime/src/jet/typeinfo/TypeInfoVariance.java b/runtime/src/jet/typeinfo/TypeInfoVariance.java deleted file mode 100644 index c70b526df25..00000000000 --- a/runtime/src/jet/typeinfo/TypeInfoVariance.java +++ /dev/null @@ -1,38 +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 jet.typeinfo; - -import org.jetbrains.jet.rt.signature.JetSignatureVariance; - -public enum TypeInfoVariance { - INVARIANT("", JetSignatureVariance.INVARIANT) , - IN("in", JetSignatureVariance.IN), - OUT("out", JetSignatureVariance.OUT); - - private final String label; - private final JetSignatureVariance variance; - - TypeInfoVariance(String label, JetSignatureVariance variance) { - this.label = label; - this.variance = variance; - } - - @Override - public String toString() { - return label; - } -} diff --git a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureAdapter.java b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureAdapter.java deleted file mode 100644 index 4d753d62057..00000000000 --- a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureAdapter.java +++ /dev/null @@ -1,99 +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.rt.signature; - -import jet.typeinfo.TypeInfoVariance; - -public class JetSignatureAdapter implements JetSignatureVisitor { - @Override - public JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance, boolean reified) { - return this; - } - - @Override - public void visitFormalTypeParameterEnd() { - } - - @Override - public JetSignatureVisitor visitClassBound() { - return this; - } - - @Override - public JetSignatureVisitor visitInterfaceBound() { - return this; - } - - @Override - public JetSignatureVisitor visitSuperclass() { - return this; - } - - @Override - public JetSignatureVisitor visitInterface() { - return this; - } - - @Override - public JetSignatureVisitor visitParameterType() { - return this; - } - - @Override - public JetSignatureVisitor visitReturnType() { - return this; - } - - @Override - public JetSignatureVisitor visitExceptionType() { - return this; - } - - @Override - public void visitBaseType(char descriptor, boolean nullable) { - } - - @Override - public void visitTypeVariable(String name, boolean nullable) { - } - - @Override - public JetSignatureVisitor visitArrayType(boolean nullable, JetSignatureVariance wildcard) { - return this; - } - - @Override - public void visitClassType(String name, boolean nullable, boolean forceReal) { - } - - @Override - public void visitInnerClassType(String name, boolean nullable, boolean forceReal) { - } - - @Override - public void visitTypeArgument() { - } - - @Override - public JetSignatureVisitor visitTypeArgument(JetSignatureVariance wildcard) { - return this; - } - - @Override - public void visitEnd() { - } -} diff --git a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureExceptionsAdapter.java b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureExceptionsAdapter.java deleted file mode 100644 index 4a0d6fbd222..00000000000 --- a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureExceptionsAdapter.java +++ /dev/null @@ -1,106 +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.rt.signature; - -import jet.typeinfo.TypeInfoVariance; - -public class JetSignatureExceptionsAdapter implements JetSignatureVisitor { - @Override - public JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance, boolean reified) { - throw new IllegalStateException(); - } - - @Override - public void visitFormalTypeParameterEnd() { - throw new IllegalStateException(); - } - - @Override - public JetSignatureVisitor visitClassBound() { - throw new IllegalStateException(); - } - - @Override - public JetSignatureVisitor visitInterfaceBound() { - throw new IllegalStateException(); - } - - @Override - public JetSignatureVisitor visitSuperclass() { - throw new IllegalStateException(); - } - - @Override - public JetSignatureVisitor visitInterface() { - throw new IllegalStateException(); - } - - @Override - public JetSignatureVisitor visitParameterType() { - throw new IllegalStateException(); - } - - @Override - public JetSignatureVisitor visitReturnType() { - throw new IllegalStateException(); - } - - @Override - public JetSignatureVisitor visitExceptionType() { - throw new IllegalStateException(); - } - - @Override - public void visitBaseType(char descriptor, boolean nullable) { - throw new IllegalStateException(); - } - - @Override - public void visitTypeVariable(String name, boolean nullable) { - throw new IllegalStateException(); - } - - @Override - public JetSignatureVisitor visitArrayType(boolean nullable, JetSignatureVariance wildcard) { - throw new IllegalStateException(); - } - - @Override - public void visitClassType(String name, boolean nullable, boolean forceReal) { - throw new IllegalStateException(); - } - - @Override - public void visitInnerClassType(String name, boolean nullable, boolean forceReal) { - throw new IllegalStateException(); - } - - @Override - public void visitTypeArgument() { - throw new IllegalStateException(); - } - - @Override - public JetSignatureVisitor visitTypeArgument(JetSignatureVariance wildcard) { - throw new IllegalStateException(); - } - - @Override - public void visitEnd() { - throw new IllegalStateException(); - } -} diff --git a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureReader.java b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureReader.java deleted file mode 100644 index 97cf2f2513d..00000000000 --- a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureReader.java +++ /dev/null @@ -1,263 +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.rt.signature; - -import jet.typeinfo.TypeInfoVariance; - -/** - * @see SignatureReader - */ -public class JetSignatureReader { - - private final String signature; - - public JetSignatureReader(String signature) { - this.signature = signature; - } - - - public void accept(JetSignatureVisitor v) { - String signature = this.signature; - int len = signature.length(); - int pos = acceptFormalTypeParameters(v); - - if (signature.charAt(pos) == '(') { - pos++; - while (signature.charAt(pos) != ')') { - pos = parseType(signature, pos, v.visitParameterType()); - } - pos = parseType(signature, pos + 1, v.visitReturnType()); - while (pos < len) { - pos = parseType(signature, pos + 1, v.visitExceptionType()); - } - } - else { - pos = parseType(signature, pos, v.visitSuperclass()); - while (pos < len) { - pos = parseType(signature, pos, v.visitInterface()); - } - } - - if (pos != signature.length()) { - throw new IllegalStateException(); - } - } - - public int acceptFormalTypeParameters(JetSignatureVisitor v) { - int pos; - char c; - if (signature.length() > 0 && signature.charAt(0) == '<') { - pos = 1; - do { - TypeInfoVariance variance; - boolean reified = true; - - if (signature.substring(pos).startsWith("erased ")) { - reified = false; - pos += "erased ".length(); - } - if (signature.substring(pos).startsWith("in ")) { - variance = TypeInfoVariance.IN; - pos += "in ".length(); - } - else if (signature.substring(pos).startsWith("out ")) { - variance = TypeInfoVariance.OUT; - pos += "out ".length(); - } - else { - variance = TypeInfoVariance.INVARIANT; - pos += "".length(); - } - int end = signature.indexOf(':', pos); - if (end < 0) { - throw new IllegalStateException(); - } - String typeParameterName = signature.substring(pos, end); - if (typeParameterName.isEmpty()) { - throw new IllegalStateException("incorrect signature: " + signature); - } - JetSignatureVisitor parameterVisitor = v.visitFormalTypeParameter(typeParameterName, variance, reified); - pos = end + 1; - - c = signature.charAt(pos); - if (c == 'L' || c == 'M' || c == '[' || c == 'T' || c == '?') { - pos = parseType(signature, pos, parameterVisitor.visitClassBound()); - } - - while ((c = signature.charAt(pos)) == ':') { - ++pos; - pos = parseType(signature, pos, parameterVisitor.visitInterfaceBound()); - } - - parameterVisitor.visitFormalTypeParameterEnd(); - } while (c != '>'); - ++pos; - } - else { - pos = 0; - } - return pos; - } - - public void acceptFormalTypeParametersOnly(JetSignatureVisitor v) { - int r = acceptFormalTypeParameters(v); - if (r != signature.length()) { - throw new IllegalStateException(); - } - } - - public int acceptType(JetSignatureVisitor v) { - return parseType(this.signature, 0, v); - } - - public void acceptTypeOnly(JetSignatureVisitor v) { - int r = acceptType(v); - if (r != signature.length()) { - throw new IllegalStateException(); - } - } - - - private static int parseType( - String signature, - int pos, - JetSignatureVisitor v) - { - if (signature.length() == 0) { - throw new IllegalStateException(); - } - - char c; - int start; - int end; - boolean visited; - boolean inner; - - boolean nullable; - if (signature.charAt(pos) == '?') { - nullable = true; - pos++; - } - else { - nullable = false; - } - - switch (c = signature.charAt(pos++)) { - case 'Z': - case 'C': - case 'B': - case 'S': - case 'I': - case 'F': - case 'J': - case 'D': - case 'V': - v.visitBaseType(c, nullable); - return pos; - - case '[': - switch (c = signature.charAt(pos)) { - case '+': - case '-': - return parseType(signature, pos + 1, v.visitArrayType(nullable, JetSignatureVariance.parseVariance(c))); - default: - return parseType(signature, pos, v.visitArrayType(nullable, JetSignatureVariance.INVARIANT)); - } - - case 'T': - end = signature.indexOf(';', pos); - v.visitTypeVariable(signature.substring(pos, end), nullable); - return end + 1; - - case 'L': - case 'M': - boolean forceReal = signature.charAt(pos - 1) == 'M'; - start = pos; - visited = false; - inner = false; - while (true) { - switch (c = signature.charAt(pos++)) { - case '.': - case ';': - if (!visited) { - parseTypeConstructor(signature, v, start, pos, inner, nullable, forceReal); - } - if (c == ';') { - v.visitEnd(); - return pos; - } - visited = false; - inner = true; - break; - - case '<': - parseTypeConstructor(signature, v, start, pos, inner, nullable, forceReal); - visited = true; - pos = parseTypeArguments(signature, pos, v); - - default: - break; - } - } - default: - throw new IllegalStateException(); - } - } - - private static void parseTypeConstructor( - String signature, - JetSignatureVisitor v, - int start, - int pos, - boolean inner, - boolean nullable, - boolean forceReal - ) { - String name = signature.substring(start, pos - 1); - if (inner) { - v.visitInnerClassType(name, nullable, forceReal); - } - else { - v.visitClassType(name, nullable, forceReal); - } - } - - private static int parseTypeArguments(String signature, int pos, JetSignatureVisitor v) { - char c; - while (true) { - switch (c = signature.charAt(pos)) { - case '>': - return pos; - case '*': - ++pos; - v.visitTypeArgument(); - break; - case '+': - case '-': - pos = parseType(signature, - pos + 1, - v.visitTypeArgument(JetSignatureVariance.parseVariance(c))); - break; - default: - pos = parseType(signature, - pos, - v.visitTypeArgument(JetSignatureVariance.INVARIANT)); - break; - } - } - } -} diff --git a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureVariance.java b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureVariance.java deleted file mode 100644 index bb98984ac55..00000000000 --- a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureVariance.java +++ /dev/null @@ -1,43 +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.rt.signature; - -public enum JetSignatureVariance { - INVARIANT('='), - IN('-'), - OUT('+'), - ; - - private final char c; - - private JetSignatureVariance(char c) { - this.c = c; - } - - public char getChar() { - return c; - } - - public static JetSignatureVariance parseVariance(char c) { - switch (c) { - case '=': return INVARIANT; - case '+': return OUT; - case '-': return IN; - default: throw new IllegalStateException(); - } - } -} diff --git a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureVisitor.java b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureVisitor.java deleted file mode 100644 index 9ce2a872aa2..00000000000 --- a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureVisitor.java +++ /dev/null @@ -1,159 +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.rt.signature; - -import jet.typeinfo.TypeInfoVariance; - -/** - * @see SignatureVisitor - * @url http://confluence.jetbrains.net/display/JET/Jet+Signatures - */ -public interface JetSignatureVisitor { - - /** - * Wildcard for an "extends" type argument. - */ - char EXTENDS = '+'; - - /** - * Wildcard for a "super" type argument. - */ - char SUPER = '-'; - - /** - * Wildcard for a normal type argument. - */ - char INSTANCEOF = '='; - - /** - * Visits a formal type parameter. - * - * TODO should not store reified flag in signature - * - * @param name the name of the formal parameter. - */ - JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance, boolean reified); - - void visitFormalTypeParameterEnd(); - - /** - * Visits the class bound of the last visited formal type parameter. - * - * @return a non null visitor to visit the signature of the class bound. - */ - JetSignatureVisitor visitClassBound(); - - /** - * Visits an interface bound of the last visited formal type parameter. - * - * @return a non null visitor to visit the signature of the interface bound. - */ - JetSignatureVisitor visitInterfaceBound(); - - /** - * Visits the type of the super class. - * - * @return a non null visitor to visit the signature of the super class - * type. - */ - JetSignatureVisitor visitSuperclass(); - - /** - * Visits the type of an interface implemented by the class. - * - * @return a non null visitor to visit the signature of the interface type. - */ - JetSignatureVisitor visitInterface(); - - /** - * Visits the type of a method parameter. - * - * @return a non null visitor to visit the signature of the parameter type. - */ - JetSignatureVisitor visitParameterType(); - - /** - * Visits the return type of the method. - * - * @return a non null visitor to visit the signature of the return type. - */ - JetSignatureVisitor visitReturnType(); - - /** - * Visits the type of a method exception. - * - * @return a non null visitor to visit the signature of the exception type. - */ - JetSignatureVisitor visitExceptionType(); - - /** - * Visits a signature corresponding to a primitive type. - * - * @param descriptor the descriptor of the primitive type, or 'V' for - * void. - */ - void visitBaseType(char descriptor, boolean nullable); - - /** - * Visits a signature corresponding to a type variable. - * - * @param name the name of the type variable. - */ - void visitTypeVariable(String name, boolean nullable); - - /** - * Visits a signature corresponding to an array type. - * - * @return a non null visitor to visit the signature of the array element - * type. - */ - JetSignatureVisitor visitArrayType(boolean nullable, JetSignatureVariance wildcard); - - /** - * Starts the visit of a signature corresponding to a class or interface - * type. - * - * @param name the internal name of the class or interface. - */ - void visitClassType(String name, boolean nullable, boolean forceReal); - - /** - * Visits an inner class. - * - * @param name the full name of the inner class. - */ - void visitInnerClassType(String name, boolean nullable, boolean forceReal); - - /** - * Visits an unbounded type argument of the last visited class or inner - * class type. - */ - void visitTypeArgument(); - - /** - * Visits a type argument of the last visited class or inner class type. - * - * @param wildcard '+', '-' or '='. - * @return a non null visitor to visit the signature of the type argument. - */ - JetSignatureVisitor visitTypeArgument(JetSignatureVariance wildcard); - - /** - * Ends the visit of a signature corresponding to a class or interface type. - */ - void visitEnd(); -} diff --git a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureWriter.java b/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureWriter.java deleted file mode 100644 index dec3d80af53..00000000000 --- a/runtime/src/org/jetbrains/jet/rt/signature/JetSignatureWriter.java +++ /dev/null @@ -1,238 +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.rt.signature; - -import jet.typeinfo.TypeInfoVariance; - -/** - * @see SignatureWriter - */ -public class JetSignatureWriter implements JetSignatureVisitor { - - /** - * Buffer used to construct the signature. - */ - private final StringBuffer buf = new StringBuffer(); - - /** - * Indicates if the signature contains formal type parameters. - */ - private boolean hasFormals; - - /** - * Indicates if the signature contains method parameter types. - */ - private boolean hasParameters; - - /** - * Stack used to keep track of class types that have arguments. Each element - * of this stack is a boolean encoded in one bit. The top of the stack is - * the lowest order bit. Pushing false = *2, pushing true = *2+1, popping = - * /2. - */ - private int argumentStack; - - /** - * Constructs a new {@link SignatureWriter} object. - */ - public JetSignatureWriter() { - } - - // ------------------------------------------------------------------------ - // Implementation of the SignatureVisitor interface - // ------------------------------------------------------------------------ - - @Override - public JetSignatureVisitor visitFormalTypeParameter(String name, TypeInfoVariance variance, boolean reified) { - if (!hasFormals) { - hasFormals = true; - buf.append('<'); - } - if (!reified) { - buf.append("erased "); - } - switch (variance) { - case OUT: - buf.append("out "); - break; - case IN: - buf.append("in "); - break; - case INVARIANT: - break; - default: - throw new IllegalStateException(); - } - buf.append(name); - buf.append(':'); - return this; - } - - @Override - public void visitFormalTypeParameterEnd() { - } - - @Override - public JetSignatureWriter visitClassBound() { - return this; - } - - @Override - public JetSignatureWriter visitInterfaceBound() { - buf.append(':'); - return this; - } - - @Override - public JetSignatureWriter visitSuperclass() { - endFormals(); - return this; - } - - @Override - public JetSignatureWriter visitInterface() { - return this; - } - - @Override - public JetSignatureWriter visitParameterType() { - endFormals(); - if (!hasParameters) { - hasParameters = true; - buf.append('('); - } - return this; - } - - @Override - public JetSignatureWriter visitReturnType() { - endFormals(); - if (!hasParameters) { - buf.append('('); - } - buf.append(')'); - return this; - } - - @Override - public JetSignatureWriter visitExceptionType() { - buf.append('^'); - return this; - } - - private void visitNullabe(boolean nullable) { - if (nullable) { - buf.append('?'); - } - } - - @Override - public void visitBaseType(char descriptor, boolean nullable) { - visitNullabe(nullable); - buf.append(descriptor); - } - - @Override - public void visitTypeVariable(String name, boolean nullable) { - visitNullabe(nullable); - buf.append('T'); - buf.append(name); - buf.append(';'); - } - - @Override - public JetSignatureWriter visitArrayType(boolean nullable, JetSignatureVariance wildcard) { - visitNullabe(nullable); - buf.append('['); - if (wildcard != JetSignatureVariance.INVARIANT) { - buf.append(wildcard.getChar()); - } - return this; - } - - @Override - public void visitClassType(String name, boolean nullable, boolean forceReal) { - visitNullabe(nullable); - buf.append(forceReal ? 'M' : 'L'); - buf.append(name); - argumentStack *= 2; - } - - @Override - public void visitInnerClassType(String name, boolean nullable, boolean forceReal) { - endArguments(); - visitNullabe(nullable); - buf.append('.'); - buf.append(name); - argumentStack *= 2; - } - - @Override - public void visitTypeArgument() { - if (argumentStack % 2 == 0) { - ++argumentStack; - buf.append('<'); - } - buf.append('*'); - } - - @Override - public JetSignatureWriter visitTypeArgument(JetSignatureVariance variance) { - if (argumentStack % 2 == 0) { - ++argumentStack; - buf.append('<'); - } - if (variance != JetSignatureVariance.INVARIANT) { - buf.append(variance.getChar()); - } - return this; - } - - @Override - public void visitEnd() { - endArguments(); - buf.append(';'); - } - - public String toString() { - return buf.toString(); - } - - // ------------------------------------------------------------------------ - // Utility methods - // ------------------------------------------------------------------------ - - /** - * Ends the formal type parameters section of the signature. - */ - private void endFormals() { - if (hasFormals) { - hasFormals = false; - buf.append('>'); - } - } - - /** - * Ends the type arguments of a class or inner class type. - */ - private void endArguments() { - if (argumentStack % 2 != 0) { - buf.append('>'); - } - argumentStack /= 2; - } -}