Skip to content

Commit 273053c

Browse files
committed
Swift: Extract self parameter declarations.
1 parent 4df2e5d commit 273053c

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

swift/codegen/schema.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ AstNode:
8181
Callable:
8282
_children:
8383
params: ParamDecl*
84+
self_param: ParamDecl?
8485
body: BraceStmt?
8586

8687
ConditionElement:

swift/extractor/visitors/DeclVisitor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ void DeclVisitor::fillAbstractFunctionDecl(const swift::AbstractFunctionDecl& de
327327
entry.name = !decl.hasName() ? "(unnamed function decl)" : constructName(decl.getName());
328328
entry.body = dispatcher_.fetchOptionalLabel(decl.getBody());
329329
entry.params = dispatcher_.fetchRepeatedLabels(*decl.getParameters());
330+
auto self = const_cast<swift::ParamDecl* const>(decl.getImplicitSelfDecl());
331+
entry.self_param = dispatcher_.fetchOptionalLabel(self);
330332
fillValueDecl(decl, entry);
331333
fillGenericContext(decl, entry);
332334
}

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ class ParamDecl extends ParamDeclBase {
55
/** Gets the function which declares this parameter. */
66
Callable getDeclaringFunction() { result.getAParam() = this }
77

8-
/** Gets the index of this parameter in its declaring function's parameter list. */
8+
/**
9+
* Gets the index of this parameter in its declaring function's parameter list,
10+
* or -1 if this is `self`.
11+
*/
912
int getIndex() { exists(Callable func | func.getParam(result) = this) }
1013
}
14+
15+
/** A `self` parameter. */
16+
class SelfParamDecl extends ParamDecl {
17+
Callable call;
18+
19+
SelfParamDecl() { call.getSelfParam() = this }
20+
21+
override Callable getDeclaringFunction() { result = call }
22+
23+
override int getIndex() { result = -1 }
24+
}

0 commit comments

Comments
 (0)