mirror of
https://github.com/github/codeql.git
synced 2026-02-20 00:43:44 +01:00
Remove 'Method' class
This commit is contained in:
@@ -1,46 +1,8 @@
|
||||
private import codeql_ruby.AST
|
||||
private import codeql_ruby.controlflow.ControlFlowGraph
|
||||
private import internal.AST
|
||||
private import internal.Method
|
||||
private import internal.TreeSitter
|
||||
|
||||
/**
|
||||
* A representation of a method.
|
||||
*/
|
||||
class Method extends TMethod {
|
||||
/** Gets a declaration of this module, if any. */
|
||||
MethodBase getADeclaration() { result.getMethod() = this }
|
||||
|
||||
/** Gets the name of this method */
|
||||
string getName() { this = TInstanceMethod(_, result) }
|
||||
|
||||
/** Gets the module in which this method is defined */
|
||||
Module getModule() { this = TInstanceMethod(result, _) }
|
||||
|
||||
/** Gets a textual representation of this method. */
|
||||
string toString() {
|
||||
exists(Module m, string name |
|
||||
this = TInstanceMethod(m, name) and result = m.toString() + "." + name
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the location of this method. */
|
||||
Location getLocation() {
|
||||
result =
|
||||
min(MethodBase decl, Module m, string name, Location loc, int weight |
|
||||
this = TInstanceMethod(m, name) and
|
||||
decl = methodDeclaration(m, name) and
|
||||
loc = decl.getLocation() and
|
||||
if exists(loc.getFile().getRelativePath()) then weight = 0 else weight = 1
|
||||
|
|
||||
loc
|
||||
order by
|
||||
weight, count(decl.getAStmt()) desc, loc.getFile().getAbsolutePath(), loc.getStartLine(),
|
||||
loc.getStartColumn()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** A callable. */
|
||||
class Callable extends Expr, Scope, TCallable {
|
||||
/** Gets the number of parameters of this callable. */
|
||||
@@ -62,9 +24,6 @@ class MethodBase extends Callable, BodyStmt, Scope, TMethodBase {
|
||||
/** Gets the name of this method. */
|
||||
string getName() { none() }
|
||||
|
||||
/** Gets the method defined by this declaration. */
|
||||
Method getMethod() { none() }
|
||||
|
||||
override AstNode getAChild(string pred) {
|
||||
result = Callable.super.getAChild(pred)
|
||||
or
|
||||
@@ -85,12 +44,6 @@ class MethodDeclaration extends MethodBase, TMethodDeclaration {
|
||||
result = g.getName().(Generated::Setter).getName().getValue() + "="
|
||||
}
|
||||
|
||||
final override Method getMethod() {
|
||||
exists(Module owner, string name |
|
||||
result = TInstanceMethod(owner, name) and this = methodDeclaration(owner, name)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if this is a setter method, as in the following example:
|
||||
* ```rb
|
||||
|
||||
@@ -14,12 +14,6 @@ class Module extends TModule {
|
||||
/** Gets the super class of this module, if any. */
|
||||
Module getSuperClass() { result = getSuperClass(this) }
|
||||
|
||||
/** Gets a method defined in this module by name. */
|
||||
Method getMethod(string name) { result.getName() = name and result.getModule() = this }
|
||||
|
||||
/** Look up a method in this module's ancestor chain. */
|
||||
Method lookupMethod(string name) { result = lookupMethod(this, name) }
|
||||
|
||||
/** Gets a `prepend`ed module. */
|
||||
Module getAPrependedModule() { result = getAPrependedModule(this) }
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
private import codeql_ruby.ast.Method
|
||||
private import codeql_ruby.ast.Module
|
||||
private import codeql_ruby.ast.internal.Module
|
||||
|
||||
newtype TMethod =
|
||||
TInstanceMethod(TModule owner, string name) { exists(methodDeclaration(owner, name)) }
|
||||
|
||||
MethodDeclaration methodDeclaration(TModule owner, string name) {
|
||||
exists(ModuleBase m | m.getModule() = owner and result = m.getMethod(name))
|
||||
}
|
||||
@@ -301,18 +301,22 @@ private Module getAncestors(Module m) {
|
||||
result = getAncestors(m.getAPrependedModule())
|
||||
}
|
||||
|
||||
private Method lookupMethod0(Module m, string name) {
|
||||
MethodDeclaration getMethod(TModule owner, string name) {
|
||||
exists(ModuleBase m | m.getModule() = owner and result = m.getMethod(name))
|
||||
}
|
||||
|
||||
private MethodDeclaration lookupMethod0(Module m, string name) {
|
||||
result = lookupMethod0(m.getAPrependedModule(), name)
|
||||
or
|
||||
not exists(getAncestors(m.getAPrependedModule()).getMethod(name)) and
|
||||
not exists(getMethod(getAncestors(m.getAPrependedModule()), name)) and
|
||||
(
|
||||
result = m.getMethod(name)
|
||||
result = getMethod(m, name)
|
||||
or
|
||||
not exists(m.getMethod(name)) and result = lookupMethod0(m.getAnIncludedModule(), name)
|
||||
not exists(getMethod(m, name)) and result = lookupMethod0(m.getAnIncludedModule(), name)
|
||||
)
|
||||
}
|
||||
|
||||
Method lookupMethod(Module m, string name) {
|
||||
MethodDeclaration lookupMethod(Module m, string name) {
|
||||
result = lookupMethod0(m, name)
|
||||
or
|
||||
not exists(lookupMethod0(m, name)) and
|
||||
|
||||
Reference in New Issue
Block a user