Add AstNode.getEnclosingBlock()

This commit is contained in:
Owen Mansel-Chan
2026-02-01 22:59:19 +00:00
parent 5204255615
commit 8aa1bff9a5

View File

@@ -84,6 +84,16 @@ class AstNode extends @node, Locatable {
pragma[nomagic]
FuncDef getEnclosingFunction() { result = this.getParent().parentInSameFunction*() }
/** Gets the innermost block statement to which this AST node belongs, if any. */
BlockStmt getEnclosingBlock() {
exists(AstNode p | p = this.getParent() |
result = p
or
not p instanceof BlockStmt and
result = p.getEnclosingBlock()
)
}
/**
* Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs.
*/