Unified the types of 'case' values in a switch statement

This commit is contained in:
Stiver 2014-08-17 19:09:28 +02:00
parent 929056d727
commit e098fbf669
2 changed files with 21 additions and 6 deletions

View File

@ -48,6 +48,10 @@ public class SwitchExprent extends Exprent {
return swexpr; return swexpr;
} }
public VarType getExprType() {
return value.getExprType();
}
public CheckTypesResult checkExprTypeBounds() { public CheckTypesResult checkExprTypeBounds() {
CheckTypesResult result = new CheckTypesResult(); CheckTypesResult result = new CheckTypesResult();
@ -81,12 +85,17 @@ public class SwitchExprent extends Exprent {
} }
public boolean equals(Object o) { public boolean equals(Object o) {
if(o == this) return true; if(o == this) {
if(o == null || !(o instanceof SwitchExprent)) return false; return true;
}
if(o == null || !(o instanceof SwitchExprent)) {
return false;
}
SwitchExprent sw = (SwitchExprent)o; SwitchExprent sw = (SwitchExprent) o;
return InterpreterUtil.equalObjects(value, sw.getValue()); return InterpreterUtil.equalObjects(value, sw.getValue());
} }
public void replaceExprent(Exprent oldexpr, Exprent newexpr) { public void replaceExprent(Exprent oldexpr, Exprent newexpr) {
if(oldexpr == value) { if(oldexpr == value) {

View File

@ -31,6 +31,7 @@ import de.fernflower.modules.decompiler.StatEdge;
import de.fernflower.modules.decompiler.exps.ConstExprent; import de.fernflower.modules.decompiler.exps.ConstExprent;
import de.fernflower.modules.decompiler.exps.Exprent; import de.fernflower.modules.decompiler.exps.Exprent;
import de.fernflower.modules.decompiler.exps.SwitchExprent; import de.fernflower.modules.decompiler.exps.SwitchExprent;
import de.fernflower.struct.gen.VarType;
import de.fernflower.util.InterpreterUtil; import de.fernflower.util.InterpreterUtil;
public class SwitchStatement extends Statement { public class SwitchStatement extends Statement {
@ -126,6 +127,8 @@ public class SwitchStatement extends Statement {
buf.append(indstr+headexprent.get(0).toJava(indent)+" {" + new_line_separator); buf.append(indstr+headexprent.get(0).toJava(indent)+" {" + new_line_separator);
VarType switch_type = headexprent.get(0).getExprType();
for(int i=0;i<caseStatements.size();i++) { for(int i=0;i<caseStatements.size();i++) {
Statement stat = caseStatements.get(i); Statement stat = caseStatements.get(i);
@ -136,7 +139,10 @@ public class SwitchStatement extends Statement {
if(edges.get(j) == default_edge) { if(edges.get(j) == default_edge) {
buf.append(indstr+"default:" + new_line_separator); buf.append(indstr+"default:" + new_line_separator);
} else { } else {
buf.append(indstr+"case "+ values.get(j).toJava(indent)+":" + new_line_separator); ConstExprent value = (ConstExprent)values.get(j).copy();
value.setConsttype(switch_type);
buf.append(indstr+"case "+ value.toJava(indent)+":" + new_line_separator);
} }
} }