Skip to content

Commit 90401b3

Browse files
authored
Merge pull request #21254 from owen-mc/go/astnode-get-enclosing-block
Go: Add `AstNode.getEnclosingBlock()`
2 parents d0bd845 + 8aa1bff commit 90401b3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

go/ql/lib/semmle/go/AST.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ class AstNode extends @node, Locatable {
8484
pragma[nomagic]
8585
FuncDef getEnclosingFunction() { result = this.getParent().parentInSameFunction*() }
8686

87+
/** Gets the innermost block statement to which this AST node belongs, if any. */
88+
BlockStmt getEnclosingBlock() {
89+
exists(AstNode p | p = this.getParent() |
90+
result = p
91+
or
92+
not p instanceof BlockStmt and
93+
result = p.getEnclosingBlock()
94+
)
95+
}
96+
8797
/**
8898
* Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs.
8999
*/

0 commit comments

Comments
 (0)