Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
C#: Simplify to avoid binding sets.
  • Loading branch information
michaelnebel committed Sep 30, 2026
commit 964adaa448f79e2ecd54768be95a40a44093eec8
24 changes: 11 additions & 13 deletions csharp/ql/src/Language Abuse/SimplifyBoolExpr.ql
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ predicate rewriteBinaryExpr(BinaryOperation op, boolean value, string oldPattern
literalChild(op, 1, value) and oldPattern = "A " + op.getOperator() + " " + value
}

bindingset[withFalseOperand, withTrueOperand]
predicate rewriteBinaryExpr(
BinaryOperation op, string oldPattern, string withFalseOperand, string withTrueOperand,
string newPattern
) {
rewriteBinaryExpr(op, false, oldPattern) and newPattern = withFalseOperand
or
rewriteBinaryExpr(op, true, oldPattern) and newPattern = withTrueOperand
}

predicate rewriteConditionalExpr(ConditionalExpr cond, string oldPattern, string newPattern) {
literalChild(cond, 1, false) and oldPattern = "A ? false : B" and newPattern = "!A && B"
or
Expand Down Expand Up @@ -115,12 +105,20 @@ predicate pushNegation(LogicalNotExpr expr, string oldPattern, string newPattern
)
}

predicate rewrite(Expr expr, string oldPattern, string newPattern) {
predicate rewriteBinaryOperation(BinaryOperation op, string oldPattern, string newPattern) {
exists(string withFalseOperand, string withTrueOperand |
simplifyBinaryExpr(expr.(BinaryOperation).getOperator(), withFalseOperand, withTrueOperand)
simplifyBinaryExpr(op.getOperator(), withFalseOperand, withTrueOperand)
|
rewriteBinaryExpr(expr, oldPattern, withFalseOperand, withTrueOperand, newPattern)
rewriteBinaryExpr(op, false, oldPattern) and
newPattern = withFalseOperand
or
rewriteBinaryExpr(op, true, oldPattern) and
newPattern = withTrueOperand
)
}

predicate rewrite(Expr expr, string oldPattern, string newPattern) {
rewriteBinaryOperation(expr, oldPattern, newPattern)
or
rewriteConditionalExpr(expr, oldPattern, newPattern)
or
Expand Down