Skip to content

Commit 8aa1bff

Browse files
committed
Add AstNode.getEnclosingBlock()
1 parent 5204255 commit 8aa1bff

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)