Merge pull request #8582 from Marcono1234/marcono1234/JumpStmt-superclass

Java: Make `JumpStmt` a proper superclass
This commit is contained in:
Anders Schack-Mulligen
2022-04-25 12:22:20 +02:00
committed by GitHub
11 changed files with 67 additions and 21 deletions

View File

@@ -16,6 +16,6 @@ import java
from DoStmt do, ContinueStmt continue
where
do.getCondition().(BooleanLiteral).getBooleanValue() = false and
continue.(JumpStmt).getTarget() = do
continue.getTarget() = do
select continue, "This 'continue' never re-runs the loop - the $@ is always false.",
do.getCondition(), "loop condition"

View File

@@ -32,7 +32,7 @@ predicate loopExit(LoopStmt loop, Stmt exit) {
exit.getEnclosingStmt*() = loop.getBody() and
(
exit instanceof ReturnStmt or
exit.(BreakStmt).(JumpStmt).getTarget() = loop.getEnclosingStmt*()
exit.(BreakStmt).getTarget() = loop.getEnclosingStmt*()
)
}

View File

@@ -44,11 +44,11 @@ class PointlessLoop extends WhileStmt {
PointlessLoop() {
this.getCondition().(BooleanLiteral).getBooleanValue() = true and
// The only `break` must be the last statement.
forall(BreakStmt break | break.(JumpStmt).getTarget() = this |
forall(BreakStmt break | break.getTarget() = this |
this.getStmt().(BlockStmt).getLastStmt() = break
) and
// No `continue` statements.
not exists(ContinueStmt continue | continue.(JumpStmt).getTarget() = this)
not exists(ContinueStmt continue | continue.getTarget() = this)
}
}

View File

@@ -26,7 +26,7 @@ predicate loopCondition(LoopStmt loop, Expr cond, boolean polarity) {
ifstmt.getEnclosingStmt*() = loop.getBody() and
ifstmt.getCondition() = cond and
(
exit.(BreakStmt).(JumpStmt).getTarget() = loop or
exit.(BreakStmt).getTarget() = loop or
exit.(ReturnStmt).getEnclosingStmt*() = loop.getBody()
) and
(