diff --git a/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorRunnable.java b/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorRunnable.java index 16d7788..9bcd3ba 100644 --- a/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorRunnable.java +++ b/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorRunnable.java @@ -253,8 +253,10 @@ public static void printMethod(Statement root, String name, VarProcessor varProc for (Object obj : root.getSequentialObjects()) { if (obj instanceof Statement) { printStatement((Statement)obj, " ",varProc); + } else if (obj == null) { + System.out.println(" null"); } else { - System.out.println(" " + obj.getClass().getSimpleName()); + System.out.println(" " + obj.getClass().getSimpleName()); } } if (root instanceof RootStatement) { @@ -292,7 +294,7 @@ private static void printStatement(Statement statement, String indent, VarProces int start = values.nextSetBit(0); int end = values.length()-1; - System.out.print(indent + "{" + statement.type + "}:" + statement.id + " (" + start + ", " + end + ") " + statement.getClass().getSimpleName()); + System.out.print(indent + "{" + statement.getClass().getSimpleName() + "}:" + statement.id + " (" + start + ", " + end + ") " + statement.getClass().getSimpleName()); if (statement.type == Statement.TYPE_DO) { System.out.print(" t:"+((DoStatement)statement).getLooptype()); } else if (statement.type == Statement.TYPE_BASICBLOCK) { diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/DomHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/DomHelper.java index c45f5e0..e780bd6 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/DomHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/DomHelper.java @@ -483,11 +483,11 @@ private static Statement findGeneralStatement(Statement stat, boolean forceall, boolean same = (post == head); - HashSet setNodes = new HashSet(); + LinkedHashSet setNodes = new LinkedHashSet(); HashSet setPreds = new HashSet(); // collect statement nodes - HashSet setHandlers = new HashSet(); + HashSet setHandlers = new LinkedHashSet(); setHandlers.add(head); while (true) { diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/DominatorTreeExceptionFilter.java b/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/DominatorTreeExceptionFilter.java index 89e6849..1c3a8e1 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/DominatorTreeExceptionFilter.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/DominatorTreeExceptionFilter.java @@ -27,10 +27,10 @@ public class DominatorTreeExceptionFilter { private final Statement statement; // idom, nodes - private final Map> mapTreeBranches = new HashMap>(); + private final Map> mapTreeBranches = new LinkedHashMap>(); // handler, range nodes - private final Map> mapExceptionRanges = new HashMap>(); + private final Map> mapExceptionRanges = new LinkedHashMap>(); // handler, head dom private Map mapExceptionDoms = new HashMap(); @@ -86,7 +86,7 @@ private void buildDominatorTree() { Set set = mapTreeBranches.get(idom); if (set == null) { - mapTreeBranches.put(idom, set = new HashSet()); + mapTreeBranches.put(idom, set = new LinkedHashSet()); } set.add(key); } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/FastExtendedPostdominanceHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/FastExtendedPostdominanceHelper.java index eee7b15..349f522 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/FastExtendedPostdominanceHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/decompose/FastExtendedPostdominanceHelper.java @@ -28,9 +28,9 @@ public class FastExtendedPostdominanceHelper { private List lstReversePostOrderList; - private HashMap> mapSupportPoints = new HashMap>(); + private HashMap> mapSupportPoints = new LinkedHashMap>(); - private final HashMap> mapExtPostdominators = new HashMap>(); + private final HashMap> mapExtPostdominators = new LinkedHashMap>(); private Statement statement; @@ -40,7 +40,7 @@ public HashMap> getExtendedPostdominators(Statem this.statement = statement; - HashSet set = new HashSet(); + HashSet set = new LinkedHashSet(); for (Statement st : statement.getStats()) { set.add(st.id); } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/GeneralStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/GeneralStatement.java index 499894a..f7e0080 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/GeneralStatement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/GeneralStatement.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.HashSet; +import java.util.LinkedHashSet; public class GeneralStatement extends Statement { @@ -39,7 +40,7 @@ public GeneralStatement(Statement head, Collection statements, Statem first = head; stats.addWithKey(head, head.id); - HashSet set = new HashSet(statements); + LinkedHashSet set = new LinkedHashSet(statements); set.remove(head); for (Statement st : set) { diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java index 2a29309..af522d9 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/stats/SwitchStatement.java @@ -80,7 +80,15 @@ private SwitchStatement(Statement head, Statement poststat) { default_edge = head.getSuccessorEdges(Statement.STATEDGE_DIRECT_ALL).get(0); - for (Statement st : lstNodes) { + //We need to use set above in case we have multiple edges to the same node. But HashSets iterator is not ordered, so sort + List sorted = new ArrayList(lstNodes); + Collections.sort(sorted, new Comparator() { + @Override + public int compare(Statement o1, Statement o2) { + return o1.id - o2.id; + } + }); + for (Statement st : sorted) { stats.addWithKey(st, st.id); } } diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarDefinitionHelper.java b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarDefinitionHelper.java index 726edd7..164ddb5 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarDefinitionHelper.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarDefinitionHelper.java @@ -18,6 +18,7 @@ import org.jetbrains.java.decompiler.code.CodeConstants; import org.jetbrains.java.decompiler.main.DecompilerContext; import org.jetbrains.java.decompiler.main.collectors.VarNamesCollector; +import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor; import org.jetbrains.java.decompiler.modules.decompiler.exps.AssignmentExprent; import org.jetbrains.java.decompiler.modules.decompiler.exps.ConstExprent; import org.jetbrains.java.decompiler.modules.decompiler.exps.Exprent; @@ -31,6 +32,7 @@ import org.jetbrains.java.decompiler.struct.StructMethod; import org.jetbrains.java.decompiler.struct.gen.MethodDescriptor; import org.jetbrains.java.decompiler.struct.gen.VarType; +import org.jetbrains.java.decompiler.struct.gen.generics.GenericType; import java.util.*; import java.util.Map.Entry; @@ -421,36 +423,43 @@ private static boolean setDefinition(Exprent expr, Integer index) { } private void propogateLVTs(Statement stat) { - if (varproc.getLVT() == null) { - return; - } - MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor()); - Map types = new HashMap(); + Map types = new HashMap(); int index = 0; if (!mt.hasModifier(CodeConstants.ACC_STATIC)) { - types.put(new VarVersionPair(index, 0), varproc.getLVT().getCandidates(index++).get(0)); + types.put(new VarVersionPair(index, 0), new VarInfo(varproc.getLVT().getCandidates(index++).get(0), new VarType(mt.getClassStruct().qualifiedName))); } for (VarType var : md.params) { List vars = varproc.getLVT().getCandidates(index); if (vars != null) { - types.put(new VarVersionPair(index, 0), vars.get(0)); + types.put(new VarVersionPair(index, 0), new VarInfo(vars.get(0), var)); } index += var.stackSize; } findTypes(stat, types); - for (Entry e : types.entrySet()) { - varproc.setVarLVT(e.getKey(), e.getValue()); + //renameTypes(types); + + for (Entry e : types.entrySet()) { + if (e.getValue().lvt != null) { + varproc.setVarLVT(e.getKey(), e.getValue().lvt); + } } - applyTypes(stat, types); + Map lvts = new HashMap(); + for (Entry e : types.entrySet()) { + if (e.getValue().lvt != null) { + lvts.put(e.getKey(), e.getValue().lvt); + } + } + + applyTypes(stat, lvts); } - private void findTypes(Statement stat, Map types) { + private void findTypes(Statement stat, Map types) { if (stat == null) { return; } @@ -476,27 +485,40 @@ else if (obj instanceof Exprent) { } } - private void findTypes(Exprent exp, Map types) { + private void findTypes(Exprent exp, Map types) { List lst = exp.getAllExprents(true); lst.add(exp); for (Exprent exprent : lst) { if (exprent.type == Exprent.EXPRENT_VAR) { VarExprent var = (VarExprent)exprent; - if (var.getLVT() == null) { - continue; - } VarVersionPair ver = new VarVersionPair(var); if (var.isDefinition()) { - types.put(ver, var.getLVT()); + types.put(ver, new VarInfo(var.getLVT(), var.getVarType())); } else if (!types.containsKey(ver)) { - types.put(ver, var.getLVT()); + types.put(ver, new VarInfo(var.getLVT(), var.getVarType())); } } } } + private static class VarInfo { + LVTVariable lvt; + String cast; + private VarInfo(LVTVariable lvt, VarType type) { + if (lvt != null && lvt.getSig() != null) { + cast = ExprProcessor.getCastTypeName(GenericType.parse(lvt.getSig())); + } + else if (lvt != null) { + cast = ExprProcessor.getCastTypeName(lvt.getVarType()); + } + else { + cast = ExprProcessor.getCastTypeName(type); + } + } + } + private void applyTypes(Statement stat, Map types) { if (stat == null || types.size() == 0) {