Skip to content

Commit 0db3282

Browse files
committed
C#: Let assign operations be operator calls.
1 parent 11af6ee commit 0db3282

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ class AssignExpr extends Assignment, @simple_assign_expr {
6464

6565
/**
6666
* An assignment operation. Either an arithmetic assignment operation
67-
* (`AssignArithmeticOperation`), a bitwise assignment operation
68-
* (`AssignBitwiseOperation`), or an event assignment (`AddOrRemoveEventExpr`).
67+
* (`AssignArithmeticOperation`), a bitwise assignment operation or
68+
* (`AssignBitwiseOperation`).
6969
*/
70-
class AssignOperation extends Assignment, @assign_op_expr {
70+
class AssignOperation extends Assignment, OperatorCall, @assign_op_expr {
7171
override string getOperator() { none() }
7272

7373
/**
@@ -79,7 +79,7 @@ class AssignOperation extends Assignment, @assign_op_expr {
7979
* If an expanded version exists, then it is used in the control
8080
* flow graph.
8181
*/
82-
AssignExpr getExpandedAssignment() { expr_parent(result, 2, this) }
82+
AssignExpr getExpandedAssignment() { none() }
8383

8484
/**
8585
* Holds if this assignment operation has an expanded version.
@@ -92,6 +92,16 @@ class AssignOperation extends Assignment, @assign_op_expr {
9292
*/
9393
predicate hasExpandedAssignment() { exists(this.getExpandedAssignment()) }
9494

95+
override Expr getLeftOperand() { result = this.getChild(0) }
96+
97+
override Expr getRightOperand() { result = this.getChild(1) }
98+
99+
/** Gets the left operand of this assignment. */
100+
override Expr getLValue() { result = this.getChild(0) }
101+
102+
/** Gets the right operand of this assignment. */
103+
override Expr getRValue() { result = this.getChild(1) }
104+
95105
override string toString() { result = "... " + this.getOperator() + " ..." }
96106
}
97107

@@ -218,13 +228,21 @@ class AssignUnsighedRightShiftExpr extends AssignBitwiseOperation, @assign_urshi
218228
* An event assignment. Either an event addition (`AddEventExpr`) or an event
219229
* removal (`RemoveEventExpr`).
220230
*/
221-
class AddOrRemoveEventExpr extends AssignOperation, @assign_event_expr {
231+
class AddOrRemoveEventExpr extends Assignment, @assign_event_expr {
232+
override string getOperator() { none() }
233+
222234
/** Gets the event targeted by this event assignment. */
223235
Event getTarget() { result = this.getLValue().getTarget() }
224236

225237
override EventAccess getLValue() { result = this.getChild(1) }
226238

227239
override Expr getRValue() { result = this.getChild(0) }
240+
241+
override EventAccess getLeftOperand() { result = this.getChild(1) }
242+
243+
override Expr getRightOperand() { result = this.getChild(0) }
244+
245+
override string toString() { result = "... " + this.getOperator() + " ..." }
228246
}
229247

230248
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ class ConstructorInitializer extends Call, @constructor_init_expr {
493493
* }
494494
* ```
495495
*/
496-
class OperatorCall extends Call, LateBindableExpr, @operator_invocation_expr {
496+
class OperatorCall extends Call, LateBindableExpr, @op_invoke_expr {
497497
override Operator getTarget() { expr_call(this, result) }
498498

499499
override Operator getARuntimeTarget() { result = Call.super.getARuntimeTarget() }

0 commit comments

Comments
 (0)