Skip to content

Commit 84518c8

Browse files
authored
Merge pull request github#9404 from MathiasVP/swift-get-enclosing-function
Swift: Add `getEnclosingFunction` to `AstNode`
2 parents 3ae6080 + cde2880 commit 84518c8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed
Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
1-
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
21
private import codeql.swift.generated.AstNode
2+
private import codeql.swift.elements.decl.AbstractFunctionDecl
3+
private import codeql.swift.generated.GetImmediateParent
34

4-
class AstNode extends AstNodeBase { }
5+
private Element getEnclosingFunctionStep(Element e) {
6+
not e instanceof AbstractFunctionDecl and
7+
result = getImmediateParent(e)
8+
}
9+
10+
cached
11+
private AbstractFunctionDecl getEnclosingFunctionCached(AstNode ast) {
12+
result = getEnclosingFunctionStep*(getImmediateParent(ast))
13+
}
14+
15+
class AstNode extends AstNodeBase {
16+
final AbstractFunctionDecl getEnclosingFunction() { result = getEnclosingFunctionCached(this) }
17+
}

0 commit comments

Comments
 (0)