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

master
Stiver 11 years ago
parent 929056d727
commit e098fbf669
  1. 15
      src/de/fernflower/modules/decompiler/exps/SwitchExprent.java
  2. 8
      src/de/fernflower/modules/decompiler/stats/SwitchStatement.java

@ -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,10 +85,15 @@ 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());
} }

@ -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);
} }
} }

Loading…
Cancel
Save