diff --git a/sootup.core/src/main/java/sootup/core/graph/MutableBlockStmtGraph.java b/sootup.core/src/main/java/sootup/core/graph/MutableBlockStmtGraph.java index 8f30d79fd34..d27f2170116 100644 --- a/sootup.core/src/main/java/sootup/core/graph/MutableBlockStmtGraph.java +++ b/sootup.core/src/main/java/sootup/core/graph/MutableBlockStmtGraph.java @@ -35,7 +35,10 @@ import sootup.core.jimple.basic.StmtPositionInfo; import sootup.core.jimple.basic.Trap; import sootup.core.jimple.common.ref.JCaughtExceptionRef; -import sootup.core.jimple.common.stmt.*; +import sootup.core.jimple.common.stmt.BranchingStmt; +import sootup.core.jimple.common.stmt.FallsThroughStmt; +import sootup.core.jimple.common.stmt.JIdentityStmt; +import sootup.core.jimple.common.stmt.Stmt; import sootup.core.signatures.MethodSignature; import sootup.core.types.ClassType; import sootup.core.types.Type; @@ -53,7 +56,7 @@ public class MutableBlockStmtGraph extends MutableStmtGraph { @Nonnull private final Map> stmtToBlock = new IdentityHashMap<>(); - @Nonnull private final Set blocks = new HashSet<>(); + @Nonnull private final Set blocks = new LinkedHashSet<>(); public MutableBlockStmtGraph() {} diff --git a/sootup.core/src/main/java/sootup/core/jimple/basic/JimpleComparator.java b/sootup.core/src/main/java/sootup/core/jimple/basic/JimpleComparator.java index d25e0944d74..ab5e0b83277 100644 --- a/sootup.core/src/main/java/sootup/core/jimple/basic/JimpleComparator.java +++ b/sootup.core/src/main/java/sootup/core/jimple/basic/JimpleComparator.java @@ -28,12 +28,7 @@ import sootup.core.jimple.common.constant.Constant; import sootup.core.jimple.common.constant.IntConstant; import sootup.core.jimple.common.expr.*; -import sootup.core.jimple.common.ref.JArrayRef; -import sootup.core.jimple.common.ref.JCaughtExceptionRef; -import sootup.core.jimple.common.ref.JInstanceFieldRef; -import sootup.core.jimple.common.ref.JParameterRef; -import sootup.core.jimple.common.ref.JStaticFieldRef; -import sootup.core.jimple.common.ref.JThisRef; +import sootup.core.jimple.common.ref.*; import sootup.core.jimple.common.stmt.*; import sootup.core.jimple.javabytecode.stmt.*; @@ -200,7 +195,7 @@ public boolean caseSwitchStmt(JSwitchStmt stmt, Object o) { } JSwitchStmt otherSwitchStmt = (JSwitchStmt) o; - if (stmt.getKey() != otherSwitchStmt.getKey()) { + if (!stmt.getKey().equivTo(otherSwitchStmt.getKey())) { return false; } diff --git a/sootup.core/src/test/java/sootup/core/jimple/basic/JimpleComparatorTest.java b/sootup.core/src/test/java/sootup/core/jimple/basic/JimpleComparatorTest.java new file mode 100644 index 00000000000..6a81ce1a0e7 --- /dev/null +++ b/sootup.core/src/test/java/sootup/core/jimple/basic/JimpleComparatorTest.java @@ -0,0 +1,42 @@ +package sootup.core.jimple.basic; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import sootup.core.jimple.Jimple; +import sootup.core.jimple.common.constant.IntConstant; +import sootup.core.jimple.javabytecode.stmt.JSwitchStmt; +import sootup.core.types.PrimitiveType; + +@Tag("Java8") +public class JimpleComparatorTest { + + @Test + public void test() { + // l1 and l2 are equal, l1 and l3 are not + Local l1 = Jimple.newLocal("l", PrimitiveType.getInt()); + Local l2 = Jimple.newLocal("l", PrimitiveType.getInt()); + Local l3 = Jimple.newLocal("l", PrimitiveType.getBoolean()); + + List lookup1 = new ArrayList<>(); + lookup1.add(IntConstant.getInstance(3)); + lookup1.add(IntConstant.getInstance(5)); + lookup1.add(IntConstant.getInstance(999)); + + List lookup2 = new ArrayList<>(); + lookup2.add(IntConstant.getInstance(3)); + lookup2.add(IntConstant.getInstance(5)); + lookup2.add(IntConstant.getInstance(999)); + + JSwitchStmt switch1 = Jimple.newLookupSwitchStmt(l1, lookup1, StmtPositionInfo.NOPOSITION); + JSwitchStmt switch2 = Jimple.newLookupSwitchStmt(l2, lookup2, StmtPositionInfo.NOPOSITION); + JSwitchStmt switch3 = Jimple.newLookupSwitchStmt(l3, lookup2, StmtPositionInfo.NOPOSITION); + + assertTrue(switch1.equivTo(switch2)); + assertFalse(switch1.equivTo(switch3)); + } +} diff --git a/sootup.java.core/src/test/java/sootup/java/core/jimple/javabytecode/stmt/JSwitchStmtTest.java b/sootup.java.core/src/test/java/sootup/java/core/jimple/javabytecode/stmt/JSwitchStmtTest.java index 99a727d1e3d..080874f409d 100644 --- a/sootup.java.core/src/test/java/sootup/java/core/jimple/javabytecode/stmt/JSwitchStmtTest.java +++ b/sootup.java.core/src/test/java/sootup/java/core/jimple/javabytecode/stmt/JSwitchStmtTest.java @@ -2,7 +2,10 @@ import static org.junit.jupiter.api.Assertions.*; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.ListIterator; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import sootup.core.jimple.basic.StmtPositionInfo; @@ -24,7 +27,6 @@ public void testLookupSwitchStmt() { Stmt stmt = new JSwitchStmt(IntConstant.getInstance(42), lookupValues, nop); Stmt stmtDifferentKey = new JSwitchStmt(IntConstant.getInstance(123), lookupValues, nop); - Stmt stmtDifferentDefault = new JSwitchStmt(IntConstant.getInstance(42), lookupValues, nop); // toString assertEquals("switch(42) { default: }", stmt.toString()); @@ -43,7 +45,6 @@ public void testLookupSwitchStmt() { assertFalse(stmt.equivTo(this)); assertTrue(stmt.equivTo(stmt)); assertFalse(stmt.equivTo(switchWithDefault)); - assertFalse(stmt.equivTo(stmtDifferentDefault)); assertFalse(stmt.equivTo(stmtDifferentKey)); } @@ -57,7 +58,6 @@ public void testTableSwitchStmt() { targets.add(new JNopStmt(nop)); JSwitchStmt stmt = new JSwitchStmt(IntConstant.getInstance(123), 1, 4, nop); - ArrayList targets2 = new ArrayList<>(); targets.add(new JReturnStmt(IntConstant.getInstance(1), nop)); targets.add(new JReturnStmt(IntConstant.getInstance(2), nop)); targets.add(new JNopStmt(nop)); @@ -66,7 +66,6 @@ public void testTableSwitchStmt() { Stmt stmt3 = new JSwitchStmt(IntConstant.getInstance(456), 1, 4, nop); Stmt stmt4 = new JSwitchStmt(IntConstant.getInstance(123), 2, 4, nop); Stmt stmt5 = new JSwitchStmt(IntConstant.getInstance(123), 1, 5, nop); - Stmt stmt6 = new JSwitchStmt(IntConstant.getInstance(123), 1, 4, nop); // toString assertEquals( @@ -76,13 +75,11 @@ public void testTableSwitchStmt() { // equivTo assertFalse(stmt.equivTo(666)); assertTrue(stmt.equivTo(stmt)); - assertFalse(stmt.equivTo(stmt2)); + assertTrue(stmt.equivTo(stmt2)); - assertFalse(stmt.equivTo(stmt2)); assertFalse(stmt.equivTo(stmt3)); assertFalse(stmt.equivTo(stmt4)); assertFalse(stmt.equivTo(stmt5)); - assertFalse(stmt.equivTo(stmt6)); } @Test @@ -220,7 +217,6 @@ public void testLookupSwitch() { Stmt switchStmt = new JSwitchStmt(IntConstant.getInstance(42), lookupValues, nop); Stmt stmtDifferentKey = new JSwitchStmt(IntConstant.getInstance(123), lookupValues, nop); - Stmt stmtDifferentDefault = new JSwitchStmt(IntConstant.getInstance(42), lookupValues, nop); // toString assertEquals("switch(42) { default: }", switchStmt.toString()); @@ -237,7 +233,6 @@ public void testLookupSwitch() { assertFalse(switchStmt.equivTo(this)); assertTrue(switchStmt.equivTo(switchStmt)); assertFalse(switchStmt.equivTo(differentSwitchStmt)); - assertFalse(switchStmt.equivTo(stmtDifferentDefault)); assertFalse(switchStmt.equivTo(stmtDifferentKey)); } }