Skip to content

Commit 91d56cd

Browse files
committed
Use dataflow to find method call targets
This includes both local and non-local methods, and is also simpler than the previous definition.
1 parent cd3192e commit 91d56cd

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

ql/src/queries/analysis/Definitions.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
import ruby
1414
import codeql_ruby.ast.internal.Module
1515
import codeql_ruby.dataflow.SSA
16+
import codeql_ruby.dataflow.internal.DataFlowDispatch
1617

1718
from DefLoc loc, Expr src, Expr target, string kind
1819
where
1920
ConstantDefLoc(src, target) = loc and kind = "constant"
2021
or
21-
LocalMethodLoc(src, target) = loc and kind = "method"
22+
MethodLoc(src, target) = loc and kind = "method"
2223
or
2324
LocalVariableLoc(src, target) = loc and kind = "variable"
2425
or
@@ -36,10 +37,9 @@ select src, target, kind
3637
newtype DefLoc =
3738
/** A constant, module or class. */
3839
ConstantDefLoc(ConstantReadAccess read, ConstantWriteAccess write) { write = definitionOf(read) } or
39-
/** A call to a method that is defined in the same class as the call. */
40-
LocalMethodLoc(MethodCall call, Method meth) {
41-
meth = lookupMethod(call.getEnclosingModule().getModule(), call.getMethodName()) and
42-
call.getReceiver() instanceof Self
40+
/** A method call. */
41+
MethodLoc(MethodCall call, Method meth) {
42+
exists(DataFlowCall c | c.getExpr() = call and c.getTarget() = meth)
4343
} or
4444
/** A local variable. */
4545
LocalVariableLoc(VariableReadAccess read, VariableWriteAccess write) {

ql/test/query-tests/analysis/Definitions.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| Definitions.rb:32:7:32:7 | y | Definitions.rb:31:10:31:10 | y | variable |
77
| Definitions.rb:36:7:36:7 | A | Definitions.rb:1:1:17:3 | A | constant |
88
| Definitions.rb:36:7:36:10 | B | Definitions.rb:4:3:16:5 | B | constant |
9+
| Definitions.rb:36:7:36:18 | call to g | Definitions.rb:9:5:11:7 | g | method |
910
| Definitions.rb:36:18:36:18 | y | Definitions.rb:35:11:35:11 | y | variable |
1011
| Definitions.rb:39:7:39:8 | @e | Definitions.rb:30:7:30:8 | @e | instance variable |
1112
| Definitions.rb:41:7:41:9 | @@b | Definitions.rb:27:5:27:7 | @@b | class variable |

0 commit comments

Comments
 (0)