Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into ffbulktest
Browse files Browse the repository at this point in the history
  • Loading branch information
cpw committed Nov 6, 2015
2 parents 72d2067 + 360216c commit 2971389
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,11 @@ private static Statement findGeneralStatement(Statement stat, boolean forceall,

boolean same = (post == head);

HashSet<Statement> setNodes = new HashSet<Statement>();
LinkedHashSet<Statement> setNodes = new LinkedHashSet<Statement>();
HashSet<Statement> setPreds = new HashSet<Statement>();

// collect statement nodes
HashSet<Statement> setHandlers = new HashSet<Statement>();
HashSet<Statement> setHandlers = new LinkedHashSet<Statement>();
setHandlers.add(head);
while (true) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public class DominatorTreeExceptionFilter {
private final Statement statement;

// idom, nodes
private final Map<Integer, Set<Integer>> mapTreeBranches = new HashMap<Integer, Set<Integer>>();
private final Map<Integer, Set<Integer>> mapTreeBranches = new LinkedHashMap<Integer, Set<Integer>>();

// handler, range nodes
private final Map<Integer, Set<Integer>> mapExceptionRanges = new HashMap<Integer, Set<Integer>>();
private final Map<Integer, Set<Integer>> mapExceptionRanges = new LinkedHashMap<Integer, Set<Integer>>();

// handler, head dom
private Map<Integer, Integer> mapExceptionDoms = new HashMap<Integer, Integer>();
Expand Down Expand Up @@ -86,7 +86,7 @@ private void buildDominatorTree() {

Set<Integer> set = mapTreeBranches.get(idom);
if (set == null) {
mapTreeBranches.put(idom, set = new HashSet<Integer>());
mapTreeBranches.put(idom, set = new LinkedHashSet<Integer>());
}
set.add(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class FastExtendedPostdominanceHelper {

private List<Statement> lstReversePostOrderList;

private HashMap<Integer, FastFixedSet<Integer>> mapSupportPoints = new HashMap<Integer, FastFixedSet<Integer>>();
private HashMap<Integer, FastFixedSet<Integer>> mapSupportPoints = new LinkedHashMap<Integer, FastFixedSet<Integer>>();

private final HashMap<Integer, FastFixedSet<Integer>> mapExtPostdominators = new HashMap<Integer, FastFixedSet<Integer>>();
private final HashMap<Integer, FastFixedSet<Integer>> mapExtPostdominators = new LinkedHashMap<Integer, FastFixedSet<Integer>>();

private Statement statement;

Expand All @@ -40,7 +40,7 @@ public HashMap<Integer, LinkedHashSet<Integer>> getExtendedPostdominators(Statem

this.statement = statement;

HashSet<Integer> set = new HashSet<Integer>();
HashSet<Integer> set = new LinkedHashSet<Integer>();
for (Statement st : statement.getStats()) {
set.add(st.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;


public class GeneralStatement extends Statement {
Expand All @@ -39,7 +40,7 @@ public GeneralStatement(Statement head, Collection<Statement> statements, Statem
first = head;
stats.addWithKey(head, head.id);

HashSet<Statement> set = new HashSet<Statement>(statements);
LinkedHashSet<Statement> set = new LinkedHashSet<Statement>(statements);
set.remove(head);

for (Statement st : set) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Statement> sorted = new ArrayList<Statement>(lstNodes);
Collections.sort(sorted, new Comparator<Statement>() {
@Override
public int compare(Statement o1, Statement o2) {
return o1.id - o2.id;
}
});
for (Statement st : sorted) {
stats.addWithKey(st, st.id);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<VarVersionPair, LVTVariable> types = new HashMap<VarVersionPair, LVTVariable>();
Map<VarVersionPair, VarInfo> types = new HashMap<VarVersionPair, VarInfo>();

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<LVTVariable> 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<VarVersionPair, LVTVariable> e : types.entrySet()) {
varproc.setVarLVT(e.getKey(), e.getValue());
//renameTypes(types);

for (Entry<VarVersionPair, VarInfo> e : types.entrySet()) {
if (e.getValue().lvt != null) {
varproc.setVarLVT(e.getKey(), e.getValue().lvt);
}
}

applyTypes(stat, types);
Map<VarVersionPair, LVTVariable> lvts = new HashMap<VarVersionPair, LVTVariable>();
for (Entry<VarVersionPair, VarInfo> e : types.entrySet()) {
if (e.getValue().lvt != null) {
lvts.put(e.getKey(), e.getValue().lvt);
}
}

applyTypes(stat, lvts);
}

private void findTypes(Statement stat, Map<VarVersionPair, LVTVariable> types) {
private void findTypes(Statement stat, Map<VarVersionPair, VarInfo> types) {
if (stat == null) {
return;
}
Expand All @@ -476,27 +485,40 @@ else if (obj instanceof Exprent) {
}
}

private void findTypes(Exprent exp, Map<VarVersionPair, LVTVariable> types) {
private void findTypes(Exprent exp, Map<VarVersionPair, VarInfo> types) {
List<Exprent> 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<VarVersionPair, LVTVariable> types) {
if (stat == null || types.size() == 0) {
Expand Down

0 comments on commit 2971389

Please sign in to comment.