Skip to content

Commit a232f28

Browse files
committed
C#: Preserve the semantics of the cs/complex-condition query.
1 parent fc5347b commit a232f28

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

csharp/ql/src/Complexity/ComplexCondition.ql

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,38 @@
1212

1313
import csharp
1414

15-
predicate nontrivialLogicalOperator(BinaryLogicalOperation e) {
16-
not exists(BinaryLogicalOperation parent |
15+
abstract class RelevantBinaryOperations extends Operation { }
16+
17+
private class AddBinaryLogicalOperationRelevantBinaryOperations extends RelevantBinaryOperations,
18+
BinaryLogicalOperation
19+
{ }
20+
21+
private class AddAssignCoalesceExprRelevantBinaryOperations extends RelevantBinaryOperations,
22+
AssignCoalesceExpr
23+
{ }
24+
25+
abstract class RelevantOperations extends Operation { }
26+
27+
private class AddLogicalOperationRelevantOperations extends RelevantOperations, LogicalOperation { }
28+
29+
private class AddAssignCoalesceExprRelevantOperations extends RelevantOperations, AssignCoalesceExpr
30+
{ }
31+
32+
predicate nontrivialLogicalOperator(RelevantBinaryOperations e) {
33+
not exists(RelevantBinaryOperations parent |
1734
parent = e.getParent() and
1835
parent.getOperator() = e.getOperator()
1936
)
2037
}
2138

22-
predicate logicalParent(LogicalOperation op, LogicalOperation parent) { parent = op.getParent() }
39+
predicate logicalParent(RelevantOperations op, RelevantOperations parent) {
40+
parent = op.getParent()
41+
}
2342

2443
from Expr e, int operators
2544
where
26-
not e.getParent() instanceof LogicalOperation and
45+
not e.getParent() instanceof RelevantOperations and
2746
operators =
28-
count(BinaryLogicalOperation op | logicalParent*(op, e) and nontrivialLogicalOperator(op)) and
47+
count(RelevantBinaryOperations op | logicalParent*(op, e) and nontrivialLogicalOperator(op)) and
2948
operators > 3
3049
select e, "Complex condition: too many logical operations in this expression."

0 commit comments

Comments
 (0)