Generalise splitting of parenthesized exprs to all statement sequences

This commit is contained in:
Nick Rolfe
2021-03-18 11:21:11 +00:00
parent c8eab42c1d
commit ceda7c8fd2
5 changed files with 8 additions and 8 deletions

View File

@@ -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()) }

View File

@@ -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 {

View File

@@ -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

View File

@@ -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

View File

@@ -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