Minor, remove duplicate method in ExpressionCodegen

This commit is contained in:
Alexander Udalov
2014-09-02 14:55:15 +04:00
parent 937404239e
commit 8c781e5d14
3 changed files with 16 additions and 29 deletions
@@ -339,13 +339,17 @@ public class AsmUtil {
} }
} }
public static void genThrow(@NotNull MethodVisitor mv, @NotNull String exception, @NotNull String message) { public static void genThrow(@NotNull InstructionAdapter v, @NotNull String exception, @Nullable String message) {
InstructionAdapter iv = new InstructionAdapter(mv); v.anew(Type.getObjectType(exception));
iv.anew(Type.getObjectType(exception)); v.dup();
iv.dup(); if (message != null) {
iv.aconst(message); v.aconst(message);
iv.invokespecial(exception, "<init>", "(Ljava/lang/String;)V", false); v.invokespecial(exception, "<init>", "(Ljava/lang/String;)V", false);
iv.athrow(); }
else {
v.invokespecial(exception, "<init>", "()V", false);
}
v.athrow();
} }
public static void genClosureFields(CalculatedClosure closure, ClassBuilder v, JetTypeMapper typeMapper) { public static void genClosureFields(CalculatedClosure closure, ClassBuilder v, JetTypeMapper typeMapper) {
@@ -3650,9 +3650,9 @@ The "returned" value of try expression with no finally is either the last expres
v.ifnonnull(nonnull); v.ifnonnull(nonnull);
JetType leftType = bindingContext.get(EXPRESSION_TYPE, left); JetType leftType = bindingContext.get(EXPRESSION_TYPE, left);
assert leftType != null; assert leftType != null;
throwNewException("kotlin/TypeCastException", DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(leftType) + genThrow(v, "kotlin/TypeCastException", DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(leftType) +
" cannot be cast to " + " cannot be cast to " +
DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(rightType)); DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(rightType));
v.mark(nonnull); v.mark(nonnull);
} }
} }
@@ -3812,7 +3812,7 @@ The "returned" value of try expression with no finally is either the last expres
) { ) {
if (Boolean.TRUE.equals(bindingContext.get(BindingContext.EXHAUSTIVE_WHEN, expression))) { if (Boolean.TRUE.equals(bindingContext.get(BindingContext.EXHAUSTIVE_WHEN, expression))) {
// when() is supposed to be exhaustive // when() is supposed to be exhaustive
throwNewException("kotlin/NoWhenBranchMatchedException"); genThrow(v, "kotlin/NoWhenBranchMatchedException", null);
} }
else { else {
// non-exhaustive when() with no else -> Unit must be expected // non-exhaustive when() with no else -> Unit must be expected
@@ -3854,23 +3854,6 @@ The "returned" value of try expression with no finally is either the last expres
return false; return false;
} }
private void throwNewException(@NotNull String className) {
throwNewException(className, null);
}
private void throwNewException(@NotNull String className, @Nullable String message) {
v.anew(Type.getObjectType(className));
v.dup();
if (message != null) {
v.visitLdcInsn(message);
v.invokespecial(className, "<init>", "(Ljava/lang/String;)V", false);
}
else {
v.invokespecial(className, "<init>", "()V", false);
}
v.athrow();
}
private Call makeFakeCall(ReceiverValue initializerAsReceiver) { private Call makeFakeCall(ReceiverValue initializerAsReceiver) {
JetSimpleNameExpression fake = JetPsiFactory(state.getProject()).createSimpleName("fake"); JetSimpleNameExpression fake = JetPsiFactory(state.getProject()).createSimpleName("fake");
return CallMaker.makeCall(fake, initializerAsReceiver); return CallMaker.makeCall(fake, initializerAsReceiver);
@@ -565,7 +565,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
MethodVisitor mv = v.newMethod(NO_ORIGIN, access, name, desc, null, null); MethodVisitor mv = v.newMethod(NO_ORIGIN, access, name, desc, null, null);
if (descriptor.getKind() != ClassKind.TRAIT) { if (descriptor.getKind() != ClassKind.TRAIT) {
mv.visitCode(); mv.visitCode();
genThrow(mv, "java/lang/UnsupportedOperationException", "Mutating immutable collection"); genThrow(new InstructionAdapter(mv), "java/lang/UnsupportedOperationException", "Mutating immutable collection");
FunctionCodegen.endVisit(mv, "built-in stub for " + name + desc, null); FunctionCodegen.endVisit(mv, "built-in stub for " + name + desc, null);
} }
} }