Account for pattern-cases in more places

This commit is contained in:
Chris Smowton
2023-10-30 12:19:15 +00:00
parent 2b16121638
commit 9a450b09be
2 changed files with 7 additions and 5 deletions

View File

@@ -73,13 +73,15 @@ class MetricCallable extends Callable {
// so there should be a branching point for each non-default switch
// case (ignoring those that just fall through to the next case).
private predicate branchingSwitchCase(ConstCase sc) {
not sc.(ControlFlowNode).getASuccessor() instanceof ConstCase and
not sc.(ControlFlowNode).getASuccessor() instanceof DefaultCase and
not sc.(ControlFlowNode).getASuccessor() instanceof SwitchCase and
not defaultFallThrough(sc)
}
private predicate defaultFallThrough(ConstCase sc) {
exists(DefaultCase default | default.(ControlFlowNode).getASuccessor() = sc) or
exists(SwitchCase default | default.hasDefaultLabel() |
default.(ControlFlowNode).getASuccessor() = sc
)
or
defaultFallThrough(sc.(ControlFlowNode).getAPredecessor())
}
@@ -90,6 +92,7 @@ private predicate branchingStmt(Stmt stmt) {
stmt instanceof DoStmt or
stmt instanceof ForStmt or
stmt instanceof EnhancedForStmt or
stmt instanceof PatternCase or
branchingSwitchCase(stmt) or
stmt instanceof CatchClause
}

View File

@@ -17,8 +17,7 @@ import Common
from SwitchStmt s, Stmt c
where
c = s.getACase() and
not c.(ControlFlowNode).getASuccessor() instanceof ConstCase and
not c.(ControlFlowNode).getASuccessor() instanceof DefaultCase and
not c.(ControlFlowNode).getASuccessor() instanceof SwitchCase and
not s.(Annotatable).suppressesWarningsAbout("fallthrough") and
mayDropThroughWithoutComment(s, c)
select c,