Skip to content

Commit 164d97d

Browse files
authored
Merge pull request #22475 from aschackmull/unified/ast-binaryexpr
Unified: Add some more AST classes.
2 parents 8e5e63b + 0909279 commit 164d97d

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

unified/ql/lib/codeql/unified/internal/AstExtra.qll

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@
55
private import unified
66

77
module Public {
8-
/**
9-
* A logical 'and' expression with short-circuiting.
10-
*/
8+
/** A short-circuiting logical AND expression. */
119
class LogicalAndExpr extends BinaryExpr {
1210
LogicalAndExpr() { this.getOperator().getValue() = "&&" }
11+
}
12+
13+
/** A short-circuiting logical OR expression. */
14+
class LogicalOrExpr extends BinaryExpr {
15+
LogicalOrExpr() { this.getOperator().getValue() = "||" }
16+
}
17+
18+
/** A short-circuiting null-coalescing expression. */
19+
class NullCoalescingExpr extends BinaryExpr {
20+
NullCoalescingExpr() { this.getOperator().getValue() = "??" }
21+
}
1322

14-
Expr getAnOperand() { result = [this.getLeft(), this.getRight()] }
23+
/** A logical NOT expression. */
24+
class LogicalNotExpr extends UnaryExpr {
25+
LogicalNotExpr() { this.getOperator().(PrefixOperator).getValue() = "!" }
1526
}
1627

1728
/**

unified/ql/lib/codeql/unified/internal/FacadeAst.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ module Unified {
4949
}
5050
}
5151

52+
/** A binary expression. */
53+
class BinaryExpr extends G::BinaryExpr {
54+
/** Gets an operand of this binary expression. */
55+
Expr getAnOperand() { result = [this.getLeft(), this.getRight()] }
56+
}
57+
5258
/** A function call */
5359
class CallExpr extends G::CallExpr {
5460
/** Gets the named argument with the given `name`. */

0 commit comments

Comments
 (0)