diff --git a/ql/src/codeql_ql/ast/Ast.qll b/ql/src/codeql_ql/ast/Ast.qll index fc96dabb75c..3ef2a87a7f4 100644 --- a/ql/src/codeql_ql/ast/Ast.qll +++ b/ql/src/codeql_ql/ast/Ast.qll @@ -56,6 +56,15 @@ class AstNode extends TAstNode { * Gets the primary QL class for the ast node. */ string getAPrimaryQlClass() { result = "???" } + + /** + * Gets the predicate that contains this AST node. + */ + pragma[noinline] + Predicate getEnclosingPredicate() { + not this instanceof Predicate and + toGenerated(result) = toGenerated(this).getParent+() + } } /** A toplevel QL program, i.e. a file. */