Swift: Use regexp for function name.

This commit is contained in:
Geoffrey White
2023-05-31 10:46:25 +01:00
parent 560aa43953
commit daad2e1bd3
2 changed files with 11 additions and 1 deletions

View File

@@ -6,6 +6,16 @@ private import codeql.swift.elements.decl.Method
*/
class Function extends Generated::Function, Callable {
override string toString() { result = this.getName() }
/**
* Gets the name of this function, without the argument list. For example
* a function with name `myFunction(arg:)` has short name `myFunction`.
*/
string getShortName() {
// match as many characters as possible that are not `(`.
// (`*+` is possessive matching)
result = this.getName().regexpCapture("([^(]*+).*", 1)
}
}
/**

View File

@@ -102,7 +102,7 @@ private class SensitiveFunction extends Function {
string name; // name of the function, not including the argument list.
SensitiveFunction() {
name = this.getName().splitAt("(", 0) and
name = this.getShortName() and
name.regexpMatch(sensitiveType.getRegexp())
}