mirror of
https://github.com/github/codeql.git
synced 2026-04-25 16:55:19 +02:00
Swift: Extract self parameter declarations.
This commit is contained in:
@@ -81,6 +81,7 @@ AstNode:
|
||||
Callable:
|
||||
_children:
|
||||
params: ParamDecl*
|
||||
self_param: ParamDecl?
|
||||
body: BraceStmt?
|
||||
|
||||
ConditionElement:
|
||||
|
||||
@@ -327,6 +327,8 @@ void DeclVisitor::fillAbstractFunctionDecl(const swift::AbstractFunctionDecl& de
|
||||
entry.name = !decl.hasName() ? "(unnamed function decl)" : constructName(decl.getName());
|
||||
entry.body = dispatcher_.fetchOptionalLabel(decl.getBody());
|
||||
entry.params = dispatcher_.fetchRepeatedLabels(*decl.getParameters());
|
||||
auto self = const_cast<swift::ParamDecl* const>(decl.getImplicitSelfDecl());
|
||||
entry.self_param = dispatcher_.fetchOptionalLabel(self);
|
||||
fillValueDecl(decl, entry);
|
||||
fillGenericContext(decl, entry);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,20 @@ class ParamDecl extends ParamDeclBase {
|
||||
/** Gets the function which declares this parameter. */
|
||||
Callable getDeclaringFunction() { result.getAParam() = this }
|
||||
|
||||
/** Gets the index of this parameter in its declaring function's parameter list. */
|
||||
/**
|
||||
* Gets the index of this parameter in its declaring function's parameter list,
|
||||
* or -1 if this is `self`.
|
||||
*/
|
||||
int getIndex() { exists(Callable func | func.getParam(result) = this) }
|
||||
}
|
||||
|
||||
/** A `self` parameter. */
|
||||
class SelfParamDecl extends ParamDecl {
|
||||
Callable call;
|
||||
|
||||
SelfParamDecl() { call.getSelfParam() = this }
|
||||
|
||||
override Callable getDeclaringFunction() { result = call }
|
||||
|
||||
override int getIndex() { result = -1 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user