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
stable
jochen 26 years ago
parent 1b019d0f63
commit 8f668dc5b1
  1. 31
      jode/jode/expr/InstanceOfOperator.java

@ -23,20 +23,16 @@ import jode.Type;
public class InstanceOfOperator extends SimpleOperator { public class InstanceOfOperator extends SimpleOperator {
Type instanceType; 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) { public InstanceOfOperator(Type type) {
super(Type.tBoolean, 0, 1); 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.instanceType = type;
this.operandTypes[0] = Type.tUnknown; this.operandTypes[0] = Type.tUnknown;
} }
@ -52,7 +48,18 @@ public class InstanceOfOperator extends SimpleOperator {
return getPriority(); return getPriority();
} }
public void setOperandType(Type[] type) {
super.setOperandType(type);
superType = instanceType.getCastHelper(type[0]);
}
public String toString(String[] operands) { 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();
} }
} }

Loading…
Cancel
Save