Skip to content

Commit a99deca

Browse files
committed
C#: Swap left and right child in assignments in the QL library.
1 parent fe3c85a commit a99deca

File tree

5 files changed

+8
-36
lines changed

5 files changed

+8
-36
lines changed

csharp/ql/lib/semmle/code/csharp/Property.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class Property extends DeclarationWithGetSetAccessors, @property {
226226
* }
227227
* ```
228228
*/
229-
Expr getInitializer() { result = this.getChildExpr(1).getChildExpr(0) }
229+
Expr getInitializer() { result = this.getChildExpr(1).getChildExpr(1) }
230230

231231
/**
232232
* Holds if this property has an initial value. For example, the initial

csharp/ql/lib/semmle/code/csharp/Variable.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ class Field extends Variable, AssignableMember, Attributable, TopLevelExprParent
408408
* }
409409
* ```
410410
*/
411-
final override Expr getInitializer() { result = this.getChildExpr(0).getChildExpr(0) }
411+
final override Expr getInitializer() { result = this.getChildExpr(0).getChildExpr(1) }
412412

413413
/**
414414
* Holds if this field has an initial value. For example, the initial

csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ module Expressions {
469469
private AstNode getExprChild0(Expr e, int i) {
470470
not e instanceof NameOfExpr and
471471
not e instanceof QualifiableExpr and
472-
not e instanceof Assignment and
473472
not e instanceof AnonymousFunctionExpr and
474473
result = e.getChild(i)
475474
or
@@ -480,15 +479,6 @@ module Expressions {
480479
not qe instanceof ExtensionMethodCall and
481480
result = qe.getChild(i)
482481
)
483-
or
484-
// TODO: This can be fixed if the extracted indexes are fixed.
485-
e =
486-
any(Assignment a |
487-
// The left-hand side of an assignment is evaluated before the right-hand side
488-
i = 0 and result = a.getLValue()
489-
or
490-
i = 1 and result = a.getRValue()
491-
)
492482
}
493483

494484
private AstNode getExprChild(Expr e, int i) {

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

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,14 @@ class Assignment extends BinaryOperation, @assign_expr {
1717
implies
1818
// Same as `this.(LocalVariableDeclExpr).hasInitializer()` but avoids
1919
// negative recursion
20-
expr_parent(_, 0, this)
20+
expr_parent(_, 1, this)
2121
}
2222

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

3026
/** Gets the right operand of this assignment. */
31-
Expr getRValue() { result = this.getChild(0) }
27+
Expr getRValue() { result = this.getRightOperand() }
3228

3329
/** Gets the variable being assigned to, if any. */
3430
Variable getTargetVariable() { result.getAnAccess() = this.getLValue() }
@@ -80,16 +76,6 @@ class AssignOperation extends Assignment, OperatorCall, @assign_op_expr {
8076
*/
8177
deprecated predicate hasExpandedAssignment() { none() }
8278

83-
override Expr getLeftOperand() { result = this.getChild(0) }
84-
85-
override Expr getRightOperand() { result = this.getChild(1) }
86-
87-
/** Gets the left operand of this assignment. */
88-
override Expr getLValue() { result = this.getChild(0) }
89-
90-
/** Gets the right operand of this assignment. */
91-
override Expr getRValue() { result = this.getChild(1) }
92-
9379
override string toString() { result = "... " + this.getOperator() + " ..." }
9480
}
9581

@@ -222,13 +208,9 @@ class AddOrRemoveEventExpr extends Assignment, @assign_event_expr {
222208
/** Gets the event targeted by this event assignment. */
223209
Event getTarget() { result = this.getLValue().getTarget() }
224210

225-
override EventAccess getLValue() { result = this.getChild(1) }
226-
227-
override Expr getRValue() { result = this.getChild(0) }
228-
229-
override EventAccess getLeftOperand() { result = this.getChild(1) }
211+
override EventAccess getLValue() { result = this.getChild(0) }
230212

231-
override Expr getRightOperand() { result = this.getChild(0) }
213+
override EventAccess getLeftOperand() { result = this.getChild(0) }
232214

233215
override string toString() { result = "... " + this.getOperator() + " ..." }
234216
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class LocalVariableDeclExpr extends Expr, @local_var_decl_expr {
154154
string getName() { result = this.getVariable().getName() }
155155

156156
/** Gets the initializer expression of this local variable declaration, if any. */
157-
Expr getInitializer() { result = this.getChild(0) }
157+
Expr getInitializer() { result = this.getChild(1) }
158158

159159
/** Holds if this local variable declaration has an initializer. */
160160
predicate hasInitializer() { exists(this.getInitializer()) }

0 commit comments

Comments
 (0)