Merge pull request #9404 from MathiasVP/swift-get-enclosing-function

Swift: Add `getEnclosingFunction` to `AstNode`
This commit is contained in:
Robert Marsh
2022-06-13 09:37:51 -04:00
committed by GitHub

View File

@@ -1,4 +1,17 @@
// generated by codegen/codegen.py, remove this comment if you wish to edit this file
private import codeql.swift.generated.AstNode
private import codeql.swift.elements.decl.AbstractFunctionDecl
private import codeql.swift.generated.GetImmediateParent
class AstNode extends AstNodeBase { }
private Element getEnclosingFunctionStep(Element e) {
not e instanceof AbstractFunctionDecl and
result = getImmediateParent(e)
}
cached
private AbstractFunctionDecl getEnclosingFunctionCached(AstNode ast) {
result = getEnclosingFunctionStep*(getImmediateParent(ast))
}
class AstNode extends AstNodeBase {
final AbstractFunctionDecl getEnclosingFunction() { result = getEnclosingFunctionCached(this) }
}