From d12a2dab069defb55128cb72bb255ae9eb2f9410 Mon Sep 17 00:00:00 2001 From: Graham Date: Fri, 11 Sep 2020 19:21:11 +0100 Subject: [PATCH] Split custom merge logic into a separate shouldMerge function --- .../decompiler/vars/VarVersionsProcessor.java | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java b/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java index d575b54..d46cbba 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/vars/VarVersionsProcessor.java +++ b/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 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 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 mapExprentMaxTypes = typeProcessor.getMapExprentMaxTypes(); Map mapExprentMinTypes = typeProcessor.getMapExprentMinTypes();