Add StmtExpr flow

This commit is contained in:
Tony Torralba
2022-02-21 15:42:52 +01:00
committed by Ian Lynagh
parent b626e80a61
commit c4c254587e
2 changed files with 14 additions and 6 deletions

View File

@@ -990,9 +990,7 @@ class ValueNEExpr extends BinaryExpr, @valueneexpr {
* need to distinguish them, use `EQExpr` or `ValueEQExpr` instead.
*/
class AnyEqualsExpr extends BinaryExpr {
AnyEqualsExpr() {
this instanceof EQExpr or this instanceof ValueEQExpr
}
AnyEqualsExpr() { this instanceof EQExpr or this instanceof ValueEQExpr }
}
/**
@@ -1002,9 +1000,7 @@ class AnyEqualsExpr extends BinaryExpr {
* need to distinguish them, use `EQExpr` or `ValueEQExpr` instead.
*/
class AnyNotEqualsExpr extends BinaryExpr {
AnyNotEqualsExpr() {
this instanceof NEExpr or this instanceof ValueNEExpr
}
AnyNotEqualsExpr() { this instanceof NEExpr or this instanceof ValueNEExpr }
}
/**
@@ -2353,6 +2349,16 @@ class StmtExpr extends Expr, @stmtexpr {
override string getHalsteadID() { result = "StmtExpr" }
override string getAPrimaryQlClass() { result = "StmtExpr" }
/**
* Gets the result expression of the enclosed statement.
*/
Expr getResultExpr() { result = getStmtResultExpr(this.getStmt()) }
}
private Expr getStmtResultExpr(Stmt stmt) {
result = stmt.(ExprStmt).getExpr() or
result = getStmtResultExpr(stmt.(BlockStmt).getLastStmt())
}
/**

View File

@@ -152,6 +152,8 @@ predicate simpleLocalFlowStep(Node node1, Node node2) {
or
node2.asExpr().(ArrayCreationExpr).getInit() = node1.asExpr()
or
node2.asExpr() = any(StmtExpr stmtExpr | node1.asExpr() = stmtExpr.getResultExpr())
or
exists(MethodAccess ma, ValuePreservingMethod m, int argNo |
ma.getCallee().getSourceDeclaration() = m and m.returnsValue(argNo)
|