Java: Make JumpStmt a proper superclass

This commit is contained in:
Marcono1234
2022-03-28 19:13:16 +02:00
parent 8faabb837a
commit a93b4ed0f2
11 changed files with 65 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
(