Skip to content

Commit a7d9715

Browse files
committed
C++: BinaryOperation.hasOperands
QLDoc borrowed from JavaScript. Implementation borrowed from Java. Parameter names changed.
1 parent edc5e5f commit a7d9715

File tree

1 file changed

+11
-0
lines changed
  • cpp/ql/src/semmle/code/cpp/exprs

1 file changed

+11
-0
lines changed

cpp/ql/src/semmle/code/cpp/exprs/Expr.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,17 @@ class BinaryOperation extends Operation, @bin_op_expr {
539539
/** Gets the right operand of this binary operation. */
540540
Expr getRightOperand() { this.hasChild(result, 1) }
541541

542+
/**
543+
* Holds if `e1` and `e2` (in either order) are the two operands of this
544+
* binary operation.
545+
*/
546+
predicate hasOperands(Expr e1, Expr e2) {
547+
exists(int i | i in [0 .. 1] |
548+
this.hasChild(e1, i) and
549+
this.hasChild(e2, 1 - i)
550+
)
551+
}
552+
542553
override string toString() { result = "... " + this.getOperator() + " ..." }
543554

544555
override predicate mayBeImpure() {

0 commit comments

Comments
 (0)