mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Add pattern-case support and generally debug switch CFGs
These were reasonably broken beforehand, due to not taking switch rules into account in enough places, and confusing the expression/statement switch rule distinction with the distinction between switch statements and expressions.
(For example, `switch(x) { 1 -> System.out.println("Hello world") ... }` is a statement, but has a rule expression).
This commit is contained in:
@@ -387,7 +387,8 @@ class SwitchStmt extends Stmt, @switchstmt {
|
||||
* which may be either a normal `case` or a `default`.
|
||||
*/
|
||||
SwitchCase getCase(int i) {
|
||||
result = rank[i](SwitchCase case, int idx | case.isNthChildOf(this, idx) | case order by idx)
|
||||
result =
|
||||
rank[i + 1](SwitchCase case, int idx | case.isNthChildOf(this, idx) | case order by idx)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -469,7 +470,17 @@ class SwitchCase extends Stmt, @case {
|
||||
* This predicate is mutually exclusive with `getRuleExpression`.
|
||||
*/
|
||||
Stmt getRuleStatement() {
|
||||
result.getParent() = this and result.getIndex() = -1 and not result instanceof ExprStmt
|
||||
result = this.getRuleStatementOrExpressionStatement() and not result instanceof ExprStmt
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the statement, including an expression statement, on the RHS of the arrow, if any.
|
||||
*
|
||||
* This means this could be an explicit `case e1 -> { s1; ... }` or an implicit
|
||||
* `case e1 -> stmt;` rule.
|
||||
*/
|
||||
Stmt getRuleStatementOrExpressionStatement() {
|
||||
result.getParent() = this and result.getIndex() = -1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user