insert casts for hidden fields

git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1003 379699f6-c40d-0410-875b-85095c16579e
stable
jochen 26 years ago
parent fb79ffefc2
commit 320c5ad2c9
  1. 24
      jode/jode/expr/GetFieldOperator.java
  2. 24
      jode/jode/expr/PutFieldOperator.java

@ -21,6 +21,7 @@ package jode.expr;
import jode.type.Type;
import jode.type.NullType;
import jode.type.ClassInterfacesType;
import jode.bytecode.FieldInfo;
import jode.bytecode.ClassInfo;
import jode.bytecode.Reference;
import jode.decompiler.MethodAnalyzer;
@ -111,6 +112,26 @@ public class GetFieldOperator extends Operator {
return null;
}
public boolean needsCast(Type type) {
if (type instanceof NullType)
return true;
if (!(type instanceof ClassInterfacesType
&& classType instanceof ClassInterfacesType))
return false;
ClassInfo clazz = ((ClassInterfacesType) classType).getClassInfo();
ClassInfo parClazz = ((ClassInterfacesType) type).getClassInfo();
while (clazz != parClazz && clazz != null) {
FieldInfo[] fields = parClazz.getFields();
for (int i = 0; i < fields.length; i++) {
if (fields[i].getName().equals(ref.getName()))
return true;
}
parClazz = parClazz.getSuperclass();
}
return false;
}
public void dumpExpression(TabbedPrintWriter writer)
throws java.io.IOException {
boolean opIsThis = !staticFlag
@ -123,8 +144,7 @@ public class GetFieldOperator extends Operator {
writer.print(".");
}
writer.print(fieldName);
} else if (subExpressions[0].getType().getCanonic()
instanceof NullType) {
} else if (needsCast(subExpressions[0].getType().getCanonic())) {
writer.print("((");
writer.printType(classType);
writer.print(") ");

@ -23,6 +23,7 @@ import jode.type.NullType;
import jode.type.ClassInterfacesType;
import jode.bytecode.Reference;
import jode.bytecode.ClassInfo;
import jode.bytecode.FieldInfo;
import jode.decompiler.MethodAnalyzer;
import jode.decompiler.ClassAnalyzer;
import jode.decompiler.FieldAnalyzer;
@ -115,6 +116,26 @@ public class PutFieldOperator extends LValueExpression {
updateParentType(getFieldType());
}
public boolean needsCast(Type type) {
if (type instanceof NullType)
return true;
if (!(type instanceof ClassInterfacesType
&& classType instanceof ClassInterfacesType))
return false;
ClassInfo clazz = ((ClassInterfacesType) classType).getClassInfo();
ClassInfo parClazz = ((ClassInterfacesType) type).getClassInfo();
while (clazz != parClazz && clazz != null) {
FieldInfo[] fields = parClazz.getFields();
for (int i = 0; i < fields.length; i++) {
if (fields[i].getName().equals(ref.getName()))
return true;
}
parClazz = parClazz.getSuperclass();
}
return false;
}
public void dumpExpression(TabbedPrintWriter writer)
throws java.io.IOException {
boolean opIsThis = !staticFlag
@ -127,8 +148,7 @@ public class PutFieldOperator extends LValueExpression {
writer.print(".");
}
writer.print(fieldName);
} else if (subExpressions[0].getType().getCanonic()
instanceof NullType) {
} else if (needsCast(subExpressions[0].getType().getCanonic())) {
writer.print("((");
writer.printType(classType);
writer.print(") ");

Loading…
Cancel
Save