Skip to content

Commit 8d775d4

Browse files
committed
C#: Let assign operations be operator calls.
1 parent 1bd9636 commit 8d775d4

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class AssignExpr extends Assignment, @simple_assign_expr {
6767
* (`AssignArithmeticOperation`), a bitwise assignment operation
6868
* (`AssignBitwiseOperation`), or an event assignment (`AddOrRemoveEventExpr`).
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

@@ -219,8 +229,9 @@ class AssignUnsighedRightShiftExpr extends AssignBitwiseOperation, @assign_urshi
219229
* removal (`RemoveEventExpr`).
220230
*/
221231
class AddOrRemoveEventExpr extends AssignOperation, @assign_event_expr {
232+
// TODO: We need to handle such cases differently as there is no underlying operatorcall.
222233
/** Gets the event targeted by this event assignment. */
223-
Event getTarget() { result = this.getLValue().getTarget() }
234+
Event getTargetEvent() { result = this.getLValue().getTarget() }
224235

225236
override EventAccess getLValue() { result = this.getChild(1) }
226237

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)