From 5dcc161f2da9faadecb955748e0f164eaca85f81 Mon Sep 17 00:00:00 2001 From: Erik Krogh Kristensen Date: Sat, 29 May 2021 08:25:56 +0000 Subject: [PATCH] add getEnclosingPredicate utility predicate --- ql/src/codeql_ql/ast/Ast.qll | 9 +++++++++ 1 file changed, 9 insertions(+) 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. */