Swift: move getName to Callable (hand-written)

Now that getStaticTarget returns a Callable.
This commit is contained in:
Nora Dimitrijević
2022-12-13 17:04:20 -05:00
parent 89cd082f0a
commit 535daf39b7
3 changed files with 20 additions and 8 deletions

View File

@@ -1,4 +1,19 @@
private import codeql.swift.generated.Callable
private import codeql.swift.elements.AstNode
private import codeql.swift.elements.decl.Decl
class Callable extends Generated::Callable, AstNode { }
class Callable extends Generated::Callable, AstNode {
/**
* Holds if this Callable is a function named `funcName`.
*/
predicate hasName(string funcName) { this.getName() = funcName }
/**
* Holds if this Callable is a function named `funcName` defined in a module
* called `moduleName`.
*/
predicate hasName(string moduleName, string funcName) {
this.hasName(funcName) and
this.(Decl).getModule().getFullName() = moduleName
}
}

View File

@@ -1,16 +1,12 @@
private import codeql.swift.generated.decl.AbstractFunctionDecl
private import codeql.swift.elements.decl.MethodDecl
private import codeql.swift.elements.Callable
/**
* A function.
*/
class AbstractFunctionDecl extends Generated::AbstractFunctionDecl {
class AbstractFunctionDecl extends Generated::AbstractFunctionDecl, Callable {
override string toString() { result = this.getName() }
/**
* Holds if this function is called `funcName`.
*/
predicate hasName(string funcName) { this.getName() = funcName }
}
/**

View File

@@ -177,12 +177,13 @@ class ParamDecl(VarDecl):
""")
class Callable(Element):
name: optional[string] | doc("name of this Callable")
self_param: optional[ParamDecl] | child
params: list[ParamDecl] | child
body: optional["BraceStmt"] | child | desc("The body is absent within protocol declarations.")
class AbstractFunctionDecl(GenericContext, ValueDecl, Callable):
name: string | doc("name of this function")
pass
class EnumElementDecl(ValueDecl):
name: string