Skip to content

Commit 964adaa

Browse files
committed
C#: Simplify to avoid binding sets.
1 parent 838e1f7 commit 964adaa

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

‎csharp/ql/src/Language Abuse/SimplifyBoolExpr.ql‎

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@ predicate rewriteBinaryExpr(BinaryOperation op, boolean value, string oldPattern
3737
literalChild(op, 1, value) and oldPattern = "A " + op.getOperator() + " " + value
3838
}
3939

40-
bindingset[withFalseOperand, withTrueOperand]
41-
predicate rewriteBinaryExpr(
42-
BinaryOperation op, string oldPattern, string withFalseOperand, string withTrueOperand,
43-
string newPattern
44-
) {
45-
rewriteBinaryExpr(op, false, oldPattern) and newPattern = withFalseOperand
46-
or
47-
rewriteBinaryExpr(op, true, oldPattern) and newPattern = withTrueOperand
48-
}
49-
5040
predicate rewriteConditionalExpr(ConditionalExpr cond, string oldPattern, string newPattern) {
5141
literalChild(cond, 1, false) and oldPattern = "A ? false : B" and newPattern = "!A && B"
5242
or
@@ -115,12 +105,20 @@ predicate pushNegation(LogicalNotExpr expr, string oldPattern, string newPattern
115105
)
116106
}
117107

118-
predicate rewrite(Expr expr, string oldPattern, string newPattern) {
108+
predicate rewriteBinaryOperation(BinaryOperation op, string oldPattern, string newPattern) {
119109
exists(string withFalseOperand, string withTrueOperand |
120-
simplifyBinaryExpr(expr.(BinaryOperation).getOperator(), withFalseOperand, withTrueOperand)
110+
simplifyBinaryExpr(op.getOperator(), withFalseOperand, withTrueOperand)
121111
|
122-
rewriteBinaryExpr(expr, oldPattern, withFalseOperand, withTrueOperand, newPattern)
112+
rewriteBinaryExpr(op, false, oldPattern) and
113+
newPattern = withFalseOperand
114+
or
115+
rewriteBinaryExpr(op, true, oldPattern) and
116+
newPattern = withTrueOperand
123117
)
118+
}
119+
120+
predicate rewrite(Expr expr, string oldPattern, string newPattern) {
121+
rewriteBinaryOperation(expr, oldPattern, newPattern)
124122
or
125123
rewriteConditionalExpr(expr, oldPattern, newPattern)
126124
or

0 commit comments

Comments
 (0)