Split custom merge logic into a separate shouldMerge function

master
Graham 4 years ago
parent 9e525f7aeb
commit d12a2dab06
  1. 62
      src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java

@ -169,35 +169,7 @@ public class VarVersionsProcessor {
for (int j = i + 1; j < lstVersions.size(); j++) {
VarVersionPair secondPair = new VarVersionPair(ent.getKey(), lstVersions.get(j));
// find all scopes the two variable versions are assigned in
Set<DirectNode> nodes = new HashSet<>();
for (DirectNode node : graph.nodes) {
for (Exprent expr : node.exprents) {
if (expr.type != Exprent.EXPRENT_ASSIGNMENT) {
continue;
}
AssignmentExprent assignExpr = (AssignmentExprent) expr;
Exprent leftExpr = assignExpr.getLeft();
if (leftExpr.type != Exprent.EXPRENT_VAR) {
continue;
}
VarExprent varExpr = (VarExprent) leftExpr;
int index = varExpr.getIndex();
int version = varExpr.getVersion();
if (index == firstPair.var && version == firstPair.version) {
nodes.add(node);
} else if (index == secondPair.var && version == secondPair.version) {
nodes.add(node);
}
}
}
// only merge variables if they're assigned in the same scope
if (nodes.size() > 1) {
if (!shouldMerge(graph, firstPair, secondPair)) {
continue;
}
@ -239,6 +211,38 @@ public class VarVersionsProcessor {
}
}
private static boolean shouldMerge(DirectGraph graph, VarVersionPair firstPair, VarVersionPair secondPair) {
// find all scopes the two variable versions are assigned in
Set<DirectNode> nodes = new HashSet<>();
for (DirectNode node : graph.nodes) {
for (Exprent expr : node.exprents) {
if (expr.type != Exprent.EXPRENT_ASSIGNMENT) {
continue;
}
AssignmentExprent assignExpr = (AssignmentExprent) expr;
Exprent leftExpr = assignExpr.getLeft();
if (leftExpr.type != Exprent.EXPRENT_VAR) {
continue;
}
VarExprent varExpr = (VarExprent) leftExpr;
int index = varExpr.getIndex();
int version = varExpr.getVersion();
if (index == firstPair.var && version == firstPair.version) {
nodes.add(node);
} else if (index == secondPair.var && version == secondPair.version) {
nodes.add(node);
}
}
}
// only merge variables if they're assigned in the same scope
return nodes.size() > 1;
}
private void setNewVarIndices(VarTypeProcessor typeProcessor, DirectGraph graph, VarVersionsProcessor previousVersionsProcessor) {
final Map<VarVersionPair, VarType> mapExprentMaxTypes = typeProcessor.getMapExprentMaxTypes();
Map<VarVersionPair, VarType> mapExprentMinTypes = typeProcessor.getMapExprentMinTypes();

Loading…
Cancel
Save