Skip to content

Commit 535daf3

Browse files
committed
Swift: move getName to Callable (hand-written)
Now that getStaticTarget returns a Callable.
1 parent 89cd082 commit 535daf3

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
private import codeql.swift.generated.Callable
22
private import codeql.swift.elements.AstNode
3+
private import codeql.swift.elements.decl.Decl
34

4-
class Callable extends Generated::Callable, AstNode { }
5+
class Callable extends Generated::Callable, AstNode {
6+
/**
7+
* Holds if this Callable is a function named `funcName`.
8+
*/
9+
predicate hasName(string funcName) { this.getName() = funcName }
10+
11+
/**
12+
* Holds if this Callable is a function named `funcName` defined in a module
13+
* called `moduleName`.
14+
*/
15+
predicate hasName(string moduleName, string funcName) {
16+
this.hasName(funcName) and
17+
this.(Decl).getModule().getFullName() = moduleName
18+
}
19+
}

swift/ql/lib/codeql/swift/elements/decl/AbstractFunctionDecl.qll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
private import codeql.swift.generated.decl.AbstractFunctionDecl
22
private import codeql.swift.elements.decl.MethodDecl
3+
private import codeql.swift.elements.Callable
34

45
/**
56
* A function.
67
*/
7-
class AbstractFunctionDecl extends Generated::AbstractFunctionDecl {
8+
class AbstractFunctionDecl extends Generated::AbstractFunctionDecl, Callable {
89
override string toString() { result = this.getName() }
9-
10-
/**
11-
* Holds if this function is called `funcName`.
12-
*/
13-
predicate hasName(string funcName) { this.getName() = funcName }
1410
}
1511

1612
/**

swift/schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,13 @@ class ParamDecl(VarDecl):
177177
""")
178178

179179
class Callable(Element):
180+
name: optional[string] | doc("name of this Callable")
180181
self_param: optional[ParamDecl] | child
181182
params: list[ParamDecl] | child
182183
body: optional["BraceStmt"] | child | desc("The body is absent within protocol declarations.")
183184

184185
class AbstractFunctionDecl(GenericContext, ValueDecl, Callable):
185-
name: string | doc("name of this function")
186+
pass
186187

187188
class EnumElementDecl(ValueDecl):
188189
name: string

0 commit comments

Comments
 (0)