Skip to content

Commit 82d09f6

Browse files
committed
C#: Add a QL class for UnaryNotOperation.
1 parent 94079fb commit 82d09f6

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

csharp/ql/lib/semmle/code/csharp/exprs/Expr.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,24 @@ class UnaryCallOperation extends OperatorCall, UnaryOperation, @un_op_call_expr
243243
override string toString() { result = UnaryOperation.super.toString() }
244244
}
245245

246+
/**
247+
* A logical 'not', for example `!String.IsNullOrEmpty(s)` or a call to a user-defined
248+
* not operator such as `!x` in:
249+
* ```csharp
250+
* class Negatable {
251+
* public static Negatable operator !(Negatable n) => { ...};
252+
* }
253+
*
254+
* var x = new Negatable();
255+
* var y = !x;
256+
* ```
257+
*/
258+
class UnaryNotOperation extends UnaryCallOperation, @un_not_op_expr {
259+
override string getOperator() { result = "!" }
260+
261+
override string getAPrimaryQlClass() { result = "UnaryNotOperation" }
262+
}
263+
246264
/**
247265
* A binary operation. Either a binary arithmetic operation
248266
* (`BinaryArithmeticOperation`), a binary bitwise operation

csharp/ql/lib/semmle/code/csharp/exprs/LogicalOperation.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class UnaryLogicalOperation extends LogicalOperation, UnaryCallOperation, @un_lo
2323
/**
2424
* A logical 'not', for example `!String.IsNullOrEmpty(s)`.
2525
*/
26-
class LogicalNotExpr extends UnaryLogicalOperation, @log_not_expr {
27-
override string getOperator() { result = "!" }
26+
class LogicalNotExpr extends UnaryLogicalOperation, UnaryNotOperation, @log_not_expr {
27+
override string getOperator() { result = UnaryNotOperation.super.getOperator() }
2828

2929
override string getAPrimaryQlClass() { result = "LogicalNotExpr" }
3030
}

0 commit comments

Comments
 (0)