Skip to content

Commit 76346ec

Browse files
authored
Merge pull request #21417 from aschackmull/csharp/binary-assignment
C#: Make Assignment extend BinaryOperation.
2 parents feb45e5 + d9ef9f8 commit 76346ec

File tree

10 files changed

+5970
-4
lines changed

10 files changed

+5970
-4
lines changed

csharp/downgrades/e73ca2c93df8aae162f1704edc4817a5cb330529/old.dbscheme

Lines changed: 1489 additions & 0 deletions
Large diffs are not rendered by default.

csharp/downgrades/e73ca2c93df8aae162f1704edc4817a5cb330529/semmlecode.csharp.dbscheme

Lines changed: 1489 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
description: Remove inclusion of @assign_expr in @bin_op
2+
compatibility: full

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Expr
1111
* (`LocalVariableDeclAndInitExpr`), a simple assignment (`AssignExpr`), or
1212
* an assignment operation (`AssignOperation`).
1313
*/
14-
class Assignment extends Operation, @assign_expr {
14+
class Assignment extends BinaryOperation, @assign_expr {
1515
Assignment() {
1616
this instanceof LocalVariableDeclExpr
1717
implies
@@ -20,6 +20,10 @@ class Assignment extends Operation, @assign_expr {
2020
expr_parent(_, 0, this)
2121
}
2222

23+
override Expr getLeftOperand() { result = this.getChild(1) }
24+
25+
override Expr getRightOperand() { result = this.getChild(0) }
26+
2327
/** Gets the left operand of this assignment. */
2428
Expr getLValue() { result = this.getChild(1) }
2529

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ class UnaryOperation extends Operation, @un_op {
244244
* A binary operation. Either a binary arithmetic operation
245245
* (`BinaryArithmeticOperation`), a binary bitwise operation
246246
* (`BinaryBitwiseOperation`), a comparison operation (`ComparisonOperation`),
247-
* or a binary logical operation (`BinaryLogicalOperation`).
247+
* a binary logical operation (`BinaryLogicalOperation`), or an
248+
* assignment (`Assignment`).
248249
*/
249250
class BinaryOperation extends Operation, @bin_op {
250251
/** Gets the left operand of this binary operation. */

csharp/ql/lib/semmlecode.csharp.dbscheme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,10 +1261,10 @@ case @expr.kind of
12611261
@rel_op_expr = @gt_expr | @lt_expr| @ge_expr | @le_expr;
12621262
@comp_expr = @equality_op_expr | @rel_op_expr;
12631263

1264-
@op_expr = @assign_expr | @un_op | @bin_op | @ternary_op;
1264+
@op_expr = @un_op | @bin_op | @ternary_op;
12651265

12661266
@ternary_op = @ternary_log_op_expr;
1267-
@bin_op = @bin_arith_op_expr | @bin_log_op_expr | @bin_bit_op_expr | @comp_expr;
1267+
@bin_op = @assign_expr | @bin_arith_op_expr | @bin_log_op_expr | @bin_bit_op_expr | @comp_expr;
12681268
@un_op = @un_arith_op_expr | @un_log_op_expr | @un_bit_op_expr | @sizeof_expr
12691269
| @pointer_indirection_expr | @address_of_expr;
12701270

0 commit comments

Comments
 (0)