Skip to content

Commit cf08644

Browse files
committed
Swift: Add an AST class for possible method declarations.
1 parent e2478d1 commit cf08644

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
private import swift
2+
3+
private Decl getAMember(IterableDeclContext ctx) {
4+
ctx.getAMember() = result
5+
or
6+
exists(VarDecl var |
7+
ctx.getAMember() = var and
8+
var.getAnAccessorDecl() = result
9+
)
10+
}
11+
12+
class MethodDecl extends AbstractFunctionDecl {
13+
MethodDecl() {
14+
this = getAMember(any(ClassDecl c))
15+
or
16+
this = getAMember(any(StructDecl c))
17+
or
18+
this = getAMember(any(ExtensionDecl c))
19+
or
20+
this = getAMember(any(EnumDecl c))
21+
or
22+
this = getAMember(any(ProtocolDecl c))
23+
}
24+
}

swift/ql/lib/swift.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22

33
import codeql.swift.elements
44
import codeql.swift.elements.expr.LogicalOperation
5+
import codeql.swift.elements.decl.MethodDecl

0 commit comments

Comments
 (0)