Skip to content

Commit

Permalink
predicate for Java
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Aug 9, 2024
1 parent fc680f6 commit 93eba94
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,17 @@ private fun handleIfStatement(
val evalResult = ValueEvaluator().evaluate(n.condition)

val (unreachableEdge, remainingEdges) =
if (evalResult is Boolean && evalResult == true) {
if (evalResult == true) {
// If the condition is always true, the "false" branch is always unreachable
Pair(
n.nextEOGEdges.firstOrNull { e -> e.index == 1 },
n.nextEOGEdges.filter { e -> e.index != 1 }
n.nextEOGEdges.firstOrNull { e -> e.branch == false },
n.nextEOGEdges.filter { e -> e.branch != false }
)
} else if (evalResult is Boolean && evalResult == false) {
} else if (evalResult == false) {
// If the condition is always false, the "true" branch is always unreachable
Pair(
n.nextEOGEdges.firstOrNull { e -> e.index == 0 },
n.nextEOGEdges.filter { e -> e.index != 0 }
n.nextEOGEdges.firstOrNull { e -> e.branch == true },
n.nextEOGEdges.filter { e -> e.branch != true }
)
} else {
Pair(null, n.nextEOGEdges)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ internal class EOGTest : BaseTest() {
en = Util.Edge.ENTRIES,
n = ifSimple.thenStatement,
cr = Connect.NODE,
branch = true,
predicate = { it.branch == true },
refs = listOf(ifSimple)
)
)
Expand All @@ -129,7 +129,7 @@ internal class EOGTest : BaseTest() {
cn = Connect.NODE,
en = Util.Edge.EXITS,
n = ifSimple,
branch = true,
predicate = { it.branch == true },
refs = listOf(ifSimple.thenStatement)
)
)
Expand Down Expand Up @@ -161,7 +161,7 @@ internal class EOGTest : BaseTest() {
cn = Connect.NODE,
en = Util.Edge.EXITS,
n = ifBranched,
branch = true,
predicate = { it.branch == true },
refs = listOf(ifBranched.thenStatement)
)
)
Expand All @@ -170,7 +170,7 @@ internal class EOGTest : BaseTest() {
cn = Connect.NODE,
en = Util.Edge.EXITS,
n = ifBranched,
branch = false,
predicate = { it.branch == false },
refs = listOf(ifBranched.elseStatement)
)
)
Expand All @@ -183,7 +183,7 @@ internal class EOGTest : BaseTest() {
en = Util.Edge.ENTRIES,
n = ifBranched.thenStatement,
cr = Connect.NODE,
branch = true,
predicate = { it.branch == true },
refs = listOf(ifBranched)
)
)
Expand All @@ -194,7 +194,7 @@ internal class EOGTest : BaseTest() {
en = Util.Edge.ENTRIES,
n = ifBranched.elseStatement,
cr = Connect.NODE,
branch = false,
predicate = { it.branch == false },
refs = listOf(ifBranched)
)
)
Expand Down Expand Up @@ -236,7 +236,7 @@ internal class EOGTest : BaseTest() {
en = Util.Edge.ENTRIES,
n = bo.rhs,
cr = Connect.SUBTREE,
branch = (bo.operatorCode == "&&"),
predicate = { it.branch == (bo.operatorCode == "&&") },
refs = listOf(bo.lhs)
)
)
Expand Down Expand Up @@ -267,7 +267,7 @@ internal class EOGTest : BaseTest() {
en = Util.Edge.ENTRIES,
n = bo,
cr = Connect.SUBTREE,
branch = (bo.operatorCode != "&&"),
predicate = { it.branch == (bo.operatorCode != "&&") },
refs = listOf(bo.lhs)
)
)
Expand Down Expand Up @@ -398,7 +398,7 @@ internal class EOGTest : BaseTest() {
en = Util.Edge.EXITS,
n = fs,
cr = Connect.SUBTREE,
branch = false,
predicate = { it.branch == false },
refs = listOf(prints[2])
)
)
Expand Down Expand Up @@ -471,7 +471,7 @@ internal class EOGTest : BaseTest() {
en = Util.Edge.ENTRIES,
n = wstat.statement,
cr = Connect.NODE,
branch = true,
predicate = { it.branch == true },
refs = listOf(wstat)
)
)
Expand All @@ -483,7 +483,7 @@ internal class EOGTest : BaseTest() {
cn = Connect.SUBTREE,
en = Util.Edge.EXITS,
n = wstat,
branch = false,
predicate = { it.branch == false },
refs = listOf(prints[1])
)
)
Expand Down Expand Up @@ -516,7 +516,7 @@ internal class EOGTest : BaseTest() {
cn = Connect.NODE,
en = Util.Edge.EXITS,
n = dostat,
branch = true,
predicate = { it.branch == true },
refs = listOf(dostat.statement)
)
)
Expand All @@ -537,7 +537,7 @@ internal class EOGTest : BaseTest() {
cn = Connect.SUBTREE,
en = Util.Edge.EXITS,
n = dostat,
branch = false,
predicate = { it.branch == false },
refs = listOf(prints[2])
)
)
Expand Down

0 comments on commit 93eba94

Please sign in to comment.