From 8f668dc5b18133ae83af33f096ea11ad35360789 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 12 Feb 1999 15:23:45 +0000 Subject: [PATCH] use a proper middle type for casts git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@266 379699f6-c40d-0410-875b-85095c16579e --- jode/jode/expr/InstanceOfOperator.java | 31 ++++++++++++++++---------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/jode/jode/expr/InstanceOfOperator.java b/jode/jode/expr/InstanceOfOperator.java index 93ea6d5..f390134 100644 --- a/jode/jode/expr/InstanceOfOperator.java +++ b/jode/jode/expr/InstanceOfOperator.java @@ -23,20 +23,16 @@ import jode.Type; public class InstanceOfOperator extends SimpleOperator { Type instanceType; + /** + * There are special cases where a instanceof isn't allowed. We must cast + * to the common super type before. This cases always give a runtime + * error, but we want to decompile even bad programs. + */ + Type superType = null; + public InstanceOfOperator(Type type) { super(Type.tBoolean, 0, 1); - /* The following is wrong. The operand must not - * be a super type of the given type, but any type - * especially if type is an interface. - * - * If operand is of class type, it is probably a - * super type, but who knows? - * - * this.operandTypes[0] = Type.tSuperType(type); - * - * The forgiving solution: - */ this.instanceType = type; this.operandTypes[0] = Type.tUnknown; } @@ -52,7 +48,18 @@ public class InstanceOfOperator extends SimpleOperator { return getPriority(); } + public void setOperandType(Type[] type) { + super.setOperandType(type); + superType = instanceType.getCastHelper(type[0]); + } + public String toString(String[] operands) { - return operands[0] + " instanceof "+instanceType; + StringBuffer sb = new StringBuffer(); + if (superType != null) + sb.append("((").append(superType).append(")"); + sb.append(operands[0]); + if (superType != null) + sb.append(")"); + return sb.append(" instanceof ").append(instanceType).toString(); } }