mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
Ruby: Further speed up private method modelling
This commit is contained in:
@@ -49,6 +49,7 @@ private class MethodModifier extends MethodCall {
|
||||
Expr getMethodArgument() { result = this.getArgument(0) }
|
||||
|
||||
/** Holds if this call modifies a method with name `name` in namespace `n`. */
|
||||
pragma[noinline]
|
||||
predicate modifiesMethod(Namespace n, string name) {
|
||||
this = n.getAStmt() and
|
||||
[
|
||||
@@ -139,7 +140,10 @@ class Method extends MethodBase, TMethod {
|
||||
* ```
|
||||
*/
|
||||
override predicate isPrivate() {
|
||||
any(Private p).modifiesMethod(this.getEnclosingModule(), this.getName())
|
||||
exists(Namespace n, string name |
|
||||
any(Private p).modifiesMethod(n, name) and
|
||||
isDeclaredIn(this, n, name)
|
||||
)
|
||||
or
|
||||
// Top-level methods are private members of the Object class
|
||||
this.getEnclosingModule() instanceof Toplevel
|
||||
@@ -152,6 +156,14 @@ class Method extends MethodBase, TMethod {
|
||||
final override string toString() { result = this.getName() }
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if the method `m` has name `name` and is declared in namespace `n`.
|
||||
*/
|
||||
pragma[noinline]
|
||||
private predicate isDeclaredIn(MethodBase m, Namespace n, string name) {
|
||||
n = m.getEnclosingModule() and name = m.getName()
|
||||
}
|
||||
|
||||
/** A singleton method. */
|
||||
class SingletonMethod extends MethodBase, TSingletonMethod {
|
||||
private Ruby::SingletonMethod g;
|
||||
@@ -205,7 +217,10 @@ class SingletonMethod extends MethodBase, TSingletonMethod {
|
||||
* ```
|
||||
*/
|
||||
override predicate isPrivate() {
|
||||
any(PrivateClassMethod p).modifiesMethod(this.getEnclosingModule(), this.getName())
|
||||
exists(Namespace n, string name |
|
||||
any(PrivateClassMethod p).modifiesMethod(n, name) and
|
||||
isDeclaredIn(this, n, name)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user