mirror of
https://github.com/github/codeql.git
synced 2025-12-24 12:46:34 +01:00
Generalise splitting of parenthesized exprs to all statement sequences
This commit is contained in:
@@ -73,8 +73,8 @@ class StmtSequence extends Expr, TStmtSequence {
|
||||
/** Gets a statement in this sequence. */
|
||||
final Stmt getAStmt() { result = this.getStmt(_) }
|
||||
|
||||
/** Gets the last expression in this sequence, if any. */
|
||||
final Expr getLastExpr() { result = this.getStmt(this.getNumberOfStatements() - 1) }
|
||||
/** Gets the last statement in this sequence, if any. */
|
||||
final Stmt getLastStmt() { result = this.getStmt(this.getNumberOfStatements() - 1) }
|
||||
|
||||
/** Gets the number of statements in this sequence. */
|
||||
final int getNumberOfStatements() { result = count(this.getAStmt()) }
|
||||
|
||||
@@ -284,7 +284,7 @@ module ExprNodes {
|
||||
}
|
||||
|
||||
private class StmtSequenceChildMapping extends ExprChildMapping, StmtSequence {
|
||||
override predicate relevantChild(Expr e) { e = this.getLastExpr() }
|
||||
override predicate relevantChild(Expr e) { e = this.getLastStmt() }
|
||||
}
|
||||
|
||||
/** A control-flow node that wraps a `StmtSequence` AST expression. */
|
||||
@@ -293,8 +293,8 @@ module ExprNodes {
|
||||
|
||||
final override StmtSequence getExpr() { result = ExprCfgNode.super.getExpr() }
|
||||
|
||||
/** Gets the last expression in this sequence, if any. */
|
||||
final ExprCfgNode getLastExpr() { e.hasCfgChild(e.getLastExpr(), this, result) }
|
||||
/** Gets the last statement in this sequence, if any. */
|
||||
final ExprCfgNode getLastStmt() { e.hasCfgChild(e.getLastStmt(), this, result) }
|
||||
}
|
||||
|
||||
private class ForExprChildMapping extends ExprChildMapping, ForExpr {
|
||||
|
||||
@@ -176,7 +176,7 @@ private predicate inBooleanContext(AstNode n) {
|
||||
or
|
||||
n = any(NotExpr parent | inBooleanContext(parent)).getOperand()
|
||||
or
|
||||
n = any(StmtSequence parent | inBooleanContext(parent)).getLastExpr()
|
||||
n = any(StmtSequence parent | inBooleanContext(parent)).getLastStmt()
|
||||
or
|
||||
exists(CaseExpr c, WhenExpr w |
|
||||
not exists(c.getValue()) and
|
||||
|
||||
@@ -226,7 +226,7 @@ private module ConditionalCompletionSplitting {
|
||||
last(succ.(LogicalOrExpr).getAnOperand(), pred, c) and
|
||||
completion = c
|
||||
or
|
||||
last(succ.(ParenthesizedExpr).getLastExpr(), pred, c) and
|
||||
last(succ.(StmtSequence).getLastStmt(), pred, c) and
|
||||
completion = c
|
||||
or
|
||||
last(succ.(ConditionalExpr).getBranch(_), pred, c) and
|
||||
|
||||
@@ -126,7 +126,7 @@ private module Cached {
|
||||
or
|
||||
nodeFrom.asExpr() = nodeTo.asExpr().(CfgNodes::ExprNodes::AssignExprCfgNode).getRhs()
|
||||
or
|
||||
nodeFrom.asExpr() = nodeTo.asExpr().(CfgNodes::ExprNodes::StmtSequenceCfgNode).getLastExpr()
|
||||
nodeFrom.asExpr() = nodeTo.asExpr().(CfgNodes::ExprNodes::StmtSequenceCfgNode).getLastStmt()
|
||||
or
|
||||
nodeFrom.asExpr() = nodeTo.asExpr().(CfgNodes::ExprNodes::ConditionalExprCfgNode).getBranch(_)
|
||||
or
|
||||
|
||||
Reference in New Issue
Block a user