Skip to content

Commit 970e991

Browse files
committed
unified: Add a few more AST helper classes
1 parent 982f6a5 commit 970e991

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,39 @@
55
private import unified
66

77
module Public {
8+
/**
9+
* A logical 'and' expression with short-circuiting.
10+
*/
11+
class LogicalAndExpr extends BinaryExpr {
12+
LogicalAndExpr() { this.getOperator().getValue() = "&&" }
13+
14+
Expr getAnOperand() { result = [this.getLeft(), this.getRight()] }
15+
}
16+
17+
/**
18+
* Declaration of a local or top-level variable.
19+
*/
20+
class LocalVariableDeclaration extends VariableDeclaration {
21+
private Block block;
22+
23+
LocalVariableDeclaration() { this = block.getStmt(_) }
24+
25+
/** Gets the block in which this variable is declared. */
26+
Block getDeclaringBlock() { result = block }
27+
}
28+
29+
/**
30+
* Declaration of a local or top-level function.
31+
*/
32+
class LocalFunctionDeclaration extends FunctionDeclaration {
33+
private Block block;
34+
35+
LocalFunctionDeclaration() { this = block.getStmt(_) }
36+
37+
/** Gets the block in which this function is declared. */
38+
Block getDeclaringBlock() { result = block }
39+
}
40+
841
/**
942
* A comment appearing in the source code.
1043
*/

0 commit comments

Comments
 (0)