Replace getDefaultOrNullDefaultCase with getDefaultCase

This commit is contained in:
Chris Smowton
2023-11-16 14:23:56 +00:00
parent 0bb051e08c
commit d2ff1baff0
7 changed files with 17 additions and 15 deletions

View File

@@ -923,7 +923,7 @@ private module ControlFlowGraphImpl {
completion = NormalCompletion()
or
// if no default case exists, then normal completion of the expression may terminate the switch
not exists(switch.getDefaultOrNullDefaultCase()) and
not exists(switch.getDefaultCase()) and
last(switch.getExpr(), last, completion) and
completion = NormalCompletion()
)

View File

@@ -1530,11 +1530,12 @@ class SwitchExpr extends Expr, StmtParent, @switchexpr {
/** Gets a (non-default) pattern `case` of this `switch` expression. */
PatternCase getAPatternCase() { result = this.getACase() }
/** Gets the `default` case of this switch expression, if any. */
DefaultCase getDefaultCase() { result = this.getACase() }
/** Gets the `default` or `case null, default` case of this switch statement, if any. */
SwitchCase getDefaultOrNullDefaultCase() { result = this.getACase() and result.hasDefaultLabel() }
/**
* Gets the `default` case of this switch statement, if any.
*
* Note this may be `default` or `case null, default`.
*/
SwitchCase getDefaultCase() { result = this.getACase() and result.hasDefaultLabel() }
/** Gets the expression of this `switch` expression. */
Expr getExpr() { result.getParent() = this }

View File

@@ -403,11 +403,12 @@ class SwitchStmt extends Stmt, @switchstmt {
/** Gets a (non-default) pattern `case` of this `switch` statement. */
PatternCase getAPatternCase() { result = this.getACase() }
/** Gets the `default` case of this switch statement, if any. */
DefaultCase getDefaultCase() { result = this.getACase() }
/** Gets the `default` or `case null, default` case of this switch statement, if any. */
SwitchCase getDefaultOrNullDefaultCase() { result = this.getACase() and result.hasDefaultLabel() }
/**
* Gets the `default` case of this switch statement, if any.
*
* Note this may be `default` or `case null, default`.
*/
SwitchCase getDefaultCase() { result = this.getACase() and result.hasDefaultLabel() }
/** Gets the expression of this `switch` statement. */
Expr getExpr() { result.getParent() = this }

View File

@@ -174,7 +174,7 @@ class ConstSwitchStmt extends SwitchStmt {
exists(this.getExpr().(ConstantExpr).getIntValue()) and
if exists(this.getMatchingConstCase())
then result = this.getMatchingConstCase()
else result = this.getDefaultOrNullDefaultCase()
else result = this.getDefaultCase()
}
/**